diff --git a/bower.json b/bower.json index 6da89eb..d6d923f 100644 --- a/bower.json +++ b/bower.json @@ -8,7 +8,7 @@ "bootswatch-dist": "3.3.2-cerulean", "jsencrypt": "~2.1.0", "animate.css": "~3.2.6", - "remarkable-bootstrap-notify": "~3.0.0", + "remarkable-bootstrap-notify": "~3.0.1", "angular-ladda": "~0.2.2" } } diff --git a/public/css/style.css b/public/css/style.css index ced8790..145e6a0 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -10,6 +10,6 @@ body { width: 90%; } -[data-notify="progressbar"] { - display: none; +[data-notify="title"] { + display: block; } diff --git a/public/js/controllers/MembreCtrl.js b/public/js/controllers/MembreCtrl.js index 2f173c0..52d078c 100644 --- a/public/js/controllers/MembreCtrl.js +++ b/public/js/controllers/MembreCtrl.js @@ -16,25 +16,27 @@ angular.module('MembreCtrl', ['SessionsServ', 'NotifyServ']).controller('MembreC }); $scope.createMembre = function () { + var not = NotifyServ.promise("Ajout du membre..."); $http.post('/api/membres', $scope.formData) .success(function (data) { $scope.formData = {}; $scope.membres = data; - NotifyServ.success("Membre ajouté"); + not.success("Membre ajouté"); }) .error(function (data) { - NotifyServ.error("Impossible d'ajouter le membre", data); + not.error("Impossible d'ajouter le membre"); }); }; $scope.deleteMembre = function (id) { + var not = NotifyServ.promise("Suppression du membre..."); $http.delete('/api/membres/' + id) .success(function (data) { $scope.membres = data; - NotifyServ.success("Membre supprimé."); + not.success("Membre supprimé"); }) .error(function (data) { - NotifyServ.error("Impossible de supprimer le membre", data); + not.error("Impossible de supprimer le membre", data); }); }; diff --git a/public/js/services/NotifyServ.js b/public/js/services/NotifyServ.js index 5c3f55e..9e88602 100644 --- a/public/js/services/NotifyServ.js +++ b/public/js/services/NotifyServ.js @@ -1,29 +1,94 @@ angular.module('NotifyServ', []).service('NotifyServ', [ function () { + $.notifyDefaults({ + placement: { + from: 'bottom', + align: 'left' + }, + animate: { + enter: 'animated bounceInUp', + exit: 'animated bounceOutDown' + }, + newest_on_top: false, + showProgressbar: false, + delay: 3000 + }); return { - notify: function (type, message) { - $.notify({ + notify: $.notify, + info: function (message) { + this.notify({ message: message }, { - type: type, - animate: { - enter: 'animated bounceInDown', - exit: 'animated bounceOutUp' - } + type: 'info' }); }, success: function (message) { - this.notify('success', message); - }, - info: function (message) { - this.notify('info', message); + this.notify({ + message: message + }, { + type: 'success' + }); }, warn: function (message) { - this.notify('warning', message); + this.notify({ + message: message + }, { + type: 'warning' + }); + console.warn(message); }, error: function (context, error) { - this.notify('danger', context); + this.notify({ + title: context, + message: error + }, { + type: 'danger' + }); console.error(context, error); + }, + promise: function (message) { + if (!message) { + message = "Opération en cours..."; + } + var not = this.notify({ + message: message + }, { + delay: 0 + }); + return { + update: function (commands) { + not.update(commands); + $('[data-notify=message]', not.$ele).addClass('animated flash'); + }, + finally: function (commands) { + this.update(commands); + _this = this; + setTimeout(function () { + not.close(); + }, $.notifyDefaults().delay); + }, + success: function (message) { + this.finally({ + message: message, + type: 'success' + }); + }, + warn: function (message) { + this.finally({ + message: message, + type: 'warning' + }); + }, + error: function (context, error) { + commands = { + title: context, + message: error, + type: 'danger' + }; + console.error(context, error); + this.finally(commands); + } + }; } }; } diff --git a/public/js/services/SessionServ.js b/public/js/services/SessionServ.js index d75e2ca..f3ee32d 100644 --- a/public/js/services/SessionServ.js +++ b/public/js/services/SessionServ.js @@ -15,7 +15,7 @@ angular.module('SessionsServ', ['NotifyServ', 'EncryptServ']).service('SessionSe if (typeof data === 'object') { this.cur = data; } else if (data === 'expired') { - NotifyServ.warn("Votre session a expiré"); + NotifyServ.warn("Session expirée"); } else { this.cur = false; } @@ -37,6 +37,7 @@ angular.module('SessionsServ', ['NotifyServ', 'EncryptServ']).service('SessionSe }, connect: function (login, pass, cb) { _this = this; + var not = NotifyServ.promise("Connexion..."); data = JSON.stringify({ login: login, pass: pass @@ -45,24 +46,29 @@ angular.module('SessionsServ', ['NotifyServ', 'EncryptServ']).service('SessionSe $http.post('/api/session', [dataCrypt]).success(function (body) { _this.updateSessionInfos(body); if (_this.cur) { - NotifyServ.info("Connecté en tant que " + _this.cur.nom + ""); + not.success("Connecté en tant que " + _this.cur.nom + ""); if (cb) cb(null); } else { if (body === 'invalid') { - NotifyServ.warn("Identifiants invalides"); + not.warn("Identifiants invalides"); } if (cb) cb(body); } + }).error(function (body) { + not.error("Impossible de se connecter", body); }); }); }, disconnect: function () { _this = this; + var not = NotifyServ.promise("Déconnexion..."); $http.delete('/api/session').success(function () { _this.updateSessionInfos(false); - NotifyServ.info("Déconnecté"); + not.success("Déconnecté"); + }).error(function(body) { + not.error("Impossible de se déconnecter", body); }); } }; -- libgit2 0.21.2