diff options
| author | Teddy Wing | 2017-06-09 15:34:55 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-06-09 15:34:55 +0200 |
| commit | aba69469b1eb19d5347fb9cf1d7d28efe055d33f (patch) | |
| tree | 212968dc05208012ccfad298d0a6fe5383958948 | |
| parent | 0fb0bd13e4e09c910bc4159985b714f43f6d0fe0 (diff) | |
| download | chouette-core-aba69469b1eb19d5347fb9cf1d7d28efe055d33f.tar.bz2 | |
TableBuilderHelper: Extract checkboxes to a private method
Build checkboxes using a new private method to reduce duplication and
increase naming.
Used the name `id_name` because the value gets used for both the `id`
and `name` attributes of the checkbox input.
Refs #3479
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 3e8602dac..ef728a12d 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -32,10 +32,7 @@ module TableBuilderHelper # Adds checkbox to table header if selectable - cbx = content_tag :div, '', class: 'checkbox' do - check_box_tag('0', 'all').concat(content_tag(:label, '', for: '0')) - end - hcont << content_tag(:th, cbx) + hcont << content_tag(:th, checkbox(id_name: '0', value: 'all')) end columns.map do |k, v| @@ -62,14 +59,11 @@ module TableBuilderHelper content_tag :tr do bcont = [] - # Adds item checkboxes whose value = the row object's id - # Apparently the object id is also used in the HTML id attribute without any prefix if selectable - # TODO: Extract method `build_checkbox(attribute)` - cbx = content_tag :div, '', class: 'checkbox' do - check_box_tag(item.try(:id), item.try(:id)).concat(content_tag(:label, '', for: item.try(:id))) - end - bcont << content_tag(:td, cbx) + bcont << content_tag( + :td, + checkbox(id_name: item.try(:id), value: item.try(:id)) + ) end columns.map do |k, attribute| @@ -214,4 +208,12 @@ module TableBuilderHelper I18n.t("activerecord.attributes.#{model_key}.#{field}") end + + def checkbox(id_name:, value:) + content_tag :div, '', class: 'checkbox' do + check_box_tag(id_name, value).concat( + content_tag(:label, '', for: id_name) + ) + end + end end |
