appwrite/public/scripts/services/alerts.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-05-09 06:54:39 +00:00
(function (window) {
"use strict";
2019-05-09 08:01:51 +00:00
window.ls.container.set('alerts', function (window) {
2019-08-07 20:35:20 +00:00
return {
list: [],
counter: 0,
add: function (message, time) {
var scope = this;
message.id = this.counter++;
scope.list.unshift(message);
if (time > 0) { // When 0 alert is unlimited in time
window.setTimeout(function (message) {
return function () {
scope.remove(message.id)
}
}(message), time);
}
return message.id;
},
remove: function (id) {
let scope = this;
for (let index = 0; index < scope.list.length; index++) {
let obj = scope.list[index];
if (obj.id === parseInt(id)) {
if (typeof obj.callback === "function") {
obj.callback();
}
scope.list.splice(index, 1);
};
}
2019-05-09 06:54:39 +00:00
}
};
2019-08-07 20:35:20 +00:00
}, true, true);
2019-05-09 06:54:39 +00:00
})(window);