Sha256: 01fae7638513ebba44ed1898aee25bfa70006a29314a193ef60ddbd14d000f0d

Contents?: true

Size: 1.43 KB

Versions: 11

Compression:

Stored size: 1.43 KB

Contents

ActiveAdmin.modal_dialog = (message, inputs, callback)->
  html = """<form id="dialog_confirm" title="#{message}"><ul>"""
  for name, type of inputs
    if /^(datepicker|checkbox|text)$/.test type
      wrapper = 'input'
    else if type is 'textarea'
      wrapper = 'textarea'
    else if $.isArray type
      [wrapper, elem, opts, type] = ['select', 'option', type, '']
    else
      throw new Error "Unsupported input type: {#{name}: #{type}}"

    klass = if type is 'datepicker' then type else ''
    html += """<li>
      <label>#{name.charAt(0).toUpperCase() + name.slice(1)}</label>
      <#{wrapper} name="#{name}" class="#{klass}" type="#{type}">""" +
        (if opts then (
          for v in opts
            $elem = $("<#{elem}/>")
            if $.isArray v
              $elem.text(v[0]).val(v[1])
            else
              $elem.text(v)
            $elem.wrap('<div>').parent().html()
        ).join '' else '') +
      "</#{wrapper}>" +
    "</li>"
    [wrapper, elem, opts, type, klass] = [] # unset any temporary variables

  html += "</ul></form>"

  form = $(html).appendTo('body')
  $('body').trigger 'modal_dialog:before_open', [form]

  form.dialog
    modal: true
    open: (event, ui) ->
      $('body').trigger 'modal_dialog:after_open', [form]
    dialogClass: 'active_admin_dialog'
    buttons:
      OK: ->
        callback $(@).serializeObject()
        $(@).dialog('close')
      Cancel: ->
        $(@).dialog('close').remove()

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-orac-1.0.0.pre4 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-orac-1.0.0 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-orac-1.0.0.pre.orac app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.0.0.pre4 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.0.0.pre3 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.0.0.pre2 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee