Class: Reactive::View::Wx::Helpers::ModelListCtrl
- Inherits:
-
Wx::ListCtrl
- Object
- Wx::ListCtrl
- Reactive::View::Wx::Helpers::ModelListCtrl
- Defined in:
- lib/helpers/model_list_ctrl_class.rb
Defined Under Namespace
Classes: SelectedItemDataCollection
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #append_item(record) ⇒ Object
- #append_items(collection) ⇒ Object
-
#initialize(parent, model, collection, options = {}) ⇒ ModelListCtrl
constructor
A new instance of ModelListCtrl.
-
#selected_records ⇒ Object
returns the currently selected record (Used to determine allowed toolbar actions).
- #set_columns(columns) ⇒ Object
Constructor Details
#initialize(parent, model, collection, options = {}) ⇒ ModelListCtrl
Returns a new instance of ModelListCtrl.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/helpers/model_list_ctrl_class.rb', line 38 def initialize(parent, model, collection, = {}) super(parent, .merge(:style => Wx::LC_REPORT)) @model = model evt_list_col_click(self) {|event| sort_items{|a,b| nil_aware_comparaison(a.send(@columns[event.get_column].name), b.send(@columns[event.get_column].name))} } bind self, :list_item_activated => {:link => {:controller => model.to_s.downcase.pluralize, :action => 'show'}, :late => proc{|params, event| params[:id] = get_item_data(event.get_index).id} } @columns = @model.content_columns @other_columns = @model.content_columns.dup @first_column = @other_columns.shift set_columns(@model.content_columns.map(&:human_name)) append_items(collection) if collection end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/helpers/model_list_ctrl_class.rb', line 5 def model @model end |
Instance Method Details
#append_item(record) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/helpers/model_list_ctrl_class.rb', line 58 def append_item(record) index = get_item_count insert_item(index, record.send(@first_column.name).to_s) set_item_data(index, record) col_index = 0 @other_columns.each {|column| set_item(index, col_index+=1, record.send(column.name).to_s)} end |
#append_items(collection) ⇒ Object
66 67 68 |
# File 'lib/helpers/model_list_ctrl_class.rb', line 66 def append_items(collection) collection.each {|record| append_item(record)} end |
#selected_records ⇒ Object
returns the currently selected record (Used to determine allowed toolbar actions)
34 35 36 |
# File 'lib/helpers/model_list_ctrl_class.rb', line 34 def selected_records selected_data.collect end |
#set_columns(columns) ⇒ Object
53 54 55 56 |
# File 'lib/helpers/model_list_ctrl_class.rb', line 53 def set_columns(columns) index = -1 columns.each {|column| insert_column(index+=1, column)} end |