@azrico/webobject 1.4.176 → 1.4.179
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/dist/index.js +1 -16
- package/dist/src/WebObjects/ParentWebObject.js +68 -115
- package/dist/src/WebObjects/WebObject.d.ts +2 -2
- package/dist/src/WebObjects/WebObject.js +498 -1303
- package/dist/src/WebObjects/WebObjectManager.js +257 -831
- package/dist/src/WebObjects/WebObjectPathHelper.js +71 -142
- package/dist/src/WebObjects/WebObjectPathHelper.test.js +31 -122
- package/dist/src/index.js +10 -115
- package/dist/src/structs/DummyObject.js +8 -32
- package/dist/src/structs/MapableObject.js +75 -121
- package/dist/src/structs/MetaObject.js +35 -121
- package/dist/src/structs/ObjectArray.js +43 -68
- package/dist/src/structs/ObjectManager.js +277 -721
- package/dist/src/structs/ObjectWithTemp.js +25 -64
- package/dist/src/structs/SimpleObject.js +954 -1535
- package/package.json +1 -1
|
@@ -1,1343 +1,538 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
24
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
25
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
26
|
-
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
27
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
28
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
29
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
30
|
-
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
31
|
-
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
32
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
33
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
34
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
35
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
36
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
37
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
38
|
-
var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
39
|
-
function WebObject() {
|
|
40
|
-
var _this;
|
|
41
|
-
var is_readonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
42
|
-
_classCallCheck(this, WebObject);
|
|
43
|
-
_this = _callSuper(this, WebObject, [is_readonly]);
|
|
44
|
-
_defineProperty(_this, "meta_data", void 0);
|
|
45
|
-
//created date
|
|
46
|
-
_defineProperty(_this, "_created_date", void 0);
|
|
47
|
-
//the owner of the object
|
|
48
|
-
_defineProperty(_this, "_creator", void 0);
|
|
49
|
-
//multiple users can work on one object
|
|
50
|
-
_defineProperty(_this, "_users", void 0);
|
|
51
|
-
_this.meta_data = {};
|
|
52
|
-
return _this;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* get a list of all user ids that work on the given object
|
|
56
|
-
* _creator + _users + attentions(old)
|
|
57
|
-
* removes duplicates
|
|
58
|
-
* @returns array of ids
|
|
59
|
-
*/
|
|
60
|
-
_inherits(WebObject, _SimpleObject);
|
|
61
|
-
return _createClass(WebObject, [{
|
|
62
|
-
key: "getAllUsers",
|
|
63
|
-
value: function getAllUsers() {
|
|
64
|
-
return WebObject.getAllUsers(this);
|
|
65
|
-
}
|
|
1
|
+
import { SimpleObject } from "../index";
|
|
2
|
+
import { array_chunks, array_merge, array_remove_duplicates, fn_eval_this, object_equals, object_first, object_getStatic, object_isEmpty, wrap_array, } from "@azrico/object";
|
|
3
|
+
import { string_compress, string_decompress } from "@azrico/string";
|
|
4
|
+
import { gfunc } from "@azrico/global";
|
|
5
|
+
import FormatHelper from "@azrico/convert";
|
|
6
|
+
import WebObjectPathHelper from "./WebObjectPathHelper";
|
|
7
|
+
export class WebObject extends SimpleObject {
|
|
8
|
+
static __web_path = "";
|
|
9
|
+
static __protectedProperties = ["_users"];
|
|
10
|
+
//you cant create a new weboject without these properties
|
|
11
|
+
static __requiredProperties = [];
|
|
12
|
+
meta_data;
|
|
13
|
+
//created date
|
|
14
|
+
_created_date;
|
|
15
|
+
//the owner of the object
|
|
16
|
+
_creator;
|
|
17
|
+
//multiple users can work on one object
|
|
18
|
+
_users;
|
|
19
|
+
constructor(is_readonly = false) {
|
|
20
|
+
super(is_readonly);
|
|
21
|
+
this.meta_data = {};
|
|
22
|
+
}
|
|
66
23
|
/**
|
|
67
24
|
* get a list of all user ids that work on the given object
|
|
68
25
|
* _creator + _users + attentions(old)
|
|
69
26
|
* removes duplicates
|
|
70
27
|
* @returns array of ids
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
28
|
+
*/
|
|
29
|
+
getAllUsers() {
|
|
30
|
+
return WebObject.getAllUsers(this);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* get a list of all user ids that work on the given object
|
|
34
|
+
* _creator + _users + attentions(old)
|
|
35
|
+
* removes duplicates
|
|
36
|
+
* @returns array of ids
|
|
37
|
+
*/
|
|
38
|
+
static getAllUsers(obj) {
|
|
39
|
+
if (typeof obj != "object")
|
|
40
|
+
return [];
|
|
41
|
+
return array_remove_duplicates(array_merge(obj._creator, wrap_array(obj._users), wrap_array(obj.attentions))
|
|
42
|
+
.map((r) => String(typeof r === "object" ? WebObject.getID(r) : r))
|
|
43
|
+
.filter((s) => s));
|
|
44
|
+
}
|
|
45
|
+
/* -------------------------------------------------------------------------- */
|
|
46
|
+
/* Meta data */
|
|
47
|
+
/* -------------------------------------------------------------------------- */
|
|
78
48
|
/**
|
|
79
49
|
* Update meta value of this object , meta data is stored in meta_data variable
|
|
80
50
|
* @param key
|
|
81
51
|
* @param value
|
|
82
52
|
* @param sendChange
|
|
83
53
|
* @returns
|
|
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
|
-
_context.next = 13;
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
if (!(this.__throw_errors !== false)) {
|
|
112
|
-
_context.next = 12;
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
throw Error("Bad key at setMetaValue");
|
|
116
|
-
case 12:
|
|
117
|
-
return _context.abrupt("return", false);
|
|
118
|
-
case 13:
|
|
119
|
-
old_value = WebObject.getMetaValue(this, key);
|
|
120
|
-
if (!(0, _object.object_equals)(old_value, value)) {
|
|
121
|
-
_context.next = 16;
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
return _context.abrupt("return", false);
|
|
125
|
-
case 16:
|
|
126
|
-
//same value, no changes
|
|
127
|
-
new_metalist = _objectSpread({}, this.getValue("meta_data"));
|
|
128
|
-
new_metalist[key] = value;
|
|
129
|
-
_context.next = 20;
|
|
130
|
-
return this.setValue("meta_data", new_metalist);
|
|
131
|
-
case 20:
|
|
132
|
-
if (!(sendChange !== false)) {
|
|
133
|
-
_context.next = 23;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
_context.next = 23;
|
|
137
|
-
return this.notifyChanged("meta", key, value);
|
|
138
|
-
case 23:
|
|
139
|
-
return _context.abrupt("return", true);
|
|
140
|
-
case 24:
|
|
141
|
-
case "end":
|
|
142
|
-
return _context.stop();
|
|
143
|
-
}
|
|
144
|
-
}, _callee, this);
|
|
145
|
-
}));
|
|
146
|
-
function setMetaValue(_x, _x2) {
|
|
147
|
-
return _setMetaValue.apply(this, arguments);
|
|
148
|
-
}
|
|
149
|
-
return setMetaValue;
|
|
150
|
-
}()
|
|
54
|
+
*/
|
|
55
|
+
async setMetaValue(key, value, sendChange = "auto") {
|
|
56
|
+
if (!this.canModify) {
|
|
57
|
+
if (this.__throw_errors !== false)
|
|
58
|
+
throw Error(`Cant use setMetaValue on ${key} when on readonly mode`);
|
|
59
|
+
else
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (!key || typeof key != "string") {
|
|
63
|
+
if (this.__throw_errors !== false)
|
|
64
|
+
throw Error(`Bad key at setMetaValue`);
|
|
65
|
+
else
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const old_value = WebObject.getMetaValue(this, key);
|
|
69
|
+
if (object_equals(old_value, value))
|
|
70
|
+
return false; //same value, no changes
|
|
71
|
+
const new_metalist = { ...this.getValue("meta_data") };
|
|
72
|
+
new_metalist[key] = value;
|
|
73
|
+
await this.setValue("meta_data", new_metalist);
|
|
74
|
+
if (sendChange !== false)
|
|
75
|
+
await this.notifyChanged("meta", key, value);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
151
78
|
/**
|
|
152
79
|
* Get meta value by key
|
|
153
80
|
* @param key
|
|
154
81
|
* @returns value or undefined
|
|
155
|
-
*/
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
value: function getMetaValue(key) {
|
|
160
|
-
return WebObject.getMetaValue(this, key);
|
|
161
|
-
}
|
|
82
|
+
*/
|
|
83
|
+
getMetaValue(key) {
|
|
84
|
+
return WebObject.getMetaValue(this, key);
|
|
85
|
+
}
|
|
162
86
|
/**
|
|
163
87
|
* Get meta value by key
|
|
164
88
|
* @param o
|
|
165
89
|
* @param key
|
|
166
90
|
* @returns value or undefined
|
|
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
|
-
return _WebObjectPathHelper["default"].get_path(this, "unlock");
|
|
348
|
-
case 4:
|
|
349
|
-
usepath = _context5.sent;
|
|
350
|
-
_context5.next = 7;
|
|
351
|
-
return _global.gfunc.run_action("post", usepath);
|
|
352
|
-
case 7:
|
|
353
|
-
resultObject = _context5.sent;
|
|
354
|
-
this.setSaveResult(resultObject, "auto", true);
|
|
355
|
-
_context5.next = 11;
|
|
356
|
-
return this.onUnLock();
|
|
357
|
-
case 11:
|
|
358
|
-
return _context5.abrupt("return", resultObject);
|
|
359
|
-
case 12:
|
|
360
|
-
case "end":
|
|
361
|
-
return _context5.stop();
|
|
362
|
-
}
|
|
363
|
-
}, _callee5, this);
|
|
364
|
-
}));
|
|
365
|
-
function UnLock() {
|
|
366
|
-
return _UnLock.apply(this, arguments);
|
|
367
|
-
}
|
|
368
|
-
return UnLock;
|
|
369
|
-
}()
|
|
370
|
-
}, {
|
|
371
|
-
key: "Archive",
|
|
372
|
-
value: function () {
|
|
373
|
-
var _Archive = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
374
|
-
var usepath, resultObject;
|
|
375
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
376
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
377
|
-
case 0:
|
|
378
|
-
if (!(this.isNew || this.isArchived)) {
|
|
379
|
-
_context6.next = 2;
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
return _context6.abrupt("return");
|
|
383
|
-
case 2:
|
|
384
|
-
_context6.next = 4;
|
|
385
|
-
return _WebObjectPathHelper["default"].get_path(this, "archive");
|
|
386
|
-
case 4:
|
|
387
|
-
usepath = _context6.sent;
|
|
388
|
-
_context6.next = 7;
|
|
389
|
-
return _global.gfunc.run_action("post", usepath);
|
|
390
|
-
case 7:
|
|
391
|
-
resultObject = _context6.sent;
|
|
392
|
-
this.setSaveResult(resultObject, "auto", true);
|
|
393
|
-
_context6.next = 11;
|
|
394
|
-
return this.onArchive();
|
|
395
|
-
case 11:
|
|
396
|
-
return _context6.abrupt("return", resultObject);
|
|
397
|
-
case 12:
|
|
398
|
-
case "end":
|
|
399
|
-
return _context6.stop();
|
|
400
|
-
}
|
|
401
|
-
}, _callee6, this);
|
|
402
|
-
}));
|
|
403
|
-
function Archive() {
|
|
404
|
-
return _Archive.apply(this, arguments);
|
|
405
|
-
}
|
|
406
|
-
return Archive;
|
|
407
|
-
}()
|
|
408
|
-
}, {
|
|
409
|
-
key: "UnArchive",
|
|
410
|
-
value: function () {
|
|
411
|
-
var _UnArchive = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
412
|
-
var usepath, resultObject;
|
|
413
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
414
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
415
|
-
case 0:
|
|
416
|
-
if (!(this.isNew || !this.isArchived)) {
|
|
417
|
-
_context7.next = 2;
|
|
418
|
-
break;
|
|
419
|
-
}
|
|
420
|
-
return _context7.abrupt("return");
|
|
421
|
-
case 2:
|
|
422
|
-
_context7.next = 4;
|
|
423
|
-
return _WebObjectPathHelper["default"].get_path(this, "unarchive");
|
|
424
|
-
case 4:
|
|
425
|
-
usepath = _context7.sent;
|
|
426
|
-
_context7.next = 7;
|
|
427
|
-
return _global.gfunc.run_action("post", usepath);
|
|
428
|
-
case 7:
|
|
429
|
-
resultObject = _context7.sent;
|
|
430
|
-
_context7.next = 10;
|
|
431
|
-
return this.onUnArchive();
|
|
432
|
-
case 10:
|
|
433
|
-
return _context7.abrupt("return", resultObject);
|
|
434
|
-
case 11:
|
|
435
|
-
case "end":
|
|
436
|
-
return _context7.stop();
|
|
437
|
-
}
|
|
438
|
-
}, _callee7, this);
|
|
439
|
-
}));
|
|
440
|
-
function UnArchive() {
|
|
441
|
-
return _UnArchive.apply(this, arguments);
|
|
442
|
-
}
|
|
443
|
-
return UnArchive;
|
|
444
|
-
}() /* -------------------------------------------------------------------------- */
|
|
445
|
-
}, {
|
|
446
|
-
key: "canSave",
|
|
447
|
-
value: function canSave(deltaObj) {
|
|
448
|
-
var deltaRes = this.deltaIsValid(deltaObj);
|
|
449
|
-
if (deltaRes !== true) return deltaRes;
|
|
450
|
-
return true;
|
|
451
|
-
}
|
|
452
|
-
}, {
|
|
453
|
-
key: "canDelete",
|
|
454
|
-
value: function canDelete() {
|
|
455
|
-
return true;
|
|
456
|
-
}
|
|
457
|
-
}, {
|
|
458
|
-
key: "canArchive",
|
|
459
|
-
value: function canArchive() {
|
|
460
|
-
return true;
|
|
461
|
-
}
|
|
462
|
-
}, {
|
|
463
|
-
key: "deltaIsValid",
|
|
464
|
-
value: function deltaIsValid(d) {
|
|
465
|
-
return true;
|
|
466
|
-
}
|
|
91
|
+
*/
|
|
92
|
+
static getMetaValue(o, key) {
|
|
93
|
+
if (o == null)
|
|
94
|
+
return null;
|
|
95
|
+
if (!key || typeof key != "string")
|
|
96
|
+
return undefined;
|
|
97
|
+
let metalist = {};
|
|
98
|
+
if (typeof o === "object") {
|
|
99
|
+
metalist =
|
|
100
|
+
typeof o.getValue === "function"
|
|
101
|
+
? o.getValue("meta_data")
|
|
102
|
+
: o.meta_data;
|
|
103
|
+
}
|
|
104
|
+
return metalist[key];
|
|
105
|
+
}
|
|
106
|
+
/* -------------------------------------------------------------------------- */
|
|
107
|
+
/* Save */
|
|
108
|
+
/* -------------------------------------------------------------------------- */
|
|
109
|
+
static zipSaveList(svlist) {
|
|
110
|
+
if (typeof svlist === "object")
|
|
111
|
+
svlist = JSON.stringify(svlist);
|
|
112
|
+
return string_compress(svlist);
|
|
113
|
+
}
|
|
114
|
+
static unzipSaveList(svlist) {
|
|
115
|
+
try {
|
|
116
|
+
if (typeof svlist === "object") {
|
|
117
|
+
if (Array.isArray(svlist))
|
|
118
|
+
return svlist;
|
|
119
|
+
if (svlist.__save_list)
|
|
120
|
+
return this.unzipSaveList(svlist.__save_list);
|
|
121
|
+
}
|
|
122
|
+
else if (typeof svlist === "string")
|
|
123
|
+
return wrap_array(JSON.parse(string_decompress(svlist)));
|
|
124
|
+
}
|
|
125
|
+
catch { }
|
|
126
|
+
return wrap_array(svlist);
|
|
127
|
+
}
|
|
128
|
+
static async saveList(itemList, extraOptions = {}) {
|
|
129
|
+
if (!extraOptions)
|
|
130
|
+
extraOptions = {};
|
|
131
|
+
const chunks = array_chunks(itemList, extraOptions.chunksize ?? 50);
|
|
132
|
+
delete extraOptions.chunksize;
|
|
133
|
+
const putAddress = this.get_webpath();
|
|
134
|
+
for (let index = 0; index < chunks.length; index++) {
|
|
135
|
+
const items_to_save = chunks[index];
|
|
136
|
+
const save_array = [];
|
|
137
|
+
for (let k = 0; k < items_to_save.length; k++) {
|
|
138
|
+
const item = items_to_save[k];
|
|
139
|
+
const dlt = await item.get_deltaObject();
|
|
140
|
+
save_array.push(item.isNew
|
|
141
|
+
? {
|
|
142
|
+
...dlt,
|
|
143
|
+
}
|
|
144
|
+
: {
|
|
145
|
+
_id: item.getID(),
|
|
146
|
+
...dlt,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const resultObject = await gfunc.run_action("post", putAddress, {
|
|
150
|
+
__save_list: WebObject.zipSaveList(save_array),
|
|
151
|
+
...extraOptions,
|
|
152
|
+
});
|
|
153
|
+
if (Array.isArray(resultObject)) {
|
|
154
|
+
for (let index = 0; index < Math.min(resultObject.length, items_to_save.length); index++) {
|
|
155
|
+
const res = resultObject[index];
|
|
156
|
+
const item = items_to_save[index];
|
|
157
|
+
item.setSaveResult(res);
|
|
158
|
+
await item.onSave();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
for (let index = 0; index < itemList.length; index++) {
|
|
163
|
+
const item = itemList[index];
|
|
164
|
+
if (!item.isSaved)
|
|
165
|
+
return false;
|
|
166
|
+
if (item.getSaveResultType() != "normal")
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
async Save() {
|
|
172
|
+
try {
|
|
173
|
+
if (this.manager) {
|
|
174
|
+
await this.manager.setOption("saving", true);
|
|
175
|
+
await this.manager.setOption("loading", true);
|
|
176
|
+
}
|
|
177
|
+
const deltaObject = await this.get_deltaObject();
|
|
178
|
+
const putAction = "post";
|
|
179
|
+
const usepath = await WebObjectPathHelper.get_path(this, this.isNew ? "new" : "save");
|
|
180
|
+
/* ---------------------------------- save ---------------------------------- */
|
|
181
|
+
if (!object_isEmpty(deltaObject)) {
|
|
182
|
+
const canSaveResult = this.canSave(deltaObject);
|
|
183
|
+
if (canSaveResult !== true) {
|
|
184
|
+
WebObject.addError(this, "Save not allowed", String(canSaveResult), true);
|
|
185
|
+
this.setSaveResult(false, "canceled");
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
const resultObject = await gfunc.run_action(putAction, usepath, deltaObject);
|
|
189
|
+
this.setSaveResult(resultObject, "auto");
|
|
190
|
+
if (!this.__saveResultIsSuccess) {
|
|
191
|
+
console.error("bad save result : ", resultObject);
|
|
192
|
+
WebObject.addError(this, "Save result is not valid", "the response from server was not a valid saveresult object !", true);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
/* nothing to save */
|
|
197
|
+
this.setSaveResult(null, "nothing");
|
|
198
|
+
}
|
|
199
|
+
if (this.isSaved) {
|
|
200
|
+
await this.onSave();
|
|
201
|
+
return this.getSaveResult();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
if (this.manager) {
|
|
206
|
+
await this.manager.setOption("saving", false);
|
|
207
|
+
await this.manager.setOption("loading", false);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async Delete() {
|
|
212
|
+
if (this.isNew)
|
|
213
|
+
return;
|
|
214
|
+
const usepath = await WebObjectPathHelper.get_path(this, "delete");
|
|
215
|
+
const resultObject = await gfunc.run_action("delete", usepath);
|
|
216
|
+
this.setSaveResult(resultObject, "auto", true);
|
|
217
|
+
await this.onDelete();
|
|
218
|
+
return resultObject;
|
|
219
|
+
}
|
|
220
|
+
async Lock() {
|
|
221
|
+
if (this.isNew || this.isArchived)
|
|
222
|
+
return;
|
|
223
|
+
const usepath = await WebObjectPathHelper.get_path(this, "lock");
|
|
224
|
+
const resultObject = await gfunc.run_action("post", usepath);
|
|
225
|
+
this.setSaveResult(resultObject, "auto", true);
|
|
226
|
+
await this.onLock();
|
|
227
|
+
return resultObject;
|
|
228
|
+
}
|
|
229
|
+
async UnLock() {
|
|
230
|
+
if (this.isNew || this.isArchived)
|
|
231
|
+
return;
|
|
232
|
+
const usepath = await WebObjectPathHelper.get_path(this, "unlock");
|
|
233
|
+
const resultObject = await gfunc.run_action("post", usepath);
|
|
234
|
+
this.setSaveResult(resultObject, "auto", true);
|
|
235
|
+
await this.onUnLock();
|
|
236
|
+
return resultObject;
|
|
237
|
+
}
|
|
238
|
+
async Archive() {
|
|
239
|
+
if (this.isNew || this.isArchived)
|
|
240
|
+
return;
|
|
241
|
+
const usepath = await WebObjectPathHelper.get_path(this, "archive");
|
|
242
|
+
const resultObject = await gfunc.run_action("post", usepath);
|
|
243
|
+
this.setSaveResult(resultObject, "auto", true);
|
|
244
|
+
await this.onArchive();
|
|
245
|
+
return resultObject;
|
|
246
|
+
}
|
|
247
|
+
async UnArchive() {
|
|
248
|
+
if (this.isNew || !this.isArchived)
|
|
249
|
+
return;
|
|
250
|
+
const usepath = await WebObjectPathHelper.get_path(this, "unarchive");
|
|
251
|
+
const resultObject = await gfunc.run_action("post", usepath);
|
|
252
|
+
await this.onUnArchive();
|
|
253
|
+
return resultObject;
|
|
254
|
+
}
|
|
255
|
+
/* -------------------------------------------------------------------------- */
|
|
256
|
+
canSave(deltaObj) {
|
|
257
|
+
const deltaRes = this.deltaIsValid(deltaObj);
|
|
258
|
+
if (deltaRes !== true)
|
|
259
|
+
return deltaRes;
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
canDelete() {
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
canArchive() {
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
deltaIsValid(d) {
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
467
271
|
/**
|
|
468
272
|
* calls the `get_deltaObject` with `allProperties=true` `extraProperties=true`
|
|
469
273
|
*
|
|
470
274
|
* useful in server applications
|
|
471
275
|
* @returns
|
|
472
|
-
*/
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
case 0:
|
|
480
|
-
_context8.next = 2;
|
|
481
|
-
return this.get_deltaObject({
|
|
482
|
-
allProperties: true,
|
|
483
|
-
extraProperties: true
|
|
484
|
-
});
|
|
485
|
-
case 2:
|
|
486
|
-
return _context8.abrupt("return", _context8.sent);
|
|
487
|
-
case 3:
|
|
488
|
-
case "end":
|
|
489
|
-
return _context8.stop();
|
|
490
|
-
}
|
|
491
|
-
}, _callee8, this);
|
|
492
|
-
}));
|
|
493
|
-
function get_fullDeltaObject(_x3) {
|
|
494
|
-
return _get_fullDeltaObject.apply(this, arguments);
|
|
495
|
-
}
|
|
496
|
-
return get_fullDeltaObject;
|
|
497
|
-
}()
|
|
276
|
+
*/
|
|
277
|
+
async get_fullDeltaObject(p) {
|
|
278
|
+
return await this.get_deltaObject({
|
|
279
|
+
allProperties: true,
|
|
280
|
+
extraProperties: true,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
498
283
|
/**
|
|
499
284
|
* You will post this to the server for saving
|
|
500
285
|
* automatically removes unchangable fields
|
|
501
286
|
* @returns
|
|
502
|
-
*/
|
|
503
|
-
)
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
key: "manager",
|
|
684
|
-
get: function get() {
|
|
685
|
-
return this.get_managerClass() || undefined;
|
|
686
|
-
}
|
|
687
|
-
}, {
|
|
688
|
-
key: "__web_path",
|
|
689
|
-
get: function get() {
|
|
690
|
-
return this.constructor["__web_path"] || this.__db_name;
|
|
691
|
-
}
|
|
692
|
-
}, {
|
|
693
|
-
key: "get_webpath",
|
|
694
|
-
value: function get_webpath() {
|
|
695
|
-
return this.__web_path || this.__db_name || "";
|
|
696
|
-
}
|
|
697
|
-
}, {
|
|
698
|
-
key: "onDelete",
|
|
699
|
-
value: ( /* -------------------------------------------------------------------------- */function () {
|
|
700
|
-
var _onDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
701
|
-
var _this$manager;
|
|
702
|
-
var _len,
|
|
703
|
-
p,
|
|
704
|
-
_key,
|
|
705
|
-
_args12 = arguments;
|
|
706
|
-
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
707
|
-
while (1) switch (_context12.prev = _context12.next) {
|
|
708
|
-
case 0:
|
|
709
|
-
if (this.isSaved) this.isDeleted = true;
|
|
710
|
-
for (_len = _args12.length, p = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
711
|
-
p[_key] = _args12[_key];
|
|
712
|
-
}
|
|
713
|
-
_context12.next = 4;
|
|
714
|
-
return (_this$manager = this.manager) === null || _this$manager === void 0 ? void 0 : _this$manager.onDelete.apply(_this$manager, p);
|
|
715
|
-
case 4:
|
|
716
|
-
return _context12.abrupt("return", _context12.sent);
|
|
717
|
-
case 5:
|
|
718
|
-
case "end":
|
|
719
|
-
return _context12.stop();
|
|
720
|
-
}
|
|
721
|
-
}, _callee12, this);
|
|
722
|
-
}));
|
|
723
|
-
function onDelete() {
|
|
724
|
-
return _onDelete.apply(this, arguments);
|
|
725
|
-
}
|
|
726
|
-
return onDelete;
|
|
727
|
-
}())
|
|
728
|
-
}, {
|
|
729
|
-
key: "onArchive",
|
|
730
|
-
value: function () {
|
|
731
|
-
var _onArchive = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
732
|
-
var _this$manager2;
|
|
733
|
-
var _len2,
|
|
734
|
-
p,
|
|
735
|
-
_key2,
|
|
736
|
-
_args13 = arguments;
|
|
737
|
-
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
738
|
-
while (1) switch (_context13.prev = _context13.next) {
|
|
739
|
-
case 0:
|
|
740
|
-
if (this.isSaved) this.isArchived = true;
|
|
741
|
-
for (_len2 = _args13.length, p = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
742
|
-
p[_key2] = _args13[_key2];
|
|
743
|
-
}
|
|
744
|
-
_context13.next = 4;
|
|
745
|
-
return (_this$manager2 = this.manager) === null || _this$manager2 === void 0 ? void 0 : _this$manager2.onArchive.apply(_this$manager2, p);
|
|
746
|
-
case 4:
|
|
747
|
-
return _context13.abrupt("return", _context13.sent);
|
|
748
|
-
case 5:
|
|
749
|
-
case "end":
|
|
750
|
-
return _context13.stop();
|
|
751
|
-
}
|
|
752
|
-
}, _callee13, this);
|
|
753
|
-
}));
|
|
754
|
-
function onArchive() {
|
|
755
|
-
return _onArchive.apply(this, arguments);
|
|
756
|
-
}
|
|
757
|
-
return onArchive;
|
|
758
|
-
}()
|
|
759
|
-
}, {
|
|
760
|
-
key: "onUnArchive",
|
|
761
|
-
value: function () {
|
|
762
|
-
var _onUnArchive = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
763
|
-
var _this$manager3;
|
|
764
|
-
var _len3,
|
|
765
|
-
p,
|
|
766
|
-
_key3,
|
|
767
|
-
_args14 = arguments;
|
|
768
|
-
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
769
|
-
while (1) switch (_context14.prev = _context14.next) {
|
|
770
|
-
case 0:
|
|
771
|
-
if (this.isSaved) this.isArchived = false;
|
|
772
|
-
for (_len3 = _args14.length, p = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
773
|
-
p[_key3] = _args14[_key3];
|
|
774
|
-
}
|
|
775
|
-
_context14.next = 4;
|
|
776
|
-
return (_this$manager3 = this.manager) === null || _this$manager3 === void 0 ? void 0 : _this$manager3.onUnArchive.apply(_this$manager3, p);
|
|
777
|
-
case 4:
|
|
778
|
-
return _context14.abrupt("return", _context14.sent);
|
|
779
|
-
case 5:
|
|
780
|
-
case "end":
|
|
781
|
-
return _context14.stop();
|
|
782
|
-
}
|
|
783
|
-
}, _callee14, this);
|
|
784
|
-
}));
|
|
785
|
-
function onUnArchive() {
|
|
786
|
-
return _onUnArchive.apply(this, arguments);
|
|
787
|
-
}
|
|
788
|
-
return onUnArchive;
|
|
789
|
-
}()
|
|
790
|
-
}, {
|
|
791
|
-
key: "onLock",
|
|
792
|
-
value: function () {
|
|
793
|
-
var _onLock = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
794
|
-
var _this$manager4;
|
|
795
|
-
var _len4,
|
|
796
|
-
p,
|
|
797
|
-
_key4,
|
|
798
|
-
_args15 = arguments;
|
|
799
|
-
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
800
|
-
while (1) switch (_context15.prev = _context15.next) {
|
|
801
|
-
case 0:
|
|
802
|
-
if (this.isSaved) this.isLocked = true;
|
|
803
|
-
for (_len4 = _args15.length, p = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
804
|
-
p[_key4] = _args15[_key4];
|
|
805
|
-
}
|
|
806
|
-
_context15.next = 4;
|
|
807
|
-
return (_this$manager4 = this.manager) === null || _this$manager4 === void 0 ? void 0 : _this$manager4.onLock.apply(_this$manager4, p);
|
|
808
|
-
case 4:
|
|
809
|
-
return _context15.abrupt("return", _context15.sent);
|
|
810
|
-
case 5:
|
|
811
|
-
case "end":
|
|
812
|
-
return _context15.stop();
|
|
813
|
-
}
|
|
814
|
-
}, _callee15, this);
|
|
815
|
-
}));
|
|
816
|
-
function onLock() {
|
|
817
|
-
return _onLock.apply(this, arguments);
|
|
818
|
-
}
|
|
819
|
-
return onLock;
|
|
820
|
-
}()
|
|
821
|
-
}, {
|
|
822
|
-
key: "onUnLock",
|
|
823
|
-
value: function () {
|
|
824
|
-
var _onUnLock = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
|
|
825
|
-
var _this$manager5;
|
|
826
|
-
var _len5,
|
|
827
|
-
p,
|
|
828
|
-
_key5,
|
|
829
|
-
_args16 = arguments;
|
|
830
|
-
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
831
|
-
while (1) switch (_context16.prev = _context16.next) {
|
|
832
|
-
case 0:
|
|
833
|
-
if (this.isSaved) this.isLocked = false;
|
|
834
|
-
for (_len5 = _args16.length, p = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
835
|
-
p[_key5] = _args16[_key5];
|
|
836
|
-
}
|
|
837
|
-
_context16.next = 4;
|
|
838
|
-
return (_this$manager5 = this.manager) === null || _this$manager5 === void 0 ? void 0 : _this$manager5.onUnLock.apply(_this$manager5, p);
|
|
839
|
-
case 4:
|
|
840
|
-
return _context16.abrupt("return", _context16.sent);
|
|
841
|
-
case 5:
|
|
842
|
-
case "end":
|
|
843
|
-
return _context16.stop();
|
|
844
|
-
}
|
|
845
|
-
}, _callee16, this);
|
|
846
|
-
}));
|
|
847
|
-
function onUnLock() {
|
|
848
|
-
return _onUnLock.apply(this, arguments);
|
|
849
|
-
}
|
|
850
|
-
return onUnLock;
|
|
851
|
-
}()
|
|
852
|
-
}, {
|
|
853
|
-
key: "onLoad",
|
|
854
|
-
value: function () {
|
|
855
|
-
var _onLoad = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
|
856
|
-
var _this$manager6;
|
|
857
|
-
var _len6,
|
|
858
|
-
p,
|
|
859
|
-
_key6,
|
|
860
|
-
_args17 = arguments;
|
|
861
|
-
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
862
|
-
while (1) switch (_context17.prev = _context17.next) {
|
|
863
|
-
case 0:
|
|
864
|
-
this.isDeleted = false;
|
|
865
|
-
for (_len6 = _args17.length, p = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
866
|
-
p[_key6] = _args17[_key6];
|
|
867
|
-
}
|
|
868
|
-
_context17.next = 4;
|
|
869
|
-
return (_this$manager6 = this.manager) === null || _this$manager6 === void 0 ? void 0 : _this$manager6.onLoad.apply(_this$manager6, p);
|
|
870
|
-
case 4:
|
|
871
|
-
return _context17.abrupt("return", _context17.sent);
|
|
872
|
-
case 5:
|
|
873
|
-
case "end":
|
|
874
|
-
return _context17.stop();
|
|
875
|
-
}
|
|
876
|
-
}, _callee17, this);
|
|
877
|
-
}));
|
|
878
|
-
function onLoad() {
|
|
879
|
-
return _onLoad.apply(this, arguments);
|
|
880
|
-
}
|
|
881
|
-
return onLoad;
|
|
882
|
-
}()
|
|
883
|
-
}, {
|
|
884
|
-
key: "onSave",
|
|
885
|
-
value: function () {
|
|
886
|
-
var _onSave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
|
|
887
|
-
var _this$manager8;
|
|
888
|
-
var srObject,
|
|
889
|
-
_this$manager7,
|
|
890
|
-
_len7,
|
|
891
|
-
p,
|
|
892
|
-
_key7,
|
|
893
|
-
_args18 = arguments;
|
|
894
|
-
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
895
|
-
while (1) switch (_context18.prev = _context18.next) {
|
|
896
|
-
case 0:
|
|
897
|
-
if (!this.isSaved) {
|
|
898
|
-
_context18.next = 7;
|
|
899
|
-
break;
|
|
900
|
-
}
|
|
901
|
-
this.apply_changes();
|
|
902
|
-
srObject = this.getSaveResult(true);
|
|
903
|
-
if (!this.saveResultHasID(srObject)) {
|
|
904
|
-
_context18.next = 7;
|
|
905
|
-
break;
|
|
906
|
-
}
|
|
907
|
-
/* -------------------------------------------------------------------------- */
|
|
908
|
-
WebObject.LoadIdsFromSaveResult(this, srObject);
|
|
909
|
-
_context18.next = 7;
|
|
910
|
-
return (_this$manager7 = this.manager) === null || _this$manager7 === void 0 ? void 0 : _this$manager7.event_run("on_id_change");
|
|
911
|
-
case 7:
|
|
912
|
-
for (_len7 = _args18.length, p = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
913
|
-
p[_key7] = _args18[_key7];
|
|
914
|
-
}
|
|
915
|
-
_context18.next = 10;
|
|
916
|
-
return (_this$manager8 = this.manager) === null || _this$manager8 === void 0 ? void 0 : _this$manager8.onSave.apply(_this$manager8, p);
|
|
917
|
-
case 10:
|
|
918
|
-
_context18.next = 12;
|
|
919
|
-
return this.onAfterSave();
|
|
920
|
-
case 12:
|
|
921
|
-
return _context18.abrupt("return", true);
|
|
922
|
-
case 13:
|
|
923
|
-
case "end":
|
|
924
|
-
return _context18.stop();
|
|
925
|
-
}
|
|
926
|
-
}, _callee18, this);
|
|
927
|
-
}));
|
|
928
|
-
function onSave() {
|
|
929
|
-
return _onSave.apply(this, arguments);
|
|
930
|
-
}
|
|
931
|
-
return onSave;
|
|
932
|
-
}()
|
|
933
|
-
}, {
|
|
934
|
-
key: "onAfterSave",
|
|
935
|
-
value: function () {
|
|
936
|
-
var _onAfterSave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
|
|
937
|
-
var _this$manager9;
|
|
938
|
-
var _len8,
|
|
939
|
-
p,
|
|
940
|
-
_key8,
|
|
941
|
-
_args19 = arguments;
|
|
942
|
-
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
943
|
-
while (1) switch (_context19.prev = _context19.next) {
|
|
944
|
-
case 0:
|
|
945
|
-
for (_len8 = _args19.length, p = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
|
|
946
|
-
p[_key8] = _args19[_key8];
|
|
947
|
-
}
|
|
948
|
-
_context19.next = 3;
|
|
949
|
-
return (_this$manager9 = this.manager) === null || _this$manager9 === void 0 ? void 0 : _this$manager9.onAfterSave.apply(_this$manager9, p);
|
|
950
|
-
case 3:
|
|
951
|
-
return _context19.abrupt("return", true);
|
|
952
|
-
case 4:
|
|
953
|
-
case "end":
|
|
954
|
-
return _context19.stop();
|
|
955
|
-
}
|
|
956
|
-
}, _callee19, this);
|
|
957
|
-
}));
|
|
958
|
-
function onAfterSave() {
|
|
959
|
-
return _onAfterSave.apply(this, arguments);
|
|
960
|
-
}
|
|
961
|
-
return onAfterSave;
|
|
962
|
-
}()
|
|
963
|
-
}, {
|
|
964
|
-
key: "getSaveResult",
|
|
965
|
-
value: function getSaveResult() {
|
|
966
|
-
var _this3 = this;
|
|
967
|
-
var original = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
968
|
-
var srObject = _get(_getPrototypeOf(WebObject.prototype), "getSaveResult", this).call(this, original);
|
|
969
|
-
if (!srObject) return false;
|
|
970
|
-
if (Array.isArray(srObject)) {
|
|
971
|
-
var actual_sr = srObject.find(function (s) {
|
|
972
|
-
return _this3.saveResultHasID(s);
|
|
973
|
-
});
|
|
974
|
-
if (actual_sr) srObject = actual_sr;
|
|
975
|
-
}
|
|
976
|
-
return srObject;
|
|
977
|
-
}
|
|
978
|
-
}, {
|
|
979
|
-
key: "onNew",
|
|
980
|
-
value: function () {
|
|
981
|
-
var _onNew = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
|
|
982
|
-
var _this$manager10;
|
|
983
|
-
var _len9,
|
|
984
|
-
p,
|
|
985
|
-
_key9,
|
|
986
|
-
_args20 = arguments;
|
|
987
|
-
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
988
|
-
while (1) switch (_context20.prev = _context20.next) {
|
|
989
|
-
case 0:
|
|
990
|
-
for (_len9 = _args20.length, p = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
|
|
991
|
-
p[_key9] = _args20[_key9];
|
|
992
|
-
}
|
|
993
|
-
_context20.next = 3;
|
|
994
|
-
return (_this$manager10 = this.manager) === null || _this$manager10 === void 0 ? void 0 : _this$manager10.onNew.apply(_this$manager10, p);
|
|
995
|
-
case 3:
|
|
996
|
-
return _context20.abrupt("return", _context20.sent);
|
|
997
|
-
case 4:
|
|
998
|
-
case "end":
|
|
999
|
-
return _context20.stop();
|
|
1000
|
-
}
|
|
1001
|
-
}, _callee20, this);
|
|
1002
|
-
}));
|
|
1003
|
-
function onNew() {
|
|
1004
|
-
return _onNew.apply(this, arguments);
|
|
1005
|
-
}
|
|
1006
|
-
return onNew;
|
|
1007
|
-
}() /* -------------------------------------------------------------------------- */
|
|
1008
|
-
}, {
|
|
1009
|
-
key: "saveResultHasID",
|
|
1010
|
-
value: function saveResultHasID(s) {
|
|
1011
|
-
return WebObject.saveResultHasID(s);
|
|
1012
|
-
}
|
|
1013
|
-
}], [{
|
|
1014
|
-
key: "getAllUsers",
|
|
1015
|
-
value: function getAllUsers(obj) {
|
|
1016
|
-
if (_typeof(obj) != "object") return [];
|
|
1017
|
-
return (0, _object.array_remove_duplicates)((0, _object.array_merge)(obj._creator, (0, _object.wrap_array)(obj._users), (0, _object.wrap_array)(obj.attentions)).map(function (r) {
|
|
1018
|
-
return String(_typeof(r) === "object" ? WebObject.getID(r) : r);
|
|
1019
|
-
}).filter(function (s) {
|
|
1020
|
-
return s;
|
|
1021
|
-
}));
|
|
1022
|
-
}
|
|
1023
|
-
}, {
|
|
1024
|
-
key: "getMetaValue",
|
|
1025
|
-
value: function getMetaValue(o, key) {
|
|
1026
|
-
if (o == null) return null;
|
|
1027
|
-
if (!key || typeof key != "string") return undefined;
|
|
1028
|
-
var metalist = {};
|
|
1029
|
-
if (_typeof(o) === "object") {
|
|
1030
|
-
metalist = typeof o.getValue === "function" ? o.getValue("meta_data") : o.meta_data;
|
|
1031
|
-
}
|
|
1032
|
-
return metalist[key];
|
|
1033
|
-
}
|
|
1034
|
-
/* -------------------------------------------------------------------------- */
|
|
1035
|
-
/* Save */
|
|
1036
|
-
/* -------------------------------------------------------------------------- */
|
|
1037
|
-
}, {
|
|
1038
|
-
key: "zipSaveList",
|
|
1039
|
-
value: function zipSaveList(svlist) {
|
|
1040
|
-
if (_typeof(svlist) === "object") svlist = JSON.stringify(svlist);
|
|
1041
|
-
return (0, _string.string_compress)(svlist);
|
|
1042
|
-
}
|
|
1043
|
-
}, {
|
|
1044
|
-
key: "unzipSaveList",
|
|
1045
|
-
value: function unzipSaveList(svlist) {
|
|
1046
|
-
try {
|
|
1047
|
-
if (_typeof(svlist) === "object") {
|
|
1048
|
-
if (Array.isArray(svlist)) return svlist;
|
|
1049
|
-
if (svlist.__save_list) return this.unzipSaveList(svlist.__save_list);
|
|
1050
|
-
} else if (typeof svlist === "string") return (0, _object.wrap_array)(JSON.parse((0, _string.string_decompress)(svlist)));
|
|
1051
|
-
} catch (_unused) {}
|
|
1052
|
-
return (0, _object.wrap_array)(svlist);
|
|
1053
|
-
}
|
|
1054
|
-
}, {
|
|
1055
|
-
key: "saveList",
|
|
1056
|
-
value: function () {
|
|
1057
|
-
var _saveList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(itemList) {
|
|
1058
|
-
var _extraOptions$chunksi;
|
|
1059
|
-
var extraOptions,
|
|
1060
|
-
chunks,
|
|
1061
|
-
putAddress,
|
|
1062
|
-
index,
|
|
1063
|
-
items_to_save,
|
|
1064
|
-
save_array,
|
|
1065
|
-
k,
|
|
1066
|
-
item,
|
|
1067
|
-
dlt,
|
|
1068
|
-
resultObject,
|
|
1069
|
-
_index,
|
|
1070
|
-
res,
|
|
1071
|
-
_item,
|
|
1072
|
-
_index2,
|
|
1073
|
-
_item2,
|
|
1074
|
-
_args21 = arguments;
|
|
1075
|
-
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1076
|
-
while (1) switch (_context21.prev = _context21.next) {
|
|
1077
|
-
case 0:
|
|
1078
|
-
extraOptions = _args21.length > 1 && _args21[1] !== undefined ? _args21[1] : {};
|
|
1079
|
-
if (!extraOptions) extraOptions = {};
|
|
1080
|
-
chunks = (0, _object.array_chunks)(itemList, (_extraOptions$chunksi = extraOptions.chunksize) !== null && _extraOptions$chunksi !== void 0 ? _extraOptions$chunksi : 50);
|
|
1081
|
-
delete extraOptions.chunksize;
|
|
1082
|
-
putAddress = this.get_webpath();
|
|
1083
|
-
index = 0;
|
|
1084
|
-
case 6:
|
|
1085
|
-
if (!(index < chunks.length)) {
|
|
1086
|
-
_context21.next = 36;
|
|
1087
|
-
break;
|
|
1088
|
-
}
|
|
1089
|
-
items_to_save = chunks[index];
|
|
1090
|
-
save_array = [];
|
|
1091
|
-
k = 0;
|
|
1092
|
-
case 10:
|
|
1093
|
-
if (!(k < items_to_save.length)) {
|
|
1094
|
-
_context21.next = 19;
|
|
1095
|
-
break;
|
|
1096
|
-
}
|
|
1097
|
-
item = items_to_save[k];
|
|
1098
|
-
_context21.next = 14;
|
|
1099
|
-
return item.get_deltaObject();
|
|
1100
|
-
case 14:
|
|
1101
|
-
dlt = _context21.sent;
|
|
1102
|
-
save_array.push(item.isNew ? _objectSpread({}, dlt) : _objectSpread({
|
|
1103
|
-
_id: item.getID()
|
|
1104
|
-
}, dlt));
|
|
1105
|
-
case 16:
|
|
1106
|
-
k++;
|
|
1107
|
-
_context21.next = 10;
|
|
1108
|
-
break;
|
|
1109
|
-
case 19:
|
|
1110
|
-
_context21.next = 21;
|
|
1111
|
-
return _global.gfunc.run_action("post", putAddress, _objectSpread({
|
|
1112
|
-
__save_list: WebObject.zipSaveList(save_array)
|
|
1113
|
-
}, extraOptions));
|
|
1114
|
-
case 21:
|
|
1115
|
-
resultObject = _context21.sent;
|
|
1116
|
-
if (!Array.isArray(resultObject)) {
|
|
1117
|
-
_context21.next = 33;
|
|
1118
|
-
break;
|
|
1119
|
-
}
|
|
1120
|
-
_index = 0;
|
|
1121
|
-
case 24:
|
|
1122
|
-
if (!(_index < Math.min(resultObject.length, items_to_save.length))) {
|
|
1123
|
-
_context21.next = 33;
|
|
1124
|
-
break;
|
|
1125
|
-
}
|
|
1126
|
-
res = resultObject[_index];
|
|
1127
|
-
_item = items_to_save[_index];
|
|
1128
|
-
_item.setSaveResult(res);
|
|
1129
|
-
_context21.next = 30;
|
|
1130
|
-
return _item.onSave();
|
|
1131
|
-
case 30:
|
|
1132
|
-
_index++;
|
|
1133
|
-
_context21.next = 24;
|
|
1134
|
-
break;
|
|
1135
|
-
case 33:
|
|
1136
|
-
index++;
|
|
1137
|
-
_context21.next = 6;
|
|
1138
|
-
break;
|
|
1139
|
-
case 36:
|
|
1140
|
-
_index2 = 0;
|
|
1141
|
-
case 37:
|
|
1142
|
-
if (!(_index2 < itemList.length)) {
|
|
1143
|
-
_context21.next = 46;
|
|
1144
|
-
break;
|
|
1145
|
-
}
|
|
1146
|
-
_item2 = itemList[_index2];
|
|
1147
|
-
if (_item2.isSaved) {
|
|
1148
|
-
_context21.next = 41;
|
|
1149
|
-
break;
|
|
1150
|
-
}
|
|
1151
|
-
return _context21.abrupt("return", false);
|
|
1152
|
-
case 41:
|
|
1153
|
-
if (!(_item2.getSaveResultType() != "normal")) {
|
|
1154
|
-
_context21.next = 43;
|
|
1155
|
-
break;
|
|
1156
|
-
}
|
|
1157
|
-
return _context21.abrupt("return", false);
|
|
1158
|
-
case 43:
|
|
1159
|
-
_index2++;
|
|
1160
|
-
_context21.next = 37;
|
|
1161
|
-
break;
|
|
1162
|
-
case 46:
|
|
1163
|
-
return _context21.abrupt("return", true);
|
|
1164
|
-
case 47:
|
|
1165
|
-
case "end":
|
|
1166
|
-
return _context21.stop();
|
|
1167
|
-
}
|
|
1168
|
-
}, _callee21, this);
|
|
1169
|
-
}));
|
|
1170
|
-
function saveList(_x7) {
|
|
1171
|
-
return _saveList.apply(this, arguments);
|
|
1172
|
-
}
|
|
1173
|
-
return saveList;
|
|
1174
|
-
}()
|
|
1175
|
-
}, {
|
|
1176
|
-
key: "get_webpath",
|
|
1177
|
-
value: function get_webpath() {
|
|
1178
|
-
return this.__web_path || this.__db_name || "";
|
|
1179
|
-
}
|
|
1180
|
-
}, {
|
|
1181
|
-
key: "saveResultHasID",
|
|
1182
|
-
value: function saveResultHasID(s) {
|
|
1183
|
-
if (_typeof(s) !== "object" || s == null || !s) return false;
|
|
1184
|
-
return s.insertedId || s._id || s._index_value && !Number.isNaN(s._index_value);
|
|
1185
|
-
}
|
|
287
|
+
*/
|
|
288
|
+
async get_deltaObject(p) {
|
|
289
|
+
if (!p)
|
|
290
|
+
p = {};
|
|
291
|
+
const final_object = {};
|
|
292
|
+
//@ts-ignore
|
|
293
|
+
const isChild = Boolean(p.isChild || p.ischild);
|
|
294
|
+
//@ts-ignore
|
|
295
|
+
const useDelta = this.__use_delta || Boolean(p.useDelta || p.usedelta);
|
|
296
|
+
//@ts-ignore
|
|
297
|
+
const allProperties = Boolean(p.allProperties || p.allproperties);
|
|
298
|
+
//@ts-ignore
|
|
299
|
+
const needId = Boolean(p.needId || p.needid);
|
|
300
|
+
const chkChangables = this.__changeables != null || this.__unchangeables != null;
|
|
301
|
+
const useExtraProps = Boolean(p.extraProperties);
|
|
302
|
+
//child objects usually dont update their __delta, so we read info from all of its properties
|
|
303
|
+
const dlt = allProperties || (!useDelta && isChild && chkChangables)
|
|
304
|
+
? { ...this.allproperties }
|
|
305
|
+
: { ...this.__delta };
|
|
306
|
+
const allkeys = Object.keys(dlt);
|
|
307
|
+
const changableKeys = chkChangables
|
|
308
|
+
? allkeys.filter((s) => SimpleObject.canChangeKey(this, s, {
|
|
309
|
+
useExtraProps: useExtraProps,
|
|
310
|
+
ignoreProtected: allProperties,
|
|
311
|
+
}))
|
|
312
|
+
: allkeys;
|
|
313
|
+
await FormatHelper.applyFormats({
|
|
314
|
+
inputobject: dlt,
|
|
315
|
+
formats: object_getStatic(this, "__formatList"),
|
|
316
|
+
changableKeys: changableKeys,
|
|
317
|
+
});
|
|
318
|
+
/* -------------------------------------------------------------------------- */
|
|
319
|
+
/* __functionProperties */
|
|
320
|
+
/* -------------------------------------------------------------------------- */
|
|
321
|
+
const functionProps = object_getStatic(this, "__functionProperties");
|
|
322
|
+
if (Array.isArray(functionProps)) {
|
|
323
|
+
for (let index = 0; index < functionProps.length; index++) {
|
|
324
|
+
const fp = functionProps[index];
|
|
325
|
+
if (dlt[fp])
|
|
326
|
+
dlt[fp] = fn_eval_this(this, dlt[fp]);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/* -------------------------------------------------------------------------- */
|
|
330
|
+
/* parse all changableKeys */
|
|
331
|
+
/* -------------------------------------------------------------------------- */
|
|
332
|
+
async function parseObj(obj) {
|
|
333
|
+
if (obj == null)
|
|
334
|
+
return undefined;
|
|
335
|
+
if (Array.isArray(obj))
|
|
336
|
+
return await Promise.all(obj.map(async (r) => await parseObj(r)));
|
|
337
|
+
if (obj instanceof WebObject &&
|
|
338
|
+
typeof obj.get_deltaObject === "function") {
|
|
339
|
+
//child elements have different kind of delta
|
|
340
|
+
const newobj_dlt = await obj.get_deltaObject({
|
|
341
|
+
...p,
|
|
342
|
+
isChild: true,
|
|
343
|
+
});
|
|
344
|
+
if (!object_isEmpty(newobj_dlt))
|
|
345
|
+
return newobj_dlt;
|
|
346
|
+
else
|
|
347
|
+
return obj;
|
|
348
|
+
}
|
|
349
|
+
return obj;
|
|
350
|
+
}
|
|
351
|
+
for (const key of changableKeys) {
|
|
352
|
+
final_object[key] = await parseObj(dlt[key]);
|
|
353
|
+
}
|
|
354
|
+
/* -------------------- add acrhived and date properties -------------------- */
|
|
355
|
+
if (allProperties) {
|
|
356
|
+
final_object["_created_date"] = this["_created_date"];
|
|
357
|
+
final_object["_archived"] = this.isArchived;
|
|
358
|
+
final_object["_deleted"] = this.isDeleted;
|
|
359
|
+
}
|
|
360
|
+
/* ---------------------------- add id properties --------------------------- */
|
|
361
|
+
if (allProperties || needId) {
|
|
362
|
+
if (this["_index_key"])
|
|
363
|
+
final_object["_index_key"] = this["_index_key"];
|
|
364
|
+
const gotIndex = this.getIndex();
|
|
365
|
+
const gotId = this.getID();
|
|
366
|
+
if (gotIndex && gotIndex >= 0)
|
|
367
|
+
final_object["_index_value"] = gotIndex;
|
|
368
|
+
if (gotId)
|
|
369
|
+
final_object["_id"] = gotId;
|
|
370
|
+
}
|
|
371
|
+
/* -------------------------------------------------------------------------- */
|
|
372
|
+
/* fix _user property */
|
|
373
|
+
/* -------------------------------------------------------------------------- */
|
|
374
|
+
if (final_object["_users"]) {
|
|
375
|
+
let tempusers = final_object["_users"];
|
|
376
|
+
if (typeof tempusers === "string")
|
|
377
|
+
tempusers = tempusers.split(",").filter((s) => s);
|
|
378
|
+
final_object["_users"] = wrap_array(tempusers);
|
|
379
|
+
}
|
|
380
|
+
return final_object;
|
|
381
|
+
}
|
|
382
|
+
/* --------------------------------- Getters -------------------------------- */
|
|
383
|
+
get manager() {
|
|
384
|
+
return this.get_managerClass() || undefined;
|
|
385
|
+
}
|
|
386
|
+
get __web_path() {
|
|
387
|
+
return this.constructor["__web_path"] || this.__db_name;
|
|
388
|
+
}
|
|
389
|
+
get_webpath() {
|
|
390
|
+
return this.__web_path || this.__db_name || "";
|
|
391
|
+
}
|
|
392
|
+
static get_webpath() {
|
|
393
|
+
return this.__web_path || this.__db_name || "";
|
|
394
|
+
}
|
|
395
|
+
/* -------------------------------------------------------------------------- */
|
|
396
|
+
async onDelete(...p) {
|
|
397
|
+
if (this.isSaved)
|
|
398
|
+
this.isDeleted = true;
|
|
399
|
+
return await this.manager?.onDelete(...p); //events are handled by the manager
|
|
400
|
+
}
|
|
401
|
+
async onArchive(...p) {
|
|
402
|
+
if (this.isSaved)
|
|
403
|
+
this.isArchived = true;
|
|
404
|
+
return await this.manager?.onArchive(...p); //events are handled by the manager
|
|
405
|
+
}
|
|
406
|
+
async onUnArchive(...p) {
|
|
407
|
+
if (this.isSaved)
|
|
408
|
+
this.isArchived = false;
|
|
409
|
+
return await this.manager?.onUnArchive(...p); //events are handled by the manager
|
|
410
|
+
}
|
|
411
|
+
async onLock(...p) {
|
|
412
|
+
if (this.isSaved)
|
|
413
|
+
this.isLocked = true;
|
|
414
|
+
return await this.manager?.onLock(...p); //events are handled by the manager
|
|
415
|
+
}
|
|
416
|
+
async onUnLock(...p) {
|
|
417
|
+
if (this.isSaved)
|
|
418
|
+
this.isLocked = false;
|
|
419
|
+
return await this.manager?.onUnLock(...p); //events are handled by the manager
|
|
420
|
+
}
|
|
421
|
+
async onLoad(...p) {
|
|
422
|
+
this.isDeleted = false;
|
|
423
|
+
return await this.manager?.onLoad(...p); //events are handled by the manager
|
|
424
|
+
}
|
|
425
|
+
async onSave(...p) {
|
|
426
|
+
if (this.isSaved) {
|
|
427
|
+
this.apply_changes();
|
|
428
|
+
var srObject = this.getSaveResult(true);
|
|
429
|
+
if (this.saveResultHasID(srObject)) {
|
|
430
|
+
/* -------------------------------------------------------------------------- */
|
|
431
|
+
WebObject.LoadIdsFromSaveResult(this, srObject);
|
|
432
|
+
await this.manager?.event_run("on_id_change");
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
await this.manager?.onSave(...p); //events are handled by the manager
|
|
436
|
+
await this.onAfterSave();
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
async onAfterSave(...p) {
|
|
440
|
+
await this.manager?.onAfterSave(...p); //events are handled by the manager
|
|
441
|
+
return true;
|
|
442
|
+
}
|
|
443
|
+
getSaveResult(original = false) {
|
|
444
|
+
let srObject = super.getSaveResult(original);
|
|
445
|
+
if (!srObject)
|
|
446
|
+
return false;
|
|
447
|
+
if (Array.isArray(srObject)) {
|
|
448
|
+
const actual_sr = srObject.find((s) => this.saveResultHasID(s));
|
|
449
|
+
if (actual_sr)
|
|
450
|
+
srObject = actual_sr;
|
|
451
|
+
}
|
|
452
|
+
return srObject;
|
|
453
|
+
}
|
|
454
|
+
async onNew(...p) {
|
|
455
|
+
return await this.manager?.onNew(...p); //events are handled by the manager
|
|
456
|
+
}
|
|
457
|
+
/* -------------------------------------------------------------------------- */
|
|
458
|
+
saveResultHasID(s) {
|
|
459
|
+
return WebObject.saveResultHasID(s);
|
|
460
|
+
}
|
|
461
|
+
static saveResultHasID(s) {
|
|
462
|
+
if (typeof s !== "object" || s == null || !s)
|
|
463
|
+
return false;
|
|
464
|
+
return (s.insertedId ||
|
|
465
|
+
s._id ||
|
|
466
|
+
(s._index_value && !Number.isNaN(s._index_value)));
|
|
467
|
+
}
|
|
1186
468
|
/**
|
|
1187
469
|
* Load Id and _index_value from the given save result into our object
|
|
1188
470
|
* @param o
|
|
1189
471
|
* @param srObject
|
|
1190
472
|
* @returns
|
|
1191
|
-
*/
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
/* -------------------------------------------------------------------------- */
|
|
473
|
+
*/
|
|
474
|
+
static LoadIdsFromSaveResult(o, srObject) {
|
|
475
|
+
if (typeof o !== "object" || typeof srObject !== "object")
|
|
476
|
+
return;
|
|
477
|
+
/* -------------------------------------------------------------------------- */
|
|
478
|
+
const srID = srObject.insertedId || srObject._id || WebObject.getID(srObject);
|
|
479
|
+
if (srID) {
|
|
480
|
+
o._id = srID;
|
|
481
|
+
}
|
|
482
|
+
/* -------------------------------------------------------------------------- */
|
|
483
|
+
if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
|
|
484
|
+
o._index_value = Number(srObject._index_value);
|
|
485
|
+
}
|
|
486
|
+
/* -------------------------------------------------------------------------- */
|
|
487
|
+
if (srObject._index_key) {
|
|
488
|
+
o._index_key = srObject._index_key;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/* -------------------------------------------------------------------------- */
|
|
1211
492
|
/**
|
|
1212
493
|
* get a single web object
|
|
1213
494
|
* default order of parameters : search,readonly,fetchID
|
|
1214
|
-
*/
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
case
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
_context22.next = 6;
|
|
1239
|
-
break;
|
|
1240
|
-
}
|
|
1241
|
-
return _context22.abrupt("return", undefined);
|
|
1242
|
-
case 6:
|
|
1243
|
-
params = {};
|
|
1244
|
-
params.context = readonly ? "view" : "edit";
|
|
1245
|
-
_context22.t0 = _typeof(search);
|
|
1246
|
-
_context22.next = _context22.t0 === "string" ? 11 : _context22.t0 === "number" ? 11 : _context22.t0 === "object" ? 19 : 19;
|
|
1247
|
-
break;
|
|
1248
|
-
case 11:
|
|
1249
|
-
search = String(search);
|
|
1250
|
-
_context22.t1 = this;
|
|
1251
|
-
_context22.t2 = this;
|
|
1252
|
-
_context22.next = 16;
|
|
1253
|
-
return _global.gfunc.run_action("get", this.__web_path + "/" + search, params, {
|
|
1254
|
-
fetchID: fetchID
|
|
1255
|
-
});
|
|
1256
|
-
case 16:
|
|
1257
|
-
_context22.t3 = _context22.sent;
|
|
1258
|
-
res = _context22.t1.ensure.call(_context22.t1, _context22.t2, _context22.t3);
|
|
1259
|
-
return _context22.abrupt("break", 25);
|
|
1260
|
-
case 19:
|
|
1261
|
-
_context22.t4 = _object.object_first;
|
|
1262
|
-
_context22.next = 22;
|
|
1263
|
-
return this.get_list(search, readonly, fetchID);
|
|
1264
|
-
case 22:
|
|
1265
|
-
_context22.t5 = _context22.sent;
|
|
1266
|
-
res = (0, _context22.t4)(_context22.t5);
|
|
1267
|
-
return _context22.abrupt("break", 25);
|
|
1268
|
-
case 25:
|
|
1269
|
-
WebObject.setReadonly(res, readonly);
|
|
1270
|
-
return _context22.abrupt("return", res);
|
|
1271
|
-
case 27:
|
|
1272
|
-
case "end":
|
|
1273
|
-
return _context22.stop();
|
|
1274
|
-
}
|
|
1275
|
-
}, _callee22, this);
|
|
1276
|
-
}));
|
|
1277
|
-
function get_single() {
|
|
1278
|
-
return _get_single.apply(this, arguments);
|
|
1279
|
-
}
|
|
1280
|
-
return get_single;
|
|
1281
|
-
}()
|
|
495
|
+
*/
|
|
496
|
+
static async get_single(...p) {
|
|
497
|
+
let search = p.shift();
|
|
498
|
+
let readonly = p.shift();
|
|
499
|
+
let fetchID = p.shift();
|
|
500
|
+
if (object_isEmpty(search))
|
|
501
|
+
return undefined;
|
|
502
|
+
let res;
|
|
503
|
+
const params = {};
|
|
504
|
+
params.context = readonly ? "view" : "edit";
|
|
505
|
+
switch (typeof search) {
|
|
506
|
+
case "string":
|
|
507
|
+
case "number":
|
|
508
|
+
search = String(search);
|
|
509
|
+
res = this.ensure(this, await gfunc.run_action("get", this.__web_path + "/" + search, params, { fetchID: fetchID }));
|
|
510
|
+
break;
|
|
511
|
+
case "object":
|
|
512
|
+
default:
|
|
513
|
+
res = object_first(await this.get_list(search, readonly, fetchID));
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
WebObject.setReadonly(res, readonly);
|
|
517
|
+
return res;
|
|
518
|
+
}
|
|
1282
519
|
/**
|
|
1283
520
|
* Get a list of web objects
|
|
1284
521
|
* default order of parameters : search,readonly,fetchID
|
|
1285
|
-
*/
|
|
1286
|
-
)
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
while (1) switch (_context23.prev = _context23.next) {
|
|
1303
|
-
case 0:
|
|
1304
|
-
for (_len11 = _args23.length, p = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
|
|
1305
|
-
p[_key11] = _args23[_key11];
|
|
1306
|
-
}
|
|
1307
|
-
search = p.shift();
|
|
1308
|
-
readonly = p.shift();
|
|
1309
|
-
fetchID = p.shift();
|
|
1310
|
-
if (!search) search = {};
|
|
1311
|
-
_context23.next = 7;
|
|
1312
|
-
return _WebObjectPathHelper["default"].get_path(this, "get");
|
|
1313
|
-
case 7:
|
|
1314
|
-
usepath = _context23.sent;
|
|
1315
|
-
_context23.next = 10;
|
|
1316
|
-
return _global.gfunc.run_action("get", usepath, search, {
|
|
1317
|
-
fetchID: fetchID
|
|
1318
|
-
});
|
|
1319
|
-
case 10:
|
|
1320
|
-
result_items = _context23.sent;
|
|
1321
|
-
// const selftype = (this.constructor ||
|
|
1322
|
-
// Object.getPrototypeOf(this)) as any;
|
|
1323
|
-
res = WebObject.map_rowindex(WebObject.mapto(this, result_items, readonly));
|
|
1324
|
-
WebObject.setReadonly(res, readonly);
|
|
1325
|
-
return _context23.abrupt("return", res);
|
|
1326
|
-
case 14:
|
|
1327
|
-
case "end":
|
|
1328
|
-
return _context23.stop();
|
|
1329
|
-
}
|
|
1330
|
-
}, _callee23, this);
|
|
1331
|
-
}));
|
|
1332
|
-
function get_list() {
|
|
1333
|
-
return _get_list.apply(this, arguments);
|
|
1334
|
-
}
|
|
1335
|
-
return get_list;
|
|
1336
|
-
}())
|
|
1337
|
-
}]);
|
|
1338
|
-
}(_index3.SimpleObject);
|
|
1339
|
-
_defineProperty(WebObject, "__web_path", "");
|
|
1340
|
-
_defineProperty(WebObject, "__protectedProperties", ["_users"]);
|
|
1341
|
-
//you cant create a new weboject without these properties
|
|
1342
|
-
_defineProperty(WebObject, "__requiredProperties", []);
|
|
1343
|
-
var _default = exports["default"] = WebObject;
|
|
522
|
+
*/
|
|
523
|
+
static async get_list(...p) {
|
|
524
|
+
let search = p.shift();
|
|
525
|
+
let readonly = p.shift();
|
|
526
|
+
let fetchID = p.shift();
|
|
527
|
+
if (!search)
|
|
528
|
+
search = {};
|
|
529
|
+
const usepath = await WebObjectPathHelper.get_path(this, "get");
|
|
530
|
+
let result_items = await gfunc.run_action("get", usepath, search, { fetchID: fetchID });
|
|
531
|
+
// const selftype = (this.constructor ||
|
|
532
|
+
// Object.getPrototypeOf(this)) as any;
|
|
533
|
+
const res = WebObject.map_rowindex(WebObject.mapto(this, result_items, readonly));
|
|
534
|
+
WebObject.setReadonly(res, readonly);
|
|
535
|
+
return res;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
export default WebObject;
|