diff options
| author | Teddy Wing | 2017-06-15 19:07:09 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-06-15 19:07:09 +0200 | 
| commit | 6e17029c934abf7e09b05245e7bb25c3c6480fe9 (patch) | |
| tree | 27f105afaebd168348085454a221e6e40a3627b9 /app/helpers | |
| parent | 5a54186ab087484334d6ff15976d7198ee79371a (diff) | |
| download | chouette-core-6e17029c934abf7e09b05245e7bb25c3c6480fe9.tar.bz2 | |
MultipleSelectionToolbox: Clean up code; Add to workbenches/show.html
Keep the helper code globally the same.
Changes:
* Remove `if action == :edit` since we never execute that branch. In
  fact, the only place we ever use the multiple selection toolbox in
  conjunction with the table builder is on Workbenches#show, and that
  page only uses a :delete action.
* Rename `dPath` to be clearer
* Add some whitespace to improve readability
* Rename `actitem` to `action_link` for better readability
* Connect the links and label with `#+` instead of `#concat`
Add the toolbox to "workbenches/show.html.slim" to get the page looking
like it was before I changed the table builder.
Needed to wrap the table and toolbox in a `<div class="select_table">`
in order for the JavaScript part of it to work (otherwise selection
wouldn't activate the link, and likely other stuff would be messed up
too).
Now that the table builder and the selection toolbox are separate, it
makes sense to put the "select_table" `<div>` in the template.
Refs #3479
Diffstat (limited to 'app/helpers')
| -rw-r--r-- | app/helpers/multiple_selection_toolbox_helper.rb | 39 | 
1 files changed, 26 insertions, 13 deletions
diff --git a/app/helpers/multiple_selection_toolbox_helper.rb b/app/helpers/multiple_selection_toolbox_helper.rb index f8f19fda6..85294af6d 100644 --- a/app/helpers/multiple_selection_toolbox_helper.rb +++ b/app/helpers/multiple_selection_toolbox_helper.rb @@ -1,27 +1,40 @@  module MultipleSelectionToolboxHelper    # Box of links that floats at the bottom right of the page    def multiple_selection_toolbox(actions) -    tools = content_tag :ul do -      dPath = nil -      dPath = referentials_workbench_path if params[:controller] = 'workbenches' +    links = content_tag :ul do +      delete_path = nil -      actions.collect do |action| -        if action == :edit -          actitem = link_to('#', title: t("actions.#{action}")) do -            content_tag :span, '', class: 'fa fa-pencil' -          end -        elsif action == :delete -          actitem = link_to('#', method: :delete, data: { path: dPath, confirm: 'Etes-vous sûr(e) de vouloir effectuer cette action ?' }, title: t("actions.#{action}")) do +      if params[:controller] = 'workbenches' +        delete_path = referentials_workbench_path +      end + +      actions.map do |action| +        if action == :delete +          action_link = link_to( +            '#', +            method: :delete, +            data: { +              path: delete_path, +              confirm: 'Etes-vous sûr(e) de vouloir effectuer cette action ?' +            }, +            title: t("actions.#{action}") +          ) do              content_tag :span, '', class: 'fa fa-trash'            end          end -        content_tag :li, actitem, class: 'st_action' +        content_tag :li, action_link, class: 'st_action'        end.join.html_safe -      end + +    label = content_tag( +      :span, +      ("<span>0</span> élément(s) sélectionné(s)").html_safe, +      class: 'info-msg' +    ) +      content_tag :div, '', class: 'select_toolbox noselect' do -      tools.concat(content_tag(:span, ("<span>0</span> élément(s) sélectionné(s)").html_safe, class: 'info-msg')) +      links + label      end    end  end  | 
