2018-08-30 15:07:55 +05:30
|
|
|
angular.module("webui.ctrls.alert", ["webui.services.alerts"]).controller("AlertCtrl", [
|
|
|
|
"$scope",
|
|
|
|
"$alerts",
|
|
|
|
"$sce",
|
|
|
|
function(scope, alerts, sce) {
|
|
|
|
scope.pendingAlerts = [];
|
2013-02-22 19:28:10 +01:00
|
|
|
|
2018-08-30 15:07:55 +05:30
|
|
|
scope.removeAlert = function(ind) {
|
|
|
|
this.pendingAlerts.splice(ind, 1);
|
|
|
|
};
|
2013-02-22 19:28:10 +01:00
|
|
|
|
2018-08-30 15:07:55 +05:30
|
|
|
alerts.addAlerter(function(msg, type) {
|
|
|
|
type = type || "warning";
|
|
|
|
var obj = { msg: sce.trustAsHtml(msg), type: type };
|
|
|
|
scope.pendingAlerts = _.filter(scope.pendingAlerts, function(al) {
|
|
|
|
return !al.expired;
|
|
|
|
});
|
|
|
|
scope.pendingAlerts.push(obj);
|
2013-02-22 20:44:10 +01:00
|
|
|
|
2018-08-30 15:07:55 +05:30
|
|
|
setTimeout(function() {
|
|
|
|
var ind = scope.pendingAlerts.indexOf(obj);
|
|
|
|
if (ind != -1) {
|
|
|
|
scope.pendingAlerts[ind].expired = true;
|
2014-05-31 20:42:09 +08:00
|
|
|
|
2018-08-30 15:07:55 +05:30
|
|
|
// only remove if more notifications are pending in the pipeline
|
|
|
|
if (scope.pendingAlerts.length > 0) scope.removeAlert(ind);
|
|
|
|
}
|
|
|
|
}, type == "error" ? 15000 : 5000);
|
2013-02-22 20:44:10 +01:00
|
|
|
|
2018-08-30 15:07:55 +05:30
|
|
|
scope.$digest();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
]);
|