This repository was archived by the owner on Sep 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathUser.js
97 lines (82 loc) · 2.17 KB
/
User.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
User Module
============
ui.validate is part of angular-ui-validate
*/
var module = angular.module('App.User', ['ui.router', 'ui.validate']);
module.config(function($stateProvider) {
$stateProvider.state( 'users', {
parent: 'admin',
url: '/users',
templateUrl: 'modules/User/Users.html',
controller: 'Users',
resolve: {
users: (User) => User.list()
}
});
// Multi-Step Registration Wizard
$stateProvider.state( 'register', {
parent: 'guest',
url: '/register',
resolve: {
// shared & accessible from all steps (and their controllers if necessary)
user: (User) => new User(),
wizard: (user, RegistrationWizard) => new RegistrationWizard(user)
},
templateUrl: 'modules/User/Register.html',
controller: 'UserForm'
});
$stateProvider.state( 'register.step1', {
url: '/step1', // /register/step1
templateUrl: 'modules/User/RegisterStep1.html'
});
$stateProvider.state( 'register.step2', {
url: '/step2', // /register/step1
templateUrl: 'modules/User/RegisterStep2.html',
resolve: {
// prevent accessing step prematurely
validate: (wizard, $state) => {
if (!wizard.stepsCompleted(1))
$state.go('register.step1');
}
}
});
$stateProvider.state( 'register.step3', {
url: '/step3', // /register/step3
templateUrl: 'modules/User/RegisterStep3.html',
resolve: {
// prevent accessing step prematurely
validate: (wizard, $state) => {
if (!wizard.stepsCompleted(2))
$state.go('register.step2');
}
}
});
});
module.controller( 'Users', ($scope, users) => {
$scope.users = users;
});
module.controller( 'UserForm', ($scope, user, wizard) => {
$scope.user = user;
$scope.wizard = wizard;
});
module.factory( 'RegistrationWizard', () => {
class RegistrationWizard {
constructor(user) {
this.user = user;
}
stepsCompleted(stepCount) {
this['step'+stepCount]();
}
step1() {
return this.user.valid('name') && this.user.valid('email');
}
step2() {
// ...
}
step3() {
return this.user.valid('password');
}
}
return RegistrationWizard;
});