@azrico/webobject 1.4.127 → 1.4.129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/dist/index.js +1 -16
- package/dist/src/WebObjects/ParentWebObject.js +20 -51
- package/dist/src/WebObjects/WebObject.js +452 -1032
- package/dist/src/WebObjects/WebObjectManager.js +194 -509
- package/dist/src/index.js +9 -104
- package/dist/src/structs/DummyObject.js +8 -35
- package/dist/src/structs/MapableObject.js +76 -126
- package/dist/src/structs/MetaObject.js +35 -113
- package/dist/src/structs/ObjectArray.js +43 -71
- package/dist/src/structs/ObjectManager.d.ts +2 -2
- package/dist/src/structs/ObjectManager.js +252 -648
- package/dist/src/structs/ObjectWithTemp.js +25 -65
- package/dist/src/structs/SimpleObject.d.ts +5 -6
- package/dist/src/structs/SimpleObject.js +890 -1396
- package/package.json +4 -4
|
@@ -1,1466 +1,960 @@
|
|
|
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
|
-
|
|
1
|
+
import { array_first, array_intersection, array_isEmpty, array_merge, fn_eval, fn_eval_this, object_clone, object_equals, object_get, object_getStatic, object_isClass, object_isEmpty, object_isTrue, object_removeKeys, object_set, wrap_array, } from "@azrico/object";
|
|
2
|
+
import { combine_if_not_blank, string_isEmpty } from "@azrico/string";
|
|
3
|
+
import { gcache, gfunc } from "@azrico/global";
|
|
4
|
+
import { MapableObject } from "./MapableObject";
|
|
5
|
+
import ObjectManager from "./ObjectManager";
|
|
6
|
+
export class SimpleObject extends MapableObject {
|
|
7
|
+
static __cache_name;
|
|
8
|
+
//these properties should not be changed and are usually set by server
|
|
9
|
+
static __unchangeables;
|
|
10
|
+
//these properties can be directly changed and are included in deltaObject
|
|
11
|
+
static __changeables;
|
|
12
|
+
//these properties can only be changed by the _creator
|
|
13
|
+
static __protectedProperties;
|
|
14
|
+
//these properties will be evaluated when needed
|
|
15
|
+
static __functionProperties;
|
|
16
|
+
//apply these string formats
|
|
17
|
+
static __formatList;
|
|
18
|
+
//these properties usually are not directly changed and sometimes are included in deltaObject
|
|
19
|
+
static __extraProperties;
|
|
20
|
+
//types for children can be used when importing children
|
|
21
|
+
static __childTypes;
|
|
22
|
+
//these fields are used when importing
|
|
23
|
+
static __importColumns;
|
|
24
|
+
//these fields can be used when importing and checking if an item exists
|
|
25
|
+
static __checkProperties;
|
|
26
|
+
static __use_delta = true;
|
|
27
|
+
_static() {
|
|
28
|
+
return this.constructor;
|
|
29
|
+
}
|
|
30
|
+
//an exact copy of this object is stored here
|
|
31
|
+
__originalobject;
|
|
32
|
+
//changes are saved here
|
|
33
|
+
__delta = {};
|
|
34
|
+
__changed = false;
|
|
35
|
+
//the last thing that was changed on this object
|
|
36
|
+
__lastChanged;
|
|
37
|
+
//is the object read only
|
|
38
|
+
__is_readonly;
|
|
39
|
+
//should we throw errors when encountering an error?
|
|
40
|
+
//is TRUE by default
|
|
41
|
+
__throw_errors;
|
|
42
|
+
//is this object marked as deleted?
|
|
43
|
+
_deleted;
|
|
44
|
+
_archived;
|
|
45
|
+
_deletedBy;
|
|
46
|
+
//errors
|
|
47
|
+
__errors;
|
|
48
|
+
__showErrors;
|
|
49
|
+
//refresh func
|
|
50
|
+
__refresh_functions;
|
|
51
|
+
//save results
|
|
52
|
+
__saveResultObject;
|
|
53
|
+
__saveResultIsSuccess = true;
|
|
54
|
+
__saveResultType;
|
|
55
|
+
//sequence key (usually managed by the database)
|
|
56
|
+
_index_key = "";
|
|
57
|
+
//sequence value , used to index the object with increasing numbers
|
|
58
|
+
_index_value = -1;
|
|
59
|
+
constructor(is_readonly = false) {
|
|
60
|
+
super();
|
|
61
|
+
this.__is_readonly = is_readonly;
|
|
62
|
+
this.clear_changes();
|
|
63
|
+
}
|
|
64
|
+
#setSubProperty(key, subkey, value) {
|
|
65
|
+
let subobj = this.#getProperty(key);
|
|
66
|
+
//@ts-ignore
|
|
67
|
+
if (subobj == null || typeof subobj !== "object")
|
|
68
|
+
subobj = {};
|
|
69
|
+
else
|
|
70
|
+
subobj = { ...subobj }; //make a clone so we dont update the original
|
|
71
|
+
subobj[subkey] = value;
|
|
72
|
+
this.#setProperty(key, subobj);
|
|
73
|
+
}
|
|
74
|
+
#getSubProperty(key, subkey, original = false) {
|
|
75
|
+
let subobj = this.#getProperty(key, original);
|
|
76
|
+
if (subobj == null || typeof subobj !== "object")
|
|
77
|
+
return undefined;
|
|
78
|
+
return subobj[subkey];
|
|
79
|
+
}
|
|
80
|
+
#setProperty(key, value) {
|
|
81
|
+
if (!this.__use_delta) {
|
|
82
|
+
this[key] = value; //on noDelta mode, also update the obj
|
|
83
|
+
this.__delta[key] = value; //always update delta to keep track of changes
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
if (this[key] === value) {
|
|
88
|
+
/**
|
|
89
|
+
* We set something back to its original value so no need to save it as Delta
|
|
90
|
+
*/
|
|
91
|
+
delete this.__delta[key];
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this.__delta[key] = value; //always update delta to keep track of changes
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
#setDefaultProperty(key, value) {
|
|
101
|
+
//@ts-ignore
|
|
102
|
+
if (this[key] == undefined || this[key] === "" || this[key] === 0) {
|
|
103
|
+
this[key] = value;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
#setDefaultPropertyNow(key) {
|
|
109
|
+
//@ts-ignore
|
|
110
|
+
if (this[key] == undefined || this[key] === "" || this[key] === 0) {
|
|
111
|
+
this[key] = new Date();
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
#getProperty(key, original = false) {
|
|
117
|
+
//check if we should treat the prop as a function
|
|
118
|
+
const is_fnc = this.constructor["__functionProperties"] != null &&
|
|
119
|
+
this.constructor["__functionProperties"].includes(key);
|
|
120
|
+
//check if we should use delta version or normal version for this property
|
|
121
|
+
const use_orig = original || !this.__use_delta || !(key in this.__delta);
|
|
122
|
+
if (is_fnc) {
|
|
123
|
+
if (use_orig)
|
|
124
|
+
return fn_eval_this(this, this[key]);
|
|
125
|
+
return fn_eval_this(this, this.__delta[key]);
|
|
126
|
+
}
|
|
127
|
+
if (use_orig)
|
|
128
|
+
return this[key];
|
|
129
|
+
return this.__delta[key];
|
|
130
|
+
}
|
|
131
|
+
/* -------------------------------------------------------------------------- */
|
|
132
|
+
/* Load */
|
|
133
|
+
/* -------------------------------------------------------------------------- */
|
|
134
|
+
loadValues(initObject, fullUpdate = false) {
|
|
135
|
+
return SimpleObject.loadValues(this, initObject, fullUpdate);
|
|
136
|
+
}
|
|
137
|
+
static loadValues(obj, initObject, fullUpdate = false) {
|
|
138
|
+
SimpleObject.factoryClear(obj);
|
|
139
|
+
if (initObject == null) {
|
|
140
|
+
for (const key in obj) {
|
|
141
|
+
if (typeof obj[key] === "function")
|
|
142
|
+
continue;
|
|
143
|
+
if (key.startsWith("__"))
|
|
144
|
+
continue;
|
|
145
|
+
delete obj[key];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (typeof initObject == "object") {
|
|
149
|
+
for (const key in initObject) {
|
|
150
|
+
if (key.startsWith("__"))
|
|
151
|
+
continue;
|
|
152
|
+
if (fullUpdate ||
|
|
153
|
+
Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
154
|
+
obj[key] = initObject[key];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
/* -------------------------------------------------------------------------- */
|
|
161
|
+
static getValue(o, key, original = false) {
|
|
162
|
+
if (o == null)
|
|
163
|
+
return undefined;
|
|
164
|
+
if (o instanceof SimpleObject && typeof o.getValue === "function")
|
|
165
|
+
return o.getValue(key, original);
|
|
166
|
+
if (!original &&
|
|
167
|
+
o.__use_delta != false &&
|
|
168
|
+
typeof o.__delta === "object" &&
|
|
169
|
+
key in o.__delta) {
|
|
170
|
+
//@ts-ignore
|
|
171
|
+
return o.__delta[key];
|
|
172
|
+
}
|
|
173
|
+
return o[key];
|
|
174
|
+
}
|
|
175
|
+
getValue = this.#getProperty;
|
|
176
|
+
get = this.#getProperty;
|
|
52
177
|
/**
|
|
53
|
-
* set
|
|
54
|
-
* @param toObj
|
|
55
|
-
*/
|
|
56
|
-
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _setSaveResultObject);
|
|
57
|
-
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _getProperty);
|
|
58
|
-
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _setDefaultPropertyNow);
|
|
59
|
-
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _setDefaultProperty);
|
|
60
|
-
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _setProperty);
|
|
61
|
-
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _getSubProperty);
|
|
62
|
-
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _setSubProperty);
|
|
63
|
-
//an exact copy of this object is stored here
|
|
64
|
-
_defineProperty(_assertThisInitialized(_this), "__originalobject", void 0);
|
|
65
|
-
//changes are saved here
|
|
66
|
-
_defineProperty(_assertThisInitialized(_this), "__delta", {});
|
|
67
|
-
_defineProperty(_assertThisInitialized(_this), "__changed", false);
|
|
68
|
-
//the last thing that was changed on this object
|
|
69
|
-
_defineProperty(_assertThisInitialized(_this), "__lastChanged", void 0);
|
|
70
|
-
//is the object read only
|
|
71
|
-
_defineProperty(_assertThisInitialized(_this), "__is_readonly", void 0);
|
|
72
|
-
//should we throw errors when encountering an error?
|
|
73
|
-
//is TRUE by default
|
|
74
|
-
_defineProperty(_assertThisInitialized(_this), "__throw_errors", void 0);
|
|
75
|
-
//is this object marked as deleted?
|
|
76
|
-
_defineProperty(_assertThisInitialized(_this), "_deleted", void 0);
|
|
77
|
-
_defineProperty(_assertThisInitialized(_this), "_archived", void 0);
|
|
78
|
-
_defineProperty(_assertThisInitialized(_this), "_deletedBy", void 0);
|
|
79
|
-
//errors
|
|
80
|
-
_defineProperty(_assertThisInitialized(_this), "__errors", void 0);
|
|
81
|
-
_defineProperty(_assertThisInitialized(_this), "__showErrors", void 0);
|
|
82
|
-
//refresh func
|
|
83
|
-
_defineProperty(_assertThisInitialized(_this), "__refresh_functions", void 0);
|
|
84
|
-
//save results
|
|
85
|
-
_defineProperty(_assertThisInitialized(_this), "__saveResultObject", void 0);
|
|
86
|
-
_defineProperty(_assertThisInitialized(_this), "__saveResultIsSuccess", true);
|
|
87
|
-
_defineProperty(_assertThisInitialized(_this), "__saveResultType", void 0);
|
|
88
|
-
//sequence key (usually managed by the database)
|
|
89
|
-
_defineProperty(_assertThisInitialized(_this), "_index_key", "");
|
|
90
|
-
//sequence value , used to index the object with increasing numbers
|
|
91
|
-
_defineProperty(_assertThisInitialized(_this), "_index_value", -1);
|
|
92
|
-
_defineProperty(_assertThisInitialized(_this), "getValue", _classPrivateMethodGet(_assertThisInitialized(_this), _getProperty, _getProperty2));
|
|
93
|
-
_defineProperty(_assertThisInitialized(_this), "get", _classPrivateMethodGet(_assertThisInitialized(_this), _getProperty, _getProperty2));
|
|
94
|
-
_defineProperty(_assertThisInitialized(_this), "set", _this.setValue);
|
|
95
|
-
/**
|
|
96
|
-
* set value of a key to now date time
|
|
178
|
+
* set value
|
|
97
179
|
* @param key
|
|
98
180
|
* @param value
|
|
181
|
+
* @return true if changed , false otherwise
|
|
182
|
+
*/
|
|
183
|
+
async setValue(key, value, sendChanges = "auto") {
|
|
184
|
+
if (!this.canModify) {
|
|
185
|
+
if (this.__throw_errors !== false)
|
|
186
|
+
throw Error("Cant use setValue when on readonly mode");
|
|
187
|
+
else
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
let isValueChanged = false;
|
|
191
|
+
try {
|
|
192
|
+
const oldval = this.getValue(key);
|
|
193
|
+
if (!object_equals(oldval, value, {
|
|
194
|
+
strictArrayCheck: true,
|
|
195
|
+
ignoredStartingWords: "_",
|
|
196
|
+
})) {
|
|
197
|
+
this.#setProperty(key, value);
|
|
198
|
+
isValueChanged = true;
|
|
199
|
+
}
|
|
200
|
+
else
|
|
201
|
+
isValueChanged = false;
|
|
202
|
+
//console.log("SV:", isValueChanged, oldval, key, value);
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
if (sendChanges === true ||
|
|
206
|
+
(sendChanges === "auto" && isValueChanged)) {
|
|
207
|
+
await this.notifyChanged("", key, value);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return isValueChanged;
|
|
211
|
+
}
|
|
212
|
+
set = this.setValue;
|
|
213
|
+
async setTemp(key, value, sendChanges = false) {
|
|
214
|
+
let isValueChanged = await super.setTemp(key, value);
|
|
215
|
+
if (sendChanges === true ||
|
|
216
|
+
(sendChanges === "auto" && isValueChanged)) {
|
|
217
|
+
await this.notifyChanged("temp", key, value);
|
|
218
|
+
}
|
|
219
|
+
return isValueChanged;
|
|
220
|
+
}
|
|
221
|
+
/* ---------------------------- refresh functions --------------------------- */
|
|
222
|
+
async clearRefreshFunction() {
|
|
223
|
+
this.__refresh_functions = undefined;
|
|
224
|
+
}
|
|
225
|
+
async setRefreshFunction(new_fnc) {
|
|
226
|
+
return await this.addRefreshFunction(new_fnc);
|
|
227
|
+
}
|
|
228
|
+
async addRefreshFunction(key, new_fnc) {
|
|
229
|
+
if (typeof key === "function") {
|
|
230
|
+
new_fnc = key;
|
|
231
|
+
key = "main";
|
|
232
|
+
}
|
|
233
|
+
key = key || "main";
|
|
234
|
+
let oldFunctions = this.__refresh_functions;
|
|
235
|
+
if (oldFunctions == null || typeof oldFunctions !== "object")
|
|
236
|
+
oldFunctions = {};
|
|
237
|
+
oldFunctions[key] = new_fnc;
|
|
238
|
+
this.__refresh_functions = oldFunctions;
|
|
239
|
+
}
|
|
240
|
+
async runRefreshFunction(...params) {
|
|
241
|
+
let oldFunctions = this.__refresh_functions;
|
|
242
|
+
if (oldFunctions == null || typeof oldFunctions !== "object")
|
|
243
|
+
return;
|
|
244
|
+
const fncArray = Object.values(oldFunctions);
|
|
245
|
+
for (let index = 0; index < fncArray.length; index++) {
|
|
246
|
+
const fnc = fncArray[index];
|
|
247
|
+
await fn_eval(fnc, ...params);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/* -------------------------------------------------------------------------- */
|
|
251
|
+
/**
|
|
252
|
+
* calls `setValue` function for all props of `setObj`
|
|
253
|
+
* @param setObj
|
|
254
|
+
* @param changeablesOnly only updates the `__changeables` fields
|
|
99
255
|
* @returns
|
|
100
|
-
*/
|
|
101
|
-
|
|
256
|
+
*/
|
|
257
|
+
async setAll(setObj, changeablesOnly = true) {
|
|
258
|
+
let finalRes = true;
|
|
259
|
+
const checkKeys = changeablesOnly
|
|
260
|
+
? array_intersection(this.__changeables, Object.keys(setObj))
|
|
261
|
+
: Object.keys(setObj);
|
|
262
|
+
for (let index = 0; index < checkKeys.length; index++) {
|
|
263
|
+
const key = checkKeys[index];
|
|
264
|
+
if (!(await this.setValue(key, setObj[key])))
|
|
265
|
+
finalRes = false;
|
|
266
|
+
}
|
|
267
|
+
return finalRes;
|
|
268
|
+
}
|
|
102
269
|
/**
|
|
103
270
|
* set value of a key only if the value is empty (null,undef,"")
|
|
104
271
|
* @param key
|
|
105
272
|
* @param value
|
|
106
273
|
* @returns
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return undefined;
|
|
112
|
-
});
|
|
113
|
-
_this.__is_readonly = is_readonly;
|
|
114
|
-
_this.clear_changes();
|
|
115
|
-
return _this;
|
|
116
|
-
}
|
|
117
|
-
_createClass(SimpleObject, [{
|
|
118
|
-
key: "_static",
|
|
119
|
-
value: function _static() {
|
|
120
|
-
return this.constructor;
|
|
121
|
-
}
|
|
122
|
-
}, {
|
|
123
|
-
key: "loadValues",
|
|
124
|
-
value: /* -------------------------------------------------------------------------- */
|
|
125
|
-
/* Load */
|
|
126
|
-
/* -------------------------------------------------------------------------- */
|
|
127
|
-
function loadValues(initObject) {
|
|
128
|
-
var fullUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
129
|
-
return SimpleObject.loadValues(this, initObject, fullUpdate);
|
|
130
|
-
}
|
|
131
|
-
}, {
|
|
132
|
-
key: "setValue",
|
|
133
|
-
value:
|
|
274
|
+
*/
|
|
275
|
+
setDefaultValue(key, value) {
|
|
276
|
+
return this.#setDefaultProperty(key, value);
|
|
277
|
+
}
|
|
134
278
|
/**
|
|
135
|
-
* set value
|
|
279
|
+
* set value of a key to now date time
|
|
136
280
|
* @param key
|
|
137
281
|
* @param value
|
|
138
|
-
* @return true if changed , false otherwise
|
|
139
|
-
*/
|
|
140
|
-
function setValue(_x, _x2) {
|
|
141
|
-
return (_setValue = _setValue || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, value) {
|
|
142
|
-
var sendChanges,
|
|
143
|
-
isValueChanged,
|
|
144
|
-
oldval,
|
|
145
|
-
_args = arguments;
|
|
146
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
147
|
-
while (1) switch (_context.prev = _context.next) {
|
|
148
|
-
case 0:
|
|
149
|
-
sendChanges = _args.length > 2 && _args[2] !== undefined ? _args[2] : "auto";
|
|
150
|
-
if (this.canModify) {
|
|
151
|
-
_context.next = 7;
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
if (!(this.__throw_errors !== false)) {
|
|
155
|
-
_context.next = 6;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
throw Error("Cant use setValue when on readonly mode");
|
|
159
|
-
case 6:
|
|
160
|
-
return _context.abrupt("return", false);
|
|
161
|
-
case 7:
|
|
162
|
-
isValueChanged = false;
|
|
163
|
-
_context.prev = 8;
|
|
164
|
-
oldval = this.getValue(key);
|
|
165
|
-
if (!(0, _object.object_equals)(oldval, value, {
|
|
166
|
-
strictArrayCheck: true,
|
|
167
|
-
ignoredStartingWords: "_"
|
|
168
|
-
})) {
|
|
169
|
-
_classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, value);
|
|
170
|
-
isValueChanged = true;
|
|
171
|
-
} else isValueChanged = false;
|
|
172
|
-
//console.log("SV:", isValueChanged, oldval, key, value);
|
|
173
|
-
case 11:
|
|
174
|
-
_context.prev = 11;
|
|
175
|
-
if (!(sendChanges === true || sendChanges === "auto" && isValueChanged)) {
|
|
176
|
-
_context.next = 15;
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
_context.next = 15;
|
|
180
|
-
return this.notifyChanged("", key, value);
|
|
181
|
-
case 15:
|
|
182
|
-
return _context.finish(11);
|
|
183
|
-
case 16:
|
|
184
|
-
return _context.abrupt("return", isValueChanged);
|
|
185
|
-
case 17:
|
|
186
|
-
case "end":
|
|
187
|
-
return _context.stop();
|
|
188
|
-
}
|
|
189
|
-
}, _callee, this, [[8,, 11, 16]]);
|
|
190
|
-
}))).apply(this, arguments);
|
|
191
|
-
}
|
|
192
|
-
}, {
|
|
193
|
-
key: "setTemp",
|
|
194
|
-
value: function setTemp(_x3, _x4) {
|
|
195
|
-
return (_setTemp = _setTemp || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, value) {
|
|
196
|
-
var sendChanges,
|
|
197
|
-
isValueChanged,
|
|
198
|
-
_args2 = arguments;
|
|
199
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
200
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
201
|
-
case 0:
|
|
202
|
-
sendChanges = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : false;
|
|
203
|
-
_context2.next = 3;
|
|
204
|
-
return _get(_getPrototypeOf(SimpleObject.prototype), "setTemp", this).call(this, key, value);
|
|
205
|
-
case 3:
|
|
206
|
-
isValueChanged = _context2.sent;
|
|
207
|
-
if (!(sendChanges === true || sendChanges === "auto" && isValueChanged)) {
|
|
208
|
-
_context2.next = 7;
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
_context2.next = 7;
|
|
212
|
-
return this.notifyChanged("temp", key, value);
|
|
213
|
-
case 7:
|
|
214
|
-
return _context2.abrupt("return", isValueChanged);
|
|
215
|
-
case 8:
|
|
216
|
-
case "end":
|
|
217
|
-
return _context2.stop();
|
|
218
|
-
}
|
|
219
|
-
}, _callee2, this);
|
|
220
|
-
}))).apply(this, arguments);
|
|
221
|
-
} /* ---------------------------- refresh functions --------------------------- */
|
|
222
|
-
}, {
|
|
223
|
-
key: "clearRefreshFunction",
|
|
224
|
-
value: function clearRefreshFunction() {
|
|
225
|
-
return (_clearRefreshFunction = _clearRefreshFunction || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
226
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
227
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
228
|
-
case 0:
|
|
229
|
-
this.__refresh_functions = undefined;
|
|
230
|
-
case 1:
|
|
231
|
-
case "end":
|
|
232
|
-
return _context3.stop();
|
|
233
|
-
}
|
|
234
|
-
}, _callee3, this);
|
|
235
|
-
}))).apply(this, arguments);
|
|
236
|
-
}
|
|
237
|
-
}, {
|
|
238
|
-
key: "setRefreshFunction",
|
|
239
|
-
value: function setRefreshFunction(_x5) {
|
|
240
|
-
return (_setRefreshFunction = _setRefreshFunction || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(new_fnc) {
|
|
241
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
242
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
243
|
-
case 0:
|
|
244
|
-
_context4.next = 2;
|
|
245
|
-
return this.addRefreshFunction(new_fnc);
|
|
246
|
-
case 2:
|
|
247
|
-
return _context4.abrupt("return", _context4.sent);
|
|
248
|
-
case 3:
|
|
249
|
-
case "end":
|
|
250
|
-
return _context4.stop();
|
|
251
|
-
}
|
|
252
|
-
}, _callee4, this);
|
|
253
|
-
}))).apply(this, arguments);
|
|
254
|
-
}
|
|
255
|
-
}, {
|
|
256
|
-
key: "addRefreshFunction",
|
|
257
|
-
value: function addRefreshFunction(_x6, _x7) {
|
|
258
|
-
return (_addRefreshFunction = _addRefreshFunction || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(key, new_fnc) {
|
|
259
|
-
var oldFunctions;
|
|
260
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
261
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
262
|
-
case 0:
|
|
263
|
-
if (typeof key === "function") {
|
|
264
|
-
new_fnc = key;
|
|
265
|
-
key = "main";
|
|
266
|
-
}
|
|
267
|
-
key = key || "main";
|
|
268
|
-
oldFunctions = this.__refresh_functions;
|
|
269
|
-
if (oldFunctions == null || _typeof(oldFunctions) !== "object") oldFunctions = {};
|
|
270
|
-
oldFunctions[key] = new_fnc;
|
|
271
|
-
this.__refresh_functions = oldFunctions;
|
|
272
|
-
case 6:
|
|
273
|
-
case "end":
|
|
274
|
-
return _context5.stop();
|
|
275
|
-
}
|
|
276
|
-
}, _callee5, this);
|
|
277
|
-
}))).apply(this, arguments);
|
|
278
|
-
}
|
|
279
|
-
}, {
|
|
280
|
-
key: "runRefreshFunction",
|
|
281
|
-
value: function runRefreshFunction() {
|
|
282
|
-
return (_runRefreshFunction = _runRefreshFunction || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
283
|
-
var oldFunctions,
|
|
284
|
-
fncArray,
|
|
285
|
-
_len,
|
|
286
|
-
params,
|
|
287
|
-
_key,
|
|
288
|
-
index,
|
|
289
|
-
fnc,
|
|
290
|
-
_args6 = arguments;
|
|
291
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
292
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
293
|
-
case 0:
|
|
294
|
-
oldFunctions = this.__refresh_functions;
|
|
295
|
-
if (!(oldFunctions == null || _typeof(oldFunctions) !== "object")) {
|
|
296
|
-
_context6.next = 3;
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
299
|
-
return _context6.abrupt("return");
|
|
300
|
-
case 3:
|
|
301
|
-
fncArray = Object.values(oldFunctions);
|
|
302
|
-
for (_len = _args6.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
303
|
-
params[_key] = _args6[_key];
|
|
304
|
-
}
|
|
305
|
-
index = 0;
|
|
306
|
-
case 6:
|
|
307
|
-
if (!(index < fncArray.length)) {
|
|
308
|
-
_context6.next = 13;
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
fnc = fncArray[index];
|
|
312
|
-
_context6.next = 10;
|
|
313
|
-
return _object.fn_eval.apply(void 0, [fnc].concat(params));
|
|
314
|
-
case 10:
|
|
315
|
-
index++;
|
|
316
|
-
_context6.next = 6;
|
|
317
|
-
break;
|
|
318
|
-
case 13:
|
|
319
|
-
case "end":
|
|
320
|
-
return _context6.stop();
|
|
321
|
-
}
|
|
322
|
-
}, _callee6, this);
|
|
323
|
-
}))).apply(this, arguments);
|
|
324
|
-
}
|
|
325
|
-
/* -------------------------------------------------------------------------- */
|
|
326
|
-
/**
|
|
327
|
-
* calls `setValue` function for all props of `setObj`
|
|
328
|
-
* @param setObj
|
|
329
|
-
* @param changeablesOnly only updates the `__changeables` fields
|
|
330
282
|
* @returns
|
|
331
|
-
*/
|
|
332
|
-
|
|
333
|
-
key: "setAll",
|
|
334
|
-
value: function setAll(_x8) {
|
|
335
|
-
return (_setAll = _setAll || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(setObj) {
|
|
336
|
-
var changeablesOnly,
|
|
337
|
-
finalRes,
|
|
338
|
-
checkKeys,
|
|
339
|
-
index,
|
|
340
|
-
key,
|
|
341
|
-
_args7 = arguments;
|
|
342
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
343
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
344
|
-
case 0:
|
|
345
|
-
changeablesOnly = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : true;
|
|
346
|
-
finalRes = true;
|
|
347
|
-
checkKeys = changeablesOnly ? (0, _object.array_intersection)(this.__changeables, Object.keys(setObj)) : Object.keys(setObj);
|
|
348
|
-
index = 0;
|
|
349
|
-
case 4:
|
|
350
|
-
if (!(index < checkKeys.length)) {
|
|
351
|
-
_context7.next = 13;
|
|
352
|
-
break;
|
|
353
|
-
}
|
|
354
|
-
key = checkKeys[index];
|
|
355
|
-
_context7.next = 8;
|
|
356
|
-
return this.setValue(key, setObj[key]);
|
|
357
|
-
case 8:
|
|
358
|
-
if (_context7.sent) {
|
|
359
|
-
_context7.next = 10;
|
|
360
|
-
break;
|
|
361
|
-
}
|
|
362
|
-
finalRes = false;
|
|
363
|
-
case 10:
|
|
364
|
-
index++;
|
|
365
|
-
_context7.next = 4;
|
|
366
|
-
break;
|
|
367
|
-
case 13:
|
|
368
|
-
return _context7.abrupt("return", finalRes);
|
|
369
|
-
case 14:
|
|
370
|
-
case "end":
|
|
371
|
-
return _context7.stop();
|
|
372
|
-
}
|
|
373
|
-
}, _callee7, this);
|
|
374
|
-
}))).apply(this, arguments);
|
|
375
|
-
}
|
|
283
|
+
*/
|
|
284
|
+
setDefaultValueNow = this.#setDefaultPropertyNow;
|
|
376
285
|
/**
|
|
377
286
|
* set value of a key only if the value is empty (null,undef,"")
|
|
378
287
|
* @param key
|
|
379
288
|
* @param value
|
|
380
289
|
* @returns
|
|
381
|
-
*/
|
|
382
|
-
|
|
383
|
-
key: "setDefaultValue",
|
|
384
|
-
value: function setDefaultValue(key, value) {
|
|
385
|
-
return _classPrivateMethodGet(this, _setDefaultProperty, _setDefaultProperty2).call(this, key, value);
|
|
386
|
-
}
|
|
387
|
-
}, {
|
|
388
|
-
key: "setSubValue",
|
|
389
|
-
value:
|
|
290
|
+
*/
|
|
291
|
+
setDefault = this.setDefaultValue;
|
|
390
292
|
/**
|
|
391
293
|
* set key of subObject
|
|
392
294
|
* @param key
|
|
393
295
|
* @param value
|
|
394
296
|
* @param subvalue
|
|
395
297
|
* @return true if changed , false otherwise
|
|
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
|
-
_classPrivateMethodGet(this, _setSubProperty, _setSubProperty2).call(this, key, objKey, subvalue);
|
|
428
|
-
isValueChanged = true;
|
|
429
|
-
} else isValueChanged = false;
|
|
430
|
-
case 11:
|
|
431
|
-
_context8.prev = 11;
|
|
432
|
-
if (!(sendChanges === true || sendChanges === "auto" && isValueChanged)) {
|
|
433
|
-
_context8.next = 15;
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
_context8.next = 15;
|
|
437
|
-
return this.notifyChanged("", key, objKey, subvalue);
|
|
438
|
-
case 15:
|
|
439
|
-
return _context8.finish(11);
|
|
440
|
-
case 16:
|
|
441
|
-
return _context8.abrupt("return", isValueChanged);
|
|
442
|
-
case 17:
|
|
443
|
-
case "end":
|
|
444
|
-
return _context8.stop();
|
|
445
|
-
}
|
|
446
|
-
}, _callee8, this, [[8,, 11, 16]]);
|
|
447
|
-
}))).apply(this, arguments);
|
|
448
|
-
}
|
|
449
|
-
}, {
|
|
450
|
-
key: "pushValue",
|
|
451
|
-
value:
|
|
298
|
+
*/
|
|
299
|
+
async setSubValue(key, objKey, subvalue, sendChanges = "auto") {
|
|
300
|
+
if (!this.canModify) {
|
|
301
|
+
if (this.__throw_errors !== false)
|
|
302
|
+
throw Error("Cant use setValue when on readonly mode");
|
|
303
|
+
else
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
let isValueChanged = false;
|
|
307
|
+
try {
|
|
308
|
+
//if accessing subval of an object, make sure the object is not null
|
|
309
|
+
const subval = this.#getSubProperty(key, objKey);
|
|
310
|
+
if (!object_equals(subval, subvalue, {
|
|
311
|
+
ignoredStartingWords: "_",
|
|
312
|
+
strictArrayCheck: true,
|
|
313
|
+
})) {
|
|
314
|
+
this.#setSubProperty(key, objKey, subvalue);
|
|
315
|
+
isValueChanged = true;
|
|
316
|
+
}
|
|
317
|
+
else
|
|
318
|
+
isValueChanged = false;
|
|
319
|
+
}
|
|
320
|
+
finally {
|
|
321
|
+
if (sendChanges === true ||
|
|
322
|
+
(sendChanges === "auto" && isValueChanged)) {
|
|
323
|
+
await this.notifyChanged("", key, objKey, subvalue);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return isValueChanged;
|
|
327
|
+
}
|
|
328
|
+
getSubValue = this.#getSubProperty;
|
|
452
329
|
/**
|
|
453
330
|
* Push a single value to array property
|
|
454
331
|
* @param key
|
|
455
332
|
* @param value
|
|
456
333
|
* @param sendChanges
|
|
457
334
|
* @returns
|
|
458
|
-
*/
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
_args9 = arguments;
|
|
463
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
464
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
465
|
-
case 0:
|
|
466
|
-
sendChanges = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : "auto";
|
|
467
|
-
_context9.next = 3;
|
|
468
|
-
return this.pushValues(key, [value], sendChanges);
|
|
469
|
-
case 3:
|
|
470
|
-
return _context9.abrupt("return", _context9.sent);
|
|
471
|
-
case 4:
|
|
472
|
-
case "end":
|
|
473
|
-
return _context9.stop();
|
|
474
|
-
}
|
|
475
|
-
}, _callee9, this);
|
|
476
|
-
}))).apply(this, arguments);
|
|
477
|
-
}
|
|
335
|
+
*/
|
|
336
|
+
async pushValue(key, value, sendChanges = "auto") {
|
|
337
|
+
return await this.pushValues(key, [value], sendChanges);
|
|
338
|
+
}
|
|
478
339
|
/**
|
|
479
340
|
* Push a list of values to array property
|
|
480
341
|
* @param key
|
|
481
342
|
* @param values
|
|
482
343
|
* @param sendChanges
|
|
483
344
|
* @returns
|
|
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
|
-
_classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, (0, _object.array_merge)(tempArray, values));
|
|
529
|
-
if (!(sendChanges === true || sendChanges === "auto")) {
|
|
530
|
-
_context10.next = 21;
|
|
531
|
-
break;
|
|
532
|
-
}
|
|
533
|
-
_context10.next = 21;
|
|
534
|
-
return this.notifyChanged("", key, values);
|
|
535
|
-
case 21:
|
|
536
|
-
return _context10.abrupt("return", tempArray);
|
|
537
|
-
case 22:
|
|
538
|
-
case "end":
|
|
539
|
-
return _context10.stop();
|
|
540
|
-
}
|
|
541
|
-
}, _callee10, this);
|
|
542
|
-
}))).apply(this, arguments);
|
|
543
|
-
}
|
|
544
|
-
}, {
|
|
545
|
-
key: "notifyChanged",
|
|
546
|
-
value: function notifyChanged(_x16, _x17, _x18, _x19) {
|
|
547
|
-
return (_notifyChanged = _notifyChanged || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(type, key, value, subvalue) {
|
|
548
|
-
var lc, manager_class;
|
|
549
|
-
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
550
|
-
while (1) switch (_context11.prev = _context11.next) {
|
|
551
|
-
case 0:
|
|
552
|
-
if (value === undefined && type == "") value = this.getValue(key);
|
|
553
|
-
this.__changed = true;
|
|
554
|
-
lc = "";
|
|
555
|
-
if (type) lc += "$".concat(String(type), "$");
|
|
556
|
-
if (subvalue) {
|
|
557
|
-
lc += "".concat(String(key), ".").concat(value);
|
|
558
|
-
} else {
|
|
559
|
-
lc += "".concat(String(key));
|
|
560
|
-
}
|
|
561
|
-
this.__lastChanged = lc;
|
|
562
|
-
/* --------------------------- notify the manager --------------------------- */
|
|
563
|
-
manager_class = this.manager;
|
|
564
|
-
if (!(manager_class instanceof _ObjectManager["default"])) {
|
|
565
|
-
_context11.next = 10;
|
|
566
|
-
break;
|
|
567
|
-
}
|
|
568
|
-
_context11.next = 10;
|
|
569
|
-
return manager_class.notifyChanged(type, key, value, subvalue);
|
|
570
|
-
case 10:
|
|
571
|
-
case "end":
|
|
572
|
-
return _context11.stop();
|
|
573
|
-
}
|
|
574
|
-
}, _callee11, this);
|
|
575
|
-
}))).apply(this, arguments);
|
|
576
|
-
}
|
|
345
|
+
*/
|
|
346
|
+
async pushValues(key, values, sendChanges = "auto") {
|
|
347
|
+
if (array_isEmpty(values))
|
|
348
|
+
return false;
|
|
349
|
+
if (!this.canModify) {
|
|
350
|
+
if (this.__throw_errors !== false)
|
|
351
|
+
throw Error("Cant use pushValues when on readonly mode");
|
|
352
|
+
else
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
if (this.#getProperty(key) == null)
|
|
356
|
+
this.#setProperty(key, []);
|
|
357
|
+
let tempArray = this.#getProperty(key);
|
|
358
|
+
if (!Array.isArray(tempArray)) {
|
|
359
|
+
if (this.__throw_errors !== false)
|
|
360
|
+
throw Error("Cant use pushValues on non Array keys");
|
|
361
|
+
else
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
this.#setProperty(key, array_merge(tempArray, values));
|
|
365
|
+
if (sendChanges === true || sendChanges === "auto")
|
|
366
|
+
await this.notifyChanged("", key, values);
|
|
367
|
+
return tempArray;
|
|
368
|
+
}
|
|
369
|
+
async notifyChanged(type, key, value, subvalue) {
|
|
370
|
+
if (value === undefined && type == "")
|
|
371
|
+
value = this.getValue(key);
|
|
372
|
+
this.__changed = true;
|
|
373
|
+
let lc = "";
|
|
374
|
+
if (type)
|
|
375
|
+
lc += `$${String(type)}$`;
|
|
376
|
+
if (subvalue) {
|
|
377
|
+
lc += `${String(key)}.${value}`;
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
lc += `${String(key)}`;
|
|
381
|
+
}
|
|
382
|
+
this.__lastChanged = lc;
|
|
383
|
+
/* --------------------------- notify the manager --------------------------- */
|
|
384
|
+
const manager_class = this.manager;
|
|
385
|
+
if (manager_class instanceof ObjectManager) {
|
|
386
|
+
await manager_class.notifyChanged(type, key, value, subvalue);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
577
389
|
/**
|
|
578
390
|
* check if a key can be changed on an object
|
|
579
391
|
* @param object the object we are checking
|
|
580
392
|
* @param key key of the object
|
|
581
393
|
* @param useExtraProps should we check extra props?
|
|
582
394
|
* @returns
|
|
583
|
-
*/
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
395
|
+
*/
|
|
396
|
+
static canChangeKey(object, key, options) {
|
|
397
|
+
if (!object || !key)
|
|
398
|
+
return false;
|
|
399
|
+
const { useExtraProps, ignoreProtected } = options;
|
|
400
|
+
if (useExtraProps) {
|
|
401
|
+
const __extraProperties = object.constructor["__extraProperties"];
|
|
402
|
+
if (__extraProperties != null && __extraProperties.includes(key))
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
/* -------------------------------------------------------------------------- */
|
|
406
|
+
const __changeables = object.constructor["__changeables"];
|
|
407
|
+
const __unchangeables = object.constructor["__unchangeables"];
|
|
408
|
+
/* -------------------------------------------------------------------------- */
|
|
409
|
+
if (__changeables != null && !__changeables.includes(key))
|
|
410
|
+
return false;
|
|
411
|
+
if (__unchangeables != null && __unchangeables.includes(key))
|
|
412
|
+
return false;
|
|
413
|
+
if (ignoreProtected !== true) {
|
|
414
|
+
const __protectedProperties = object.constructor["__protectedProperties"];
|
|
415
|
+
if (__protectedProperties != null &&
|
|
416
|
+
__protectedProperties.includes(key)) {
|
|
417
|
+
//protected keys can only be changed by the creator of this object
|
|
418
|
+
//make sure you set the is_current_user function correctly
|
|
419
|
+
if (object.isNew)
|
|
420
|
+
return true;
|
|
421
|
+
const creatorOfObject = object.get("_creator");
|
|
422
|
+
return Boolean(gfunc.run_action_sync("is_current_user", creatorOfObject));
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
static hasIllegalChanges(referenceObject, changesObject, updaterUser) {
|
|
428
|
+
const __protectedProperties = object_getStatic(referenceObject, "__protectedProperties");
|
|
429
|
+
if (object_isEmpty(__protectedProperties))
|
|
430
|
+
return false;
|
|
431
|
+
const referenceUser = object_isClass(referenceObject)
|
|
432
|
+
? object_get(changesObject, "__user", "_creator")
|
|
433
|
+
: object_get(referenceObject, "__user", "_creator");
|
|
434
|
+
if (Boolean(SimpleObject.getID(referenceUser) ==
|
|
435
|
+
SimpleObject.getID(updaterUser))) {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
for (const key in changesObject) {
|
|
439
|
+
if (__protectedProperties.includes(key)) {
|
|
440
|
+
return true;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
/* -------------------------------------------------------------------------- */
|
|
446
|
+
/* Changes */
|
|
447
|
+
/* -------------------------------------------------------------------------- */
|
|
589
448
|
/**
|
|
590
|
-
* Apply the changes and empty the delta object
|
|
591
|
-
*/
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
449
|
+
* Apply all the changes and empty the delta object
|
|
450
|
+
*/
|
|
451
|
+
apply_changes() {
|
|
452
|
+
try {
|
|
453
|
+
if (!this.__use_delta) {
|
|
454
|
+
//in this mode , we track changes by updating the original product
|
|
455
|
+
this.setOriginal();
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
if (!this.isChanged) {
|
|
459
|
+
console.warn("No changes to apply");
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
for (const key in this.__delta) {
|
|
463
|
+
const nv = this.__delta[key];
|
|
464
|
+
this[key] = nv;
|
|
465
|
+
}
|
|
466
|
+
return true;
|
|
467
|
+
}
|
|
468
|
+
finally {
|
|
469
|
+
this.clear_changes();
|
|
470
|
+
}
|
|
471
|
+
}
|
|
612
472
|
/**
|
|
613
|
-
* apply changes for the given
|
|
473
|
+
* apply changes for the given fields
|
|
614
474
|
* @param key
|
|
615
475
|
* @returns
|
|
616
|
-
*/
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
476
|
+
*/
|
|
477
|
+
apply(keylist) {
|
|
478
|
+
wrap_array(keylist).forEach((key) => {
|
|
479
|
+
try {
|
|
480
|
+
if (!this.__use_delta) {
|
|
481
|
+
//in this mode , we track changes by updating the original
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
if (this.__delta != null && key in this.__delta) {
|
|
485
|
+
this[key] = this.__delta[key];
|
|
486
|
+
delete this.__delta[key];
|
|
487
|
+
}
|
|
488
|
+
return true;
|
|
489
|
+
}
|
|
490
|
+
finally {
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
632
495
|
/**
|
|
633
496
|
* set the value to its original
|
|
634
497
|
* @param key
|
|
635
|
-
*/
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
return (_reset = _reset || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(key) {
|
|
640
|
-
var notifyChanged,
|
|
641
|
-
_args12 = arguments;
|
|
642
|
-
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
643
|
-
while (1) switch (_context12.prev = _context12.next) {
|
|
644
|
-
case 0:
|
|
645
|
-
notifyChanged = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : "auto";
|
|
646
|
-
_context12.next = 3;
|
|
647
|
-
return this.setValue(key, this[key], notifyChanged);
|
|
648
|
-
case 3:
|
|
649
|
-
return _context12.abrupt("return", _context12.sent);
|
|
650
|
-
case 4:
|
|
651
|
-
case "end":
|
|
652
|
-
return _context12.stop();
|
|
653
|
-
}
|
|
654
|
-
}, _callee12, this);
|
|
655
|
-
}))).apply(this, arguments);
|
|
656
|
-
}
|
|
498
|
+
*/
|
|
499
|
+
async reset(key, notifyChanged = "auto") {
|
|
500
|
+
return await this.setValue(key, this[key], notifyChanged);
|
|
501
|
+
}
|
|
657
502
|
/**
|
|
658
503
|
* reset all values back to their original
|
|
659
504
|
* difference between this and clear_changes is that this function also calls on_change
|
|
660
505
|
* @param key
|
|
661
|
-
*/
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
_args13 = arguments;
|
|
670
|
-
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
671
|
-
while (1) switch (_context13.prev = _context13.next) {
|
|
672
|
-
case 0:
|
|
673
|
-
notifyChanged = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : "auto";
|
|
674
|
-
fr = true;
|
|
675
|
-
_context13.t0 = _regeneratorRuntime().keys(this.__delta);
|
|
676
|
-
case 3:
|
|
677
|
-
if ((_context13.t1 = _context13.t0()).done) {
|
|
678
|
-
_context13.next = 13;
|
|
679
|
-
break;
|
|
680
|
-
}
|
|
681
|
-
key = _context13.t1.value;
|
|
682
|
-
_context13.t2 = fr;
|
|
683
|
-
if (!_context13.t2) {
|
|
684
|
-
_context13.next = 10;
|
|
685
|
-
break;
|
|
686
|
-
}
|
|
687
|
-
_context13.next = 9;
|
|
688
|
-
return this.reset(key, notifyChanged);
|
|
689
|
-
case 9:
|
|
690
|
-
_context13.t2 = _context13.sent;
|
|
691
|
-
case 10:
|
|
692
|
-
fr = _context13.t2;
|
|
693
|
-
_context13.next = 3;
|
|
694
|
-
break;
|
|
695
|
-
case 13:
|
|
696
|
-
return _context13.abrupt("return", fr);
|
|
697
|
-
case 14:
|
|
698
|
-
case "end":
|
|
699
|
-
return _context13.stop();
|
|
700
|
-
}
|
|
701
|
-
}, _callee13, this);
|
|
702
|
-
}))).apply(this, arguments);
|
|
703
|
-
}
|
|
506
|
+
*/
|
|
507
|
+
async resetAll(notifyChanged = "auto") {
|
|
508
|
+
let fr = true;
|
|
509
|
+
for (const key in this.__delta) {
|
|
510
|
+
fr = fr && (await this.reset(key, notifyChanged));
|
|
511
|
+
}
|
|
512
|
+
return fr;
|
|
513
|
+
}
|
|
704
514
|
/**
|
|
705
515
|
* clear and discard all changes
|
|
706
516
|
* does not call any on_change functions
|
|
707
517
|
* @returns
|
|
708
|
-
*/
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
return true;
|
|
715
|
-
}
|
|
518
|
+
*/
|
|
519
|
+
clear_changes() {
|
|
520
|
+
this.__delta = {};
|
|
521
|
+
this.__changed = false;
|
|
522
|
+
return true;
|
|
523
|
+
}
|
|
716
524
|
/**
|
|
717
525
|
* clear and discard all temp values
|
|
718
526
|
* @returns
|
|
719
|
-
*/
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
return true;
|
|
725
|
-
}
|
|
527
|
+
*/
|
|
528
|
+
clear_cache() {
|
|
529
|
+
delete this.__temp;
|
|
530
|
+
return true;
|
|
531
|
+
}
|
|
726
532
|
/**
|
|
727
533
|
* Sets readonly property on given objects
|
|
728
534
|
* @param objs array of given objects or a single object
|
|
729
535
|
* @param readonlyval readonly
|
|
730
536
|
* @param clearChanges should we clean the changes after setting readonly
|
|
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
|
-
get
|
|
811
|
-
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
get
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
get
|
|
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
|
-
if (this.
|
|
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
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
537
|
+
*/
|
|
538
|
+
static setReadonly(objs, readonlyval = true, clearChanges = false) {
|
|
539
|
+
let checkObjs = [];
|
|
540
|
+
if (!objs)
|
|
541
|
+
objs = [];
|
|
542
|
+
if (!Array.isArray(objs))
|
|
543
|
+
checkObjs = [objs];
|
|
544
|
+
else
|
|
545
|
+
checkObjs = objs;
|
|
546
|
+
for (let index = 0; index < checkObjs.length; index++) {
|
|
547
|
+
const obj = checkObjs[index];
|
|
548
|
+
obj.__is_readonly = readonlyval;
|
|
549
|
+
if (obj instanceof SimpleObject) {
|
|
550
|
+
if (obj.canModify) {
|
|
551
|
+
if (!obj.getOriginal())
|
|
552
|
+
obj.setOriginal();
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
if (clearChanges)
|
|
556
|
+
obj.clear_changes();
|
|
557
|
+
//we dont need the original object in readonly mode
|
|
558
|
+
obj.setOriginal(null);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
static setThrowErrors(objs, throwErr = true) {
|
|
564
|
+
let checkObjs = [];
|
|
565
|
+
if (!objs)
|
|
566
|
+
objs = [];
|
|
567
|
+
if (!Array.isArray(objs))
|
|
568
|
+
checkObjs = [objs];
|
|
569
|
+
else
|
|
570
|
+
checkObjs = objs;
|
|
571
|
+
for (let index = 0; index < checkObjs.length; index++) {
|
|
572
|
+
const element = checkObjs[index];
|
|
573
|
+
element.__throw_errors = throwErr;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
/* -------------------------------------------------------------------------- */
|
|
577
|
+
/* Get/Check */
|
|
578
|
+
/* -------------------------------------------------------------------------- */
|
|
579
|
+
get isChanged() {
|
|
580
|
+
////const deltaIsBlank = object_isEmpty(this.__delta);
|
|
581
|
+
////if (!deltaIsBlank) return true; //delta is not blank, definitely changed
|
|
582
|
+
////if (this.__use_delta) return !deltaIsBlank; //trust the delta.
|
|
583
|
+
if (this.__use_delta)
|
|
584
|
+
return !object_isEmpty(this.__delta);
|
|
585
|
+
/* -------------------------------------------------------------------------- */
|
|
586
|
+
/* check the properties one by one */
|
|
587
|
+
/* -------------------------------------------------------------------------- */
|
|
588
|
+
const orig = this.getOriginal();
|
|
589
|
+
if (!orig)
|
|
590
|
+
return false; //we dont know if anything has changed
|
|
591
|
+
/* if object is not using delta mode, check changes by comparing changable fields with original object */
|
|
592
|
+
if (Array.isArray(this.__changeables)) {
|
|
593
|
+
//console.log("chk", this.__changeables, "for changes");
|
|
594
|
+
return (this.__changeables.find((c) => {
|
|
595
|
+
return !object_equals(this[c], orig[c]);
|
|
596
|
+
}) != undefined);
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
/* check all fields */
|
|
600
|
+
for (const key in this) {
|
|
601
|
+
if (key.startsWith("__"))
|
|
602
|
+
continue;
|
|
603
|
+
if (!object_equals(this[key], orig[key]))
|
|
604
|
+
return true;
|
|
605
|
+
}
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
610
|
+
get isArchived() {
|
|
611
|
+
return this._archived || false;
|
|
612
|
+
}
|
|
613
|
+
set isArchived(v) {
|
|
614
|
+
this._archived = v;
|
|
615
|
+
}
|
|
616
|
+
get isDeleted() {
|
|
617
|
+
return this.get("_deleted") || false;
|
|
618
|
+
}
|
|
619
|
+
set isDeleted(v) {
|
|
620
|
+
this._deleted = v;
|
|
621
|
+
}
|
|
622
|
+
get d() {
|
|
623
|
+
return this.__use_delta ? this.__delta : this;
|
|
624
|
+
}
|
|
625
|
+
/* all updated properties */
|
|
626
|
+
get allproperties() {
|
|
627
|
+
const result = { ...this, ...this.__delta };
|
|
628
|
+
result.__delta = {};
|
|
629
|
+
return result;
|
|
630
|
+
}
|
|
631
|
+
get canModify() {
|
|
632
|
+
return !Boolean(this.__is_readonly);
|
|
633
|
+
}
|
|
634
|
+
get __cache_name() {
|
|
635
|
+
return this.constructor["__cache_name"];
|
|
636
|
+
}
|
|
637
|
+
get __changeables() {
|
|
638
|
+
return this.constructor["__changeables"];
|
|
639
|
+
}
|
|
640
|
+
get __unchangeables() {
|
|
641
|
+
return this.constructor["__unchangeables"];
|
|
642
|
+
}
|
|
643
|
+
get __use_delta() {
|
|
644
|
+
return this.constructor["__use_delta"];
|
|
645
|
+
}
|
|
646
|
+
get isSaved() {
|
|
647
|
+
return Boolean(this.__saveResultIsSuccess ?? false);
|
|
648
|
+
}
|
|
649
|
+
get isNew() {
|
|
650
|
+
const mid = this.getID();
|
|
651
|
+
if (!mid)
|
|
652
|
+
return true;
|
|
653
|
+
if (typeof mid === "string")
|
|
654
|
+
return mid === "" || mid === "-1";
|
|
655
|
+
if (typeof mid === "number")
|
|
656
|
+
return mid === -1;
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
get lastChanged() {
|
|
660
|
+
return this.__lastChanged || "";
|
|
661
|
+
}
|
|
662
|
+
get manager() {
|
|
663
|
+
return this.get_managerClass() || undefined;
|
|
664
|
+
}
|
|
665
|
+
get_managerClass = () => undefined;
|
|
666
|
+
set_managerClass(mng) {
|
|
667
|
+
if (mng instanceof ObjectManager && typeof mng.event_run === "function")
|
|
668
|
+
this.get_managerClass = () => mng;
|
|
669
|
+
else {
|
|
670
|
+
console.error("set_managerClass was used with a bad manager. make sure the input to this function is a correct ObjectManager");
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
static isDeleted(obj) {
|
|
674
|
+
if (obj instanceof SimpleObject)
|
|
675
|
+
return obj.isDeleted === true;
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
getIndexOrID() {
|
|
679
|
+
return SimpleObject.getIndexOrID(this);
|
|
680
|
+
}
|
|
681
|
+
getIndex() {
|
|
682
|
+
return SimpleObject.getIndex(this);
|
|
683
|
+
}
|
|
684
|
+
getID() {
|
|
685
|
+
return SimpleObject.getID(this);
|
|
686
|
+
}
|
|
687
|
+
static getIndexOrID(o) {
|
|
688
|
+
let res = SimpleObject.getIndex(o);
|
|
689
|
+
if (!res || res == -1)
|
|
690
|
+
res = SimpleObject.getID(o);
|
|
691
|
+
return res || -1;
|
|
692
|
+
}
|
|
693
|
+
static getIndex(o) {
|
|
694
|
+
if (o == null || o == undefined)
|
|
695
|
+
return -1;
|
|
696
|
+
switch (typeof o) {
|
|
697
|
+
case "object":
|
|
698
|
+
return o._index_value || -1;
|
|
699
|
+
case "number":
|
|
700
|
+
case "string":
|
|
701
|
+
return Number(o);
|
|
702
|
+
}
|
|
703
|
+
return -1;
|
|
704
|
+
}
|
|
705
|
+
static getID(o) {
|
|
706
|
+
if (o == null || o == undefined)
|
|
707
|
+
return "";
|
|
708
|
+
switch (typeof o) {
|
|
709
|
+
case "object":
|
|
710
|
+
if (o._bsontype == "ObjectID" &&
|
|
711
|
+
typeof o.toString === "function") {
|
|
712
|
+
return o.toString();
|
|
713
|
+
}
|
|
714
|
+
return String(o._id || o.insertedId || o.ID || o.id || o.__data_id || "");
|
|
715
|
+
case "string":
|
|
716
|
+
case "number":
|
|
717
|
+
return String(o);
|
|
718
|
+
}
|
|
719
|
+
return "";
|
|
720
|
+
}
|
|
721
|
+
/* -------------------------------------------------------------------------- */
|
|
722
|
+
/* Events */
|
|
723
|
+
/* -------------------------------------------------------------------------- */
|
|
724
|
+
async event_run(eventName, ...params) {
|
|
725
|
+
if (!this.manager) {
|
|
726
|
+
if (this.__showErrors === true)
|
|
727
|
+
console.error("you cant use events if your object has no manager");
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
return await this.manager.event_run(eventName, ...params);
|
|
731
|
+
}
|
|
732
|
+
event_use(name, runEvent, onlyOn = null, runOnce = false) {
|
|
733
|
+
if (!this.manager) {
|
|
734
|
+
if (this.__showErrors === true)
|
|
735
|
+
console.error("you cant use events if your object has no manager");
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
return this.manager.event_use(name, runEvent, onlyOn, runOnce);
|
|
739
|
+
}
|
|
740
|
+
event_remove(name, uname) {
|
|
741
|
+
if (!this.manager) {
|
|
742
|
+
if (this.__showErrors === true)
|
|
743
|
+
console.error("you cant use events if your object has no manager");
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
return this.manager.event_remove(name, uname);
|
|
747
|
+
}
|
|
748
|
+
async event_add(name, uname, runEvent, onlyOn = null, runOnce = false) {
|
|
749
|
+
if (!this.manager) {
|
|
750
|
+
if (this.__showErrors === true)
|
|
751
|
+
console.error("you cant use events if your object has no manager");
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
await this.manager.event_add(name, uname, runEvent, onlyOn, runOnce);
|
|
755
|
+
}
|
|
756
|
+
/* -------------------------------------------------------------------------- */
|
|
757
|
+
/* Original */
|
|
758
|
+
/* -------------------------------------------------------------------------- */
|
|
759
|
+
getOriginal() {
|
|
760
|
+
return this.__originalobject || undefined;
|
|
761
|
+
}
|
|
762
|
+
setOriginal(toObj = 0) {
|
|
763
|
+
if (toObj === null) {
|
|
764
|
+
delete this.__originalobject;
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
if (!this.canModify) {
|
|
768
|
+
console.warn("Cant use setOriginal on non original OR readonly objects ! this will create an infinite loop");
|
|
769
|
+
delete this.__originalobject;
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
if (toObj === 0) {
|
|
773
|
+
toObj = this;
|
|
774
|
+
}
|
|
775
|
+
const cloneObject = object_clone(toObj);
|
|
776
|
+
SimpleObject.setReadonly(cloneObject, true);
|
|
777
|
+
this.__originalobject = object_removeKeys(cloneObject, ["__"]);
|
|
778
|
+
return this;
|
|
779
|
+
}
|
|
780
|
+
static setOriginal(obj, toObj = 0) {
|
|
781
|
+
if (!(obj instanceof SimpleObject))
|
|
782
|
+
return undefined;
|
|
783
|
+
return obj.setOriginal(toObj);
|
|
784
|
+
}
|
|
785
|
+
static getOriginal(obj) {
|
|
786
|
+
if (obj instanceof SimpleObject)
|
|
787
|
+
return obj.getOriginal();
|
|
788
|
+
return obj?.__originalobject;
|
|
789
|
+
}
|
|
790
|
+
/* -------------------------------------------------------------------------- */
|
|
791
|
+
/* Errors */
|
|
792
|
+
/* -------------------------------------------------------------------------- */
|
|
793
|
+
addError(title, message, sendToRegister = "auto") {
|
|
794
|
+
return SimpleObject.addError(this, title, message, sendToRegister);
|
|
795
|
+
}
|
|
796
|
+
clearErrors() {
|
|
797
|
+
return SimpleObject.clearErrors(this);
|
|
798
|
+
}
|
|
799
|
+
getErrors() {
|
|
800
|
+
return SimpleObject.getErrors(this);
|
|
801
|
+
}
|
|
802
|
+
static addError(o, title, message, sendToRegister = "auto") {
|
|
803
|
+
const errStr = combine_if_not_blank(title, " : ", message);
|
|
804
|
+
if (o) {
|
|
805
|
+
if (!Array.isArray(o.__errors))
|
|
806
|
+
o.__errors = [];
|
|
807
|
+
o.__errors.push(errStr);
|
|
808
|
+
if (o.__showErrors === false)
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
else if (sendToRegister === "auto")
|
|
812
|
+
sendToRegister = true;
|
|
813
|
+
if (sendToRegister === true) {
|
|
814
|
+
console.error("[REGISTER-ERROR]", errStr);
|
|
815
|
+
gfunc.run_action("add_error", {
|
|
816
|
+
title: title,
|
|
817
|
+
message: message,
|
|
818
|
+
type: "error",
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
console.error("[ERROR]", errStr);
|
|
823
|
+
}
|
|
824
|
+
return o?.__errors || [];
|
|
825
|
+
}
|
|
826
|
+
static getErrors(o) {
|
|
827
|
+
return o?.__errors || [];
|
|
828
|
+
}
|
|
829
|
+
static clearErrors(o) {
|
|
830
|
+
if (o)
|
|
831
|
+
o.__errors = [];
|
|
832
|
+
return true;
|
|
833
|
+
}
|
|
834
|
+
/* -------------------------------------------------------------------------- */
|
|
835
|
+
/* Save Results */
|
|
836
|
+
/* -------------------------------------------------------------------------- */
|
|
837
|
+
/**
|
|
838
|
+
* Checks if the given object is a valid and truthy save result
|
|
839
|
+
* @param result_object
|
|
840
|
+
* @returns
|
|
841
|
+
*/
|
|
842
|
+
static isResultValid(result_object, sub = false) {
|
|
843
|
+
if (object_isEmpty(result_object))
|
|
844
|
+
return false;
|
|
845
|
+
switch (typeof result_object) {
|
|
846
|
+
case "string":
|
|
847
|
+
try {
|
|
848
|
+
result_object = JSON.parse(result_object);
|
|
849
|
+
return this.isResultValid(result_object);
|
|
850
|
+
}
|
|
851
|
+
catch {
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
case "object":
|
|
855
|
+
/* --------- maybe website sends the result as array with 1 element --------- */
|
|
856
|
+
if (Array.isArray(result_object)) {
|
|
857
|
+
if (sub)
|
|
858
|
+
return false; //avoid going too deep
|
|
859
|
+
return this.isResultValid(array_first(result_object), true);
|
|
860
|
+
}
|
|
861
|
+
/* -------------------------- check if acknowledged ------------------------- */
|
|
862
|
+
if (object_isTrue(result_object.acknowledged)) {
|
|
863
|
+
return true;
|
|
864
|
+
}
|
|
865
|
+
if (result_object.expected && result_object.result) {
|
|
866
|
+
return object_equals(result_object.expected, result_object.result);
|
|
867
|
+
}
|
|
868
|
+
return !string_isEmpty(this.getID(result_object));
|
|
869
|
+
case "number":
|
|
870
|
+
return result_object > 0;
|
|
871
|
+
case "boolean":
|
|
872
|
+
return result_object === true;
|
|
873
|
+
}
|
|
874
|
+
return false;
|
|
875
|
+
}
|
|
1003
876
|
/**
|
|
1004
877
|
* set the response of last save from site
|
|
1005
878
|
* and its type
|
|
1006
879
|
* @param toObj
|
|
1007
|
-
*/
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
type
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
key: "getSaveResult",
|
|
1026
|
-
value: function getSaveResult() {
|
|
1027
|
-
var original = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1028
|
-
if (this.isSaved) return this.__saveResultObject;
|
|
1029
|
-
return false;
|
|
1030
|
-
}
|
|
1031
|
-
}, {
|
|
1032
|
-
key: "getSaveResultType",
|
|
1033
|
-
value: function getSaveResultType() {
|
|
1034
|
-
return this.__saveResultType || "nothing";
|
|
1035
|
-
}
|
|
1036
|
-
/** did we create on the last save */
|
|
1037
|
-
}, {
|
|
1038
|
-
key: "getIsLastSaveCreate",
|
|
1039
|
-
value: function getIsLastSaveCreate() {
|
|
1040
|
-
return this.isSaved && this.getSaveResult().insertedId;
|
|
1041
|
-
}
|
|
1042
|
-
/* -------------------------------------------------------------------------- */
|
|
1043
|
-
/* statics */
|
|
1044
|
-
/* -------------------------------------------------------------------------- */
|
|
1045
|
-
}], [{
|
|
1046
|
-
key: "loadValues",
|
|
1047
|
-
value: function loadValues(obj, initObject) {
|
|
1048
|
-
var fullUpdate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1049
|
-
SimpleObject.factoryClear(obj);
|
|
1050
|
-
if (initObject == null) {
|
|
1051
|
-
for (var key in obj) {
|
|
1052
|
-
if (typeof obj[key] === "function") continue;
|
|
1053
|
-
if (key.startsWith("__")) continue;
|
|
1054
|
-
delete obj[key];
|
|
1055
|
-
}
|
|
1056
|
-
} else if (_typeof(initObject) == "object") {
|
|
1057
|
-
for (var _key3 in initObject) {
|
|
1058
|
-
if (_key3.startsWith("__")) continue;
|
|
1059
|
-
if (fullUpdate || Object.prototype.hasOwnProperty.call(obj, _key3)) {
|
|
1060
|
-
obj[_key3] = initObject[_key3];
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
return true;
|
|
1065
|
-
}
|
|
1066
|
-
/* -------------------------------------------------------------------------- */
|
|
1067
|
-
}, {
|
|
1068
|
-
key: "getValue",
|
|
1069
|
-
value: function getValue(o, key) {
|
|
1070
|
-
var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1071
|
-
if (o == null) return undefined;
|
|
1072
|
-
if (o instanceof SimpleObject && typeof o.getValue === "function") return o.getValue(key, original);
|
|
1073
|
-
if (!original && o.__use_delta != false && _typeof(o.__delta) === "object" && key in o.__delta) {
|
|
1074
|
-
//@ts-ignore
|
|
1075
|
-
return o.__delta[key];
|
|
1076
|
-
}
|
|
1077
|
-
return o[key];
|
|
1078
|
-
}
|
|
1079
|
-
}, {
|
|
1080
|
-
key: "canChangeKey",
|
|
1081
|
-
value: function canChangeKey(object, key, options) {
|
|
1082
|
-
if (!object || !key) return false;
|
|
1083
|
-
var useExtraProps = options.useExtraProps,
|
|
1084
|
-
ignoreProtected = options.ignoreProtected;
|
|
1085
|
-
if (useExtraProps) {
|
|
1086
|
-
var __extraProperties = object.constructor["__extraProperties"];
|
|
1087
|
-
if (__extraProperties != null && __extraProperties.includes(key)) return true;
|
|
1088
|
-
}
|
|
1089
|
-
/* -------------------------------------------------------------------------- */
|
|
1090
|
-
var __changeables = object.constructor["__changeables"];
|
|
1091
|
-
var __unchangeables = object.constructor["__unchangeables"];
|
|
1092
|
-
/* -------------------------------------------------------------------------- */
|
|
1093
|
-
if (__changeables != null && !__changeables.includes(key)) return false;
|
|
1094
|
-
if (__unchangeables != null && __unchangeables.includes(key)) return false;
|
|
1095
|
-
if (ignoreProtected !== true) {
|
|
1096
|
-
var __protectedProperties = object.constructor["__protectedProperties"];
|
|
1097
|
-
if (__protectedProperties != null && __protectedProperties.includes(key)) {
|
|
1098
|
-
//protected keys can only be changed by the creator of this object
|
|
1099
|
-
//make sure you set the is_current_user function correctly
|
|
1100
|
-
if (object.isNew) return true;
|
|
1101
|
-
var creatorOfObject = object.get("_creator");
|
|
1102
|
-
return Boolean(_global.gfunc.run_action_sync("is_current_user", creatorOfObject));
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
return true;
|
|
1106
|
-
}
|
|
1107
|
-
}, {
|
|
1108
|
-
key: "hasIllegalChanges",
|
|
1109
|
-
value: function hasIllegalChanges(referenceObject, changesObject, updaterUser) {
|
|
1110
|
-
var __protectedProperties = (0, _object.object_getStatic)(referenceObject, "__protectedProperties");
|
|
1111
|
-
if ((0, _object.object_isEmpty)(__protectedProperties)) return false;
|
|
1112
|
-
var referenceUser = (0, _object.object_isClass)(referenceObject) ? (0, _object.object_get)(changesObject, "__user", "_creator") : (0, _object.object_get)(referenceObject, "__user", "_creator");
|
|
1113
|
-
if (Boolean(SimpleObject.getID(referenceUser) == SimpleObject.getID(updaterUser))) {
|
|
1114
|
-
return false;
|
|
1115
|
-
}
|
|
1116
|
-
for (var key in changesObject) {
|
|
1117
|
-
if (__protectedProperties.includes(key)) {
|
|
1118
|
-
return true;
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
return false;
|
|
1122
|
-
}
|
|
1123
|
-
}, {
|
|
1124
|
-
key: "setReadonly",
|
|
1125
|
-
value: function setReadonly(objs) {
|
|
1126
|
-
var readonlyval = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1127
|
-
var clearChanges = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1128
|
-
var checkObjs = [];
|
|
1129
|
-
if (!objs) objs = [];
|
|
1130
|
-
if (!Array.isArray(objs)) checkObjs = [objs];else checkObjs = objs;
|
|
1131
|
-
for (var index = 0; index < checkObjs.length; index++) {
|
|
1132
|
-
var obj = checkObjs[index];
|
|
1133
|
-
obj.__is_readonly = readonlyval;
|
|
1134
|
-
if (obj instanceof SimpleObject) {
|
|
1135
|
-
if (obj.canModify) {
|
|
1136
|
-
if (!obj.getOriginal()) obj.setOriginal();
|
|
1137
|
-
} else {
|
|
1138
|
-
if (clearChanges) obj.clear_changes();
|
|
1139
|
-
//we dont need the original object in readonly mode
|
|
1140
|
-
obj.setOriginal(null);
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
}, {
|
|
1146
|
-
key: "setThrowErrors",
|
|
1147
|
-
value: function setThrowErrors(objs) {
|
|
1148
|
-
var throwErr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1149
|
-
var checkObjs = [];
|
|
1150
|
-
if (!objs) objs = [];
|
|
1151
|
-
if (!Array.isArray(objs)) checkObjs = [objs];else checkObjs = objs;
|
|
1152
|
-
for (var index = 0; index < checkObjs.length; index++) {
|
|
1153
|
-
var element = checkObjs[index];
|
|
1154
|
-
element.__throw_errors = throwErr;
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
}, {
|
|
1158
|
-
key: "isDeleted",
|
|
1159
|
-
value: function isDeleted(obj) {
|
|
1160
|
-
if (obj instanceof SimpleObject) return obj.isDeleted === true;
|
|
1161
|
-
return false;
|
|
1162
|
-
}
|
|
1163
|
-
}, {
|
|
1164
|
-
key: "getIndexOrID",
|
|
1165
|
-
value: function getIndexOrID(o) {
|
|
1166
|
-
var res = SimpleObject.getIndex(o);
|
|
1167
|
-
if (!res || res == -1) res = SimpleObject.getID(o);
|
|
1168
|
-
return res || -1;
|
|
1169
|
-
}
|
|
1170
|
-
}, {
|
|
1171
|
-
key: "getIndex",
|
|
1172
|
-
value: function getIndex(o) {
|
|
1173
|
-
if (o == null || o == undefined) return -1;
|
|
1174
|
-
switch (_typeof(o)) {
|
|
1175
|
-
case "object":
|
|
1176
|
-
return o._index_value || -1;
|
|
1177
|
-
case "number":
|
|
1178
|
-
case "string":
|
|
1179
|
-
return Number(o);
|
|
1180
|
-
}
|
|
1181
|
-
return -1;
|
|
1182
|
-
}
|
|
1183
|
-
}, {
|
|
1184
|
-
key: "getID",
|
|
1185
|
-
value: function getID(o) {
|
|
1186
|
-
if (o == null || o == undefined) return "";
|
|
1187
|
-
switch (_typeof(o)) {
|
|
1188
|
-
case "object":
|
|
1189
|
-
if (o._bsontype == "ObjectID" && typeof o.toString === "function") {
|
|
1190
|
-
return o.toString();
|
|
1191
|
-
}
|
|
1192
|
-
return String(o._id || o.insertedId || o.ID || o.id || o.__data_id || "");
|
|
1193
|
-
case "string":
|
|
1194
|
-
case "number":
|
|
1195
|
-
return String(o);
|
|
1196
|
-
}
|
|
1197
|
-
return "";
|
|
1198
|
-
}
|
|
1199
|
-
}, {
|
|
1200
|
-
key: "setOriginal",
|
|
1201
|
-
value: function setOriginal(obj) {
|
|
1202
|
-
var toObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
1203
|
-
if (!(obj instanceof SimpleObject)) return undefined;
|
|
1204
|
-
return obj.setOriginal(toObj);
|
|
1205
|
-
}
|
|
1206
|
-
}, {
|
|
1207
|
-
key: "getOriginal",
|
|
1208
|
-
value: function getOriginal(obj) {
|
|
1209
|
-
if (obj instanceof SimpleObject) return obj.getOriginal();
|
|
1210
|
-
return obj === null || obj === void 0 ? void 0 : obj.__originalobject;
|
|
1211
|
-
}
|
|
1212
|
-
}, {
|
|
1213
|
-
key: "addError",
|
|
1214
|
-
value: function addError(o, title, message) {
|
|
1215
|
-
var sendToRegister = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "auto";
|
|
1216
|
-
var errStr = (0, _string.combine_if_not_blank)(title, " : ", message);
|
|
1217
|
-
if (o) {
|
|
1218
|
-
if (!Array.isArray(o.__errors)) o.__errors = [];
|
|
1219
|
-
o.__errors.push(errStr);
|
|
1220
|
-
if (o.__showErrors === false) return;
|
|
1221
|
-
} else if (sendToRegister === "auto") sendToRegister = true;
|
|
1222
|
-
if (sendToRegister === true) {
|
|
1223
|
-
console.error("[REGISTER-ERROR]", errStr);
|
|
1224
|
-
_global.gfunc.run_action("add_error", {
|
|
1225
|
-
title: title,
|
|
1226
|
-
message: message,
|
|
1227
|
-
type: "error"
|
|
1228
|
-
});
|
|
1229
|
-
} else {
|
|
1230
|
-
console.error("[ERROR]", errStr);
|
|
1231
|
-
}
|
|
1232
|
-
return (o === null || o === void 0 ? void 0 : o.__errors) || [];
|
|
1233
|
-
}
|
|
1234
|
-
}, {
|
|
1235
|
-
key: "getErrors",
|
|
1236
|
-
value: function getErrors(o) {
|
|
1237
|
-
return (o === null || o === void 0 ? void 0 : o.__errors) || [];
|
|
1238
|
-
}
|
|
1239
|
-
}, {
|
|
1240
|
-
key: "clearErrors",
|
|
1241
|
-
value: function clearErrors(o) {
|
|
1242
|
-
if (o) o.__errors = [];
|
|
1243
|
-
return true;
|
|
1244
|
-
}
|
|
1245
|
-
/* -------------------------------------------------------------------------- */
|
|
1246
|
-
/* Save Results */
|
|
1247
|
-
/* -------------------------------------------------------------------------- */
|
|
880
|
+
*/
|
|
881
|
+
setSaveResult(toObj, type = "auto", registerErrors = false) {
|
|
882
|
+
this.#setSaveResultObject(toObj);
|
|
883
|
+
//check if the given object is a valid save result
|
|
884
|
+
if (type === "error")
|
|
885
|
+
this.__saveResultIsSuccess = false;
|
|
886
|
+
else
|
|
887
|
+
this.__saveResultIsSuccess = Boolean(type === "nothing" || this.constructor["isResultValid"](toObj));
|
|
888
|
+
if (type === "auto") {
|
|
889
|
+
type = this.__saveResultIsSuccess ? "normal" : "error";
|
|
890
|
+
}
|
|
891
|
+
if (registerErrors && !this.__saveResultIsSuccess) {
|
|
892
|
+
console.error("bad save result : ", this.__saveResultObject);
|
|
893
|
+
SimpleObject.addError(this, "save result is not valid", "the response from server was not valid", true);
|
|
894
|
+
}
|
|
895
|
+
this.__saveResultType = type;
|
|
896
|
+
return type;
|
|
897
|
+
}
|
|
1248
898
|
/**
|
|
1249
|
-
*
|
|
1250
|
-
* @param
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
return
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
case 7:
|
|
1312
|
-
//
|
|
1313
|
-
if (obj.__temp == null) obj.__temp = {};
|
|
1314
|
-
(0, _object.object_set)(obj.__temp, key, value);
|
|
1315
|
-
case 9:
|
|
1316
|
-
case "end":
|
|
1317
|
-
return _context16.stop();
|
|
1318
|
-
}
|
|
1319
|
-
}, _callee16);
|
|
1320
|
-
}))).apply(this, arguments);
|
|
1321
|
-
}
|
|
1322
|
-
}, {
|
|
1323
|
-
key: "factoryClear",
|
|
1324
|
-
value: function factoryClear(obj) {
|
|
1325
|
-
obj.clear_changes();
|
|
1326
|
-
SimpleObject.clearErrors(obj);
|
|
1327
|
-
}
|
|
1328
|
-
}, {
|
|
1329
|
-
key: "delete_cache",
|
|
1330
|
-
value: function delete_cache(_x28) {
|
|
1331
|
-
return (_delete_cache = _delete_cache || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(context) {
|
|
1332
|
-
var cacheKey;
|
|
1333
|
-
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1334
|
-
while (1) switch (_context17.prev = _context17.next) {
|
|
1335
|
-
case 0:
|
|
1336
|
-
if (this.__cache_name) {
|
|
1337
|
-
_context17.next = 2;
|
|
1338
|
-
break;
|
|
1339
|
-
}
|
|
1340
|
-
return _context17.abrupt("return");
|
|
1341
|
-
case 2:
|
|
1342
|
-
if (context) {
|
|
1343
|
-
_context17.next = 7;
|
|
1344
|
-
break;
|
|
1345
|
-
}
|
|
1346
|
-
_context17.next = 5;
|
|
1347
|
-
return _global.gcache.delete_session_cache(this.__cache_name);
|
|
1348
|
-
case 5:
|
|
1349
|
-
_context17.next = 10;
|
|
1350
|
-
break;
|
|
1351
|
-
case 7:
|
|
1352
|
-
cacheKey = "".concat(this.__cache_name, "-").concat(context);
|
|
1353
|
-
_context17.next = 10;
|
|
1354
|
-
return _global.gcache.delete_session_cache(cacheKey);
|
|
1355
|
-
case 10:
|
|
1356
|
-
case "end":
|
|
1357
|
-
return _context17.stop();
|
|
1358
|
-
}
|
|
1359
|
-
}, _callee17, this);
|
|
1360
|
-
}))).apply(this, arguments);
|
|
1361
|
-
}
|
|
1362
|
-
}, {
|
|
1363
|
-
key: "get_canModify",
|
|
1364
|
-
value: function get_canModify(o) {
|
|
1365
|
-
if (o instanceof SimpleObject) return o.canModify;
|
|
1366
|
-
return false;
|
|
1367
|
-
}
|
|
1368
|
-
/* -------------------------------------------------------------------------- */
|
|
1369
|
-
}, {
|
|
1370
|
-
key: "equals",
|
|
1371
|
-
value: function equals(a, b) {
|
|
1372
|
-
console.warn("Dont use the default equals method !");
|
|
1373
|
-
if (a == undefined || b == undefined) return false;
|
|
1374
|
-
return a === b;
|
|
1375
|
-
}
|
|
1376
|
-
}]);
|
|
1377
|
-
return SimpleObject;
|
|
1378
|
-
}(_MapableObject2.MapableObject);
|
|
1379
|
-
exports.SimpleObject = SimpleObject;
|
|
1380
|
-
function _setSubProperty2(key, subkey, value) {
|
|
1381
|
-
var subobj = _classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key);
|
|
1382
|
-
//@ts-ignore
|
|
1383
|
-
if (subobj == null || _typeof(subobj) !== "object") subobj = {};else subobj = _objectSpread({}, subobj); //make a clone so we dont update the original
|
|
1384
|
-
subobj[subkey] = value;
|
|
1385
|
-
_classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, subobj);
|
|
1386
|
-
}
|
|
1387
|
-
function _getSubProperty2(key, subkey) {
|
|
1388
|
-
var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1389
|
-
var subobj = _classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key, original);
|
|
1390
|
-
if (subobj == null || _typeof(subobj) !== "object") return undefined;
|
|
1391
|
-
return subobj[subkey];
|
|
1392
|
-
}
|
|
1393
|
-
function _setProperty2(key, value) {
|
|
1394
|
-
if (!this.__use_delta) {
|
|
1395
|
-
this[key] = value; //on noDelta mode, also update the obj
|
|
1396
|
-
this.__delta[key] = value; //always update delta to keep track of changes
|
|
1397
|
-
return true;
|
|
1398
|
-
} else {
|
|
1399
|
-
if (this[key] === value) {
|
|
1400
|
-
/**
|
|
1401
|
-
* We set something back to its original value so no need to save it as Delta
|
|
1402
|
-
*/
|
|
1403
|
-
delete this.__delta[key];
|
|
1404
|
-
return false;
|
|
1405
|
-
} else {
|
|
1406
|
-
this.__delta[key] = value; //always update delta to keep track of changes
|
|
1407
|
-
return true;
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
function _setDefaultProperty2(key, value) {
|
|
1412
|
-
//@ts-ignore
|
|
1413
|
-
if (this[key] == undefined || this[key] === "" || this[key] === 0) {
|
|
1414
|
-
this[key] = value;
|
|
1415
|
-
return true;
|
|
1416
|
-
}
|
|
1417
|
-
return false;
|
|
1418
|
-
}
|
|
1419
|
-
function _setDefaultPropertyNow2(key) {
|
|
1420
|
-
//@ts-ignore
|
|
1421
|
-
if (this[key] == undefined || this[key] === "" || this[key] === 0) {
|
|
1422
|
-
this[key] = new Date();
|
|
1423
|
-
return true;
|
|
1424
|
-
}
|
|
1425
|
-
return false;
|
|
1426
|
-
}
|
|
1427
|
-
function _getProperty2(key) {
|
|
1428
|
-
var original = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1429
|
-
//check if we should treat the prop as a function
|
|
1430
|
-
var is_fnc = this.constructor["__functionProperties"] != null && this.constructor["__functionProperties"].includes(key);
|
|
1431
|
-
//check if we should use delta version or normal version for this property
|
|
1432
|
-
var use_orig = original || !this.__use_delta || !(key in this.__delta);
|
|
1433
|
-
if (is_fnc) {
|
|
1434
|
-
if (use_orig) return (0, _object.fn_eval_this)(this, this[key]);
|
|
1435
|
-
return (0, _object.fn_eval_this)(this, this.__delta[key]);
|
|
1436
|
-
}
|
|
1437
|
-
if (use_orig) return this[key];
|
|
1438
|
-
return this.__delta[key];
|
|
1439
|
-
}
|
|
1440
|
-
function _setSaveResultObject2(toObj) {
|
|
1441
|
-
if (toObj == null) toObj = null; //null or undefined
|
|
1442
|
-
this.__saveResultObject = toObj;
|
|
1443
|
-
return true;
|
|
1444
|
-
}
|
|
1445
|
-
_defineProperty(SimpleObject, "__cache_name", void 0);
|
|
1446
|
-
//these properties should not be changed and are usually set by server
|
|
1447
|
-
_defineProperty(SimpleObject, "__unchangeables", void 0);
|
|
1448
|
-
//these properties can be directly changed and are included in deltaObject
|
|
1449
|
-
_defineProperty(SimpleObject, "__changeables", void 0);
|
|
1450
|
-
//these properties can only be changed by the _creator
|
|
1451
|
-
_defineProperty(SimpleObject, "__protectedProperties", void 0);
|
|
1452
|
-
//these properties will be evaluated when needed
|
|
1453
|
-
_defineProperty(SimpleObject, "__functionProperties", void 0);
|
|
1454
|
-
//apply these string formats
|
|
1455
|
-
_defineProperty(SimpleObject, "__formatList", void 0);
|
|
1456
|
-
//these properties usually are not directly changed and sometimes are included in deltaObject
|
|
1457
|
-
_defineProperty(SimpleObject, "__extraProperties", void 0);
|
|
1458
|
-
//types for children can be used when importing children
|
|
1459
|
-
_defineProperty(SimpleObject, "__childTypes", void 0);
|
|
1460
|
-
//these fields are used when importing
|
|
1461
|
-
_defineProperty(SimpleObject, "__importColumns", void 0);
|
|
1462
|
-
//these fields can be used when importing and checking if an item exists
|
|
1463
|
-
_defineProperty(SimpleObject, "__checkProperties", void 0);
|
|
1464
|
-
_defineProperty(SimpleObject, "__use_delta", true);
|
|
1465
|
-
var _default = SimpleObject;
|
|
1466
|
-
exports["default"] = _default;
|
|
899
|
+
* set the response of last save from site
|
|
900
|
+
* @param toObj
|
|
901
|
+
*/
|
|
902
|
+
#setSaveResultObject(toObj) {
|
|
903
|
+
if (toObj == null)
|
|
904
|
+
toObj = null; //null or undefined
|
|
905
|
+
this.__saveResultObject = toObj;
|
|
906
|
+
return true;
|
|
907
|
+
}
|
|
908
|
+
getSaveResult(original = false) {
|
|
909
|
+
if (this.isSaved)
|
|
910
|
+
return this.__saveResultObject;
|
|
911
|
+
return false;
|
|
912
|
+
}
|
|
913
|
+
getSaveResultType() {
|
|
914
|
+
return this.__saveResultType || "nothing";
|
|
915
|
+
}
|
|
916
|
+
/** did we create on the last save */
|
|
917
|
+
getIsLastSaveCreate() {
|
|
918
|
+
return this.isSaved && this.getSaveResult().insertedId;
|
|
919
|
+
}
|
|
920
|
+
/* -------------------------------------------------------------------------- */
|
|
921
|
+
/* statics */
|
|
922
|
+
/* -------------------------------------------------------------------------- */
|
|
923
|
+
static async setTemp(obj, key, value, sendChanges = false) {
|
|
924
|
+
if (typeof obj !== "object" || !obj || Array.isArray(obj))
|
|
925
|
+
return;
|
|
926
|
+
if (obj instanceof SimpleObject)
|
|
927
|
+
return await obj.setTemp(key, value, sendChanges);
|
|
928
|
+
//
|
|
929
|
+
if (obj.__temp == null)
|
|
930
|
+
obj.__temp = {};
|
|
931
|
+
object_set(obj.__temp, key, value);
|
|
932
|
+
}
|
|
933
|
+
static factoryClear(obj) {
|
|
934
|
+
obj.clear_changes();
|
|
935
|
+
SimpleObject.clearErrors(obj);
|
|
936
|
+
}
|
|
937
|
+
static async delete_cache(context) {
|
|
938
|
+
if (!this.__cache_name)
|
|
939
|
+
return;
|
|
940
|
+
if (!context)
|
|
941
|
+
await gcache.delete_session_cache(this.__cache_name);
|
|
942
|
+
else {
|
|
943
|
+
const cacheKey = `${this.__cache_name}-${context}`;
|
|
944
|
+
await gcache.delete_session_cache(cacheKey);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
static get_canModify(o) {
|
|
948
|
+
if (o instanceof SimpleObject)
|
|
949
|
+
return o.canModify;
|
|
950
|
+
return false;
|
|
951
|
+
}
|
|
952
|
+
/* -------------------------------------------------------------------------- */
|
|
953
|
+
static equals(a, b) {
|
|
954
|
+
console.warn("Dont use the default equals method !");
|
|
955
|
+
if (a == undefined || b == undefined)
|
|
956
|
+
return false;
|
|
957
|
+
return a === b;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
export default SimpleObject;
|