2017-06-01 02:04:27 +00:00
|
|
|
import PromptModal from './prompt-modal';
|
2017-07-17 22:37:24 +00:00
|
|
|
import AlertModal from './alert-modal';
|
2017-06-01 02:04:27 +00:00
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
const modals = {};
|
|
|
|
|
2016-11-07 20:24:38 +00:00
|
|
|
export function registerModal (instance) {
|
2016-08-15 17:04:36 +00:00
|
|
|
if (instance === null) {
|
|
|
|
// Modal was unmounted
|
2017-03-03 20:09:08 +00:00
|
|
|
return;
|
2016-08-15 17:04:36 +00:00
|
|
|
}
|
|
|
|
modals[instance.constructor.name] = instance;
|
|
|
|
}
|
|
|
|
|
2017-06-01 02:04:27 +00:00
|
|
|
export function showPrompt (config) {
|
|
|
|
showModal(PromptModal, config);
|
|
|
|
}
|
|
|
|
|
2017-07-17 22:37:24 +00:00
|
|
|
export function showAlert (config) {
|
|
|
|
showModal(AlertModal, config);
|
|
|
|
}
|
|
|
|
|
2016-11-07 20:24:38 +00:00
|
|
|
export function showModal (modalCls, ...args) {
|
|
|
|
return _getModal(modalCls).show(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function toggleModal (modalCls, ...args) {
|
|
|
|
return _getModal(modalCls).toggle(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function hideModal (modalCls) {
|
|
|
|
return _getModal(modalCls).hide();
|
|
|
|
}
|
|
|
|
|
2017-08-19 22:07:55 +00:00
|
|
|
export function reloadModal (modalCls) {
|
|
|
|
return _getModal(modalCls)._load();
|
|
|
|
}
|
|
|
|
|
2017-03-29 02:21:49 +00:00
|
|
|
export function hideAllModals () {
|
|
|
|
for (const key of Object.keys(modals)) {
|
|
|
|
const modal = modals[key];
|
|
|
|
modal.hide && modal.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-07 20:24:38 +00:00
|
|
|
function _getModal (modalCls) {
|
2016-08-15 17:04:36 +00:00
|
|
|
return modals[modalCls.name];
|
|
|
|
}
|