Skip to content

Commit

Permalink
Refactor delete of attributes
Browse files Browse the repository at this point in the history
Instead of generating html code for each modal that asks for deleting an
attribute only one modal is created. Arguments for the modal are passed with
"data-*" attributes.

Adapt feature test accordingly.
  • Loading branch information
eduardoj committed Dec 14, 2018
1 parent e246c6b commit fe81388
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
15 changes: 12 additions & 3 deletions src/api/app/views/webui2/webui/attribute/_delete_dialog.html.haml
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
.modal.fade{ id: "delete-attribute-modal-#{attribute.id}", tabindex: -1, role: 'dialog', aria: { labelledby: 'delete-modal-label', hidden: true } }
.modal.fade{ id: 'delete-attribute-modal', tabindex: -1, role: 'dialog', aria: { labelledby: 'delete-modal-label', hidden: true } }
.modal-dialog.modal-dialog-centered{ role: 'document' }
.modal-content
.modal-header
%h5.modal-title
Delete attribute?
.modal-body
%p Please confirm deletion of attribute #{attribute.fullname}
= form_tag(attrib_path(attribute), method: :delete) do
%p
Please confirm deletion of attribute
%span#fullname
= form_tag(nil, method: :delete) do
.modal-footer
%a.btn.btn-sm.btn-outline-secondary.px-4{ data: { dismiss: 'modal' } }
Cancel
= submit_tag('Delete', class: 'btn btn-sm btn-danger px-4')
= content_for :ready_function do
:plain
$('#delete-attribute-modal').on('show.bs.modal', function (event) {
var link = $(event.relatedTarget);
$(this).find('#fullname').text(link.data('fullname'));
$(this).find('form').attr('action', link.data('action'));
});
7 changes: 3 additions & 4 deletions src/api/app/views/webui2/webui/attribute/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
- if attribute.values_editable?
= link_to(edit_attribs_path(project: @project.name, package: @package, attribute: attribute.fullname), title: 'Edit values') do
%i.fas.fa-edit.text-secondary
= link_to('#', data: { toggle: 'modal', target: "#delete-attribute-modal-#{attribute.id}" },
title: 'Delete attribute') do
= link_to('#', title: 'Delete attribute',
data: { toggle: 'modal', target: '#delete-attribute-modal', action: attrib_path(attribute), fullname: attribute.fullname }) do
%i.fas.fa-times-circle.text-danger
- if policy(@container).update?
= render(partial: 'delete_dialog', locals: { attribute: attribute })
- else
%p
%em No attributes set
Expand All @@ -44,3 +42,4 @@
= link_to(new_attribs_path(project: @project.name, package: @package), title: 'Add a new attribute') do
%i.fas.fa-plus-circle.text-primary
Add a new attribute
= render(partial: 'delete_dialog')
4 changes: 2 additions & 2 deletions src/api/spec/bootstrap/features/webui/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

visit index_attribs_path(project: user.home_project_name)
click_link 'Delete attribute'
expect(find("#delete-attribute-modal-#{attribute.id}")).to have_text('Delete attribute?')
within("#delete-attribute-modal-#{attribute.id} .modal-footer") do
expect(find('#delete-attribute-modal')).to have_text('Delete attribute?')
within('#delete-attribute-modal .modal-footer') do
expect(page).to have_button('Delete')
click_button('Delete')
end
Expand Down

0 comments on commit fe81388

Please sign in to comment.