Class: Interview::Grid
- Defined in:
- lib/interview/controls/grid.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#objects ⇒ Object
Returns the value of attribute objects.
-
#sortable ⇒ Object
Returns the value of attribute sortable.
Attributes inherited from Control
Instance Method Summary collapse
Methods inherited from Control
#ancestors, #build_with_params, #find_attribute, #find_attribute!, #initialize, #set_attributes, #set_defaults
Constructor Details
This class inherits a constructor from Interview::Control
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/interview/controls/grid.rb', line 5 def object @object end |
#objects ⇒ Object
Returns the value of attribute objects.
4 5 6 |
# File 'lib/interview/controls/grid.rb', line 4 def objects @objects end |
#sortable ⇒ Object
Returns the value of attribute sortable.
4 5 6 |
# File 'lib/interview/controls/grid.rb', line 4 def sortable @sortable end |
Instance Method Details
#build(b) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/interview/controls/grid.rb', line 7 def build(b) objects = @objects || find_attribute!(:objects) @object = find_attribute!(:object) sortable_id = "sortable_#{@object.class.model_name.plural}" if @sortable b.section style: 'table', html_class: 'table' do b.section style: 'thead' do b.section style: 'tr' do b.section style: 'th' if @sortable @build_captions = true b. pointer: self do yield if block_given? end end end html_opts = {} html_opts[:id] = sortable_id if @sortable b.section style: 'tbody', html_options: html_opts do objects.each do |object| @object = object html_opts = {} html_opts[:id] = "#{sortable_id}_#{object.id}" if @sortable b.section style: 'tr', htl_options: html_opts do if @sortable b.section style: 'td' do b.glyphicon style: 'resize-vertical', html_class: 'handle' end end @build_captions = false b. pointer: self do yield if block_given? end end end end end if objects.empty? b.text text: "Keine #{@object.class.human_name(count: 2)} vorhanden.", style: 'p', html_class: 'text-center text-muted' end end |
#build_child(b, control, &block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/interview/controls/grid.rb', line 49 def build_child(b, control, &block) if @build_captions b.section style: 'th' do control.(b) end else b.section style: 'td' do super end end end |