latest changes requested to remove ID number and date of birth
[namibia] / public / js / app / workspace.js
1 ;(function(){
2
3         //-- Ensure that we have a usable console object so that we don't crash finicky browsers.
4         if (!window.console)
5         {
6                 var names = [
7                             "log", "debug", "info", "warn", "error",
8                             "assert", "dir", "dirxml", "group", "groupEnd", "time",
9                             "timeEnd", "count", "trace", "profile", "profileEnd"
10                     ],
11                     i,
12                     l = names.length,
13                     noOp = function () {};
14                 window.console = {};
15                 for (i = 0; i < l; i = i + 1)
16                 {
17                         window.console[names[i]] = noOp;
18                 }
19         }
20
21         window._w = {
22
23                 itemId    : null,
24                 itemData  : null,
25                 formMeta  : null,
26                 apeLoaded : false,
27                 apeLive   : false,
28                 checkBoxChanged : false,
29
30
31                 onSwitchTemplatePublished : function()
32                 {
33                         $('.navbar li').hide();
34                         $('#su_container').hide();
35                         $('#btnPortal').click(function() {
36                                 _w.initPortal();
37                                 if (App.companyData.group == '' || App.companyData.group == null)
38                                 {
39                                         window.location.hash = '/valuations';
40                                 }
41                                 window.location.hash = '/' + App.companyData.group.landingPage;
42                         });
43                         $('#btnAdmin').click(function() {
44                                 _w.initAdmin();
45                                 window.location.hash = '/admin';
46                         });
47                 },
48
49                 onAdminTemplatePublished : function()
50                 {
51                         // nothing to do here yet, empty landing page for now.
52                 },
53
54                 initBrochure : function()
55                 {
56                         // show brochure menu
57
58                         /*$('#MobiPublicMenu').hide();
59                         $('#MobiBrochureMenu').show();
60                         $('#MobiPortalMenu').remove();*/
61
62                         App.Event.listen(
63                                 'onLoginPageTemplatePublished', 'Controller.Published:login',
64                                 $.proxy( _w.onLoginPageTemplatePublished, this ), 'Recurring'
65                                 );
66                         App.Event.listen(
67                                 'onForgotPageTemplatePublished', 'Controller.Published:forgot',
68                                 $.proxy( _w.onForgotPageTemplatePublished, this ), 'Recurring'
69                                 );
70                         App.Event.listen(
71                                 'onTemplateReady', 'Template.Ready:register',
72                                 $.proxy( _w.register.onTemplateReady, this, 'register' ), 'Recurring'
73                                 );
74                         App.Event.listen(
75                                 'onTemplatePublished', 'Controller.Published:register',
76                                 $.proxy( _w.register.onTemplatePublished, this, 'register' ), 'Recurring'
77                                 );
78
79                         App.Event.listen(
80                                 'onTemplateReady', 'Template.Ready:dealerhome',
81                                 $.proxy( _w.home.onTemplateReady, this, 'dealerhome' ), 'Recurring'
82                                 );
83                         App.Event.listen(
84                                 'onTemplatePublished', 'Controller.Published:dealerhome',
85                                 $.proxy( _w.home.onTemplatePublished, this, 'dealerhome' ), 'Recurring'
86                                 );
87
88                         // Public Valuation
89                         App.Event.listen(
90                                 'onValuationViewTemplateReadyMain', 'Template.Ready:publicvaluation',
91                                 $.proxy( _w.publicvaluation.onValuationViewTemplateReady, this, 'publicvaluation' ), 'Recurring'
92                                 );
93                     App.Event.listen(
94                                 'onValuationViewPublishedMain', 'Controller.Published:publicvaluation',
95                                 $.proxy( _w.publicvaluation.onValuationViewPublished, this, 'publicvaluation' ), 'Recurring'
96                                 );
97
98             App.Event.listen(
99                 'onCustomerValuationViewTemplateReadyMain', 'Template.Ready:customervaluation',
100                 $.proxy( _w.customervaluation.onCustomerValuationViewTemplateReady, this, 'customervaluation' ), 'Recurring'
101             );
102             App.Event.listen(
103                 'onCustomerValuationViewPublishedMain', 'Controller.Published:customervaluation',
104                 $.proxy( _w.customervaluation.onCustomerValuationViewPublished, this, 'customervaluation' ), 'Recurring'
105             );
106
107             App.Event.listen(
108                 'onCustomerCompleteValuationViewTemplateReadyMain', 'Template.Ready:customercompletevaluation',
109                 $.proxy( _w.customercompletevaluation.onCustomerCompleteValuationViewTemplateReady, this, 'customercompletevaluation' ), 'Recurring'
110             );
111             App.Event.listen(
112                 'onCustomerCompleteValuationViewPublishedMain', 'Controller.Published:customercompletevaluation',
113                 $.proxy( _w.customercompletevaluation.onCustomerCompleteValuationViewPublished, this, 'customercompletevaluation' ), 'Recurring'
114             );
115
116                 },
117
118                 initAdmin : function()
119                 {
120
121                         $('#PublicMenu').remove();
122                         $('#MobiPublicMenu').remove();
123                         $('#BrochureMenu').remove();
124                         $('#MobiBrochureMenu').remove();
125                         $('#PortalMenu').show();
126
127                         /*
128                          * Setup permissions
129                          */
130                         App.allowedPages = {};
131                         true == App.permissions.adminPage
132                                 ? $('.b_permissions').show() && (App.allowedPages.permissions = true)
133                                 : $('.b_permissions').hide() && (App.allowedPages.permissions = false);
134
135                         true == App.permissions.adminRegistration
136                                 ? $('.b_registration').show() && (App.allowedPages.registration = true)
137                                 : $('.b_registration').hide() && (App.allowedPages.registration = false);
138
139                         true == App.permissions.adminReport
140                                 ? $('.b_reports').show() && (App.allowedPages.reports = true)
141                                 : $('.b_reports').hide() && (App.allowedPages.reports = false);
142
143                         true == App.permissions.adminDealer
144                                 ? $('.b_dealers').show() && (App.allowedPages.dealers = true)
145                                 : $('.b_dealers').hide() && (App.allowedPages.dealers = false);
146                         true == App.permissions.adminDealer
147                                 ? $('.b_groups').show() && (App.allowedPages.dealers = true)
148                                 : $('.b_groups').hide() && (App.allowedPages.dealers = false);
149                         true == App.permissions.adminDealer
150                                 ? $('.b_divisions').show() && (App.allowedPages.dealers = true)
151                                 : $('.b_divisions').hide() && (App.allowedPages.dealers = false);
152
153                         true == App.permissions.adminCommunication
154                                 ? $('.b_communication').show() && (App.allowedPages.communication = true)
155                                 : $('.b_communication').hide() && (App.allowedPages.communication = false);
156
157                         true == App.permissions.adminSettings
158                                 ? $('.b_systemsettings').show() && (App.allowedPages.systemsettings = true)
159                                 : $('.b_systemsettings').hide() && (App.allowedPages.systemsettings = false);
160
161                         true == App.permissions.adminUser
162                                 ? $('.b_systemusers').show() && (App.allowedPages.systemusers = true)
163                                 : $('.b_systemusers').hide() && (App.allowedPages.systemusers = false);
164
165                         true == App.permissions.adminAuction
166                                 ? $('.b_auctions').show() && (App.allowedPages.systemauctions = true)
167                                 : $('.b_auctions').hide() && (App.allowedPages.systemauctions = false);
168
169                         true == App.permissions.adminPage
170                                 ? $('.b_newsletters').show() && (App.allowedPages.newsletters = true)
171                                 : $('.b_newsletters').hide() && (App.allowedPages.newsletters = false);
172
173
174                         /*
175                          * Setup page listeners.
176                          */
177                         App.Event.listen(
178                                 'onAdminTemplatePublished', 'Controller.Published:admin',
179                                 $.proxy( _w.onAdminTemplatePublished, this, 'admin' ), 'Recurring'
180                                 );
181                         if (true == App.permissions.adminPage)
182                         {
183                                 // Grid
184                                 App.Event.listen(
185                                         'onTemplateReady', 'Template.Ready:userpermissions',
186                                         $.proxy( _w.userpermissions.onTemplateReady, this, 'userpermissions' ), 'Recurring'
187                                         );
188                                 App.Event.listen(
189                                         'onTemplatePublished', 'Controller.Published:userpermissions',
190                                         $.proxy( _w.userpermissions.onTemplatePublished, this, 'userpermissions' ), 'Recurring'
191                                         );
192
193                                 // Edit
194                                 App.Event.listen(
195                                         'onTemplateReady', 'Template.Ready:viewuserpermissions',
196                                         $.proxy( _w.viewuserpermissions.onTemplateReady, this, 'viewuserpermissions' ), 'Recurring'
197                                         );
198                                 App.Event.listen(
199                                         'onTemplatePublished', 'Controller.Published:viewuserpermissions',
200                                         $.proxy( _w.viewuserpermissions.onTemplatePublished, this, 'viewuserpermissions' ), 'Recurring'
201                                         );
202
203                                 // Grid
204                                 App.Event.listen(
205                                         'onTemplateReady', 'Template.Ready:newsletters',
206                                         $.proxy( _w.newsletters.onTemplateReady, this, 'newsletters' ), 'Recurring'
207                                         );
208                                 App.Event.listen(
209                                         'onTemplatePublished', 'Controller.Published:newsletters',
210                                         $.proxy( _w.newsletters.onTemplatePublished, this, 'newsletters' ), 'Recurring'
211                                         );
212
213                                 // Edit
214                                 App.Event.listen(
215                                         'onTemplateReady', 'Template.Ready:newsletterview',
216                                         $.proxy( _w.newsletterview.onTemplateReady, this, 'newsletterview' ), 'Recurring'
217                                         );
218                                 App.Event.listen(
219                                         'onTemplatePublished', 'Controller.Published:newsletterview',
220                                         $.proxy( _w.newsletterview.onTemplatePublished, this, 'newsletterview' ), 'Recurring'
221                                         );
222                                 App.Event.listen(
223                                         'onTemplateDestruct', 'Controller.RemovingPage:newsletterview',
224                                         $.proxy( _w.newsletterview.onTemplateDestruct, this, 'newsletterview' ), 'Recurring'
225                                         );
226                         }
227                         if (true == App.permissions.adminDealer)
228                         {
229                                 // Grid
230                                 App.Event.listen(
231                                         'onTemplateReady', 'Template.Ready:dealers',
232                                         $.proxy( _w.dealers.onTemplateReady, this, 'dealers' ), 'Recurring'
233                                         );
234                                 App.Event.listen(
235                                         'onTemplatePublished', 'Controller.Published:dealers',
236                                         $.proxy( _w.dealers.onTemplatePublished, this, 'dealers' ), 'Recurring'
237                                         );
238
239                                 // Edit
240                                 App.Event.listen(
241                                         'onTemplateReady', 'Template.Ready:systemdealerview',
242                                         $.proxy( _w.systemdealerview.onTemplateReady, this, 'systemdealerview' ), 'Recurring'
243                                         );
244                                 App.Event.listen(
245                                         'onTemplatePublished', 'Controller.Published:systemdealerview',
246                                         $.proxy( _w.systemdealerview.onTemplatePublished, this, 'systemdealerview' ), 'Recurring'
247                                         );
248                         }
249                         if (true == App.permissions.adminSettings)
250                         {
251                                 // XmlRpc Request Grid
252                                 App.Event.listen(
253                                                 'onTemplateReady', 'Template.Ready:xmlrpcrequestlog',
254                                                 $.proxy( _w.xmlrpcrequestlog.onTemplateReady, this, 'xmlrpcrequestlog' ), 'Recurring'
255                                 );
256                                 App.Event.listen(
257                                                 'onTemplatePublished', 'Controller.Published:xmlrpcrequestlog',
258                                                 $.proxy( _w.xmlrpcrequestlog.onTemplatePublished, this, 'xmlrpcrequestlog' ), 'Recurring'
259                                 );
260                                 // XmlRpc Callback Grid
261                                 App.Event.listen(
262                                                 'onTemplateReady', 'Template.Ready:xmlrpccallbacklog',
263                                                 $.proxy( _w.xmlrpccallbacklog.onTemplateReady, this, 'xmlrpccallbacklog' ), 'Recurring'
264                                 );
265                                 App.Event.listen(
266                                                 'onTemplatePublished', 'Controller.Published:xmlrpccallbacklog',
267                                                 $.proxy( _w.xmlrpccallbacklog.onTemplatePublished, this, 'xmlrpccallbacklog' ), 'Recurring'
268                                 );
269                                 // XmlRpc Client Grid
270                                 App.Event.listen(
271                                                 'onTemplateReady', 'Template.Ready:xmlrpcclients',
272                                                 $.proxy( _w.xmlrpcclients.onTemplateReady, this, 'xmlrpcclients' ), 'Recurring'
273                                 );
274                                 App.Event.listen(
275                                                 'onTemplatePublished', 'Controller.Published:xmlrpcclients',
276                                                 $.proxy( _w.xmlrpcclients.onTemplatePublished, this, 'xmlrpcclients' ), 'Recurring'
277                                 );
278                                 // XmlRpc Client Edit
279                                 App.Event.listen(
280                                                 'onTemplateReady', 'Template.Ready:xmlrpcclientview',
281                                                 $.proxy( _w.systemxmlrpcclientview.onTemplateReady, this, 'xmlrpcclientview' ), 'Recurring'
282                                 );
283                                 App.Event.listen(
284                                                 'onTemplatePublished', 'Controller.Published:xmlrpcclientview',
285                                                 $.proxy( _w.systemxmlrpcclientview.onTemplatePublished, this, 'xmlrpcclientview' ), 'Recurring'
286                                 );
287
288                                 // System Config
289                                 App.Event.listen(
290                                         'onTemplateReady', 'Template.Ready:configview',
291                                         $.proxy( _w.configview.onTemplateReady, this, 'configview' ), 'Recurring'
292                                         );
293                                 App.Event.listen(
294                                         'onTemplatePublished', 'Controller.Published:configview',
295                                         $.proxy( _w.configview.onTemplatePublished, this, 'configview' ), 'Recurring'
296                                         );
297
298                                 // Accessories
299                                 App.Event.listen(
300                                         'onTemplateReady', 'Template.Ready:accessories',
301                                         $.proxy( _w.accessories.onTemplateReady, this, 'accessories' ), 'Recurring'
302                                         );
303                                 App.Event.listen(
304                                         'onTemplatePublished', 'Controller.Published:accessories',
305                                         $.proxy( _w.accessories.onTemplatePublished, this, 'accessories' ), 'Recurring'
306                                         );
307
308                                 // Damages
309                                 App.Event.listen(
310                                         'onTemplateReady', 'Template.Ready:damages',
311                                         $.proxy( _w.damages.onTemplateReady, this, 'damages' ), 'Recurring'
312                                         );
313                                 App.Event.listen(
314                                         'onTemplatePublished', 'Controller.Published:damages',
315                                         $.proxy( _w.damages.onTemplatePublished, this, 'damages' ), 'Recurring'
316                                         );
317
318                                 // Increments
319                                 App.Event.listen(
320                                                 'onTemplateReady', 'Template.Ready:increments',
321                                                 $.proxy( _w.increments.onTemplateReady, this, 'increments' ), 'Recurring'
322                                 );
323                                 App.Event.listen(
324                                                 'onTemplatePublished', 'Controller.Published:increments',
325                                                 $.proxy( _w.increments.onTemplatePublished, this, 'increments' ), 'Recurring'
326                                 );
327
328                                 // Groups
329                                 App.Event.listen(
330                                                 'onTemplateReady', 'Template.Ready:groups',
331                                                 $.proxy( _w.groups.onTemplateReady, this, 'groups' ), 'Recurring'
332                                 );
333                                 App.Event.listen(
334                                                 'onTemplatePublished', 'Controller.Published:groups',
335                                                 $.proxy( _w.groups.onTemplatePublished, this, 'groups' ), 'Recurring'
336                                 );
337
338                                 // Divisions
339                                 App.Event.listen(
340                                                 'onTemplateReady', 'Template.Ready:divisions',
341                                                 $.proxy( _w.divisions.onTemplateReady, this, 'divisions' ), 'Recurring'
342                                 );
343                                 App.Event.listen(
344                                                 'onTemplatePublished', 'Controller.Published:divisions',
345                                                 $.proxy( _w.divisions.onTemplatePublished, this, 'divisions' ), 'Recurring'
346                                 );
347
348                                 // Public Holidays
349                                 App.Event.listen(
350                                                 'onTemplateReady', 'Template.Ready:holidays',
351                                                 $.proxy( _w.holidays.onTemplateReady, this, 'holidays' ), 'Recurring'
352                                 );
353                                 App.Event.listen(
354                                                 'onTemplatePublished', 'Controller.Published:holidays',
355                                                 $.proxy( _w.holidays.onTemplatePublished, this, 'holidays' ), 'Recurring'
356                                 );
357
358                                 // Regional Manager
359                                 App.Event.listen(
360                                                 'onTemplateReady', 'Template.Ready:regionalmanager',
361                                                 $.proxy( _w.regionalmanager.onTemplateReady, this, 'regionalmanager' ), 'Recurring'
362                                 );
363                                 App.Event.listen(
364                                                 'onTemplatePublished', 'Controller.Published:regionalmanager',
365                                                 $.proxy( _w.regionalmanager.onTemplatePublished, this, 'regionalmanager' ), 'Recurring'
366                                 );
367
368                                 // Open Days
369                                 App.Event.listen(
370                                                 'onTemplateReady', 'Template.Ready:opendays',
371                                                 $.proxy( _w.opendays.onTemplateReady, this, 'opendays' ), 'Recurring'
372                                 );
373                                 App.Event.listen(
374                                                 'onTemplatePublished', 'Controller.Published:opendays',
375                                                 $.proxy( _w.opendays.onTemplatePublished, this, 'opendays' ), 'Recurring'
376                                 );
377                         }
378                         if (true == App.permissions.adminUser)
379                         {
380                                 // Grid
381                                 App.Event.listen(
382                                         'onTemplateReady', 'Template.Ready:systemusers',
383                                         $.proxy( _w.systemusers.onTemplateReady, this, 'systemusers' ), 'Recurring'
384                                         );
385                                 App.Event.listen(
386                                         'onTemplatePublished', 'Controller.Published:systemusers',
387                                         $.proxy( _w.systemusers.onTemplatePublished, this, 'systemusers' ), 'Recurring'
388                                         );
389
390                                 // Edit
391                                 App.Event.listen(
392                                         'onTemplateReady', 'Template.Ready:systemuserview',
393                                         $.proxy( _w.systemuserview.onTemplateReady, this, 'systemuserview' ), 'Recurring'
394                                         );
395                                 App.Event.listen(
396                                         'onTemplatePublished', 'Controller.Published:systemuserview',
397                                         $.proxy( _w.systemuserview.onTemplatePublished, this, 'systemuserview' ), 'Recurring'
398                                         );
399                                 App.Event.listen(
400                                         'onTemplatePublished', 'Controller.Published:changepinview',
401                                         $.proxy( _w.systemuserview.onTemplatePublished, this, 'changepinview' ), 'Recurring'
402                                         );
403
404                                 // Permissions
405                                 App.Event.listen(
406                                         'onTemplateReady', 'Template.Ready:override',
407                                         $.proxy( _w.override.onTemplateReady, this, 'override' ), 'Recurring'
408                                         );
409                                 App.Event.listen(
410                                         'onTemplatePublished', 'Controller.Published:override',
411                                         $.proxy( _w.override.onTemplatePublished, this, 'override' ), 'Recurring'
412                                         );
413                         }
414                         if (true == App.permissions.adminAuction)
415                         {
416                                 // Grid
417                                 App.Event.listen(
418                                         'onTemplateReady', 'Template.Ready:systemauctions',
419                                         $.proxy( _w.systemauctions.onTemplateReady, this, 'systemauctions' ), 'Recurring'
420                                         );
421                                 App.Event.listen(
422                                         'onTemplatePublished', 'Controller.Published:systemauctions',
423                                         $.proxy( _w.systemauctions.onTemplatePublished, this, 'systemauctions' ), 'Recurring'
424                                         );
425
426                                 // Edit
427                                 App.Event.listen(
428                                         'onTemplateReady', 'Template.Ready:systembidview',
429                                         $.proxy( _w.systembidview.onTemplateReady, this, 'systembidview' ), 'Recurring'
430                                         );
431                                 App.Event.listen(
432                                         'onTemplatePublished', 'Controller.Published:systembidview',
433                                         $.proxy( _w.systembidview.onTemplatePublished, this, 'systembidview' ), 'Recurring'
434                                         );
435
436                                 // Dispute Grid
437                                 App.Event.listen(
438                                         'onTemplateReady', 'Template.Ready:systemdisputes',
439                                         $.proxy( _w.systemdisputes.onTemplateReady, this, 'systemdisputes' ), 'Recurring'
440                                         );
441                                 App.Event.listen(
442                                         'onTemplatePublished', 'Controller.Published:systemdisputes',
443                                         $.proxy( _w.systemdisputes.onTemplatePublished, this, 'systemdisputes' ), 'Recurring'
444                                         );
445
446                                 // Edit Dispute
447                                 App.Event.listen(
448                                         'onTemplateReady', 'Template.Ready:systemdisputeview',
449                                         $.proxy( _w.systemdisputeview.onTemplateReady, this, 'systemdisputeview' ), 'Recurring'
450                                         );
451                                 App.Event.listen(
452                                         'onTemplatePublished', 'Controller.Published:systemdisputeview',
453                                         $.proxy( _w.systemdisputeview.onTemplatePublished, this, 'systemdisputeview' ), 'Recurring'
454                                         );
455                         }
456                 },
457
458                 initPortal : function()
459                 {
460             App.Template.retrieve( 'page', 'valuationview');
461                         /*
462                          * Setup permissions
463                          */
464                         App.allowedPages = {};
465                         App.allowedPages.contact = true;
466                         true == App.permissions.auctionPage
467                                 ? $('.b_auction').show() && (App.allowedPages.auction = true)
468                                 : $('.b_auction').hide() && (App.allowedPages.auction = false);
469
470                         true == App.permissions.stockPage
471                                 ? $('.b_stock').show() && (App.allowedPages.stock = true)
472                                 : $('.b_stock').hide() && (App.allowedPages.stock = false);
473
474                         App.companyData.dealerType == 'Trade Center'
475                                 ? $('.b_tcstock').show() && (App.allowedPages.tcstock = true)
476                                 : $('.b_tcstock').hide() && (App.allowedPages.tcstock = false);
477
478                         true == App.permissions.valuationPage
479                                 ? $('.b_valuations').show() && (App.allowedPages.valuations = true)
480                                 : $('.b_valuations').hide() && (App.allowedPages.valuations = false);
481         
482                  true == App.permissions.historicalPage
483                                 ? $('.b_historicaldata').show() && (App.allowedPages.historicaldata = true)
484                                 : $('.b_historicaldata').hide() && (App.allowedPages.historicaldata = false);
485
486                         true == App.permissions.settingsPage
487                                 ? $('.b_settings').show() && (App.allowedPages.settings = true)
488                                 : $('.b_settings').hide() && (App.allowedPages.settings = false);
489
490                         true == App.permissions.pgPage
491                                 ? $('.b_priceGuide').show() && (App.allowedPages.priceguide = true)
492                                 : $('.b_priceGuide').hide() && (App.allowedPages.priceguide = false);
493
494             //if(true == App.companyData.publicCentre && true == App.permissions.valuationPage && true == App.permissions.valuationCalendar)
495             if(true == App.permissions.valuationCalendar)
496             {
497                 console.log('show b_valuationcalandar');
498
499                 $('.b_valuationCalendar').show();
500
501                 $('.b_valuationCalendar').removeClass('hide');
502
503                 App.Event.listen(
504                     'onValuationCalendarTemplateReady', 'Template.Ready:valuationcalendar',
505                     $.proxy( _w.valuationcalendar.onValuationCalendarTemplateReady, this, 'valuationcalendar' ), 'Recurring'
506                 );
507                 App.Event.listen(
508                     'onValuationCalendarPublished', 'Controller.Published:valuationcalendar',
509                     $.proxy( _w.valuationcalendar.onValuationCalendarPublished, this, 'valuationcalendar' ), 'Recurring'
510                 );
511
512                 App.Event.listen(
513                     'onValuationAppointmentEditTemplateReady', 'Template.Ready:appointmentedit',
514                     $.proxy( _w.appointmentedit.onValuationAppointmentEditTemplateReady, this, 'appointmentedit' ), 'Recurring'
515                 );
516                 App.Event.listen(
517                     'onValuationAppointmentEditPublished', 'Controller.Published:appointmentedit',
518                     $.proxy( _w.appointmentedit.onValuationAppointmentEditPublished, this, 'appointmentedit' ), 'Recurring'
519                 );
520             }
521
522
523                         $('#PublicMenu').remove();
524                         $('#MobiPublicMenu').remove();
525                         $('#BrochureMenu').remove();
526                         $('#MobiBrochureMenu').remove();
527                         $('#PortalMenu').show();
528                         $('#MobiPortalMenu').show();
529
530                         /*
531                          * Setup page listeners.
532                          */
533       if (true == App.permissions.historicalPage)
534                         {
535         App.Event.listen(
536                                         'onHistoricaldataPageTemplateReady', 'Template.Ready:historicaldata',
537                                         $.proxy( _w.historicaldata.onHistoricaldataPageTemplateReady, this, 'historicaldata' ), 'Recurring'
538                                         );
539         App.Event.listen(
540                                         'onHistoricGridPublished', 'Controller.Published:historicaldata',
541                                         $.proxy( _w.historicaldata.onHistoricGridPublished, this, 'historicaldata' ), 'Recurring'
542                                         );
543                                         // Auction History View
544                 App.Event.listen(
545                                         'onHistoryViewTemplateReady', 'Template.Ready:historyview',
546                                         $.proxy( _w.historyview.onHistoryViewTemplateReady, this, 'historyview' ), 'Recurring'
547                                         );
548                                 App.Event.listen(
549                                         'onHistoryViewPublished', 'Controller.Published:historyview',
550                                         $.proxy( _w.historyview.onHistoryViewPublished, this, 'historyview' ), 'Recurring'
551                                         );
552
553          }
554       
555                         if (true == App.permissions.auctionPage)
556                         {
557                                 // Auction Grid
558                                 App.Event.listen(
559                                         'onAuctionPageTemplateReady', 'Template.Ready:auction',
560                                         $.proxy( _w.auction.onAuctionPageTemplateReady, this, 'auction' ), 'Recurring'
561                                         );
562                                 App.Event.listen(
563                                         'onAuctionGridPublished', 'Controller.Published:auction',
564                                         $.proxy( _w.auction.onAuctionGridPublished, this, 'auction' ), 'Recurring'
565                                         );
566                                 App.Event.listen(
567                                         'onAuctionDestruct', 'Controller.RemovingPage:auction',
568                                         $.proxy( _w.auction.onPageDestruct, this, 'auction' ), 'Recurring'
569                                         );
570
571                                 // Auction Bid View
572                                 App.Event.listen(
573                                         'onBidViewTemplateReady', 'Template.Ready:bidview',
574                                         $.proxy( _w.bidview.onBidViewTemplateReady, this, 'bidview' ), 'Recurring'
575                                         );
576                                 App.Event.listen(
577                                         'onBidViewPublished', 'Controller.Published:bidview',
578                                         $.proxy( _w.bidview.onBidViewPublished, this, 'bidview' ), 'Recurring'
579                                         );
580
581                                 // Auction Question View
582                                 App.Event.listen(
583                                                 'onViewTemplateReady', 'Template.Ready:questionview',
584                                                 $.proxy( _w.questionview.onViewTemplateReady, this, 'questionview' ), 'Recurring'
585                                 );
586                                 App.Event.listen(
587                                                 'onViewPublished', 'Controller.Published:questionview',
588                                                 $.proxy( _w.questionview.onViewPublished, this, 'questionview' ), 'Recurring'
589                                 );
590
591                                 // Auction Reply View
592                                 App.Event.listen(
593                                                 'onViewTemplateReady', 'Template.Ready:replyview',
594                                                 $.proxy( _w.replyview.onViewTemplateReady, this, 'replyview' ), 'Recurring'
595                                 );
596                                 App.Event.listen(
597                                                 'onViewPublished', 'Controller.Published:replyview',
598                                                 $.proxy( _w.replyview.onViewPublished, this, 'replyview' ), 'Recurring'
599                                 );
600
601                                 // Auction Retail View
602                                 App.Event.listen(
603                                                 'onViewTemplateReady', 'Template.Ready:retailview',
604                                                 $.proxy( _w.retailview.onViewTemplateReady, this, 'retailview' ), 'Recurring'
605                                 );
606                                 App.Event.listen(
607                                                 'onViewPublished', 'Controller.Published:retailview',
608                                                 $.proxy( _w.retailview.onViewPublished, this, 'retailview' ), 'Recurring'
609                                 );
610                         }
611                         // they dont have rights on auctionPage so buzz off to settings page
612                         else
613                         {
614                                 // Auction Grid
615                                 App.Event.listen(
616                                         'onAuctionPageTemplateReady', 'Template.Ready:auction',
617                                         function(){ window.location.hash = '/settings'; }, 'Recurring'
618                                         );
619                                 App.Event.listen(
620                                         'onAuctionGridPublished', 'Controller.Published:auction',
621                                         function(){ window.location.hash = '/settings'; }, 'Recurring'
622                                         );
623                                 App.Event.listen(
624                                         'onAuctionDestruct', 'Controller.RemovingPage:auction',
625                                         function(){ window.location.hash = '/settings'; }, 'Recurring'
626                                         );
627
628                                 // Auction Bid View
629                                 App.Event.listen(
630                                         'onBidViewTemplateReady', 'Template.Ready:bidview',
631                                         function(){ window.location.hash = '/settings'; }, 'Recurring'
632                                         );
633                                 App.Event.listen(
634                                         'onBidViewPublished', 'Controller.Published:bidview',
635                                         function(){ window.location.hash = '/settings'; }, 'Recurring'
636                                         );
637
638
639                                 // Auction Question View
640                                 App.Event.listen(
641                                                 'onViewTemplateReady', 'Template.Ready:questionview',
642                                                 function(){ window.location.hash = '/settings'; }, 'Recurring'
643                                 );
644                                 App.Event.listen(
645                                                 'onViewPublished', 'Controller.Published:questionview',
646                                                 function(){ window.location.hash = '/settings'; }, 'Recurring'
647                                 );
648
649                                 // Auction Reply View
650                                 App.Event.listen(
651                                                 'onViewTemplateReady', 'Template.Ready:replyview',
652                                                 function(){ window.location.hash = '/settings'; }, 'Recurring'
653                                 );
654                                 App.Event.listen(
655                                                 'onViewPublished', 'Controller.Published:replyview',
656                                                 function(){ window.location.hash = '/settings'; }, 'Recurring'
657                                 );
658
659                                 // Auction Retail View
660                                 App.Event.listen(
661                                                 'onViewTemplateReady', 'Template.Ready:retailview',
662                                                 function(){ window.location.hash = '/settings'; }, 'Recurring'
663                                 );
664                                 App.Event.listen(
665                                                 'onViewPublished', 'Controller.Published:retailview',
666                                                 function(){ window.location.hash = '/settings'; }, 'Recurring'
667                                 );
668
669                         }
670
671
672                         if (App.companyData.dealerType == 'Trade Center')
673                         {
674                                 // TC Stock Grid
675                                 App.Event.listen(
676                                                 'onStockPageTemplateReady', 'Template.Ready:tcstock',
677                                                 $.proxy( _w.tcstock.onStockPageTemplateReady, this, 'tcstock' ), 'Recurring'
678                                 );
679                                 App.Event.listen(
680                                                 'onStockPublished', 'Controller.Published:tcstock',
681                                                 $.proxy( _w.tcstock.onStockPublished, this, 'tcstock' ), 'Recurring'
682                                 );
683                                 App.Event.listen(
684                                                 'onStockDestruct', 'Controller.RemovingPage:tcstock',
685                                                 $.proxy( _w.tcstock.onPageDestruct, this, 'tcstock' ), 'Recurring'
686                                 );
687
688                                 // TC Stock View
689                                 App.Event.listen(
690                                                 'onStockViewTemplateReady', 'Template.Ready:tcstockview',
691                                                 $.proxy( _w.tcstockview.onStockViewTemplateReady, this, 'tcstockview' ), 'Recurring'
692                                 );
693                                 App.Event.listen(
694                                                 'onStockViewPublished', 'Controller.Published:tcstockview',
695                                                 $.proxy( _w.tcstockview.onStockViewPublished, this, 'tcstockview' ), 'Recurring'
696                                 );
697
698                                 // Limited TC Stock View
699                                 App.Event.listen(
700                                         'onStockViewTemplateReady', 'Template.Ready:limitedtcstockview',
701                                         $.proxy( _w.tcstockview.onStockViewTemplateReady, this, 'limitedtcstockview' ), 'Recurring'
702                                         );
703                             App.Event.listen(
704                                         'onStockViewPublished', 'Controller.Published:limitedtcstockview',
705                                         $.proxy( _w.tcstockview.onStockViewPublished, this, 'limitedtcstockview' ), 'Recurring'
706                                         );
707                         }
708                         if (true == App.permissions.stockPage)
709                         {
710                                 // Stock Grid
711                                 App.Event.listen(
712                                                 'onStockPageTemplateReady', 'Template.Ready:stock',
713                                                 $.proxy( _w.stock.onStockPageTemplateReady, this, 'stock' ), 'Recurring'
714                                 );
715                                 App.Event.listen(
716                                                 'onStockPublished', 'Controller.Published:stock',
717                                                 $.proxy( _w.stock.onStockPublished, this, 'stock' ), 'Recurring'
718                                 );
719                                 App.Event.listen(
720                                                 'onStockDestruct', 'Controller.RemovingPage:stock',
721                                                 $.proxy( _w.stock.onPageDestruct, this, 'stock' ), 'Recurring'
722                                 );
723
724                                 // Stock View
725                                 App.Event.listen(
726                                         'onStockViewTemplateReady', 'Template.Ready:stockview',
727                                         $.proxy( _w.stockview.onStockViewTemplateReady, this, 'stockview' ), 'Recurring'
728                                         );
729                             App.Event.listen(
730                                         'onStockViewPublished', 'Controller.Published:stockview',
731                                         $.proxy( _w.stockview.onStockViewPublished, this, 'stockview' ), 'Recurring'
732                                         );
733
734                                 // Limited Stock View
735                                 App.Event.listen(
736                                         'onStockViewTemplateReady', 'Template.Ready:limitedstockview',
737                                         $.proxy( _w.stockview.onStockViewTemplateReady, this, 'limitedstockview' ), 'Recurring'
738                                         );
739                             App.Event.listen(
740                                         'onStockViewPublished', 'Controller.Published:limitedstockview',
741                                         $.proxy( _w.stockview.onStockViewPublished, this, 'limitedstockview' ), 'Recurring'
742                                         );
743                         }
744
745                         if (true == App.permissions.valuationPage)
746                         {
747                                 // Valuation Grid
748                                 App.Event.listen(
749                                         'onValuationPageTemplateReady', 'Template.Ready:valuations',
750                                         $.proxy( _w.valuation.onValuationPageTemplateReady, this, 'valuations' ), 'Recurring'
751                                         );
752                                 App.Event.listen(
753                                         'onValuationsPublished', 'Controller.Published:valuations',
754                                         $.proxy( _w.valuation.onValuationsPublished, this, 'valuations' ), 'Recurring'
755                                         );
756                                 App.Event.listen(
757                                         'onValuationsDestruct', 'Controller.RemovingPage:valuations',
758                                         $.proxy( _w.valuation.onPageDestruct, this, 'valuations' ), 'Recurring'
759                                         );
760
761                                 // Valuation View
762                                 App.Event.listen(
763                                         'onValuationViewTemplateReadyMain', 'Template.Ready:valuationview',
764                                         $.proxy( _w.valuationview.onValuationViewTemplateReady, this, 'valuationview' ), 'Recurring'
765                                         );
766                             App.Event.listen(
767                                         'onValuationViewPublishedMain', 'Controller.Published:valuationview',
768                                         $.proxy( _w.valuationview.onValuationViewPublished, this, 'valuationview' ), 'Recurring'
769                                         );
770
771                                 // Limited Valuation View
772                                 App.Event.listen(
773                                         'onValuationViewTemplateReadyLimited', 'Template.Ready:limitedvaluationview',
774                                         $.proxy( _w.valuationview.onValuationViewTemplateReady, this, 'limitedvaluationview' ), 'Recurring'
775                                         );
776                             App.Event.listen(
777                                         'onValuationViewPublishedLimited', 'Controller.Published:limitedvaluationview',
778                                         $.proxy( _w.valuationview.onValuationViewPublished, this, 'limitedvaluationview' ), 'Recurring'
779                                         );
780                         }
781
782                         if (true == App.permissions.pgPage)
783                         {
784                                 // Price Guide Grid
785                                 App.Event.listen(
786                                         'onPriceGuidePageTemplateReady', 'Template.Ready:priceguide',
787                                         $.proxy( _w.priceguide.onPriceGuidePageTemplateReady, this, 'priceguide' ), 'Recurring'
788                                         );
789                                 App.Event.listen(
790                                         'onPriceGuideGridPublished', 'Controller.Published:priceguide',
791                                         $.proxy( _w.priceguide.onPriceGuideGridPublished, this, 'priceguide' ), 'Recurring'
792                                         );
793                                 App.Event.listen(
794                                         'onPriceGuideDestruct', 'Controller.RemovingPage:priceguide',
795                                         $.proxy( _w.priceguide.onPageDestruct, this, 'priceguide' ), 'Recurring'
796                                         );
797
798                                 // Price Guide Offer View
799                                 App.Event.listen(
800                                         'onOfferViewTemplateReady', 'Template.Ready:offerview',
801                                         $.proxy( _w.offerview.onOfferViewTemplateReady, this, 'offerview' ), 'Recurring'
802                                         );
803                                 App.Event.listen(
804                                         'onOfferViewPublished', 'Controller.Published:offerview',
805                                         $.proxy( _w.offerview.onOfferViewPublished, this, 'offerview' ), 'Recurring'
806                                         );
807                         }
808
809                         if (true == App.permissions.settingsPage)
810                         {
811                                 // Settings
812                                 App.Event.listen(
813                                         'onViewTemplateReady', 'Template.Ready:settings',
814                                         $.proxy( _w.settings.onViewTemplateReady, this, 'settings' ), 'Recurring'
815                                         );
816                             App.Event.listen(
817                                         'onViewPublished', 'Controller.Published:settings',
818                                         $.proxy( _w.settings.onViewPublished, this, 'settings' ), 'Recurring'
819                                         );
820                                 App.Event.listen(
821                                         'onSettingsDestruct', 'Controller.RemovingPage:settings',
822                                         $.proxy( _w.settings.onPageDestruct, this, 'settings' ), 'Recurring'
823                                         );
824
825                             // User View
826                             App.Event.listen(
827                                         'onViewTemplateReady', 'Template.Ready:userview',
828                                         $.proxy( _w.userview.onViewTemplateReady, this, 'userview' ), 'Recurring'
829                             );
830                             App.Event.listen(
831                                         'onViewPublished', 'Controller.Published:userview',
832                                         $.proxy( _w.userview.onViewPublished, this, 'userview' ), 'Recurring'
833                             );
834
835                             // Change pin
836                             App.Event.listen(
837                                         'onViewTemplateReady', 'Template.Ready:changepinview',
838                                         $.proxy( _w.changepinview.onViewTemplateReady, this, 'changepinview' ), 'Recurring'
839                             );
840                             App.Event.listen(
841                                         'onViewPublished', 'Controller.Published:changepinview',
842                                         $.proxy( _w.changepinview.onViewPublished, this, 'changepinview' ), 'Recurring'
843                             );
844
845                             // Dealer View
846                             App.Event.listen(
847                                         'onViewTemplateReady', 'Template.Ready:dealerview',
848                                         $.proxy( _w.dealerview.onViewTemplateReady, this, 'dealerview' ), 'Recurring'
849                             );
850                             App.Event.listen(
851                                         'onViewPublished', 'Controller.Published:dealerview',
852                                         $.proxy( _w.dealerview.onViewPublished, this, 'dealerview' ), 'Recurring'
853                             );
854
855                             // Membership View
856                             App.Event.listen(
857                                         'onViewTemplateReady', 'Template.Ready:membershipview',
858                                         $.proxy( _w.membershipview.onViewTemplateReady, this, 'membershipview' ), 'Recurring'
859                             );
860                             App.Event.listen(
861                                         'onViewPublished', 'Controller.Published:membershipview',
862                                         $.proxy( _w.membershipview.onViewPublished, this, 'membershipview' ), 'Recurring'
863                             );
864
865                             // Club View
866                             App.Event.listen(
867                                         'onViewTemplateReady', 'Template.Ready:clubview',
868                                         $.proxy( _w.clubview.onViewTemplateReady, this, 'clubview' ), 'Recurring'
869                             );
870                             App.Event.listen(
871                                         'onViewPublished', 'Controller.Published:clubview',
872                                         $.proxy( _w.clubview.onViewPublished, this, 'clubview' ), 'Recurring'
873                             );
874
875                             // Club Member View
876                             App.Event.listen(
877                                         'onViewTemplateReady', 'Template.Ready:memberview',
878                                         $.proxy( _w.memberview.onViewTemplateReady, this, 'memberview' ), 'Recurring'
879                             );
880                             App.Event.listen(
881                                         'onViewPublished', 'Controller.Published:memberview',
882                                         $.proxy( _w.memberview.onViewPublished, this, 'memberview' ), 'Recurring'
883                             );
884
885                             // User View
886                             App.Event.listen(
887                                         'onViewTemplateReady', 'Template.Ready:disputeview',
888                                         $.proxy( _w.disputeview.onViewTemplateReady, this, 'disputeview' ), 'Recurring'
889                             );
890                         }
891
892
893                         /*
894                          * SU filters
895                          */
896                         if(true == App.permissions.suAccess)
897                         {
898                                 App.DataStore.loadSelectListData('sugroups', true, 'Company', 'Group.SelectList');
899                             App.DataStore.setData('sudivisions', []);
900                             App.DataStore.setData('sucompanies', []);
901                             var sugroupMeta = {
902                                                 type        : 'select',
903                                                 id          : 'sugroup',
904                                                 selectEmpty : 'All',
905                                                 dataStoreId : 'sugroups',
906                                                 value       : false == App.permissions.suGroupFull
907                                                                                 ? App.companyData.group.id
908                                                                                 : (App.Sudo && App.Sudo.GroupId ? App.Sudo.GroupId : ''),
909                                                 onChange    : function () {
910                                                         if (!App.DataStore.getItem('BuildSelect:sugroup', false))
911                                                         {
912                                                                 if (true == App.permissions.suGroupFull)
913                                                             {
914                                                                         var leVal = $(this).val();
915
916                                                                         if ("" == leVal)
917                                                                         {
918                                                                                 App.DataStore.setData('sudivisions', []);
919                                                                                 App.DataStore.setData('sucompanies', []);
920                                                                                 $('#x_sudivision').hide();
921                                                                                 $('#x_sucompany').hide();
922                                                                         }
923                                                                         else
924                                                                         {
925                                                                                 App.DataStore.loadSelectListData(
926                                                                                                 'sudivisions', false, 'Company', 'GroupDivision.SelectList',
927                                                                                                 null, {Filter:{group:$(this).val()}}
928                                                                                                 );
929                                                                                 App.DataStore.setData('sucompanies', []);
930                                                                                 $('#sudivision').selectpicker('val', "");
931                                                                                 $('#sucompany').selectpicker('val', "");
932                                                                                 $('#x_sudivision').show();
933                                                                                 $('#x_sucompany').hide();
934                                                                         }
935
936                                                                         var leVal = '' == $(this).val() ? 0 : $(this).val();
937                                                                         App.API.execTask(
938                                                                                         'setSu', {Sudo:{Group:leVal}}, {},
939                                                                                         function(){
940                                                                                                 App.Event.trigger('SuChange', {});
941                                                                                                 App.DataStore.loadSelectListGroup([
942                                                                                                   {dataId: 'sales', isStatic: false, workspace: 'User', task: 'Profile.SalesList'},
943                                                                                                   {dataId: 'managers', isStatic: false, workspace: 'User', task: 'Profile.ManagerList'},
944                                                                                                 ]);
945                                                                                         }, _w.taskExecError
946                                                                                 );
947                                                             }
948
949
950                                                         }
951                                                         else
952                                                         {
953                                                                 if ("" != $(this).val())
954                                                                 {
955                                                                         App.DataStore.loadSelectListData(
956                                                                                         'sudivisions', false, 'Company', 'GroupDivision.SelectList',
957                                                                                         null, {Filter:{group:$(this).val()}}
958                                                                                         );
959                                                                         $('#x_sudivision').show();
960                                                                 }
961                                                         }
962                                                 }
963                                         };
964
965                             var sudivisionMeta = {
966                                                 type        : 'select',
967                                                 id          : 'sudivision',
968                                                 selectEmpty : 'All',
969                                                 dataStoreId : 'sudivisions',
970                                                 value       : false == App.permissions.suGroupFull && false == App.permissions.suDivisionFull
971                                                                                         ? (null != App.companyData.groupDivision ? App.companyData.groupDivision.id : null)
972                                                                                         : (App.Sudo && App.Sudo.DivisionId ? App.Sudo.DivisionId : ''),
973                                                 onChange    : function () {
974                                                         if (!App.DataStore.getItem('BuildSelect:sudivision', false))
975                                                         {
976
977                                                                 if (true == App.permissions.suGroupFull
978                                                                                 || true == App.permissions.suDivisionFull)
979                                                                 {
980                                                                         var leVal = $(this).val();
981
982                                                                         if ("" == leVal)
983                                                                         {
984                                                                                 App.DataStore.setData('sucompanies', []);
985                                                                                 $('#x_sucompany').hide();
986                                                                         }
987                                                                         else
988                                                                         {
989                                                                                 App.DataStore.loadSelectListData(
990                                                                                                 'sucompanies', false, 'Company', 'Company.SelectList',
991                                                                                                 null, {Filter:{groupDivision:$(this).val()}}
992                                                                                                 );
993                                                                                 $('#x_sucompany').show();
994                                                                                 $('#sucompany').selectpicker('val', "");
995                                                                         }
996
997                                                                         var leVal = '' == $(this).val() ? 0 : $(this).val();
998                                                                         App.API.execTask(
999                                                                                         'setSu', {Sudo:{Division:leVal}}, {},
1000                                                                                         function(){
1001                                                                                                 App.Event.trigger('SuChange', {});
1002                                                                                                 App.DataStore.loadSelectListGroup([
1003                                                                                                   {dataId: 'sales', isStatic: false, workspace: 'User', task: 'Profile.SalesList'},
1004                                                                                                   {dataId: 'managers', isStatic: false, workspace: 'User', task: 'Profile.ManagerList'},
1005                                                                                                 ]);
1006                                                                                         }, _w.taskExecError
1007                                                                                 );
1008                                                                 }
1009
1010
1011                                                         }
1012                                                         else
1013                                                         {
1014                                                                 if("" != $(this).val())
1015                                                                 {
1016                                                                         App.DataStore.loadSelectListData(
1017                                                                                         'sucompanies', false, 'Company', 'Company.SelectList',
1018                                                                                         null, {Filter:{groupDivision:$(this).val()}}
1019                                                                                         );
1020                                                                         $('#x_sucompany').show();
1021                                                                 }
1022                                                         }
1023                                                 }
1024                                         };
1025
1026                             var sucompanyMeta = {
1027                                                 type        : 'select',
1028                                                 id          : 'sucompany',
1029                                                 selectEmpty : 'All',
1030                                                 dataStoreId : 'sucompanies',
1031                                                 value       : false == App.permissions.suGroupFull
1032                                                                                 && false == App.permissions.suDivisionFull
1033                                                                                 && false == App.permissions.suCompanyFull
1034                                                         ? App.companyData.id
1035                                                         : (App.Sudo && App.Sudo.CompanyId ? App.Sudo.CompanyId : ''),
1036                                                 onChange    : function () {
1037                                                         if (!App.DataStore.getItem('BuildSelect:sucompany', false))
1038                                                         {
1039                                                                 if (true == App.permissions.suGroupFull
1040                                                                                 || true == App.permissions.suDivisionFull
1041                                                                                 || true == App.permissions.suCompanyFull)
1042                                                                 {
1043                                                                         var leVal = '' == $(this).val() ? 0 : $(this).val();
1044                                                                         App.API.execTask(
1045                                                                                         'setSu', {Sudo:{Company:leVal}}, {},
1046                                                                                         function(){
1047                                                                                                 App.Event.trigger('SuChange', {});
1048                                                                                                 App.DataStore.loadSelectListGroup([
1049                                                                                                   {dataId: 'sales', isStatic: false, workspace: 'User', task: 'Profile.SalesList'},
1050                                                                                                   {dataId: 'managers', isStatic: false, workspace: 'User', task: 'Profile.ManagerList'},
1051                                                                                                 ]);
1052                                                                                         }, _w.taskExecError
1053                                                                                 );
1054                                                                 }
1055                                                         }
1056                                                 }
1057                                         };
1058
1059                             $('#x_sugroup').html(App.ElementLibrary.Field.html(sugroupMeta, null));
1060                             App.ElementLibrary.Field.bind( 'x', sugroupMeta );
1061                             if (false == App.permissions.suGroupFull)
1062                             {
1063                                 $('#sugroup').attr('disabled', true);
1064                             }
1065
1066                             $('#x_sudivision').html(App.ElementLibrary.Field.html(sudivisionMeta, null));
1067                             App.ElementLibrary.Field.bind( 'x', sudivisionMeta );
1068                             if (false == App.permissions.suGroupFull
1069                                         && false == App.permissions.suDivisionFull)
1070                             {
1071                                 $('#sudivision').attr('disabled', true);
1072                             }
1073
1074                             $('#x_sucompany').html(App.ElementLibrary.Field.html(sucompanyMeta, null));
1075                             App.ElementLibrary.Field.bind( 'x', sucompanyMeta );
1076                             if (false == App.permissions.suGroupFull
1077                                         && false == App.permissions.suDivisionFull
1078                                         && false == App.permissions.suCompanyFull)
1079                             {
1080                                 $('#sucompany').attr('disabled', true);
1081                             }
1082
1083                             $('#x_sudivision').hide();
1084                                 $('#x_sucompany').hide();
1085                                 $('#su_container').show();
1086                         }
1087                 },
1088
1089                 filterIfnotEmpty : function( filter, element, field, op, append, defaultValue )
1090                 {
1091                         append = (append)
1092                                 ? append
1093                                 : '';
1094                         if ('' != $('#' + element).val() && null != $('#' + element).val())
1095                         {
1096                                 op = op ? op + ' ' : '';
1097                                 var val = $('#' + element).val();
1098
1099                                 if ($('#' + element).hasClass('selectpicker'))
1100                                 {
1101                                         op = '';
1102                                 }
1103                                 else
1104                                 {
1105                                         //val = ('' == val || !isNaN(val) || '' != op)
1106                                         //      ? val
1107                                         //      : '%' + val + '%';
1108
1109                     val = ('' == val || '' != op)
1110                         ? val
1111                         : '%' + val + '%';
1112                                 }
1113                                 if (filter.filters[field])
1114                                 {
1115                                         var nested = {};
1116                                         nested[field] = op + val + append;
1117                                         filter.filters[field + '-to'] = nested;
1118                                 }
1119                                 else
1120                                 {
1121                                         filter.filters[field] = op + val + append;
1122                                 }
1123                                 filter.count++;
1124                         }
1125                         return filter;
1126                 },
1127
1128                 populateFilters : function( filters, map )
1129                 {
1130                         for (var field in map)
1131                         {
1132                                 var nested = field.split(':');
1133                                 if (nested[1])
1134                                 {
1135                                         if (filters[nested[0]] && filters[nested[0]][nested[1]])
1136                                         {
1137                                                 filters[field] = isNaN(filters[nested[0]][nested[1]]) && '%' == filters[nested[0]][nested[1]].substring(0,1)
1138                                                         ? filters[nested[0]][nested[1]].substring(1, filters[nested[0]][nested[1]].length - 1)
1139                                                         : filters[nested[0]][nested[1]];
1140                                                 $('#' + map[field]).val(filters[field]);
1141                                                 $('#' + map[field] + '.selectpicker').selectpicker('refresh');
1142                                         }
1143                                 }
1144                                 else if (filters[field])
1145                                 {
1146                                         filters[field] = isNaN(filters[field]) && '%' == filters[field].substring(0,1)
1147                                                 ? filters[field].substring(1, filters[field].length - 1)
1148                                                 : filters[field];
1149                                         $('#' + map[field]).val(filters[field]);
1150                                         $('#' + map[field] + '.selectpicker').selectpicker('refresh');
1151                                 }
1152                         }
1153                 },
1154
1155                 taskContractError : function( response )
1156                 {
1157                         App.API.getTask(
1158                                         'getActiveAccount', 'User', 'Profile.ActiveAccount', null,
1159                                         {}, function() {
1160                                                 if ('namibia.nirph.com' != window.location.hostname
1161                                                                 && 'namibia.local' != window.location.hostname
1162                                                                 && 'www.bid4cars.com.na' != window.location.hostname)
1163                                                 {
1164                                                         alert('Please click ok to refresh this page.');
1165                                                         location.reload();
1166                                                 }
1167                                                 console.log('------------ Task Contract Error ------------');
1168                                                 console.log(response);
1169                                                 console.log('--------------------------------------');
1170                                         },_w.onActiveAccountFailure
1171                         );
1172
1173                 },
1174
1175                 taskExecError : function( response )
1176                 {
1177                         App.API.getTask(
1178                                         'getActiveAccount', 'User', 'Profile.ActiveAccount', null,
1179                                         {}, function() {
1180                                                 if ('namibia.nirph.com' != window.location.hostname
1181                                                                 && 'namibia.local' != window.location.hostname
1182                                                                 && 'www.bid4cars.com.na' != window.location.hostname)
1183                                                 {
1184                                                         alert('Please click ok to refresh this page.');
1185                                                         location.reload();
1186                                                 }
1187                                                 console.log('------------ Task Exec Error ------------');
1188                                                 console.log(response);
1189                                                 console.log('--------------------------------------');
1190                                         }, _w.onActiveAccountFailure
1191                         );
1192                 },
1193
1194                 onForgotPageTemplatePublished : function( event, eventData )
1195                 {
1196                         $('#email').val(App.Util.getCookie('UserEmail', ''));
1197                         $('#frmReset').validate({
1198                                 rules: {
1199                                         email: {
1200                                                 email: true
1201                                         },
1202                                         mobile: {
1203                                                 mobile: true
1204                                         }
1205                                 },
1206                                 submitHandler: function( form ) {
1207                                         if ('' == $('#email').val() && '' == $('#mobile').val())
1208                                         {
1209                                                 alert('Please provide email or mobile number.');
1210                                                 return;
1211                                         }
1212                                         App.API.getTask(
1213                                                         'reset', 'User', 'Profile.ForgotPassword', null,
1214                                                         {}, function() {
1215                                                                 var mobile = $('#mobile').val();
1216                                                                 mobile = ('' == mobile)
1217                                                                         ? ''
1218                                                                         : '+264' + mobile;
1219                                                                 var data = {
1220                                                                         "Reset":{
1221                                                                             "email"  : $('#email').val(),
1222                                                                             "mobile" : mobile
1223                                                                   }};
1224                                                                 App.API.execTask(
1225                                                                         'reset', data, {},
1226                                                                         function(response) {
1227                                                                                 $('#reset-fail').popover('hide');
1228                                                                                 alert('Please check your email for your new pin.');
1229                                                                                 window.location = '/#/login';
1230                                                                         }, function (data) {
1231                                                                                 $('#reset-fail').attr('data-content', data.Message);
1232                                                                                 $('#reset-fail').popover('show');
1233                                                                         }
1234                                                                 );
1235                                                         }, _w.taskContractError
1236                                         );
1237                                 }
1238                         });
1239                 },
1240
1241                 onLoginPageTemplatePublished : function( event, eventData )
1242                 {
1243                         App.Util.updateCheckboxStyles($('#frmLogin'));
1244                         $('#email').val(App.Util.getCookie('UserEmail', ''));
1245                         $('#frmLogin').validate({
1246                                 rules: {
1247                                         email: {
1248                                                 email: true,
1249                                                 required: true
1250                                         },
1251                                         pin: {
1252                                                 minlength: 3,
1253                                                 required: true
1254                                         },
1255                                         mpin: {
1256                                                 minlength: 3,
1257                                                 required: true
1258                                         }
1259                                 },
1260                                 submitHandler: function( form ) {
1261                                         App.API.getTask(
1262                                                         'login', 'User', 'Profile.Login', null,
1263                                                         {}, function() {
1264                                                                 var data = {
1265                                                                         "Login":{
1266                                                                             "email"      : $('#email').val(),
1267                                                                             "pin"        : $('#pin').val()
1268                                                                   }};
1269                                                                 App.API.execTask(
1270                                                                         'login', data, {},
1271                                                                         function(response) {
1272                                                                                 $('#login-fail').popover('hide');
1273                                                                                 var rem = $('#rememberMe').is(':checked')
1274                                                                                         ? $('#email').val()
1275                                                                                         : '';
1276                                                                                 App.Util.setCookie('UserEmail', rem, 30);
1277                                                                                 _w.onActiveAccount(response);
1278                                                                         }, function (data) {
1279                                                                                 $('#login-fail').attr('data-content', data.StatusReason);
1280                                                                                 $('#login-fail').popover('show');
1281                                                                         }
1282                                                                 );
1283                                                         }, _w.taskContractError
1284                                         );
1285                                 }
1286                         });
1287                 },
1288
1289                 synchServerTime : function()
1290                 {
1291                         var dt = new Date();
1292                         App.timeDiffStart = Math.round(dt.getTime() / 1000) + 1;
1293                         $.ajax({
1294                                 type            : 'GET',
1295                                 dataType        : 'json',
1296                                 url             : window.location.protocol
1297                                                         + '//' + window.location.hostname
1298                                                         + '//servertime.php?v=' + dt.getTime()
1299                         })
1300                         .done( function(data) {
1301                                 var dt = new Date();
1302                                 var now = Math.round(dt.getTime() / 1000);
1303                                 if ((now - App.timeDiffStart) < 4)
1304                                 {
1305                                         App.timeDiff = now - data.time;
1306                                         setTimeout(_w.synchServerTime, 600000);
1307                                 }
1308                                 else
1309                                 {
1310                                         setTimeout(_w.synchServerTime, 5000);
1311                                 }
1312                         });
1313                 },
1314
1315                 onActiveAccount : function( response )
1316                 {
1317                         /*
1318                          * Request list of public holidays.
1319                          */
1320                         $('#login_mobi').hide();
1321                         App.API.getTask(
1322                                         'listPublicHoliday', 'Auction', 'PublicHoliday.List', null,
1323                                         {}, function() {
1324                                                 App.API.execTask(
1325                                                                 'listPublicHoliday', {}, {},
1326                                                                 function(response) {
1327                                                                         App.DataStore.setData('publicHolidays', response.Data);
1328                                                                 }, _w.taskExecError
1329                                                                 );
1330                                         }, _w.taskContractError
1331                                         );
1332
1333                         /*
1334                          * User is authenticated.
1335                          */
1336                         App.Authenticated = true;
1337                         App.serverConfig = response.Data.config;
1338                         delete response.Data.config;
1339                         App.permissions = response.Data.permissions;
1340                         delete response.Data.permissions;
1341                         App.companyData = response.Data.company;
1342                         App.companyData.tC = App.companyData.tradeCenter && App.companyData.tradeCenter.id
1343                                 ? App.companyData.tradeCenter.id
1344                                 : false;
1345                         delete response.Data.company;
1346                         App.Sudo = response.Data.Sudo;
1347                         delete response.Data.Sudo;
1348                         App.userData = response.Data;
1349
1350                         //console.log("serverConfig", App.serverConfig);
1351                         //console.log("permissions", App.permissions);
1352                         //console.log("companyData", App.companyData);
1353                         //console.log("Sudo", App.Sudo);
1354                         //console.log("userData", App.userData);
1355
1356
1357                         App.openDays = response.Data.auctionOpenDays;
1358                         delete response.Data.auctionOpenDays;
1359                         if ('Auction Buyer' == App.permissions.name
1360                                 || 'Auction Buyer & Seller' == App.permissions.name)
1361                         {
1362                                 if (App.companyData.group != null){
1363                                         App.companyData.group.landingPage = 'auction';
1364                                 }
1365
1366                         }
1367                         if ('Auction Buyer' == App.permissions.name
1368                                 || 'Auction Buyer & Seller' == App.permissions.name)
1369                         {
1370                                 App.isNewAuctionUser = true;
1371                         }
1372
1373
1374                         /*
1375                          * Show and hook up logout button
1376                          */
1377                         $('.b_logout').show();
1378                         $('.b_logout').click(function()
1379                         {
1380
1381                                 $('#PortalMenu').remove();
1382
1383                                 App.Authenticated = false;
1384                                 App.permissions = {};
1385                                 App.companyDat  = {};
1386                                 App.Sudo        = {};
1387                                 App.userData    = {};
1388                                 App.API.getTask(
1389                                                 'logout:', 'User', 'Profile.Logout', null,
1390                                                 {}, function() { window.location='/'; }, function() {}
1391                                         );
1392                         });
1393
1394                         /*
1395                          * Show user details
1396                          */
1397                         $('#user-details').removeClass('invisible');
1398                         $('.auth-username').html(
1399                                         App.userData.firstName + ' ' + App.userData.familyName
1400                         );
1401                         $('.auth-name').html(
1402                                         App.userData.firstName
1403                         );
1404
1405                         /*
1406                          * Init permissions and page listeners.
1407                          */
1408                         var isMobile = 'none' == $('#mobiCheck').css('display');
1409                         if (true == App.permissions.accessPortalModule
1410                                         && false == App.permissions.accessAdminModule)
1411                         {
1412                                 _w.initPortal();
1413
1414                                 if (null == App.userData.lastLogin || '' == App.userData.lastLogin)
1415                                 {
1416                                         window.location.hash = '/changepinview?id=' + App.userData.id;
1417                                 }
1418                                 else if (App.redirect && '' != App.redirect && '#/' != App.redirect)
1419                                 {
1420                                         window.location =  '/' + App.redirect;
1421                                         delete App.redirect;
1422                                 }
1423                                 else
1424                                 {
1425
1426                                         // check for mobi redirect here
1427
1428                                         if (isMobile)
1429                                         {
1430
1431                                                 // if permissions are ok show the buttons
1432                                                 if (false == App.permissions.valuationPage)
1433                                                 {
1434                                                         $("#mobiValuationsBtn").remove();
1435                                                 }
1436                                                 if (false == App.permissions.pgPage)
1437                                                 {
1438                                                         $("#mobiPriceGuideBtn").remove();
1439                                                 }
1440                                                 if (false == App.permissions.auctionPage)
1441                                                 {
1442                                                         $("#mobiAuctionBtn").remove();
1443                                                 }
1444
1445                                                 // do a redirect to valid pages
1446                                                 if (App.permissions.valuationPage)
1447                                                 {
1448                                                         window.location.hash = '/valuations';
1449                                                 }
1450                                                 else if (App.permissions.pgPage )
1451                                                 {
1452                                                         window.location.hash = '/priceguide';
1453                                                 }
1454                                                 else if (App.permissions.auctionPage)
1455                                                 {
1456                                                         window.location.hash = '/auction';
1457                                                 }
1458
1459                                                 else
1460                                                 {
1461                                                         alert("Sorry you dont have any mobi permissions");
1462                                                         App.Authenticated = false;
1463                                                         App.permissions = {};
1464                                                         App.companyDat  = {};
1465                                                         App.Sudo        = {};
1466                                                         App.userData    = {};
1467                                                         App.API.getTask(
1468                                                                         'logout:', 'User', 'Profile.Logout', null,
1469                                                                         {}, function() { window.location='/'; }, function() {}
1470                                                                 );
1471                                                 }
1472                                         }
1473
1474                                         else
1475                                         {
1476
1477                                                 if (App.companyData.group == null)
1478                                                 {
1479
1480                                                         window.location.hash = '/settings';
1481
1482                                                 }
1483
1484
1485
1486                                                 else if (false == App.permissions.valuationPage && 'valuations' == App.companyData.group.landingPage)
1487                                                 {
1488                                                         window.location.hash = '/settings';
1489                                                 }
1490                                                 else if (false == App.permissions.pgPage && 'priceguide' == App.companyData.group.landingPage)
1491                                                 {
1492                                                         window.location.hash = '/settings';
1493                                                 }
1494                                                 else if (false == App.permissions.auctionPage && 'auction' == App.companyData.group.landingPage)
1495                                                 {
1496                                                         window.location.hash = '/settings';
1497                                                 }
1498                                                 else if ('' != App.companyData.group.landingPage && null != App.companyData.group.landingPage)
1499                                                 {
1500                                                         window.location.hash = '/' + App.companyData.group.landingPage;
1501                                                 }
1502                                                 else if (null == App.companyData.group.landingPage)
1503                                                 {
1504                                                         window.location.hash = '/settings';
1505                                                 }
1506                                                 else
1507                                                 {
1508                                                         window.location.hash = '/settings';
1509                                                 }
1510
1511                                         }
1512                                 }
1513                         }
1514                         else if (false == App.permissions.accessPortalModule
1515                                         && true == App.permissions.accessAdminModule)
1516                         {
1517                                 _w.initAdmin();
1518                                 if ('namibia.local' != window.location.hostname)
1519                                 {
1520                                         window.location.hash = '/admin';
1521                                 }
1522                                 else
1523                                 {
1524                                         if(App.redirect)
1525                                         {
1526                                                 window.location =  '/' + App.redirect;
1527                                                 delete App.redirect;
1528                                         }
1529                                         else
1530                                         {
1531                                                 window.location.hash = '/admin';
1532                                         }
1533                                 }
1534                         }
1535                         else if (true == App.permissions.accessPortalModule
1536                                         && true == App.permissions.accessAdminModule)
1537                         {
1538                                 App.Event.listen(
1539                                         'onSwitchTemplatePublished', 'Controller.Published:switch',
1540                                         $.proxy( _w.onSwitchTemplatePublished, this ), 'Recurring'
1541                                         );
1542                                 window.location.hash = '/switch';
1543                         }
1544                         else
1545                         {
1546                                 // No permissions at all
1547                                 window.location.hash = '/home';
1548                         }
1549                         _w.synchServerTime();
1550
1551                 },
1552
1553                 onActiveAccountFailure : function()
1554                 {
1555                         /*
1556                          * User is not authenticated.
1557                          */
1558                         App.Authenticated = false;
1559                         $('#login_mobi').show();
1560
1561                         /*
1562                          * Hide nav
1563                          */
1564                         $('#b_logout').hide();
1565                         $('#b_stock').hide();
1566                         $('#b_tcstock').hide();
1567                         $('#b_valuations').hide();
1568                 $('#b_historicaldata').hide();
1569                         $('#b_settings').hide();
1570                         $('#b_priceGuide').hide();
1571
1572                         /*
1573                          * Hide user details
1574                          */
1575                         $('#user-details').addClass("invisible");
1576
1577                         /*
1578                          * Initiate brochure.
1579                          */
1580                         _w.initBrochure();
1581
1582                         _w.synchServerTime();
1583
1584                 }
1585
1586         };
1587
1588 })();