Skip to content

Commit

Permalink
Merge pull request #497 from wearefine/optional-add-button
Browse files Browse the repository at this point in the history
Optional add button for nested tables
  • Loading branch information
jclemans authored Sep 24, 2019
2 parents 64abf65 + 902646a commit 872e11a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/views/fae/shared/_nested_table.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ruby:
assoc_name ||= assoc.to_s # 'restaurant_bars'
title ||= assoc_name.titleize # 'Restaurant Bars'
add_button_text ||= t('fae.common.add', title: title.singularize)
hide_add_button ||= false
ordered ||= false
has_thumb ||= false
edit_column ||= false
Expand All @@ -33,15 +34,16 @@ ruby:
new_path += "item_id=#{parent_item.id}&=item_class=#{parent_item.class.to_s}"
end

options_for_table = { index: index, assoc: assoc, assoc_name: assoc_name, title: title, add_button_text: add_button_text, ordered: ordered, has_thumb: has_thumb, edit_column: edit_column, cols: cols, assoc_name_singular: assoc_name_singular, new_path: new_path, edit_path: edit_path }
options_for_table = { index: index, assoc: assoc, assoc_name: assoc_name, title: title, add_button_text: add_button_text, hide_add_button: hide_add_button, ordered: ordered, has_thumb: has_thumb, edit_column: edit_column, cols: cols, assoc_name_singular: assoc_name_singular, new_path: new_path, edit_path: edit_path }
options_for_table[:parent_item] = parent_item unless index

section.addedit-form.js-addedit-form class="#{'content' if index}"
- if index
== render 'fae/shared/shared_nested_table', options_for_table

- else
a.js-add-link.table-add-link.button.-small href=new_path = add_button_text
- unless hide_add_button
a.js-add-link.table-add-link.button.-small href=new_path = add_button_text
h2 = title
- if helper_text.present?
h6.table-helper-text = helper_text
Expand Down
5 changes: 4 additions & 1 deletion app/views/fae/shared/_shared_nested_table.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ table class=table_class
i.icon-edit
td = fae_delete_button item, "/#{fae_path}/#{assoc_name}/#{item.id.to_s}", class: 'js-tooltip table-action js-delete-link', remote: true

- else
- elsif !hide_add_button
tr
- td_link = link_to 'add some', new_path, class: 'js-add-link'

td colspan=colspan.to_s No #{title} yet, #{td_link}.
- else
tr
td colspan=colspan.to_s No #{title} yet.

.js-addedit-form-wrapper
3 changes: 2 additions & 1 deletion docs/helpers/partials.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ The nested_table should go after the main form ends and should only be placed on

| option | type | default | description |
|--------|------|---------|-------------|
| index | false | boolean | used for nested index forms |
| index | boolean | false | used for nested index forms |
| assoc | symbol | | **(required)** the association's name, or the item's name if it's for the index |
| parent_item | ActiveRecord object | | **(required)** the item that the new objects will be associated to |
| cols* | array of symbols, or array of symbols and hashes | [], [{}] | an array of attributes to display on the list view, associations will display the `fae_display_field` or a thumbnail if it's a `Fae::Image` |
| title | string | assoc.to_s.titleize | the H3 directly above the form |
| add_button_text | string | "Add #{title.singularize}" | the add button's text |
| hide_add_button | boolean | false | Disables the Add button in the table header and the "add some" link in the table body |
| ordered | boolean | false | allows list view to be sortable, which is saved to a `position` attribute |
| has_thumb | boolean | false | displays a thumbnail in the list view (only applicable to `Fae::Image`)
| edit_column | boolean | false | displays edit link
Expand Down

0 comments on commit 872e11a

Please sign in to comment.