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-09-17 14:04:46 +00:00
|
|
|
import ErrorModal from './error-modal';
|
2017-06-01 02:04:27 +00:00
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
const modals = {};
|
|
|
|
|
2018-06-25 17:42:50 +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;
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function showPrompt(config) {
|
2017-11-01 14:13:51 +00:00
|
|
|
return showModal(PromptModal, config);
|
2017-06-01 02:04:27 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function showAlert(config) {
|
2017-11-01 14:13:51 +00:00
|
|
|
return showModal(AlertModal, config);
|
2017-07-17 22:37:24 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function showError(config) {
|
2018-08-01 20:08:33 +00:00
|
|
|
try {
|
|
|
|
return showModal(ErrorModal, config);
|
|
|
|
} catch (err) {
|
|
|
|
console.log('[modal] Cannot show modal', err, config);
|
|
|
|
}
|
2017-09-17 14:04:46 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function showModal(modalCls, ...args) {
|
2016-11-07 20:24:38 +00:00
|
|
|
return _getModal(modalCls).show(...args);
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function hideAllModals() {
|
2017-03-29 02:21:49 +00:00
|
|
|
for (const key of Object.keys(modals)) {
|
|
|
|
const modal = modals[key];
|
|
|
|
modal.hide && modal.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function _getModal(modalCls) {
|
2016-08-15 17:04:36 +00:00
|
|
|
return modals[modalCls.name];
|
|
|
|
}
|