forked from CommerceRack/anycommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
executable file
·3485 lines (3029 loc) · 136 KB
/
controller.js
File metadata and controls
executable file
·3485 lines (3029 loc) · 136 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* **************************************************************
Copyright 2011 Zoovy, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
************************************************************** */
var zController = function(params) {
this.u.dump('zController has been instantiated');
if(typeof Prototype == 'object') {
alert("Oh No! you appear to have the prototype ajax library installed. This library is not compatible. Please change to a non-prototype theme (2011 series).");
}
//zglobals is not required in the UI, but is for any
else if(typeof zGlobals != 'object' && !app.vars.thisSessionIsAdmin) {
//zGlobals not required in an admin session.
alert("Uh Oh! A required include (config.js) is not present. This document is required.");
}
else {
this.initialize(params);
}
}
jQuery.extend(zController.prototype, {
initialize: function(P) {
this.u.dump(" -> initialize executed.");
// app = this;
// this.u.dump(P);
app = $.extend(true,P,this); //deep extend to make sure nexted functions are preserved. If duplicates, 'this' will override P.
app.model = zoovyModel(); // will return model as object. so references are app.model.dispatchThis et all.
app.vars = app.vars || {};
app.vars.platform = P.platform ? P.platform : 'webapp'; //webapp, ios, android
app.vars.cid = null; //gets set on login. ??? I'm sure there's a reason why this is being saved outside the normal object. Figure it out and document it.
app.vars.fbUser = {};
app.vars.protocol = document.location.protocol == 'https:' ? 'https:' : 'http:';
app.handleSession(); //get existing session or create a new one.
//used in conjunction with support/admin login. nukes entire local cache.
if(app.u.getParameterByName('flush') == 1) {
app.u.dump("URI param flush is true. CLEAR LOCAL STORAGE");
localStorage.clear();
}
app.vars.debug = app.u.getParameterByName('debug'); //set a var for this so the URI doesn't have to be checked each time.
//in some cases, such as the zoovy UI, zglobals may not be defined. If that's the case, certain vars, such as jqurl, must be passed in via P in initialize:
if(typeof zGlobals == 'object') {
app.vars.profile = zGlobals.appSettings.profile.toUpperCase();
app.vars.username = zGlobals.appSettings.username.toLowerCase();
//need to make sure the secureURL ends in a / always. doesn't seem to always come in that way via zGlobals
app.vars.secureURL = zGlobals.appSettings.https_app_url;
app.vars.domain = zGlobals.appSettings.sdomain;
if('https:' == app.vars.protocol) {app.vars.jqurl = zGlobals.appSettings.https_api_url;}
else {app.vars.jqurl = zGlobals.appSettings.http_api_url}
}
// can be used to pass additional variables on all request and that get logged for certain requests (like createOrder).
// default to blank, not 'null', or += below will start with 'undefined'.
//vars should be passed as key:value; _v will start with zmvc:version.release.
app.vars.passInDispatchV = '';
app.vars.release = app.vars.release || 'unspecified'; //will get overridden if set in P. this is default.
// += is used so that this is appended to anything passed in P.
app.vars.passInDispatchV += 'browser:'+app.u.getBrowserInfo()+";OS:"+app.u.getOSInfo()+';'; //passed in model as part of dispatch Version. can be app specific.
app.ext = app.ext || {}; //for holding extensions
app.data = {}; //used to hold all data retrieved from ajax requests.
/*
app.templates holds a copy of each of the templates declared in an extension but defined in the view.
copying the template into memory was done for two reasons:
1. faster reference when template is needed.
2. solve any duplicate 'id' issues within the spec itself when original spec and cloned template are present.
-> this solution was selected over adding a var for subbing in the templates because the interpolation was thought to be too heavy.
*/
app.templates = {};
//queues are arrays, not objects, because order matters here. the model.js file outlines what each of these is used for.
app.q = {mutable : new Array(), passive: new Array(), immutable : new Array()};
app.globalAjax = {
dataType : 'json',
overrideAttempts : 0, //incremented when an override occurs. allows for a cease after X attempts.
lastDispatch : null, //timestamp.
passiveInterval : setInterval(function(){app.model.dispatchThis('passive')},5000), //auto-dispatch the passive q every five seconds.
numRequestsPerPipe : 50,
requests : {"mutable":{},"immutable":{},"passive":{}} //'holds' each ajax request. completed requests are removed.
}; //holds ajax related vars.
app.vars.extensions = app.vars.extensions || []; //the list of extensions that are/will be loaded
if(app.vars.thisSessionIsAdmin) {
app.handleAdminVars(); //needs to be late because it'll use some vars set above.
}
app.onReady();
}, //initialize
//will load _session from localStorage or create a new one.
handleSession : function() {
if(app.vars._session) {} //already defined.
else if(app.u.getParameterByName('_session')) { //get from URI, if set.
app.vars._session = app.u.getParameterByName('_session');
app.u.dump(" -> session found on URI: "+app.vars._session);
}
else {
app.vars._session = app.storageFunctions.readLocal('_session');
if(app.vars._session) {
app.u.dump(" -> session found in localStorage: "+app.vars._session);
//use the local session id.
}
else {
//create a new session id.
app.vars._session = app.u.guidGenerator();
app.storageFunctions.writeLocal('_session',app.vars._session);
app.u.dump(" -> generated new session: "+app.vars._session);
}
}
}, //handleSession
//This is run on init, BEFORE a user has logged in to see if login info is in localstorage or on URI.
//after login, the admin vars are set in the model.
handleAdminVars : function(){
// app.u.dump("BEGIN handleAdminVars");
var localVars = {}
if(app.model.fetchData('authAdminLogin')) {localVars = app.data.authAdminLogin}
// app.u.dump(" -> localVars: "); app.u.dump(localVars);
function setVars(id){
// app.u.dump("GOT HERE!");
// app.u.dump("-> "+id+": "+app.u.getParameterByName(id));
if(app.vars[id]) {} //already set, do nothing.
//check url. these get priority of local so admin/support can overwrite.
//uri ONLY gets checked for support. This is so that on redirects back to our UI from a partner interface don't update auth vars.
else if(app.u.getParameterByName('trigger') == 'support' && app.u.getParameterByName(id)) {app.vars[id] = app.u.getParameterByName(id);}
else if(localVars[id]) {app.vars[id] = localVars[id]}
else {app.vars[id] = ''}//set to blank by default.
}
setVars('deviceid');
setVars('userid');
setVars('authtoken');
setVars('domain');
setVars('username');
app.vars.username = app.vars.username.toLowerCase();
}, //handleAdminVars
onReady : function() {
this.u.dump(" -> onReady executed. V: "+app.model.version+"|"+app.vars.release);
if(app.vars.thisSessionIsAdmin) {
app.model.addExtensions(app.vars.extensions);
}
else if(app.vars.cartID) {
app.u.dump(" -> app.vars.cartID set. verify.");
app.model.destroy('cartDetail'); //do not use a cart from localstorage
app.calls.cartDetail.init({'callback':'handleNewSession'},'immutable');
app.calls.whoAmI.init({},{'callback':'suppressErrors'},'immutable'); //get this info when convenient.
app.model.dispatchThis('immutable');
}
//if cartID is set on URI, there's a good chance a redir just occured from non secure to secure.
else if(app.u.isSet(app.u.getParameterByName('cartID'))) {
app.u.dump(" -> cartID from URI used.");
app.vars.cartID = app.u.getParameterByName('cartID');
app.model.destroy('cartDetail'); //do not use a cart from localstorage
app.calls.cartDetail.init({'callback':'handleNewSession'},'immutable');
app.calls.whoAmI.init({},{'callback':'suppressErrors'},'immutable'); //get this info when convenient.
app.model.dispatchThis('immutable');
}
//check localStorage
else if(app.model.fetchCartID()) {
app.u.dump(" -> session retrieved from localstorage..");
app.vars.cartID = app.model.fetchCartID();
app.model.destroy('cartDetail'); //do not use a cart from localstorage
app.calls.cartDetail.init({'callback':'handleNewSession'},'immutable');
app.calls.whoAmI.init({},{'callback':'suppressErrors'},'immutable'); //get this info when convenient.
app.model.dispatchThis('immutable');
}
else {
app.u.dump(" -> go get a new cart id.");
app.calls.appCartCreate.init({'callback':'handleNewSession'},'immutable');
app.model.dispatchThis('immutable');
}
//if third party inits are not done before extensions, the extensions can't use any vars loaded by third parties. yuck. would rather load our code first.
// -> EX: username from FB and OPC.
app.u.handleThirdPartyInits();
}, //onReady
// ////////////////////////////////// CALLS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\
/*
calls all have an 'init' as well as a 'dispatch'.
the init allows for the call to check if the data being retrieved is already in the session or local storage and, if so, avoid a request.
If the data is not there, or there's no data to be retrieved (a Set, for instance) the init will execute the dispatch.
*/
calls : {
appBuyerCreate : {
init : function(obj,_tag) {
this.dispatch(obj,_tag);
return 1;
},
dispatch : function(obj,_tag){
obj._tag = _tag || {};
obj._cmd = "appBuyerCreate";
app.model.addDispatchToQ(obj,'immutable');
}
}, //appBuyerCreate
appBuyerLogin : {
init : function(obj,_tag) {
var r = 0;
if(obj && obj.login && obj.password) {
r = 1;
//email should be validated prior to call. allows for more custom error handling based on use case (login form vs checkout login)
app.calls.cartSet.init({"bill/email":obj.login}) //whether the login succeeds or not, set bill/email in /session
this.dispatch(obj,_tag);
}
else {$('#globalMessaging').anymessage({'message':'In app.calls.appBuyerLogin, login or password not specified.','gMessage':true});}
return r;
},
dispatch : function(obj,_tag) {
obj["_cmd"] = "appBuyerLogin";
obj['method'] = "unsecure";
obj["_tag"] = _tag || {};
obj["_tag"]["datapointer"] = "appBuyerLogin";
app.model.addDispatchToQ(obj,'immutable');
}
}, //appBuyerLogin
//formerly customerPasswordRecover
appBuyerPasswordRecover : {
init : function(login,_tag,Q) {
var r = 0;
if(login) {
r = 1;
this.dispatch(login,_tag,Q);
}
else {
$('#globalMessaging').anymessage({'message':'appBuyerPasswordRecover requires login','gMessage':true});
}
return r;
},
dispatch : function(login,_tag,Q) {
var obj = {};
obj['_cmd'] = 'appBuyerPasswordRecover';
obj.login = login;
obj.method = 'email';
obj['_tag'] = _tag;
app.model.addDispatchToQ(obj,Q || 'immutable');
}
},//appBuyerPasswordRecover
appCartCreate : {
init : function(_tag) {
this.dispatch(_tag);
return 1;
},
dispatch : function(_tag) {
app.model.addDispatchToQ({"_cmd":"appCartCreate","_tag":_tag},'immutable');
}
},//appCartCreate
appNavcatDetail : {
init : function(obj,_tag,Q) {
if(obj && obj.safe) {
var r = 0; //will return 1 if a request is needed. if zero is returned, all data needed was in local.
_tag = _tag || {};
_tag.datapointer = 'appNavcatDetail|'+obj.safe;
//the model will add the value of _tag.detail into the response so it is stored in the data and can be referenced for future comparison.
if(obj.detail) {_tag.detail = obj.detail} else {}
//if no detail or detail = fast, but anything is in memory, use it.
if(app.model.fetchData(_tag.datapointer) && (!obj.detail || obj.detail=='fast')) {
app.u.handleCallback(_tag)
}
//max is the highest level, so if we have that already, just use it.
else if(app.data[_tag.datapointer] && app.data[_tag.datapointer].detail == 'max') {
app.u.handleCallback(_tag);
}
else if (obj.detail == 'more' && (app.data[_tag.datapointer] && (!app.data[_tag.datapointer].detail == 'more' || app.data[_tag.datapointer].detail == 'max'))) {
app.u.handleCallback(_tag);
}
else {
r += 1;
this.dispatch(obj,_tag,Q);
}
}
else {
app.u.throwGMessage("In calls.appNavcatDetail, obj.safe not passed.");
app.u.dump(obj);
}
return r;
},
dispatch : function(obj,_tag,Q) {
obj._cmd = "appNavcatDetail";
obj._tag = _tag;
app.model.addDispatchToQ(obj,Q);
}
},//appNavcatDetail
//get a list of newsletter subscription lists. partition specific.
appNewsletterList : {
init : function(_tag,Q) {
var r = 0;
_tag = _tag || {};
_tag.datapointer = "appNewsletterList"
if(app.model.fetchData('appNewsletterList') == false) {
r = 1;
this.dispatch(_tag,Q);
}
else {
// app.u.dump(' -> data is local');
app.u.handleCallback(_tag);
}
return r;
},
dispatch : function(_tag,Q) {
app.model.addDispatchToQ({"_cmd":"appNewsletterList","_tag" : _tag},Q || 'immutable');
}
},//getNewsletters
appSendMessage : {
init : function(obj,_tag,Q) {
this.dispatch(obj,_tag,Q);
return 1;
},
dispatch : function(obj,_tag,Q) {
obj.msgtype = "feedback"
obj["_cmd"] = "appSendMessage";
obj['_tag'] = _tag;
app.model.addDispatchToQ(obj,Q || 'immutable');
}
},//appSendMessage
//obj should contain @products (array of pids), ship_postal (zip/postal code) and ship_country (as 2 digit country code)
appShippingTransitEstimate : {
init : function(obj,_tag,Q) {
var r = 0;
if(obj && obj.ship_postal && obj.ship_country && typeof obj['@products'] === 'object') {
this.dispatch(obj,_tag,Q);
r = 1;
}
else if(obj) {
$('#globalMessaging').anymessage({'message':'In app.calls.appShippingTransitEstimate requires ship_postal ['+obj.ship_postal+'], ship_country ['+obj.ship_country+'] and @products ['+typeof obj['@products']+']','gMessage':true});
}
else {
$('#globalMessaging').anymessage({'message':'In app.calls.appShippingTransitEstimate, no obj passed.','gMessage':true});
}
return r;
},
dispatch : function(obj,_tag,Q) {
obj._tag = _tag || {};
obj._tag.datapointer = 'appShippingTransitEstimate';
obj._cmd = "appShippingTransitEstimate"
app.model.addDispatchToQ(obj,Q || 'passive');
}
},//appShippingTransitEstimate
//get a product record.
//required params: obj.pid.
//optional params: obj.withInventory and obj.withVariations
appProductGet : {
init : function(obj,_tag,Q) {
var r = 0; //will return 1 if a request is needed. if zero is returned, all data needed was in local.
if(obj && obj.pid) {
if(typeof obj.pid === 'string') {obj.pid = obj.pid.toUpperCase();} //will error if obj.pid is a number.
_tag = _tag || {};
_tag.datapointer = "appProductGet|"+obj.pid;
//The fetchData will put the data into memory if present, so safe to check app.data... after here.
if(app.model.fetchData(_tag.datapointer) == false) {
r = 1;
this.dispatch(obj,_tag,Q)
}
//if variations or options are requested, check to see if they've been retrieved before proceeding.
else if((obj.withVariations && app.data[_tag.datapointer]['@variations'] === undefined) || (obj.withInventory && app.data[_tag.datapointer]['@inventory'] === undefined)) {
r = 1;
this.dispatch(obj,_tag,Q);
}
//if the product record is in memory BUT the inventory is zero, go get updated record in case it's back in stock.
else if(app.ext.store_product && (app.ext.store_product.u.getProductInventory(obj.pid) === 0)) {
r = 1;
this.dispatch(obj,_tag,Q);
}
else {
app.u.handleCallback(_tag);
}
}
else {
app.u.throwGMessage("In calls.appProductGet, required parameter pid was not passed");
app.u.dump(obj);
}
return r;
},
dispatch : function(obj,_tag,Q) {
obj["_cmd"] = "appProductGet";
obj["_tag"] = _tag;
app.model.addDispatchToQ(obj,Q);
}
}, //appProductGet
appProfileInfo : {
init : function(obj,_tag,Q) {
var r = 0; //will return 1 if a request is needed. if zero is returned, all data needed was in local.
if(typeof obj == 'object' && (obj.profile || obj.domain)) {
_tag = _tag || {};
_tag.datapointer = 'appProfileInfo|'+(obj.profile || obj.domain);
if(app.model.fetchData(_tag.datapointer) == false) {
r = 1;
this.dispatch(obj,_tag,Q);
}
else {
app.u.handleCallback(_tag);
}
}
else {
app.u.throwGMessage("In calls.appProfileGet, obj either missing or missing profile ["+obj.profile+"] or domain ["+obj.domain+"] var.");
app.u.dump(obj);
}
return r;
}, // init
dispatch : function(obj,_tag,Q) {
obj._cmd = "appProfileInfo";
obj._tag = _tag;
app.model.addDispatchToQ(obj,Q);
} // dispatch
}, //appProfileInfo
/*
obj is most likely a form object serialized to json.
see jquery/api webdoc for required/optional param
*/
appReviewAdd : {
init : function(obj,_tag,Q) {
this.dispatch(obj,_tag,Q);
return 1;
},
dispatch : function(obj,_tag,Q) {
obj['_cmd'] = 'appReviewAdd';
obj['_tag'] = _tag || {};
app.model.addDispatchToQ(obj,Q || 'immutable');
}
},//appReviewAdd
appStash : {
init : function(obj,_tag,Q) {
this.dispatch(obj,_tag,Q);
return 1;
},
dispatch : function(obj,_tag,Q) {
obj["_cmd"] = "appStash";
obj['_tag'] = _tag;
app.model.addDispatchToQ(obj,Q || 'immutable');
}
},//appStash
appSuck : {
init : function(obj,_tag,Q) {
this.dispatch(obj,_tag,Q);
return 1;
},
dispatch : function(obj,_tag,Q) {
obj["_cmd"] = "appSuck";
obj['_tag'] = _tag;
app.model.addDispatchToQ(obj,Q || 'immutable');
}
},//appSuck
//the authentication through FB sdk has already taken place and this is an internal server check to verify integrity.
//the getFacebookUserData function also updates bill_email and adds the fb.user info into memory in a place quickly accessed
//the obj passed in is passed into the request as the _tag
appVerifyTrustedPartner : {
init : function(partner,_tag,Q) {
var r = 0;
if(partner) {
this.dispatch(partner,_tag,Q);
r = 1;
}
else {
$('#globalMessaging').anymessage({'message':'In app.calls.appVerifyTrustedPartner, partner not specified.','gMessage':true});
}
return r;
},
dispatch : function(partner,_tag,Q) {
//note - was using FB['_session'].access_token pre v-1202. don't know how long it wasn't working, but now using _authRepsonse.accessToken
app.model.addDispatchToQ({'_cmd':'appVerifyTrustedPartner','partner':partner,'appid':zGlobals.thirdParty.facebook.appId,'token':FB['_authResponse'].accessToken,'state':app.vars.cartID,"_tag":_tag},Q || 'immutable');
}
}, //facebook
authAdminLogout : {
init : function(_tag) {
this.dispatch(_tag);
return 1;
},
dispatch : function(_tag){
app.model.addDispatchToQ({'_cmd':'authAdminLogout',"_tag":_tag},'immutable');
}
}, //authAdminLogout
authAdminLogin : {
init : function(obj,_tag) {
this.dispatch(obj,_tag);
return 1;
},
dispatch : function(obj,_tag){
app.u.dump("Attempting to log in");
obj._cmd = 'authAdminLogin';
app.vars.userid = obj.userid.toLowerCase(); // important!
obj.authtype = "md5";
obj.ts = app.u.ymdNow();
obj.authid = Crypto.MD5(obj.password+obj.ts);
obj._tag = _tag || {};
obj.device_notes = "";
if(obj.persistentAuth) {obj._tag.datapointer = "authAdminLogin"} //this is only saved locally IF 'keep me logged in' is true.
delete obj.password;
app.model.addDispatchToQ(obj,'immutable');
}
}, //authentication
authAccountCreate : {
init : function(obj,_tag){
this.dispatch(obj,_tag);
},
dispatch : function(obj,_tag){
obj._cmd = 'authUserRegister';
_tag = _tag || {};
obj['tag'] = _tag;
app.model.addDispatchToQ(obj,'immutable');
}
},
buyerAddressAddUpdate : {
init : function(cmdObj,_tag,Q) {
var r = 0;
if(cmdObj && cmdObj.shortcut) {
_tag = _tag || {};
_tag.datapointer = "buyerAddressAddUpdate|"+cmdObj.shortcut
r = 1;
this.dispatch(cmdObj,_tag,Q);
}
else {
$('#globalMessaging').anymessage({'message':'buyerAddressAddUpdate requires obj and obj.shortcut','gMessage':true});
}
return r;
},
dispatch : function(cmdObj,_tag,Q) {
cmdObj['_cmd'] = 'buyerAddressAddUpdate';
cmdObj._tag = _tag;
app.model.addDispatchToQ(cmdObj,Q || 'immutable');
}
},//buyerAddressAddUpdate
buyerAddressList : {
init : function(_tag,Q) {
var r = 0;
_tag = _tag || {};
_tag.datapointer = "buyerAddressList";
if(app.model.fetchData("buyerAddressList") == false) {
r = 1;
this.dispatch(_tag,Q);
}
else {
app.u.handleCallback(_tag);
}
return r;
},
dispatch : function(_tag,Q) {
app.model.addDispatchToQ({"_cmd":"buyerAddressList","_tag": _tag},Q || 'mutable');
}
}, //buyerAddressList
buyerNewsletters: {
init : function(_tag,Q) {
this.dispatch(_tag,Q);
return 1;
},
dispatch : function(_tag,Q) {
obj = {};
obj['_tag'] = _tag;
obj['_cmd'] = "buyerNewsletters";
app.model.addDispatchToQ(obj,Q || 'mutable');
}
}, //buyerNewsletters
//obj should always have orderid.
//may also have cartid for soft-auth (invoice view)
buyerOrderGet : {
init : function(obj,_tag,Q) {
var r = 0;
if(obj && obj.orderid) {
r = 1;
_tag = _tag || {};
_tag.datapointer = "buyerOrderGet|"+obj.orderid;
this.dispatch(obj,_tag,Q);
}
else {
$('#globalMessaging').anymessage({'message':'buyerPurchaseHistoryDetail requires orderid','gMessage':true});
}
return r;
},
dispatch : function(obj,_tag,Q) {
if(!Q) {Q = 'mutable'}
obj["_cmd"] = "buyerOrderGet";
obj['softauth'] = "order";
obj["_tag"] = _tag;
app.model.addDispatchToQ(obj,Q);
}
}, //buyerOrderGet
buyerPasswordUpdate : {
init : function(password,_tag,Q) {
var r = 0;
if(password) {
r = 1;
this.dispatch(password,_tag,Q);
}
else {
$('#globalMessaging').anymessage({'message':'buyerPasswordUpdate requires password','gMessage':true});
}
return r;
},
dispatch : function(password,_tag,Q) {
var obj = {};
obj.password = password;
obj['_tag'] = _tag;
obj['_cmd'] = "buyerPasswordUpdate";
app.model.addDispatchToQ(obj,Q || 'immutable');
}
}, //buyerPasswordUpdate
buyerProductLists : {
init : function(_tag,Q) {
var r = 0;
_tag = _tag || {};
_tag.datapointer = "buyerProductLists"
if(app.model.fetchData(_tag.datapointer) == false) {
r = 1;
this.dispatch(_tag);
}
else {
// app.u.dump(' -> data is local');
app.u.handleCallback(_tag,Q);
}
return r;
},
dispatch : function(_tag,Q) {
app.model.addDispatchToQ({"_cmd":"buyerProductLists","_tag" : _tag});
}
},//buyerProductLists
buyerProductListDetail : {
init : function(listID,_tag,Q) {
var r = 0;
if(listID) {
_tag = _tag || {};
_tag.datapointer = "buyerProductListDetail|"+listID
this.dispatch(listID,_tag,Q);
r = 1;
}
else {
$('#globalMessaging').anymessage({'message':'buyerProductListDetail requires listID','gMessage':true});
}
return r;
},
dispatch : function(listID,_tag,Q) {
app.model.addDispatchToQ({"_cmd":"buyerProductListDetail","listid":listID,"_tag" : _tag},Q);
}
},//buyerProductListDetail
//obj must include listid
//obj can include sku, qty,priority, note and replace. see github for more info.
//sku can be a fully qualified stid (w/ options)
buyerProductListAppendTo : {
init : function(obj,_tag,Q) {
var r = 0;
if(obj && obj.listid) {
r = 1;
this.dispatch(obj,_tag,Q);
}
else {
$('#globalMessaging').anymessage({'message':'buyerProductListDetail requires listid','gMessage':true});
}
return r;
},
dispatch : function(obj,_tag,Q) {
obj['_cmd'] = "buyerProductListAppendTo"
obj['_tag'] = _tag || {};
app.model.addDispatchToQ(obj,Q || 'immutable');
}
},//buyerProductListAppendTo
//formerly removeFromCustomerList
buyerProductListRemoveFrom : {
init : function(listID,stid,_tag,Q) {
var r = 0;
if(listID) {
r = 1;
this.dispatch(listID,stid,_tag,Q);
}
else {
$('#globalMessaging').anymessage({'message':'buyerProductListRemoveFrom requires listID','gMessage':true});
}
return r;
},
dispatch : function(listID,stid,_tag,Q) {
app.model.addDispatchToQ({"_cmd":"buyerProductListRemoveFrom","listid":listID,"sku":stid,"_tag" : _tag},Q || 'immutable');
}
},//buyerProductListRemoveFrom
//a request for order history should always request latest list (as per B)
//formerly getCustomerOrderList
buyerPurchaseHistory : {
init : function(_tag,Q) {
var r = 1;
_tag = _tag || {};
_tag.datapointer = "buyerPurchaseHistory"
this.dispatch(_tag,Q);
return r;
},
dispatch : function(_tag,Q) {
app.model.addDispatchToQ({"_cmd":"buyerPurchaseHistory","DETAIL":"5","_tag" : _tag},Q || 'mutable');
}
}, //buyerPurchaseHistory
buyerLogout : {
init : function(_tag) {
this.dispatch(_tag);
return 1;
},
dispatch : function(_tag) {
obj = {};
obj["_cmd"] = "buyerLogout";
obj["_tag"] = _tag || {};
obj["_tag"]["datapointer"] = "buyerLogout";
app.model.addDispatchToQ(obj,'immutable');
}
}, //appBuyerLogout
buyerWalletList : {
init : function(_tag,Q) {
var r = 0;
_tag = _tag || {};
_tag.datapointer = "buyerWalletList";
if(app.model.fetchData(_tag.datapointer)) {
app.u.handleCallback(_tag);
}
else {
r = 1;
this.dispatch(_tag,Q);
}
return r;
},
dispatch : function(_tag,Q) {
app.model.addDispatchToQ({"_cmd":"buyerWalletList","_tag": _tag},Q || 'mutable');
}
}, //buyerWalletList
canIUse : {
init : function(flag,Q) {
this.dispatch(flag,Q);
return 1;
},
dispatch : function(flag,Q) {
app.model.addDispatchToQ({"_cmd":"canIUse","flag":flag,"_tag":{"datapointer":"canIUse|"+flag}},Q);
}
}, //canIUse
//used to get a clean copy of the cart. ignores local/memory. used for logout.
cartDetail : {
init : function(_tag,Q) {
var r = 0;
_tag = _tag || {};
_tag.datapointer = "cartDetail";
if(app.model.fetchData(_tag.datapointer)) {
app.u.handleCallback(_tag);
}
else {
r = 1;
this.dispatch(_tag,Q);
}
return r;
},
dispatch : function(_tag,Q) {
app.model.addDispatchToQ({"_cmd":"cartDetail","_tag": _tag},Q || 'mutable');
}
}, // refreshCart removed comma from here line 383
cartItemAppend : {
init : function(obj,_tag) {
var r = 0;
if(obj && obj.sku && obj.qty) {
obj.uuid = app.u.guidGenerator();
this.dispatch(obj,_tag);
r = 1;
}
else {
$('#globalMessaging').anymessage({'message':'Qty or SKU left blank in cartItemAppend'});
}
return r;
},
dispatch : function(obj,_tag){
obj._tag = _tag;
obj._cmd = "cartItemAppend";
app.model.addDispatchToQ(obj,'immutable');
}
}, //cartItemAppend
// formerly updateCartQty
cartItemUpdate : {
init : function(stid,qty,_tag) {
// app.u.dump('BEGIN app.calls.cartItemUpdate.');
var r = 0;
if(stid && Number(qty) >= 0) {
r = 1;
this.dispatch(stid,qty,_tag);
}
else {
app.u.throwGMessage("In calls.cartItemUpdate, either stid ["+stid+"] or qty ["+qty+"] not passed.");
}
return r;
},
dispatch : function(stid,qty,_tag) {
// app.u.dump(' -> adding to PDQ. callback = '+callback)
app.model.addDispatchToQ({"_cmd":"cartItemUpdate","stid":stid,"quantity":qty,"_tag": _tag},'immutable');
app.ext.cco.u.nukePayPalEC(); //nuke paypal token anytime the cart is updated.
}
},
//default immutable Q
//formerly setSessionVars
cartSet : {
init : function(obj,_tag,Q) {
this.dispatch(obj,_tag,Q);
return 1;
},
dispatch : function(obj,_tag,Q) {
obj["_cmd"] = "cartSet";
obj["_tag"] = _tag || {};
app.model.addDispatchToQ(obj,Q || 'immutable');
}
}, //cartSet
cartShippingMethods : {
init : function(_tag,Q) {
var r = 0
_tag = _tag || {}; //makesure _tag is an object so that datapointer can be added w/o causing a JS error
_tag.datapointer = "cartShippingMethods";
if(app.model.fetchData('cartShippingMethods') == false) {
r = 1;
Q = Q ? Q : 'immutable'; //allow for muted request, but default to immutable. it's a priority request.
this.dispatch(_tag,Q);
}
else {
app.u.handleCallback(_tag);
}
return r;
},
dispatch : function(_tag,Q) {
app.model.addDispatchToQ({"_cmd":"cartShippingMethods","_tag": _tag},Q);
}
}, //cartShippingMethods
ping : {
init : function(_tag,Q) {
this.dispatch(_tag,Q);
return 1;
},
dispatch : function(_tag,Q) {
app.model.addDispatchToQ({"_cmd":"ping","_tag":_tag},Q || 'mutable'); //get new session id.
}
}, //ping
//used to get a clean copy of the cart. ignores local/memory. used for logout.
//this is old and, arguably, should be a utility. however it's used a lot so for now, left as is. ### search and destroy when convenient.
refreshCart : {
init : function(_tag,Q) {
app.model.destroy('cartDetail');
app.calls.cartDetail.init(_tag,Q);
}
}, // refreshCart
time : {
init : function(_tag,Q) {
this.dispatch(_tag,Q);
return true;
},
dispatch : function(_tag,Q) {
_tag = _tag || {};
_tag.datapointer = 'time';
app.model.addDispatchToQ({"_cmd":"time","_tag":_tag},Q || 'mutable');
}
}, //time
whereAmI : {
init : function(_tag,Q) {
var r = 0;
_tag = $.isEmptyObject(_tag) ? {} : _tag;
_tag.datapointer = "whereAmI"
if(app.model.fetchData('whereAmI') == false) {
r = 1;
this.dispatch(_tag,Q);
}
else {
// app.u.dump(' -> data is local');
app.u.handleCallback(_tag);
}
return r;
},
dispatch : function(_tag,Q) {
app.model.addDispatchToQ({"_cmd":"whereAmI","_tag" : _tag},Q || 'mutable');
}
},//whereAmI
//for now, no fetch is done here. it's assumed if you execute this, you don't know who you are dealing with.
whoAmI : {
init : function(obj,_tag,Q) {
this.dispatch(obj,_tag,Q);
return 1;
},
dispatch : function(obj,_tag,Q) {
obj = obj || {};
obj._cmd = "whoAmI";
obj._tag = _tag || {};
obj._tag.datapointer = "whoAmI"
app.model.addDispatchToQ(obj,Q);
}
}//whoAmI
}, // calls
// ////////////////////////////////// CALLBACKS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\
/*
Callbacks require should have an onSuccess.
Optionally, callbacks can have on onError. if you have a custom onError, no error messaging is displayed. This give the developer the opportunity to easily suppress errors for a given request/callback.
app.u.throwMessage(responseData); is the default error handler.
*/
callbacks : {
handleNewSession : {
//app.vars.cartID is set in the method. no need to set it here.
//use app.vars.cartID if you need it in the onSuccess.
//having a callback does allow for behavioral changes (update new session with old cart contents which may still be available.
onSuccess : function(_rtag) {
// app.u.dump('BEGIN app.callbacks.handleNewSession.onSuccess');
// if there are any extensions(and most likely there will be) add then to the controller.
// This is done here because a valid cart id is required.
app.model.addExtensions(app.vars.extensions);
}
},//convertSessionToOrder
//very similar to the original translate selector in the control and intented to replace it.