keeweb/app/scripts/comp/alerts.js

82 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-10-17 23:49:24 +02:00
'use strict';
var ModalView = require('../views/modal-view');
var Alerts = {
2015-11-18 19:33:04 +01:00
alertDisplayed: false,
2015-10-17 23:49:24 +02:00
buttons: {
ok: {result: 'yes', title: 'OK'},
yes: {result: 'yes', title: 'Yes'},
no: {result: '', title: 'No'}
},
alert: function(config) {
2015-11-18 19:33:04 +01:00
Alerts.alertDisplayed = true;
2015-10-17 23:49:24 +02:00
var view = new ModalView({ model: config });
view.render();
2015-11-17 21:57:32 +01:00
view.on('result', function(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
}
});
},
notImplemented: function() {
this.alert({
header: 'Not Implemented',
body: '',
icon: 'exclamation-triangle',
buttons: [this.buttons.ok],
esc: '',
click: '',
enter: ''
});
},
info: function(config) {
this.alert(_.extend({
header: '',
body: '',
icon: 'info',
buttons: [this.buttons.ok],
esc: '',
click: '',
enter: ''
}, config));
},
error: function(config) {
this.alert(_.extend({
header: '',
body: '',
icon: 'exclamation-circle',
buttons: [this.buttons.ok],
esc: '',
click: '',
enter: ''
}, config));
},
yesno: function(config) {
this.alert(_.extend({
header: '',
body: '',
icon: 'question',
buttons: [this.buttons.yes, this.buttons.no],
esc: '',
click: '',
enter: 'yes'
}, config));
}
};
module.exports = Alerts;