|
1 |
| -/* |
| 1 | +/* |
2 | 2 | * Template for error/success message,
|
3 |
| - * Show/hide error message when required, |
| 3 | + * Show/hide error message when required, |
4 | 4 | * Show/hide success message when required.
|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | (function(window, angular, undefined) {
|
8 | 8 |
|
9 | 9 | 'use strict';
|
| 10 | + |
10 | 11 | angular.module('ngAngularError', ['ng'])
|
11 |
| - .directive('awesomeError', function () { |
| 12 | + .factory('errorsList', function($http) { |
| 13 | + /* errors_list.json should contain a map of errors and user-feedback. |
| 14 | + * we use, $http to retrieve values from file errors_list.json, |
| 15 | + * errorsList factory returns a promise. */ |
| 16 | + return $http.get('errors_list.json'); |
| 17 | + }) |
| 18 | + |
| 19 | + .directive('awesomeError', function (errorsList) { |
12 | 20 | return {
|
13 | 21 | restrict: 'E',
|
14 | 22 | replace: true,
|
|
27 | 35 | </div> \
|
28 | 36 | </div> \
|
29 | 37 | </div>',
|
30 |
| - link: function(scope) { |
31 |
| - scope.errorMessage = { |
32 |
| - "USERNAME_OR_PASSWORD_NOT_CORRECT": "Invalid username or password.", |
33 |
| - "USERNAME_OR_PASSWORD_OR_TOKEN_NOT_CORRECT" : "Invalid username or password.", |
34 |
| - "MISSING_USERNAME_OR_EMAIL" : "Please, enter a username or email.", |
35 |
| - "INVALID_USERNAME_OR_EMAIL" : "Invalid username or email.", |
36 |
| - "MISSING_USERNAME" : "Please, enter a username.", |
37 |
| - "INVALID_USERNAME" : "Invalid username.", |
38 |
| - "USERNAME_NOT_AVAILABLE": "This username is already taken!", |
39 |
| - "USERNAME_ALREADY_TAKEN": "This username is already taken!", |
40 |
| - "username_REQUIRED": "Please, enter a username.", |
41 |
| - "username_INVALID_PATTERN" : "Username should be composed of alphanumerics only and 1 to 15 characters long.", |
42 |
| - "USERNAME_UPDATED" : "Username successfully updated.", |
43 |
| - |
44 |
| - "MISSING_PASSWORD" : "Please, enter a password.", |
45 |
| - "INVALID_PASSWORD" : "Invalid password.", |
46 |
| - "password_REQUIRED" : "Please, enter a password.", |
47 |
| - "password_LENGTH_PATTERN" : "Password should be 3 to 15 characters long", |
48 |
| - "PASSWORDS_DONT_MATCH" : "Passwords dont match.", |
49 |
| - "PASSWORD_UPDATED" : "Password successfully updated.", |
50 |
| - |
51 |
| - "email_INVALID" : "Invalid email.", |
52 |
| - "email_REQUIRED" : "Please, enter an email.", |
53 |
| - "MISSING_EMAIL" : "Please, enter an email.", |
54 |
| - "EMAIL_NOT_AVAILABE" : "This email is already taken!", |
55 |
| - "useremail_REQUIRED" : "Please, enter an email.", |
56 |
| - "useremail_INVALID" : "Invalid email", |
57 |
| - "MAIL_SENT_RESET_PASSWORD" : "Email with password reset instructions has been sent to your email address", |
| 38 | + link: function(scope) { |
| 39 | + scope.errorMessage = {}; |
58 | 40 |
|
59 |
| - "TOKEN_NOT_VALID" : "Oops, something went wrong. Please, try again later.", |
60 |
| - "MISSING_TOKEN" : "Oops, something went wrong. Please, try again later.", |
61 |
| - "INVALID_TOKEN" : "Oops, something went wrong. Please, try again later.", |
62 |
| - "TOKEN_NOT_CORRECT" : "Oops, something went wrong. Please, try again later.", |
63 |
| - "TOKEN_EXPIRED" : "Your session has expired. Please, try to login again.", |
64 |
| - |
65 |
| - "MISSING_GEO" : "We are not able to get your location. Please, try again.", |
66 |
| - "INVALID_GEO" : "We are not able to get your location. Please, try again.", |
| 41 | + /* fetching data present in 'errors-list.json' file */ |
| 42 | + errorsList.success(function(data) { |
| 43 | + scope.errorMessage = data; |
| 44 | + }); |
67 | 45 |
|
68 |
| - "FILE_NOT_VALID" : "File not valid", |
69 |
| - "USER_NOT_FOUND" : "This user was not found, we apologise for the inconvenience.", |
70 |
| - "SHOUT_NOT_FOUND" : "This message was not found, we apologise for the inconvenience.", |
71 |
| - "MISSING_SHOUT" : "Please, enter a message.", |
72 |
| - "INVALID_SHOUT" : "Invalid message.", |
73 |
| - "INVALID_IN_REPLY_TO" : "Invalid reply message.", |
74 |
| - "FEEDBACK_RESPONSE" : "Thank you for your feedback.", |
75 |
| - "FEEDBACK_ERROR_RESPONSE" : "Sorry the feedback could not be sent.", |
76 |
| - "FEEDBACK_MISSING" : "Please, enter a feedback.", |
77 |
| - }; |
78 |
| - |
79 | 46 | scope.$on('show error', function (args) {
|
80 | 47 | scope.showerr = true;
|
81 | 48 | });
|
|
100 | 67 | scope.showMessage = scope.errorMessage[scope.msg];
|
101 | 68 | if (scope.showMessage === "undefined") { scope.showMessage = scope.errorMessage["Undefined"]; }
|
102 | 69 | });
|
103 |
| - } |
| 70 | + } |
104 | 71 | };
|
105 | 72 | });
|
106 | 73 |
|
|
0 commit comments