Class: CWM::Pager
- Inherits:
-
CustomWidget
- Object
- AbstractWidget
- CustomWidget
- CWM::Pager
- Defined in:
- library/cwm/src/lib/cwm/pager.rb
Overview
Direct Known Subclasses
Instance Attribute Summary collapse
-
#current_page ⇒ CWM::Page?
readonly
Currently selected page; nil if no page is selected.
Attributes inherited from AbstractWidget
#handle_all_events, #widget_id
Instance Method Summary collapse
-
#contents ⇒ WidgetTerm
protected
The contents will probably include a selector, such as Tabs or Tree and must include #replace_point where Pages will appear.
- #handle(event) ⇒ Object
-
#init ⇒ Object
initializes pages, show page which is initial.
-
#initial_page ⇒ Object
protected
gets initial page This default page which return true for method initial otherwise first page passed to constructor.
-
#initialize(*pages) ⇒ Pager
constructor
A new instance of Pager.
-
#mark_page ⇒ void
protected
Mark the currently active page in the selector.
- #page_for_id(id) ⇒ Object protected
-
#page_order ⇒ Object
protected
gets visual order of pages This default implementation returns same order as passed to constructor.
- #replace_point ⇒ Object protected
-
#store_page ⇒ Object
protected
stores page with given id.
-
#switch_page(page) ⇒ Object
protected
switch to target page.
Methods inherited from CustomWidget
#cwm_contents, #cwm_definition, #find_ids, #ids_in_contents
Methods inherited from AbstractWidget
#cleanup, #cwm_definition, #disable, #displayed?, #enable, #enabled?, #focus, #fun_ref, #help, #label, #my_event?, #opt, #refresh_help, #store, #validate, widget_type=
Constructor Details
#initialize(*pages) ⇒ Pager
Returns a new instance of Pager.
20 21 22 23 24 25 26 |
# File 'library/cwm/src/lib/cwm/pager.rb', line 20 def initialize(*pages) super() @pages = pages @current_page = nil self.handle_all_events = true end |
Instance Attribute Details
#current_page ⇒ CWM::Page? (readonly)
Returns currently selected page; nil if no page is selected.
17 18 19 |
# File 'library/cwm/src/lib/cwm/pager.rb', line 17 def current_page @current_page end |
Instance Method Details
#contents ⇒ WidgetTerm (protected)
The contents will probably include a selector, such as Tabs or Tree and must include #replace_point where CWM::Pages will appear.
87 |
# File 'library/cwm/src/lib/cwm/pager.rb', line 87 abstract_method :contents |
#handle(event) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'library/cwm/src/lib/cwm/pager.rb', line 34 def handle(event) new_id = event["ID"] page = page_for_id(new_id) return nil unless page # NOTE: don't rely on new_id being equal to page.widget_id # This may not be true for subclasses redefining #page_for_id # (see bsc#1078212) return nil if @current_page. == page. unless replace_point.validate mark_page(@current_page) return nil end replace_point.store switch_page(page) nil end |
#init ⇒ Object
initializes pages, show page which is initial
29 30 31 32 |
# File 'library/cwm/src/lib/cwm/pager.rb', line 29 def init mark_page(initial_page) @current_page = initial_page end |
#initial_page ⇒ Object (protected)
gets initial page This default page which return true for method initial otherwise first page passed to constructor
92 93 94 95 96 |
# File 'library/cwm/src/lib/cwm/pager.rb', line 92 def initial_page initial = @pages.find(&:initial) initial || @pages.first end |
#mark_page ⇒ void (protected)
This method returns an undefined value.
Mark the currently active page in the selector. This is needed in case the user has switched to a different page but we need to switch back because the current one failed validation.
82 |
# File 'library/cwm/src/lib/cwm/pager.rb', line 82 abstract_method :mark_page |
#page_for_id(id) ⇒ Object (protected)
98 99 100 |
# File 'library/cwm/src/lib/cwm/pager.rb', line 98 def page_for_id(id) @pages.find { |t| t. == id } end |
#page_order ⇒ Object (protected)
gets visual order of pages This default implementation returns same order as passed to constructor
61 62 63 |
# File 'library/cwm/src/lib/cwm/pager.rb', line 61 def page_order @pages.map(&:widget_id) end |
#replace_point ⇒ Object (protected)
102 103 104 |
# File 'library/cwm/src/lib/cwm/pager.rb', line 102 def replace_point @replace_point ||= ReplacePoint.new(id: "replace_point_#{}", widget: initial_page) end |
#store_page ⇒ Object (protected)
stores page with given id
66 67 68 |
# File 'library/cwm/src/lib/cwm/pager.rb', line 66 def store_page replace_point.store end |
#switch_page(page) ⇒ Object (protected)
switch to target page
71 72 73 74 75 |
# File 'library/cwm/src/lib/cwm/pager.rb', line 71 def switch_page(page) mark_page(page) @current_page = page replace_point.replace(page) end |