Commit ec5e37f2a1a01fdd25368ae38605f936d95e87e3
1 parent
ecca2061
Exists in
master
and in
1 other branch
Remove dispensable interface for error messages
Showing
3 changed files
with
17 additions
and
19 deletions
Show diff stats
src/app/account/register-component.html
@@ -4,10 +4,10 @@ | @@ -4,10 +4,10 @@ | ||
4 | <div class="environment-signup-intro" ng-bind-html="ctrl.environment.signup_intro"></div> | 4 | <div class="environment-signup-intro" ng-bind-html="ctrl.environment.signup_intro"></div> |
5 | </div> | 5 | </div> |
6 | 6 | ||
7 | - <div class="error-messages" ng-if="errorMessages"> | 7 | + <div class="error-messages" ng-if="ctrl.errorMessages"> |
8 | <p>{{ "account.register.errorMessagesTitle" | translate }}</p> | 8 | <p>{{ "account.register.errorMessagesTitle" | translate }}</p> |
9 | <ul> | 9 | <ul> |
10 | - <li ng-repeat="error in errorMessages">{{ error.fieldName | translate }} {{ error.message | translate }}</li> | 10 | + <li ng-repeat="error in ctrl.errorMessages">{{ error.fieldName | translate }} {{ error.message | translate }}</li> |
11 | </ul> | 11 | </ul> |
12 | </div> | 12 | </div> |
13 | 13 |
src/app/account/register.component.ts
@@ -4,7 +4,7 @@ import { NotificationService } from "./../shared/services/notification.service"; | @@ -4,7 +4,7 @@ import { NotificationService } from "./../shared/services/notification.service"; | ||
4 | import { EnvironmentService } from "../../lib/ng-noosfero-api/http/environment.service"; | 4 | import { EnvironmentService } from "../../lib/ng-noosfero-api/http/environment.service"; |
5 | import { RegisterController } from "./register.controller"; | 5 | import { RegisterController } from "./register.controller"; |
6 | import { AuthController } from "./../login"; | 6 | import { AuthController } from "./../login"; |
7 | -import { IModalComponent, IErrorMessages } from "../shared/components/interfaces"; | 7 | +import { IModalComponent } from "../shared/components/interfaces"; |
8 | 8 | ||
9 | @Component({ | 9 | @Component({ |
10 | selector: 'noosfero-register', | 10 | selector: 'noosfero-register', |
@@ -21,10 +21,12 @@ export class RegisterComponent { | @@ -21,10 +21,12 @@ export class RegisterComponent { | ||
21 | 21 | ||
22 | modalInstance: ng.ui.bootstrap.IModalServiceInstance; | 22 | modalInstance: ng.ui.bootstrap.IModalServiceInstance; |
23 | 23 | ||
24 | + errorMessages: any[]; | ||
25 | + | ||
24 | constructor( | 26 | constructor( |
25 | private $state: ng.ui.IStateService, | 27 | private $state: ng.ui.IStateService, |
26 | private $uibModal: ng.ui.bootstrap.IModalService, | 28 | private $uibModal: ng.ui.bootstrap.IModalService, |
27 | - private $scope: IErrorMessages, | 29 | + private $scope: ng.IScope, |
28 | public registerService: RegisterService, | 30 | public registerService: RegisterService, |
29 | private notificationService: NotificationService, | 31 | private notificationService: NotificationService, |
30 | private environmentService: EnvironmentService | 32 | private environmentService: EnvironmentService |
@@ -37,21 +39,21 @@ export class RegisterComponent { | @@ -37,21 +39,21 @@ export class RegisterComponent { | ||
37 | let error = ''; | 39 | let error = ''; |
38 | let errors: any; | 40 | let errors: any; |
39 | let field = ''; | 41 | let field = ''; |
40 | - this.$scope.errorMessages = []; | 42 | + this.errorMessages = []; |
41 | this.registerService.createAccount(this.account).then((response) => { | 43 | this.registerService.createAccount(this.account).then((response) => { |
42 | this.$state.transitionTo('main.environment'); | 44 | this.$state.transitionTo('main.environment'); |
43 | this.notificationService.success({ title: "account.register.success.title", message: "account.register.success.message" }); | 45 | this.notificationService.success({ title: "account.register.success.title", message: "account.register.success.message" }); |
44 | }).catch((response) => { | 46 | }).catch((response) => { |
45 | - if ( response.data.error ) { | ||
46 | - errors = response.data['error'].split(', '); | ||
47 | - for (error in errors) { | ||
48 | - this.$scope.errorMessages.push({ message: errors[error] }); | ||
49 | - } | ||
50 | - } else if ( response.data.message ) { | ||
51 | - errors = JSON.parse(response.data.message); | ||
52 | - for (field in errors) { | ||
53 | - this.$scope.errorMessages.push({ fieldName: field, message: errors[field][0] }); | ||
54 | - } | 47 | + if (response.data.error) { |
48 | + errors = response.data['error'].split(', '); | ||
49 | + for (error in errors) { | ||
50 | + this.errorMessages.push({ message: errors[error] }); | ||
51 | + } | ||
52 | + } else if (response.data.message) { | ||
53 | + errors = JSON.parse(response.data.message); | ||
54 | + for (field in errors) { | ||
55 | + this.errorMessages.push({ fieldName: field, message: errors[field][0] }); | ||
56 | + } | ||
55 | } | 57 | } |
56 | this.notificationService.error({ title: "account.register.save.failed" }); | 58 | this.notificationService.error({ title: "account.register.save.failed" }); |
57 | }); | 59 | }); |
src/app/shared/components/interfaces.ts
@@ -6,7 +6,3 @@ export interface IModalComponent { | @@ -6,7 +6,3 @@ export interface IModalComponent { | ||
6 | $uibModal: ng.ui.bootstrap.IModalService; | 6 | $uibModal: ng.ui.bootstrap.IModalService; |
7 | modalInstance: ng.ui.bootstrap.IModalServiceInstance; | 7 | modalInstance: ng.ui.bootstrap.IModalServiceInstance; |
8 | } | 8 | } |
9 | - | ||
10 | -export interface IErrorMessages extends ng.IScope { | ||
11 | - errorMessages: any; | ||
12 | -} |