keeweb/app/scripts/comp/alerts.js

121 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-01-31 07:50:28 +01:00
const ModalView = require('../views/modal-view');
const Locale = require('../util/locale');
2015-10-17 23:49:24 +02:00
2017-01-31 07:50:28 +01:00
const Alerts = {
2015-11-18 19:33:04 +01:00
alertDisplayed: false,
2015-10-17 23:49:24 +02:00
buttons: {
2019-08-16 23:05:39 +02:00
ok: {
result: 'yes',
get title() {
return Locale.alertOk;
}
},
yes: {
result: 'yes',
get title() {
return Locale.alertYes;
}
},
no: {
result: '',
get title() {
return Locale.alertNo;
}
},
cancel: {
result: '',
get title() {
return Locale.alertCancel;
}
}
2015-10-17 23:49:24 +02:00
},
alert: function(config) {
2016-07-24 19:11:25 +02:00
if (config.skipIfAlertDisplayed && Alerts.alertDisplayed) {
return null;
}
2015-11-18 19:33:04 +01:00
Alerts.alertDisplayed = true;
2017-01-31 07:50:28 +01:00
const view = new ModalView({ model: config });
2015-10-17 23:49:24 +02:00
view.render();
2016-07-17 13:30:38 +02:00
view.on('result', (res, check) => {
2015-11-18 19:33:04 +01:00
Alerts.alertDisplayed = false;
2015-10-17 23:49:24 +02:00
if (res && config.success) {
2015-11-17 21:57:32 +01:00
config.success(res, check);
2015-10-17 23:49:24 +02:00
}
if (!res && config.cancel) {
config.cancel();
}
if (config.complete) {
2015-11-17 21:57:32 +01:00
config.complete(res, check);
2015-10-17 23:49:24 +02:00
}
});
2016-03-31 22:52:04 +02:00
return view;
2015-10-17 23:49:24 +02:00
},
notImplemented: function() {
this.alert({
2015-12-17 19:25:25 +01:00
header: Locale.notImplemented,
2015-10-17 23:49:24 +02:00
body: '',
icon: 'exclamation-triangle',
buttons: [this.buttons.ok],
esc: '',
click: '',
enter: ''
});
},
info: function(config) {
2019-08-16 23:05:39 +02:00
this.alert(
_.extend(
{
header: '',
body: '',
icon: 'info',
buttons: [this.buttons.ok],
esc: '',
click: '',
enter: ''
},
config
)
);
2015-10-17 23:49:24 +02:00
},
error: function(config) {
2019-08-16 23:05:39 +02:00
this.alert(
_.extend(
{
header: '',
body: '',
icon: 'exclamation-circle',
buttons: [this.buttons.ok],
esc: '',
click: '',
enter: ''
},
config
)
);
2015-10-17 23:49:24 +02:00
},
yesno: function(config) {
2019-08-16 23:05:39 +02:00
this.alert(
_.extend(
{
header: '',
body: '',
icon: 'question',
buttons: [this.buttons.yes, this.buttons.no],
esc: '',
click: '',
enter: 'yes'
},
config
)
);
2015-10-17 23:49:24 +02:00
}
};
module.exports = Alerts;