click to refresh errors
[namibia] / public / js / app / router.js
1 ;(function(){
2
3         _App.Router = function()
4         {
5                 this.initialize();
6         };
7
8         _App.Router.prototype =
9         {
10
11                 routes :
12                 {
13                         // Public
14                         '#/thankyouvaluation'    : 'thankyouvaluation',
15                         '#/thankyoucontact'      : 'thankyoucontact',
16                         '#/publicfaq'            : 'publicfaq',
17                         '#/publiccontact_us'     : 'publiccontact_us',
18                         '#/publicvaluation'      : 'publicvaluation',
19                         '#/publichome'           : 'publichome',
20
21                         // Brochure
22                         ''                       : 'dealerhome',
23                         '#/'                     : 'dealerhome',
24                         '#/dealerhome'           : 'dealerhome',
25                         '#/faq'                  : 'faq',
26                         '#/login'                : 'login',
27                         '#/forgot'               : 'forgot',
28                         '#/contact'              : 'contact',
29                         '#/register'             : 'register',
30                         '#/registered'           : 'registered',
31                         '#/contact_us'           : 'contact_us',
32                         '#/about_us'             : 'about_us',
33                         '#/terms_and_conditions' : 'terms_and_conditions',
34                         '#/unsubscribe-newsletter': 'unsubscribenewsletter',
35             '#/customervaluation'      : 'customervaluation',
36             '#/customercompletevaluation'      : 'customercompletevaluation',
37
38
39                         // Portal
40                         '#/auction'              : 'auction',
41                         '#/bidview'              : 'bidview',
42                         '#/historyview'          : 'historyview',
43                         '#/stock'                : 'stock',
44                         '#/stockview'            : 'stockview',
45                         '#/limitedstockview'     : 'limitedstockview',
46                         '#/tcstock'              : 'tcstock',
47                         '#/tcstockview'          : 'tcstockview',
48                         '#/limitedtcstockview'   : 'limitedtcstockview',
49                         '#/valuations'           : 'valuations',
50                         '#/valuationview'        : 'valuationview',
51                         '#/limitedvaluationview' : 'limitedvaluationview',
52                         '#/valuationreport'      : 'valuationreport',
53                         '#/settings'             : 'settings',
54                         '#/userview'             : 'userview',
55                         '#/dealerview'           : 'dealerview',
56                         '#/membershipview'       : 'membershipview',
57                         '#/clubview'             : 'clubview',
58                         '#/memberview'           : 'memberview',
59                         '#/disputeview'          : 'disputeview',
60                         '#/questionview'         : 'questionview',
61                         '#/replyview'            : 'replyview',
62                         '#/retailview'           : 'retailview',
63                         '#/priceguide'           : 'priceguide',
64                         '#/offerview'            : 'offerview',
65                         '#/changepinview'        : 'changepinview',
66                 '#/historicaldata'       : 'historicaldata',
67             '#/valuationcalendar'      : 'valuationcalendar',
68             '#/appointmentedit'      : 'appointmentedit',
69
70
71                         // Admin
72                         '#/switch'               : 'switch',
73                         '#/admin'                : 'admin',
74                         '#/userpermissions'      : 'userpermissions',
75                         '#/viewuserpermissions'  : 'viewuserpermissions',
76                         '#/systemusers'          : 'systemusers',
77                         '#/systemuserview'       : 'systemuserview',
78                         '#/systemauctions'       : 'systemauctions',
79                         '#/systembidview'        : 'systembidview',
80                         '#/systemdisputes'       : 'systemdisputes',
81                         '#/systemdisputeview'    : 'systemdisputeview',
82                         '#/override'             : 'override',
83                         '#/dealers'              : 'dealers',
84                         '#/systemdealerview'     : 'systemdealerview',
85                         '#/xmlrpcrequestlog'     : 'xmlrpcrequestlog',
86                         '#/xmlrpccallbacklog'    : 'xmlrpccallbacklog',
87                         '#/xmlrpcclients'        : 'xmlrpcclients',
88                         '#/xmlrpcclientview'     : 'xmlrpcclientview',
89                         '#/systemsettings'       : 'systemsettings',
90                         '#/configview'           : 'configview',
91                         '#/accessories'          : 'accessories',
92                         '#/damages'              : 'damages',
93                         '#/increments'           : 'increments',
94                         '#/groups'               : 'groups',
95                         '#/divisions'            : 'divisions',
96                         '#/holidays'             : 'holidays',
97                         '#/regionalmanager'      : 'regionalmanager',
98                         '#/opendays'             : 'opendays',
99                         '#/newsletters'          : 'newsletters',
100                         '#/newsletterview'       : 'newsletterview',
101                         '#/reports'              : 'reports',
102                         '#/smsreport'            : 'smsreport',
103                         '#/invreport'            : 'invreport',
104                         '#/auctionreport'        : 'auctionreport',
105             '#/stockauctionreport'        : 'stockauctionreport',
106             '#/stockbulkimporter'        : 'stockbulkimporter',
107                         '#/hpilogreport'         : 'hpilogreport',
108             '#/hpiaccidentlogreport'         : 'hpiaccidentlogreport',
109                         '#/pgreport'             : 'pgreport',
110                         '#/traderreport'         : 'traderreport',
111                         '#/adhreport'                    : 'adhreport',
112                         '#/loadvssoldreport'     : 'loadvssoldreport',
113                         '#/loadvssolddetreport'  : 'loadvssolddetreport',
114                         '#/pgfreport'                    : 'pgfreport',
115                         '#/pgsreport'                    : 'pgsreport',
116                         '#/auctionadherence'     : 'auctionadherence',
117                         '#/nomatch'                              : 'nomatch',
118                         '#/priceguideflash'              : 'priceguideflash',
119                         '#/emailreport'          : 'emailreport',
120                         '#/loginreport'          : 'loginreport',
121                         '#/adminvaluationreport' : 'adminvaluationreport',
122                         '#/valuationstatreport'  : 'valuationstatreport',
123                 '#/auctiontraderreport'  : 'auctiontraderreport',
124                 '#/transunionupload'     : 'transunionupload'
125                 },
126
127                 requireMenu : {
128                         'thankyou'             : 'PublicMenu',
129                         'publicfaq'            : 'PublicMenu',
130                         'publiccontact_us'     : 'PublicMenu',
131                         'publicvaluation'      : 'PublicMenu',
132             'customervaluation'      : 'PublicMenu',
133                         'publichome'           : 'PublicMenu',
134                         'home'                 : 'PublicMenu',
135                         'faq'                  : 'BrochureMenu',
136                         'login'                : 'BrochureMenu',
137                         'forgot'               : 'BrochureMenu',
138                         'contact'              : 'BrochureMenu',
139                         'register'             : 'BrochureMenu',
140                         'registered'           : 'BrochureMenu',
141                         'contact_us'           : 'BrochureMenu',
142                         'about_us'             : 'BrochureMenu',
143                         'terms_and_conditions' : 'BrochureMenu',
144                         'dealerhome'           : 'BrochureMenu'
145                 },
146
147                 requireAuth : {
148                         'auction'              : true,
149                         'bidview'              : true,
150                         'historyview'          : true,
151                         'stock'                : true,
152                         'stockview'            : true,
153                         'limitedstockview'     : true,
154                         'tcstock'              : true,
155                         'tcstockview'          : true,
156                         'limitedtcstockview'   : true,
157                         'valuations'           : true,
158                         'valuationview'        : true,
159                         'limitedvaluationview' : true,
160                         'valuationreport'      : true,
161                         'settings'             : true,
162                         'userview'             : true,
163                         'changepinview'        : true,
164                         'dealerview'           : true,
165                         'membershipview'       : true,
166                         'clubview'             : true,
167                         'memberview'           : true,
168                         'disputeview'          : true,
169                         'questionview'         : true,
170                         'replyview'            : true,
171                         'retailview'           : true,
172                         'priceguide'           : true,
173                         'offerview'            : true,
174                         'switch'               : true,
175                         'admin'                : true,
176                         'userpermissions'      : true,
177                         'viewuserpermissions'  : true,
178                         'systemusers'          : true,
179                         'systemuserview'       : true,
180                         'systemauctions'       : true,
181                         'systembidview'        : true,
182                         'systemdisputes'       : true,
183                         'systemdisputeview'    : true,
184                         'override'             : true,
185                         'dealers'              : true,
186                         'systemdealerview'     : true,
187                         'xmlrpcrequestlog'     : true,
188                         'xmlrpccallbacklog'    : true,
189                         'xmlrpcclients'        : true,
190                         'xmlrpcclientview'     : true,
191                         'systemsettings'       : true,
192                         'configview'           : true,
193                         'accessories'          : true,
194                         'damages'              : true,
195                         'increments'           : true,
196                         'groups'               : true,
197                         'divisions'            : true,
198                         'holidays'             : true,
199                         'regionalmanager'      : true,
200                         'opendays'             : true,
201                         'newsletters'          : true,
202                         'newsletterview'       : true,
203                         'reports'              : true,
204                         'smsreport'            : true,
205                         'invreport'            : true,
206                         'auctionreport'        : true,
207                         'hpilogreport'         : true,
208             'hpiaccidentlogreport'         : true,
209                         'pgreport'             : true,
210                         'traderreport'         : true,
211                         'adhreport'            : true,
212                         'loadvssoldreport'     : true,
213                         'loadvssolddetreport'  : true,
214                         'pgfreport'                : true,
215                         'pgsreport'                : true,
216                         'auctionadherence'         : true,
217                         'NoMatch'                          : true,
218                         'priceguideflash'          : true,
219                         'emailreport'          : true,
220                         'loginreport'          : true,
221                         'adminvaluationreport' : true,
222                         'valuationstatreport'  : true,
223                         'auctiontraderreport'  : true,
224                 'historicaldata'       : true
225
226                 },
227                 initialize : function()
228                 {
229                         if( !window.location.hash.length )
230                         {
231                                 window.location.hash = '/';
232                         }
233                         this.setupHashChangeListener();
234                 },
235
236                 setupHashChangeListener : function()
237                 {
238                         if( !( 'onhashchange' in window ) )
239                         {
240                                 this.pollHash();
241                         }
242                         $(window).on('hashchange', $.proxy( this.handleHashChange, this ));
243                 },
244
245                 pollHash : function()
246                 {
247                         var currentHash = window.location.hash;
248                         setInterval( function(){
249                         if( window.location.hash != currentHash )
250                         {
251                                 $(window).trigger('hashchange');
252                                 currentHash = window.location.hash;
253                         }
254                         }, 250);
255                 },
256
257                 handleHashChange : function()
258                 {
259                         var hashLoc = window.location.hash.split("?");
260                         var page = this.routes[hashLoc[0]];
261                         if (this.requireAuth[page] && !App.Authenticated)
262                         {
263                                 App.redirect = window.location.hash;
264                                 window.location.hash = '/login';
265                                 return;
266                         }
267
268             if ('home' == page
269                 && ('cash-cars.local' == window.location.host
270                 || 'cash-cars.nirph.com' == window.location.host
271                 || 'www.wepay4cars.co.za' == window.location.host
272                 || 'wepay4cars.co.za' == window.location.host
273                 || 'www.wepay4cars.co.za' == window.location.host
274                 || 'wepay4cars.co.za' == window.location.host))
275             {
276                 page = 'customervaluation';
277             }
278
279                         if ('home' == page
280                                 && ('namibia.local' == window.location.host
281                                         || 'namibia.nirph.com' == window.location.host
282                                         || 'www.bid4cars.com.na' == window.location.host))
283                         {
284                                 page = 'dealerhome';
285                         }
286                         if (this.requireMenu[page])
287                         {
288                                 $('.is-brochure-menu').hide();
289                                 $('#' + this.requireMenu[page]).show();
290                                 $('#Mobi' + this.requireMenu[page]).show();
291                         }
292                         App.Controller.changePage( page );
293                         $(window).trigger('pageChange');
294                 }
295
296         };
297
298 })();