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 " function \#{function}() {\n if (!window.symphoniaModals)\n window.symphoniaModals = {}\n if (!window.symphoniaModals['\#{element_id}']) {\n window.symphoniaModals['\#{element_id}'] = new SymphoniaDialog('\#{element_id}', \#{raw modal_options.to_json});\n }\n window.symphoniaModals['\#{element_id}'].show()\n }\n EOF\n end\nend\n" |
#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 = " if (typeof(renderModal) == \"undefined\")\n var renderModal = {}\n if (renderModal[\"\#{id}\"])\n renderModal[\"\#{id}\"].destroy();\n renderModal[\"\#{id}\"] = new SymphoniaDialog(\"\#{id}\", \#{raw opts.to_json});\n" script << %Q{ renderModal["#{id}"].body.innerHTML = "#{j(capture(&block))}"; } if block_given? script << " var submitButton = renderModal[\"\#{id}\"].body.querySelector(\"input[type=submit]\")\n if (submitButton)\n submitButton.remove()\n" unless opts[:title] script.concat " var title = document.getElementById(renderModal[\"\#{id}\"].id).querySelector(\"#page_header\");\n if (title) {\n title.className = 'modal-title'; title.id = null;\n $(renderModal[\"\#{id}\"].title).replaceWith($(title));\n renderModal[\"\#{id}\"].title = title;\n }\n" end script << %Q{renderModal["#{id}"].show();} unless opts.has_key?(:render_only) script.html_safe end |