/
Config.js
305 lines (264 loc) · 8.22 KB
/
Config.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
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
/* Config.js
*
* copyright (c) 2010-2017, Christian Mayer and the CometVisu contributers.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/**
* Main settings that an be accessed from anywhere inside the Application
*/
qx.Class.define('cv.Config', {
type:"static",
statics: {
/**
* Define ENUM of maturity levels for features, so that e.g. the editor can
* ignore some widgets when they are not supported yet
*/
Maturity : {
release: 0,
development: 1
},
/**
* The current path tree
* @type {String}
*/
treePath: "",
/**
* Path to the current page
* @type {String}
*/
currentPageId: null,
/**
* Config file version
* @type {Number}
*/
libraryVersion: 8,
/**
* @type {Boolean}
*/
libraryCheck: true,
/**
* Threshold where the mobile.css is loaded
* @type {Number}
*/
maxMobileScreenWidth: 480,
/**
* Threshold where colspan-s is used
* @type {Number}
*/
maxScreenWidthColspanS: 599,
/**
* threshold where colspan-m is used
* @type {Number}
*/
maxScreenWidthColspanM: 839,
/**
* Default scrolling speed for page changes (in ms)
* @type {Number}
*/
scrollSpeed : 400,
/**
* Default number of colums the layout should use
* @type {Number}
*/
defaultColumns : 12,
/**
* Minimum column width
* @type {Number}
*/
minColumnWidth : 120,
/**
* If true, the client only loads the states for the widgets that are part of the start page at first
* read request (should increase the performance when huge config files are used)
* @type {Boolean}
*/
enableAddressQueue : false,
/**
* Type of the used backend (*default*, *openhab* or *openhab2*)
* @type {String}
*/
backend : 'default',
/**
* Initial URL to the backend
* @type {String}
*/
backendUrl : null,
/**
* @type {String}
*/
configSuffix : null,
/**
* The design currently used
* @type {String}
*/
clientDesign : "",
/**
* Maturity level
* @type {var}
*/
use_maturity : false,
/**
* All configuration and settings from the current configuration
* (Note: all settings that need to be cached must be put in here)
*/
configSettings: {
mappings: {},
stylings: {},
/**
* Stores the rowspans used by the current confid
* @type {Map} of rowspan-value as key and true as value
*/
usedRowspans: {}
},
/**
* Array with alls icons defined in the current config file
* @type {Array}
*/
iconsFromConfig: [],
/**
* Store last visited page in LocalStorage
*/
rememberLastPage: false,
/**
* If enabled the widget instances are created on demand. Note: this must only be used when
* cache is valid!
* @type {Boolean}
*/
lazyLoading: false,
/**
* Defines which structure is supported by which designs
*/
designStructureMap: {
"pure": ["alaska", "alaska_slim", "discreet", "discreet_sand", "discreet_slim", "metal", "pitchblack", "planet", "pure"]
},
/**
* If enabled the user interaction gets logged
*/
reporting: false,
/**
* Get the structure that is related to this design
* @param design {String?} name of the design
* @return {String} name of the structure
*/
getStructure: function(design) {
if (!design) {
design = this.getDesign();
}
for (var structure in this.designStructureMap) {
if (this.designStructureMap.hasOwnProperty(structure)) {
if (this.designStructureMap[structure].indexOf(design) >= 0) {
return "structure-"+structure;
}
}
}
// fallback to pure
return "structure-pure";
},
addMapping: function (name, mapping) {
this.configSettings.mappings[name] = mapping;
},
getMapping: function (name) {
return this.configSettings.mappings[name];
},
hasMapping: function(name) {
return this.configSettings.mappings.hasOwnProperty(name);
},
clearMappings: function() {
this.configSettings.mappings = {};
},
addStyling: function (name, styling) {
this.configSettings.stylings[name] = styling;
},
getStyling: function (name) {
return this.configSettings.stylings[name];
},
hasStyling: function(name) {
return this.configSettings.stylings.hasOwnProperty(name);
},
getDesign: function() {
return this.clientDesign || this.configSettings.clientDesign;
}
},
defer: function(statics) {
var req = qx.util.Uri.parseUri(window.location.href);
if (req.queryKey.enableQueue) {
cv.Config.enableAddressQueue = true;
}
if (req.queryKey.libraryCheck) {
cv.Config.libraryCheck = req.queryKey.libraryCheck !== 'false'; // true unless set to false
}
if (req.queryKey.backend) {
cv.Config.backend = req.queryKey.backend;
}
if (req.queryKey.design) {
cv.Config.clientDesign = req.queryKey.design;
}
if (req.queryKey.startpage) {
cv.Config.startpage = req.queryKey.startpage;
}
if (req.queryKey.testMode) {
cv.Config.testMode = req.queryKey.testMode === "true";
}
// propagate to the client
cv.io.Client.TEST_MODE = cv.Config.testMode;
if (req.queryKey.config) {
cv.Config.configSuffix = req.queryKey.config;
}
if (req.queryKey.forceReload) {
cv.Config.forceReload = req.queryKey.forceReload !== 'false'; // true unless set to false
}
if (req.queryKey.reporting) {
cv.Config.reporting = req.queryKey.reporting === 'true';
}
if (req.queryKey.enableCache === "invalid") {
cv.ConfigCache.clear(cv.Config.configSuffix);
cv.Config.enableCache = true;
} else {
cv.Config.enableCache = req.queryKey.enableCache ? req.queryKey.enableCache === "true" : true;
}
// "Bug"-Fix for ID: 3204682 "Caching on web server"
// Config isn't a real fix for the problem as that's part of the web browser,
// but
// it helps to avoid the problems on the client, e.g. when the config file
// has changed but the browser doesn't even ask the server about it...
cv.Config.forceReload = true;
if (req.queryKey.forceDevice) {
cv.Config.forceMobile = req.queryKey.forceDevice === 'mobile';
cv.Config.forceNonMobile = !cv.Config.forceMobile;
} else {
cv.Config.forceMobile = false;
cv.Config.forceNonMobile = false;
}
var uagent = navigator.userAgent.toLowerCase();
cv.Config.mobileDevice = (/(android|blackberry|iphone|ipod|series60|symbian|windows ce|palm)/i.test(uagent));
if (/(nexus 7|tablet)/i.test(uagent)) {
cv.Config.mobileDevice = false; // Nexus 7 and Android Tablets have a "big" screen, so prevent Navbar from scrolling
}
cv.Config.mobileDevice |= cv.Config.forceMobile; // overwrite detection when set by URL
// Disable features that aren't ready yet
// Config can be overwritten in the URL with the parameter "maturity"
if (req.queryKey.maturity) {
cv.Config.url_maturity = req.queryKey.maturity;
if (!isNaN(cv.Config.url_maturity - 0)) {
cv.Config.use_maturity = cv.Config.url_maturity - 0; // given directly as number
} else {
cv.Config.use_maturity = statics.Maturity[cv.Config.url_maturity]; // or as the ENUM name
}
}
if (isNaN(cv.Config.use_maturity)) {
cv.Config.use_maturity = statics.Maturity.release; // default to release
}
}
});