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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Router Config file
// For routing we uses stateman state based routing
define(['stateman', 'jquery', 'moduleloader', 'global'], function(Stateman, $, MODULE_LOADER, global) {
var ROUTER = {
statemanInstance: null,
init: function() {
ROUTER.statemanInstance = new Stateman();
ROUTER.statemanInstance
.state('app', config)
.state('app.login', create({
enter: function() {
MODULE_LOADER.load('login', "Login");
},
canEnter: function() {
},
leave: function() {
},
canLeave: function() {
}
}))
.state('app.signout', create({
enter: function() {
localStorage.clear();
global.destroyAll();
window.location.href = "/";
}
}))
.state('app.layout', create({
enter: function() {
MODULE_LOADER.load('layout')
}
}))
.state('app.layout.dashboard', create({
enter: function() {
MODULE_LOADER.load('dashboard', "Dashboard");
},
canEnter: function() {
},
leave: function() {
},
canLeave: function() {
}
}))
.state('app.layout.test', create({
enter: function() {
MODULE_LOADER.load('test', "Test");
},
canEnter: function() {
},
leave: function() {
},
canLeave: function() {
}
}))
.state('404', create({
enter: function() {
MODULE_LOADER.load('404');
},
canEnter: function() {
},
leave: function() {
},
canLeave: function() {
}
}))
.on("notfound", function() {
if (global.accessToken) {
this.go('app.layout.dashboard');
} else {
this.go('app.login'); // if not found
}
})
.start();
}
};
var config = {
enter: function(option) {
// var loginData = JSON.parse(localStorage.getItem('loginData'));
// if (loginData) {
// global["accessToken"] = loginData["token"];
// } else {
// if (option.current.name != "app.login") {
// ROUTER.statemanInstance.go('app.login');
// }
// }
},
leave: function() {
console.log("leave: " + this.name)
},
canEnter: function() {
console.log("canEnter: " + this.name)
},
canLeave: function() {
console.log("canLeave: " + this.name)
}
};
function create(o) {
o = o || {};
o.enter = o.enter || config.enter;
o.leave = o.leave || config.leave;
return o;
}
return ROUTER;
});
|