Sha256: 922b45e00020b3ae99e3933f150ed9333c5bcf35ee058b1d8aef56a5817da78f

Contents?: true

Size: 1.44 KB

Versions: 16

Compression:

Stored size: 1.44 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|number)$/.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

16 entries across 16 versions & 2 rubygems

Version Path
activeadmin-rb-1.6.0 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-rb-1.5.2 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-rb-1.5.1 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-rb-1.5.0 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-rb-1.4.0 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.4.3 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.4.2 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.4.1 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.4.0 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.3.1 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.3.0 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.2.1 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.2.0 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.1.0 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.0.0 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee
activeadmin-1.0.0.pre5 app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee