Sha256: 86a40798f492e0dca83632085857c6938bb5754582df50d5fdefe5e07602dae0

Contents?: true

Size: 1.73 KB

Versions: 15

Compression:

Stored size: 1.73 KB

Contents

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

    let klass = type === 'datepicker' ? type : '';
    html += `<li>
      <label>${name.charAt(0).toUpperCase() + name.slice(1)}</label>
      <${wrapper} name="${name}" class="${klass}" type="${type}">` +
        (opts ? ((() => {
          const result = [];

          opts.forEach(v => {
            const $elem = $(`<${elem}/>`);
            if ($.isArray(v)) {
              $elem.text(v[0]).val(v[1]);
            } else {
              $elem.text(v);
            }
            result.push($elem.wrap('<div>').parent().html());
          });

          return result;
        })()).join('') : '') +
      `</${wrapper}>` +
    "</li>";
    [wrapper, elem, opts, type, klass] = []; // unset any temporary variables
  }

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

  const 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($(this).serializeObject());
        $(this).dialog('close');
      },
      Cancel() {
        $(this).dialog('close').remove();
      }
    }
  });
};

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
activeadmin-2.4.0 app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin-2.3.1 app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin-2.3.0 app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin-2.2.0 app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin-2.1.0 app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin-2.0.0 app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin-2.0.0.rc2 app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin_addons-1.7.1 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin-2.0.0.rc1 app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin_addons-1.7.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin_addons-1.6.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin_addons-1.5.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin_addons-1.4.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin_addons-1.3.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/modal_dialog.es6
activeadmin_addons-1.2.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/app/assets/javascripts/active_admin/lib/modal_dialog.es6