This repository has been archived by the owner on Feb 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
JSShop.js
145 lines (116 loc) · 4 KB
/
JSShop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
if (!window.Fit)
throw "Fit.UI must be loaded for JSShop to work";
// ======================================================
// Namespaces
// ======================================================
JSShop = {};
JSShop._internal = {};
// Settings
JSShop.Settings = {};
JSShop.Settings.ShippingExpenseExpression = null;
JSShop.Settings.ShippingExpenseVat = 0;
JSShop.Settings.ShippingExpenseMessage = null;
JSShop.Settings.BasketUrl = null;
JSShop.Settings.TermsUrl = null;
JSShop.Settings.PaymentUrl = null;
JSShop.Settings.PaymentMethods = null;
/*JSShop.Settings.PaymentMethods =
[
{ Title: "Credit Card - VISA, MasterCard, Dinners Club", Module: "DIBS" }
]*/
// Language
JSShop.Language = {};
JSShop.Language.Name = "en";
JSShop.Language.Translations = {};
// Models, Presenters, and Cookies
JSShop.Models = {};
JSShop.Presenters = {};
JSShop.Cookies = new Fit.Cookies();
JSShop.Cookies.Prefix("JSShop");
// Communication
JSShop.WebService = {};
JSShop.WebService.Products = {};
JSShop.WebService.Products.Create = null;
JSShop.WebService.Products.Retrieve = null;
JSShop.WebService.Products.Update = null;
JSShop.WebService.Products.Delete = null;
JSShop.WebService.Files = {};
JSShop.WebService.Files.Upload = null;
JSShop.WebService.Files.Remove = null;
JSShop.WebService.Orders = {};
JSShop.WebService.Orders.Create = null;
JSShop.WebService.Orders.Retrieve = null;
JSShop.WebService.Orders.Update = null;
JSShop.WebService.Orders.Delete = null;
JSShop.WebService.OrderEntries = {};
JSShop.WebService.OrderEntries.Create = null;
JSShop.WebService.OrderEntries.Retrieve = null;
JSShop.WebService.OrderEntries.Update = null;
JSShop.WebService.OrderEntries.Delete = null;
// ======================================================
// Cross model event handlers
// ======================================================
// Callback signatures: function(request, model[], operationType).
// Called when models interact with backend.
JSShop.Events = {};
JSShop.Events.OnRequest = null;
JSShop.Events.OnSuccess = null;
JSShop.Events.OnError = null;
// ======================================================
// JSShop path info
// ======================================================
// Determine path information
(function()
{
// Find Base URL - e.g. http://server.com/libs/jsshop
var src = document.scripts[document.scripts.length - 1].src;
JSShop._internal.BaseUrl = src.substring(0, src.lastIndexOf("/"));
// Calculate Base Path - e.g. /libs/jsshop
var path = JSShop._internal.BaseUrl.replace("http://", "").replace("https://", "");
JSShop._internal.BasePath = path.substring(path.indexOf("/"));
})();
JSShop.GetUrl = function()
{
return JSShop._internal.BaseUrl;
}
JSShop.GetPath = function()
{
return JSShop._internal.BasePath;
}
// ======================================================
// JSShop loader
// ======================================================
JSShop._internal.Initialized = false;
JSShop.Initialize = function(cb)
{
Fit.Validation.ExpectFunction(cb);
if (JSShop._internal.Initialized === true)
{
cb();
return;
}
Fit.Loader.LoadScripts(
[
// Load language
{ source: JSShop.GetPath() + "/Languages/" + JSShop.Language.Name.toLowerCase() + ".js" },
// Load models
{ source: JSShop.GetPath() + "/Models/Base.js" },
{ source: JSShop.GetPath() + "/Models/Product.js" },
{ source: JSShop.GetPath() + "/Models/Basket.js" },
{ source: JSShop.GetPath() + "/Models/Order.js" },
{ source: JSShop.GetPath() + "/Models/OrderEntry.js" },
// Load presenters
{ source: JSShop.GetPath() + "/Presenters/ProductForm.js" },
{ source: JSShop.GetPath() + "/Presenters/ProductList.js" },
{ source: JSShop.GetPath() + "/Presenters/Basket.js" },
{ source: JSShop.GetPath() + "/Presenters/OrderForm.js" }
],
function(cfgs)
{
JSShop._internal.Initialized = true;
Fit.Language.Translations.Required = JSShop.Language.Translations.Common.Required;
Fit.Language.Translations.Ok = JSShop.Language.Translations.Common.Ok;
Fit.Language.Translations.Cancel = JSShop.Language.Translations.Common.Cancel;
cb();
});
}