Files
discourse/app/assets/javascripts/discourse/lib/show-modal.js.es6
Robin Ward 40ab2e5667 FEATURE: Let users update their emails before confirming
This allows users who entered a typo or invalid email address when
signing up an opportunity to fix it and resending the confirmation
email to that address.
2017-04-05 16:44:49 -04:00

46 lines
1.4 KiB
JavaScript

export default function(name, opts) {
opts = opts || {};
const container = Discourse.__container__;
// We use the container here because modals are like singletons
// in Discourse. Only one can be shown with a particular state.
const route = container.lookup('route:application');
const modalController = route.controllerFor('modal');
modalController.set('modalClass', null);
const controllerName = opts.admin ? `modals/${name}` : name;
let controller = container.lookup('controller:' + controllerName);
const templateName = opts.templateName || Ember.String.dasherize(name);
const renderArgs = { into: 'modal', outlet: 'modalBody'};
if (controller) {
renderArgs.controller = controllerName;
} else {
// use a basic controller
renderArgs.controller = 'basic-modal-body';
controller = container.lookup(`controller:${renderArgs.controller}`);
}
if (opts.addModalBodyView) {
renderArgs.view = 'modal-body';
}
const modalName = `modal/${templateName}`;
const fullName = opts.admin ? `admin/templates/${modalName}` : modalName;
route.render(fullName, renderArgs);
if (opts.title) {
modalController.set('title', I18n.t(opts.title));
}
controller.set('modal', modalController);
const model = opts.model;
if (model) { controller.set('model', model); }
if (controller.onShow) { controller.onShow(); }
controller.set('flashMessage', null);
return controller;
};