Commit 501a9b80104a2dc66ef949e8ada36e6f0b40b443
1 parent
35055118
Meilleures notifications
Showing
5 changed files
with
97 additions
and
24 deletions
Show diff stats
bower.json
public/css/style.css
public/js/controllers/MembreCtrl.js
... | ... | @@ -16,25 +16,27 @@ angular.module('MembreCtrl', ['SessionsServ', 'NotifyServ']).controller('MembreC |
16 | 16 | }); |
17 | 17 | |
18 | 18 | $scope.createMembre = function () { |
19 | + var not = NotifyServ.promise("Ajout du membre..."); | |
19 | 20 | $http.post('/api/membres', $scope.formData) |
20 | 21 | .success(function (data) { |
21 | 22 | $scope.formData = {}; |
22 | 23 | $scope.membres = data; |
23 | - NotifyServ.success("Membre ajouté"); | |
24 | + not.success("Membre ajouté"); | |
24 | 25 | }) |
25 | 26 | .error(function (data) { |
26 | - NotifyServ.error("Impossible d'ajouter le membre", data); | |
27 | + not.error("Impossible d'ajouter le membre"); | |
27 | 28 | }); |
28 | 29 | }; |
29 | 30 | |
30 | 31 | $scope.deleteMembre = function (id) { |
32 | + var not = NotifyServ.promise("Suppression du membre..."); | |
31 | 33 | $http.delete('/api/membres/' + id) |
32 | 34 | .success(function (data) { |
33 | 35 | $scope.membres = data; |
34 | - NotifyServ.success("Membre supprimé."); | |
36 | + not.success("Membre supprimé"); | |
35 | 37 | }) |
36 | 38 | .error(function (data) { |
37 | - NotifyServ.error("Impossible de supprimer le membre", data); | |
39 | + not.error("Impossible de supprimer le membre", data); | |
38 | 40 | }); |
39 | 41 | }; |
40 | 42 | ... | ... |
public/js/services/NotifyServ.js
1 | 1 | angular.module('NotifyServ', []).service('NotifyServ', [ |
2 | 2 | function () { |
3 | + $.notifyDefaults({ | |
4 | + placement: { | |
5 | + from: 'bottom', | |
6 | + align: 'left' | |
7 | + }, | |
8 | + animate: { | |
9 | + enter: 'animated bounceInUp', | |
10 | + exit: 'animated bounceOutDown' | |
11 | + }, | |
12 | + newest_on_top: false, | |
13 | + showProgressbar: false, | |
14 | + delay: 3000 | |
15 | + }); | |
3 | 16 | return { |
4 | - notify: function (type, message) { | |
5 | - $.notify({ | |
17 | + notify: $.notify, | |
18 | + info: function (message) { | |
19 | + this.notify({ | |
6 | 20 | message: message |
7 | 21 | }, { |
8 | - type: type, | |
9 | - animate: { | |
10 | - enter: 'animated bounceInDown', | |
11 | - exit: 'animated bounceOutUp' | |
12 | - } | |
22 | + type: 'info' | |
13 | 23 | }); |
14 | 24 | }, |
15 | 25 | success: function (message) { |
16 | - this.notify('success', message); | |
17 | - }, | |
18 | - info: function (message) { | |
19 | - this.notify('info', message); | |
26 | + this.notify({ | |
27 | + message: message | |
28 | + }, { | |
29 | + type: 'success' | |
30 | + }); | |
20 | 31 | }, |
21 | 32 | warn: function (message) { |
22 | - this.notify('warning', message); | |
33 | + this.notify({ | |
34 | + message: message | |
35 | + }, { | |
36 | + type: 'warning' | |
37 | + }); | |
38 | + console.warn(message); | |
23 | 39 | }, |
24 | 40 | error: function (context, error) { |
25 | - this.notify('danger', context); | |
41 | + this.notify({ | |
42 | + title: context, | |
43 | + message: error | |
44 | + }, { | |
45 | + type: 'danger' | |
46 | + }); | |
26 | 47 | console.error(context, error); |
48 | + }, | |
49 | + promise: function (message) { | |
50 | + if (!message) { | |
51 | + message = "Opération en cours..."; | |
52 | + } | |
53 | + var not = this.notify({ | |
54 | + message: message | |
55 | + }, { | |
56 | + delay: 0 | |
57 | + }); | |
58 | + return { | |
59 | + update: function (commands) { | |
60 | + not.update(commands); | |
61 | + $('[data-notify=message]', not.$ele).addClass('animated flash'); | |
62 | + }, | |
63 | + finally: function (commands) { | |
64 | + this.update(commands); | |
65 | + _this = this; | |
66 | + setTimeout(function () { | |
67 | + not.close(); | |
68 | + }, $.notifyDefaults().delay); | |
69 | + }, | |
70 | + success: function (message) { | |
71 | + this.finally({ | |
72 | + message: message, | |
73 | + type: 'success' | |
74 | + }); | |
75 | + }, | |
76 | + warn: function (message) { | |
77 | + this.finally({ | |
78 | + message: message, | |
79 | + type: 'warning' | |
80 | + }); | |
81 | + }, | |
82 | + error: function (context, error) { | |
83 | + commands = { | |
84 | + title: context, | |
85 | + message: error, | |
86 | + type: 'danger' | |
87 | + }; | |
88 | + console.error(context, error); | |
89 | + this.finally(commands); | |
90 | + } | |
91 | + }; | |
27 | 92 | } |
28 | 93 | }; |
29 | 94 | } | ... | ... |
public/js/services/SessionServ.js
... | ... | @@ -15,7 +15,7 @@ angular.module('SessionsServ', ['NotifyServ', 'EncryptServ']).service('SessionSe |
15 | 15 | if (typeof data === 'object') { |
16 | 16 | this.cur = data; |
17 | 17 | } else if (data === 'expired') { |
18 | - NotifyServ.warn("Votre session a expiré"); | |
18 | + NotifyServ.warn("Session expirée"); | |
19 | 19 | } else { |
20 | 20 | this.cur = false; |
21 | 21 | } |
... | ... | @@ -37,6 +37,7 @@ angular.module('SessionsServ', ['NotifyServ', 'EncryptServ']).service('SessionSe |
37 | 37 | }, |
38 | 38 | connect: function (login, pass, cb) { |
39 | 39 | _this = this; |
40 | + var not = NotifyServ.promise("Connexion..."); | |
40 | 41 | data = JSON.stringify({ |
41 | 42 | login: login, |
42 | 43 | pass: pass |
... | ... | @@ -45,24 +46,29 @@ angular.module('SessionsServ', ['NotifyServ', 'EncryptServ']).service('SessionSe |
45 | 46 | $http.post('/api/session', [dataCrypt]).success(function (body) { |
46 | 47 | _this.updateSessionInfos(body); |
47 | 48 | if (_this.cur) { |
48 | - NotifyServ.info("Connecté en tant que <strong>" + _this.cur.nom + "</strong>"); | |
49 | + not.success("Connecté en tant que <strong>" + _this.cur.nom + "</strong>"); | |
49 | 50 | if (cb) |
50 | 51 | cb(null); |
51 | 52 | } else { |
52 | 53 | if (body === 'invalid') { |
53 | - NotifyServ.warn("Identifiants invalides"); | |
54 | + not.warn("Identifiants invalides"); | |
54 | 55 | } |
55 | 56 | if (cb) |
56 | 57 | cb(body); |
57 | 58 | } |
59 | + }).error(function (body) { | |
60 | + not.error("Impossible de se connecter", body); | |
58 | 61 | }); |
59 | 62 | }); |
60 | 63 | }, |
61 | 64 | disconnect: function () { |
62 | 65 | _this = this; |
66 | + var not = NotifyServ.promise("Déconnexion..."); | |
63 | 67 | $http.delete('/api/session').success(function () { |
64 | 68 | _this.updateSessionInfos(false); |
65 | - NotifyServ.info("Déconnecté"); | |
69 | + not.success("Déconnecté"); | |
70 | + }).error(function(body) { | |
71 | + not.error("Impossible de se déconnecter", body); | |
66 | 72 | }); |
67 | 73 | } |
68 | 74 | }; | ... | ... |