| 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 | 1
1
1
1
42
42
42
42
1
1
1
428
4
31
31
31
10
10
21
21
21
1
26
26
26
26
1
26
26
26
26
21
9
9
9
9
9
9
6
13
13
13
13
20
2
20
11
1
26
26
26
26
15
26
6
32
32
32
32
5
27
27
27
16
27
27
1
26
26
26
16
26
26
2
1
1
1
1
1
1
22
22
22
22
22
22
18
180
180
148
148
22
2
20
20
20
20
20
1
| var FieldDBObject = require("./../FieldDBObject").FieldDBObject;
var HotKeys = require("./../hotkey/HotKeys").HotKeys;
var UnicodeSymbols = require("./../unicode/UnicodeSymbols").UnicodeSymbols;
/**
* @class Hold preferences for users like the skin of the app
*
* @property {int} skin This is user's preferred skin.
* @property {int} numVisibleDatum The number of Datum visible at the time on
* the Datum*View"s.
*
* @name UserPreference
* @extends FieldDBObject
* @constructs
*/
var UserPreference = function UserPreference(options) {
Eif (!this._fieldDBtype) {
this._fieldDBtype = "UserPreference";
}
this.debug("Constructing UserPreference length: ", options);
FieldDBObject.apply(this, arguments);
};
UserPreference.preferredDashboardLayouts = ["layoutAllTheData", "layoutJustEntering", "layoutWhatsHappening", "layoutCompareDataLists"];
UserPreference.preferredDashboardTypes = ["fieldlinguistNormalUser", "fieldlinguistPowerUser"];
UserPreference.prototype = Object.create(FieldDBObject.prototype, /** @lends UserPreference.prototype */ {
constructor: {
value: UserPreference
},
defaults: {
get: function() {
return {
skin: "",
numVisibleDatum: 2, //Use two as default so users can see minimal pairs
transparentDashboard: false,
alwaysRandomizeSkin: true,
numberOfItemsInPaginatedViews: 10,
preferredDashboardLayout: "layoutAllTheData",
preferredDashboardType: "fieldlinguistNormalUser",
preferredSpreadsheetShape: {
columns: 2,
rows: 3
},
hotkeys: [],
unicodes: []
};
}
},
INTERNAL_MODELS: {
value: {
hotkeys: HotKeys,
unicodes: UnicodeSymbols
}
},
skin: {
get: function() {
return this._skin || this.defaults.skin;
},
set: function(value) {
this.debug("setting _skin from " + value);
Iif (value === this._skin) {
return;
}
if (!value) {
delete this._skin;
return;
}
Eif (value.trim) {
value = value.trim();
}
this._skin = value;
}
},
transparentDashboard: {
get: function() {
return this._transparentDashboard || this.defaults.transparentDashboard;
},
set: function(value) {
this.debug("setting _transparentDashboard from " + value);
Iif (value === this._transparentDashboard) {
return;
}
Eif (value === false || value === "false" || !value) {
this._transparentDashboard = false;
} else {
this._transparentDashboard = true;
}
}
},
alwaysRandomizeSkin: {
get: function() {
return this._alwaysRandomizeSkin || this.defaults.alwaysRandomizeSkin;
},
set: function(value) {
this.debug("setting _alwaysRandomizeSkin from " + value);
Iif (value === this._alwaysRandomizeSkin) {
return;
}
Iif (value === false || value === "false" || !value) {
this._alwaysRandomizeSkin = false;
} else {
this._alwaysRandomizeSkin = true;
}
}
},
preferedDashboardType: {
get: function() {
this.warn("preferedDashboardType is deprecated use preferredDashboardType instead");
return this.preferredDashboardType;
},
set: function(value) {
this.warn("preferedDashboardType is deprecated use preferredDashboardType instead");
this.preferredDashboardType = value;
}
},
preferredDashboardType: {
get: function() {
return this._preferredDashboardType || this.defaults.preferredDashboardType;
},
set: function(value) {
this.debug("setting _preferredDashboardType from " + value);
Iif (value === this._preferredDashboardType) {
return;
}
Iif (!value) {
delete this._preferredDashboardType;
return;
}
Eif (value.trim) {
value = value.trim();
}
this._preferredDashboardType = value;
}
},
preferedDashboardLayout: {
get: function() {
this.warn("preferedDashboardLayout is deprecated use preferredDashboardLayout instead");
return this.preferredDashboardLayout;
},
set: function(value) {
this.warn("preferedDashboardType is deprecated use preferredDashboardLayout instead");
this.preferredDashboardLayout = value;
}
},
preferredDashboardLayout: {
get: function() {
return this._preferredDashboardLayout || this.defaults.preferredDashboardLayout;
},
set: function(value) {
Iif (value === this._preferredDashboardLayout) {
return;
}
Iif (!value) {
delete this._preferredDashboardLayout;
return;
}
// Guess which kind of user this is
Iif (!this.preferredDashboardType) {
if (this._preferredDashboardLayout === "layoutAllTheData" || this._preferredDashboardLayout === "layoutJustEntering" || this._preferredDashboardLayout === "layoutWhatsHappening") {
this.preferredDashboardType = "fieldlinguistNormalUser";
} else if (this._preferredDashboardLayout === "layoutCompareDataLists" || this._preferredDashboardLayout === "layoutEverythingAtOnce") {
this.preferredDashboardType = "fieldlinguistPowerUser";
}
}
this._preferredDashboardLayout = value;
}
},
preferedSpreadsheetShape: {
get: function() {
this.warn("preferedSpreadsheetShape is deprecated use preferredSpreadsheetShape instead");
return this.preferredSpreadsheetShape;
},
set: function(value) {
this.warn("preferedDashboardType is deprecated use preferredSpreadsheetShape instead");
this.preferredSpreadsheetShape = value;
}
},
preferredSpreadsheetShape: {
get: function() {
if (!this._preferredSpreadsheetShape) {
this._preferredSpreadsheetShape = JSON.parse(JSON.stringify(this.defaults.preferredSpreadsheetShape));
}
return this._preferredSpreadsheetShape;
},
set: function(value) {
this._preferredSpreadsheetShape = value;
}
},
hotkeys: {
get: function() {
return this._hotkeys || FieldDBObject.DEFAULT_COLLECTION;
},
set: function(value) {
Iif (value === this._hotkeys) {
return;
}
Iif (!value) {
delete this._hotkeys;
return;
} else {
Iif (value.firstKey) {
value = [value];
}
if (Object.prototype.toString.call(value) === "[object Array]") {
value = new this.INTERNAL_MODELS["hotkeys"](value);
}
}
this._hotkeys = value;
}
},
unicodes: {
get: function() {
return this._unicodes || FieldDBObject.DEFAULT_COLLECTION;
},
set: function(value) {
Iif (value === this._unicodes) {
return;
}
Iif (!value) {
delete this._unicodes;
return;
} else {
Iif (Object.prototype.toString.call(value) === "[object Array]") {
value = new this.INTERNAL_MODELS["unicodes"](value);
}
}
this._unicodes = value;
}
},
numVisibleDatum: {
get: function() {
return this._numVisibleDatum || this.defaults.numVisibleDatum;
},
set: function(value) {
Iif (value === this._numVisibleDatum) {
return;
}
Iif (!value) {
delete this._numVisibleDatum;
return;
} else {
if (typeof value.trim === "function") {
value = value.trim();
}
}
value = parseInt(value, 10);
this._numVisibleDatum = value;
}
},
numberOfItemsInPaginatedViews: {
get: function() {
return this._numberOfItemsInPaginatedViews || this.defaults.numberOfItemsInPaginatedViews;
},
set: function(value) {
Iif (value === this._numberOfItemsInPaginatedViews) {
return;
}
Iif (!value) {
delete this._numberOfItemsInPaginatedViews;
return;
} else {
if (typeof value.trim === "function") {
value = value.trim();
}
}
value = parseInt(value, 10);
this._numberOfItemsInPaginatedViews = value;
}
},
preferedLocale: {
get: function() {
this.warn("preferedLocale is deprecated use preferredLocale instead");
return this.preferredLocale;
},
set: function(value) {
this.warn("preferedDashboardType is deprecated use preferredLocale instead");
this.preferredLocale = value;
}
},
preferredLocale: {
get: function() {
return this._preferredLocale;
},
set: function(value) {
this.debug("setting _preferredLocale from " + value);
Iif (value === this._preferredLocale) {
return;
}
Iif (!value) {
delete this._preferredLocale;
return;
}
Eif (value.trim) {
value = value.trim();
}
this._preferredLocale = value;
}
},
toJSON: {
value: function(includeEvenEmptyAttributes, removeEmptyAttributes) {
this.debug("Customizing toJSON ", includeEvenEmptyAttributes, removeEmptyAttributes);
var attributesNotToJsonify = ["fieldDBtype", "dateCreated", "version"];
var json = FieldDBObject.prototype.toJSON.apply(this, [includeEvenEmptyAttributes, removeEmptyAttributes, attributesNotToJsonify]);
Iif (!json) {
this.warn("Not returning json right now.");
return;
}
this.debug("JSON before removing items which match defaults", json);
if (!includeEvenEmptyAttributes) {
for (var pref in this.defaults) {
Iif (!this.defaults.hasOwnProperty(pref)) {
continue;
}
if (new FieldDBObject(json[pref]).equals(this.defaults[pref]) || (Object.prototype.toString.call(json[pref]) === "[object Array]" && json[pref].length === 0)) {
this.debug("removing pref which is set to a default " + pref);
delete json[pref];
}
}
// if (json.preferredSpreadsheetShape && json.preferredSpreadsheetShape.columns === this.defaults.preferredSpreadsheetShape.columns && json.preferredSpreadsheetShape.rows === this.defaults.preferredSpreadsheetShape.rows) {
// delete json.preferredSpreadsheetShape;
// }
}
// TODO why
if (JSON.stringify(json) === "{}") {
return {};
}
json.fieldDBtype = this.fieldDBtype;
json.version = this.version;
json.dateCreated = this.dateCreated;
this.debug("Json", json);
return json;
}
}
});
exports.UserPreference = UserPreference;
|