This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See http://git.chorem.org/pollen.git commit c5a2a282307c29dbc644a352147eff40bfa61726 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Thu Aug 28 16:23:11 2014 +0200 add trigger to hide alert --- .../src/main/webapp/js/controllers/alertCtrl.js | 101 +++++++++++++++++---- 1 file changed, 81 insertions(+), 20 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js index 486c2e1..0b40766 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/alertCtrl.js @@ -31,8 +31,44 @@ angular.module('alertControllers', []) $scope.data.alerts = []; $scope.data.persistentAlerts = []; - $scope.$on('newError', function (event, error, timeout) { - var alert = {msg:error, type:'danger', icon:'fa fa-info-error'}; + var makeAlert = function (msg, type, icon, id) { + var alert = {msg:msg, type:type}; + + if (icon !== undefined) { + alert.icon = icon; + } + + if (id !== undefined) { + alert.id = id; + } + return alert; + }; + + var getPoolAlert = function (timeout) { + if (angular.isDefined(timeout) && timeout >= 0) { + return $scope.data.alerts; + } else { + return $scope.data.persistentAlerts; + } + }; + + var hideFilterAlert = function (filter) { + var alert = $($scope.data.persistentAlerts).filter(function() { + return filter(this); + }); + + alert.add($($scope.data.alerts).filter(function () { + return filter(this); + })); + + alert.each(function () { + $scope.hideAlert(this); + }); + }; + + $scope.$on('newError', function (event, error, timeout, id) { + var alert = makeAlert(error,'danger','fa fa-info-error', id); + if (angular.isDefined(timeout)) { $scope.addAlert(alert, timeout); } else { @@ -40,8 +76,9 @@ angular.module('alertControllers', []) } }); - $scope.$on('newWarning', function (event, warning, timeout) { - var alert = {msg:warning, type:'warning', icon:'fa fa-warning'}; + $scope.$on('newWarning', function (event, warning, timeout, id) { + var alert = makeAlert(warning, 'warning', 'fa fa-warning', id); + if (angular.isDefined(timeout)) { $scope.addAlert(alert, timeout); } else { @@ -50,8 +87,9 @@ angular.module('alertControllers', []) }); - $scope.$on('newSuccess', function (event, success, timeout) { - var alert = {msg:success, type:'success', icon:'fa fa-check'}; + $scope.$on('newSuccess', function (event, success, timeout, id) { + var alert = makeAlert(success, 'success', 'fa fa-check', id); + if (angular.isDefined(timeout)) { $scope.addAlert(alert, timeout); } else { @@ -59,8 +97,9 @@ angular.module('alertControllers', []) } }); - $scope.$on('newInfo', function (event, info, timeout) { - var alert = {msg:info, type:'info', icon:'fa fa-info-circle'}; + $scope.$on('newInfo', function (event, info, timeout, id) { + var alert = makeAlert(info, 'info', 'fa fa-info-circle', id); + if (angular.isDefined(timeout)) { $scope.addAlert(alert, timeout); } else { @@ -82,15 +121,42 @@ angular.module('alertControllers', []) } }); - $scope.addAlert = function (alert, timeout) { - var alertNotExist = true; - var poolAlert; + $scope.$on('hideAlertByMsg', function (event, msg) { + var filter = function (alert) { + return alert.msg === msg; + }; + hideFilterAlert(filter); + }); - if (angular.isDefined(timeout) && timeout >= 0) { - poolAlert = $scope.data.alerts; + $scope.$on('hideAlertByType', function (event, type) { + var filter = function (alert) { + return alert.type === type; + }; + console.log("hide alert type : " + type); + hideFilterAlert(filter); + }); + + $scope.$on('hideAlertById', function (event, id) { + var filter = function (alert) { + return alert.id === id; + }; + hideFilterAlert(filter); + }); + + $scope.$on('cleanAlert', function(persistent) { + if (persistent === undefined) { + $scope.$emit('cleanAlert', false); + $scope.$emit('cleanAlert', true); + } else if (persistent) { + $scope.data.persistentAlerts = []; } else { - poolAlert = $scope.data.persistentAlerts; + $scope.data.alerts = []; } + }); + + $scope.addAlert = function (alert, timeout) { + var alertNotExist = true; + var poolAlert = getPoolAlert(timeout); angular.forEach(poolAlert, function (oneAlert) { if (angular.equals(oneAlert.msg, alert.msg) && angular.equals(oneAlert.type, alert.type)) { @@ -115,12 +181,7 @@ angular.module('alertControllers', []) }; $scope.hideAlert = function (alert) { - var poolAlert; - if (angular.isDefined(alert.timeout) && alert.timeout >= 0) { - poolAlert = $scope.data.alerts; - } else { - poolAlert = $scope.data.persistentAlerts; - } + var poolAlert = getPoolAlert(alert.timeout); var index = poolAlert.indexOf(alert); if (index >= 0) { -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.