Module: Symphonia::BootstrapModalHelper
- Defined in:
- app/helpers/symphonia/bootstrap_modal_helper.rb
Instance Method Summary collapse
-
#link_to_modal(name, element_id, **options) ⇒ Object
render link and JS script tag with function for create SymphoniaDialog.
-
#render_modal(options = {}, &block) ⇒ Object
<%= title(@entity, back: !request.xhr?) %>.
Instance Method Details
#link_to_modal(name, element_id, **options) ⇒ Object
render link and JS script tag with function for create SymphoniaDialog
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/helpers/symphonia/bootstrap_modal_helper.rb', line 70 def link_to_modal(name, element_id, **) = .delete(:modal) function = "symphoniaModal#{name.hash.to_s.remove(/[^\d]/)}" link_to(name, "javascript:#{function}()", ) + \ javascript_tag do raw <<~EOF function #{function}() { if (!window.symphoniaModals) window.symphoniaModals = {} if (!window.symphoniaModals['#{element_id}']) { window.symphoniaModals['#{element_id}'] = new SymphoniaDialog('#{element_id}', #{raw .to_json}); } window.symphoniaModals['#{element_id}'].show() } EOF end end |
#render_modal(options = {}, &block) ⇒ Object
<%= title(@entity, back: !request.xhr?) %>
<%= symphonia_form_for(@entity, remote: request.xhr?) do |f| %>
<%= render(partial: 'form', locals: { f: f }) %>
<%= f.primary unless request.xhr? %>
<% end -%>
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 48 49 50 51 52 53 54 |
# File 'app/helpers/symphonia/bootstrap_modal_helper.rb', line 21 def render_modal( = {}, &block) opts = .slice(:id, :title, :submit, :large) opts[:submit] = t(:button_submit) unless opts.has_key?(:submit) id = .delete(:id) || 'ad_hoc_modal' script = <<SCRIPT if (typeof(renderModal) == "undefined") var renderModal = {} if (renderModal["#{id}"]) renderModal["#{id}"].destroy(); renderModal["#{id}"] = new SymphoniaDialog("#{id}", #{raw opts.to_json}); SCRIPT script << %Q{ renderModal["#{id}"].body.innerHTML = "#{j(capture(&block))}"; } if block_given? script << <<SCRIPT var submitButton = renderModal["#{id}"].body.querySelector("input[type=submit]") if (submitButton) submitButton.remove() SCRIPT unless opts[:title] script.concat <<EOF var title = document.getElementById(renderModal["#{id}"].id).querySelector("#page_header"); if (title) { title.className = 'modal-title'; title.id = null; $(renderModal["#{id}"].title).replaceWith($(title)); renderModal["#{id}"].title = title; } EOF end script << %Q{renderModal["#{id}"].show();} unless opts.has_key?(:render_only) script.html_safe end |