2018-04-16 18:08:00 +02:00
|
|
|
// Converse.js
|
|
|
|
// http://conversejs.org
|
|
|
|
//
|
|
|
|
// Copyright (c) 2018, the Converse.js developers
|
|
|
|
// Licensed under the Mozilla Public License (MPLv2)
|
|
|
|
|
2018-02-22 18:41:01 +01:00
|
|
|
(function (root, factory) {
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
define([
|
|
|
|
"converse-core",
|
2018-05-09 10:09:42 +02:00
|
|
|
"tpl!alert_modal",
|
2018-02-22 18:41:01 +01:00
|
|
|
"bootstrap",
|
|
|
|
"backbone.vdomview"
|
|
|
|
], factory);
|
|
|
|
}
|
2018-05-09 10:09:42 +02:00
|
|
|
}(this, function (converse, tpl_alert_modal, bootstrap) {
|
2018-02-22 18:41:01 +01:00
|
|
|
"use strict";
|
|
|
|
|
2018-05-09 10:09:42 +02:00
|
|
|
const { Strophe, Backbone, _ } = converse.env;
|
2018-02-22 18:41:01 +01:00
|
|
|
|
|
|
|
converse.plugins.add('converse-modal', {
|
|
|
|
|
|
|
|
initialize () {
|
|
|
|
const { _converse } = this;
|
|
|
|
|
|
|
|
_converse.BootstrapModal = Backbone.VDOMView.extend({
|
|
|
|
|
|
|
|
initialize () {
|
|
|
|
this.render().insertIntoDOM();
|
|
|
|
this.modal = new bootstrap.Modal(this.el, {
|
|
|
|
backdrop: 'static',
|
|
|
|
keyboard: true
|
|
|
|
});
|
|
|
|
this.el.addEventListener('hide.bs.modal', (event) => {
|
|
|
|
if (!_.isNil(this.trigger_el)) {
|
|
|
|
this.trigger_el.classList.remove('selected');
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
insertIntoDOM () {
|
|
|
|
const container_el = _converse.chatboxviews.el.querySelector("#converse-modals");
|
|
|
|
container_el.insertAdjacentElement('beforeEnd', this.el);
|
|
|
|
},
|
|
|
|
|
|
|
|
show (ev) {
|
2018-05-09 10:09:42 +02:00
|
|
|
if (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
this.trigger_el = ev.target;
|
|
|
|
this.trigger_el.classList.add('selected');
|
|
|
|
}
|
2018-02-22 18:41:01 +01:00
|
|
|
this.modal.show();
|
|
|
|
}
|
|
|
|
});
|
2018-05-09 10:09:42 +02:00
|
|
|
|
|
|
|
_converse.Alert = _converse.BootstrapModal.extend({
|
|
|
|
|
|
|
|
initialize () {
|
|
|
|
_converse.BootstrapModal.prototype.initialize.apply(this, arguments);
|
|
|
|
this.model.on('change', this.render, this);
|
|
|
|
},
|
|
|
|
|
|
|
|
toHTML () {
|
|
|
|
return tpl_alert_modal(this.model.toJSON());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/************************ BEGIN API ************************/
|
|
|
|
// We extend the default converse.js API to add methods specific to MUC chat rooms.
|
|
|
|
let alert
|
|
|
|
|
|
|
|
_.extend(_converse.api, {
|
|
|
|
'alert': {
|
|
|
|
'show' (type, title, messages) {
|
|
|
|
if (_.isString(messages)) {
|
|
|
|
messages = [messages];
|
|
|
|
}
|
|
|
|
if (type === Strophe.LogLevel.ERROR) {
|
|
|
|
type = 'alert-danger';
|
|
|
|
} else if (type === Strophe.LogLevel.INFO) {
|
|
|
|
type = 'alert-info';
|
|
|
|
} else if (type === Strophe.LogLevel.WARN) {
|
|
|
|
type = 'alert-warning';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_.isUndefined(alert)) {
|
|
|
|
const model = new Backbone.Model({
|
|
|
|
'title': title,
|
|
|
|
'messages': messages,
|
|
|
|
'type': type
|
|
|
|
})
|
|
|
|
alert = new _converse.Alert({'model': model});
|
|
|
|
} else {
|
|
|
|
alert.model.set({
|
|
|
|
'title': title,
|
|
|
|
'messages': messages,
|
|
|
|
'type': type
|
|
|
|
});
|
|
|
|
}
|
|
|
|
alert.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2018-02-22 18:41:01 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}));
|