@azrico/webobject 1.4.128 → 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 +3 -4
- package/dist/src/structs/SimpleObject.js +889 -1399
- package/package.json +4 -4
|
@@ -1,1067 +1,487 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
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); } }
|
|
24
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
25
|
-
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); }
|
|
26
|
-
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
27
|
-
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); }
|
|
28
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
29
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
30
|
-
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); }
|
|
31
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
32
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
33
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
34
|
-
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; }
|
|
35
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
36
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
37
|
-
var WebObject = /*#__PURE__*/function (_SimpleObject, _setMetaValue, _Save, _Delete, _Archive, _UnArchive, _get_deltaObject, _onDelete, _onArchive, _onUnArchive, _onLoad, _onSave, _onAfterSave, _onNew, _saveList, _get_single, _get_list) {
|
|
38
|
-
_inherits(WebObject, _SimpleObject);
|
|
39
|
-
var _super = _createSuper(WebObject);
|
|
40
|
-
function WebObject() {
|
|
41
|
-
var _this;
|
|
42
|
-
var is_readonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
43
|
-
_classCallCheck(this, WebObject);
|
|
44
|
-
_this = _super.call(this, is_readonly);
|
|
45
|
-
_defineProperty(_assertThisInitialized(_this), "meta_data", void 0);
|
|
46
|
-
_defineProperty(_assertThisInitialized(_this), "_id", "");
|
|
47
|
-
_defineProperty(_assertThisInitialized(_this), "_created_date", void 0);
|
|
48
|
-
//the owner of the object
|
|
49
|
-
_defineProperty(_assertThisInitialized(_this), "_creator", void 0);
|
|
50
|
-
//multiple users can work on one object
|
|
51
|
-
_defineProperty(_assertThisInitialized(_this), "_users", void 0);
|
|
52
|
-
_this.meta_data = {};
|
|
53
|
-
return _this;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* get a list of all user ids that work on the given object
|
|
57
|
-
* _creator + _users + attentions(old)
|
|
58
|
-
* removes duplicates
|
|
59
|
-
* @returns array of ids
|
|
60
|
-
*/
|
|
61
|
-
_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
|
+
export class WebObject extends SimpleObject {
|
|
7
|
+
static __web_path = "";
|
|
8
|
+
static __web_type = "";
|
|
9
|
+
static __protectedProperties = ["_users"];
|
|
10
|
+
//you cant create a new weboject without these properties
|
|
11
|
+
static __requiredProperties = [];
|
|
12
|
+
meta_data;
|
|
13
|
+
_id = "";
|
|
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
|
-
}))).apply(this, arguments);
|
|
146
|
-
}
|
|
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
|
+
}
|
|
147
78
|
/**
|
|
148
79
|
* Get meta value by key
|
|
149
80
|
* @param key
|
|
150
81
|
* @returns value or undefined
|
|
151
|
-
*/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return WebObject.getMetaValue(this, key);
|
|
156
|
-
}
|
|
82
|
+
*/
|
|
83
|
+
getMetaValue(key) {
|
|
84
|
+
return WebObject.getMetaValue(this, key);
|
|
85
|
+
}
|
|
157
86
|
/**
|
|
158
87
|
* Get meta value by key
|
|
159
88
|
* @param o
|
|
160
89
|
* @param key
|
|
161
90
|
* @returns value or undefined
|
|
162
|
-
*/
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
value: function canSave(deltaObj) {
|
|
313
|
-
var deltaRes = this.deltaIsValid(deltaObj);
|
|
314
|
-
if (deltaRes !== true) return deltaRes;
|
|
315
|
-
return true;
|
|
316
|
-
}
|
|
317
|
-
}, {
|
|
318
|
-
key: "canDelete",
|
|
319
|
-
value: function canDelete() {
|
|
320
|
-
return true;
|
|
321
|
-
}
|
|
322
|
-
}, {
|
|
323
|
-
key: "canArchive",
|
|
324
|
-
value: function canArchive() {
|
|
325
|
-
return true;
|
|
326
|
-
}
|
|
327
|
-
}, {
|
|
328
|
-
key: "deltaIsValid",
|
|
329
|
-
value: function deltaIsValid(d) {
|
|
330
|
-
return true;
|
|
331
|
-
}
|
|
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_webname();
|
|
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
|
+
const deltaObject = await this.get_deltaObject();
|
|
173
|
+
const putAction = "post";
|
|
174
|
+
const putAddress = this.isNew
|
|
175
|
+
? `${this.__web_path}`
|
|
176
|
+
: `${this.__web_path}/${this.getID()}`;
|
|
177
|
+
//save
|
|
178
|
+
if (!object_isEmpty(deltaObject)) {
|
|
179
|
+
const canSaveResult = this.canSave(deltaObject);
|
|
180
|
+
if (canSaveResult !== true) {
|
|
181
|
+
WebObject.addError(this, "Save not allowed", String(canSaveResult), true);
|
|
182
|
+
this.setSaveResult(false, "canceled");
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
const resultObject = await gfunc.run_action(putAction, putAddress, deltaObject);
|
|
186
|
+
this.setSaveResult(resultObject, "auto");
|
|
187
|
+
if (!this.__saveResultIsSuccess) {
|
|
188
|
+
console.error("bad save result : ", resultObject);
|
|
189
|
+
WebObject.addError(this, "Save result is not valid", "the response from server was not a valid saveresult object !", true);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
/* nothing to save */
|
|
194
|
+
this.setSaveResult(null, "nothing");
|
|
195
|
+
}
|
|
196
|
+
if (this.isSaved) {
|
|
197
|
+
await this.onSave();
|
|
198
|
+
return this.getSaveResult();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async Delete() {
|
|
202
|
+
if (this.isNew)
|
|
203
|
+
return;
|
|
204
|
+
const resultObject = await gfunc.run_action("delete", `${this.__web_path}/${this.getID()}`);
|
|
205
|
+
this.setSaveResult(resultObject, "auto", true);
|
|
206
|
+
await this.onDelete();
|
|
207
|
+
return resultObject;
|
|
208
|
+
}
|
|
209
|
+
async Archive() {
|
|
210
|
+
if (this.isNew || this.isArchived)
|
|
211
|
+
return;
|
|
212
|
+
const resultObject = await gfunc.run_action("post", `${this.get_webname()}/${this.getID()}/archive`);
|
|
213
|
+
this.setSaveResult(resultObject, "auto", true);
|
|
214
|
+
await this.onArchive();
|
|
215
|
+
return resultObject;
|
|
216
|
+
}
|
|
217
|
+
async UnArchive() {
|
|
218
|
+
if (this.isNew || !this.isArchived)
|
|
219
|
+
return;
|
|
220
|
+
const resultObject = await gfunc.run_action("post", `${this.get_webname()}/${this.getID()}/unarchive`);
|
|
221
|
+
this.setSaveResult(resultObject, "auto", true);
|
|
222
|
+
await this.onUnArchive();
|
|
223
|
+
return resultObject;
|
|
224
|
+
}
|
|
225
|
+
/* -------------------------------------------------------------------------- */
|
|
226
|
+
canSave(deltaObj) {
|
|
227
|
+
const deltaRes = this.deltaIsValid(deltaObj);
|
|
228
|
+
if (deltaRes !== true)
|
|
229
|
+
return deltaRes;
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
canDelete() {
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
canArchive() {
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
deltaIsValid(d) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
332
241
|
/**
|
|
333
242
|
* You will post this to the server for saving
|
|
334
243
|
* automatically removes unchangable fields
|
|
335
244
|
* @returns
|
|
336
|
-
*/
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
key: "__web_type",
|
|
512
|
-
get: function get() {
|
|
513
|
-
return this.constructor["__web_type"] || this.constructor["__web_path"];
|
|
514
|
-
}
|
|
515
|
-
}, {
|
|
516
|
-
key: "manager",
|
|
517
|
-
get: function get() {
|
|
518
|
-
return this.get_managerClass() || undefined;
|
|
519
|
-
}
|
|
520
|
-
}, {
|
|
521
|
-
key: "get_webname",
|
|
522
|
-
value: function get_webname() {
|
|
523
|
-
return this.__web_path || this.__web_type || this.__cache_name || "";
|
|
524
|
-
}
|
|
525
|
-
}, {
|
|
526
|
-
key: "onDelete",
|
|
527
|
-
value: /* -------------------------------------------------------------------------- */function onDelete() {
|
|
528
|
-
return (_onDelete = _onDelete || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
529
|
-
var _this$manager;
|
|
530
|
-
var _len,
|
|
531
|
-
p,
|
|
532
|
-
_key,
|
|
533
|
-
_args9 = arguments;
|
|
534
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
535
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
536
|
-
case 0:
|
|
537
|
-
if (this.isSaved) this.isDeleted = true;
|
|
538
|
-
for (_len = _args9.length, p = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
539
|
-
p[_key] = _args9[_key];
|
|
540
|
-
}
|
|
541
|
-
_context9.next = 4;
|
|
542
|
-
return (_this$manager = this.manager) === null || _this$manager === void 0 ? void 0 : _this$manager.onDelete.apply(_this$manager, p);
|
|
543
|
-
case 4:
|
|
544
|
-
return _context9.abrupt("return", _context9.sent);
|
|
545
|
-
case 5:
|
|
546
|
-
case "end":
|
|
547
|
-
return _context9.stop();
|
|
548
|
-
}
|
|
549
|
-
}, _callee9, this);
|
|
550
|
-
}))).apply(this, arguments);
|
|
551
|
-
}
|
|
552
|
-
}, {
|
|
553
|
-
key: "onArchive",
|
|
554
|
-
value: function onArchive() {
|
|
555
|
-
return (_onArchive = _onArchive || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
556
|
-
var _this$manager2;
|
|
557
|
-
var _len2,
|
|
558
|
-
p,
|
|
559
|
-
_key2,
|
|
560
|
-
_args10 = arguments;
|
|
561
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
562
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
563
|
-
case 0:
|
|
564
|
-
if (this.isSaved) this.isArchived = true;
|
|
565
|
-
for (_len2 = _args10.length, p = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
566
|
-
p[_key2] = _args10[_key2];
|
|
567
|
-
}
|
|
568
|
-
_context10.next = 4;
|
|
569
|
-
return (_this$manager2 = this.manager) === null || _this$manager2 === void 0 ? void 0 : _this$manager2.onArchive.apply(_this$manager2, p);
|
|
570
|
-
case 4:
|
|
571
|
-
return _context10.abrupt("return", _context10.sent);
|
|
572
|
-
case 5:
|
|
573
|
-
case "end":
|
|
574
|
-
return _context10.stop();
|
|
575
|
-
}
|
|
576
|
-
}, _callee10, this);
|
|
577
|
-
}))).apply(this, arguments);
|
|
578
|
-
}
|
|
579
|
-
}, {
|
|
580
|
-
key: "onUnArchive",
|
|
581
|
-
value: function onUnArchive() {
|
|
582
|
-
return (_onUnArchive = _onUnArchive || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
583
|
-
var _this$manager3;
|
|
584
|
-
var _len3,
|
|
585
|
-
p,
|
|
586
|
-
_key3,
|
|
587
|
-
_args11 = arguments;
|
|
588
|
-
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
589
|
-
while (1) switch (_context11.prev = _context11.next) {
|
|
590
|
-
case 0:
|
|
591
|
-
if (this.isSaved) this.isArchived = false;
|
|
592
|
-
for (_len3 = _args11.length, p = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
593
|
-
p[_key3] = _args11[_key3];
|
|
594
|
-
}
|
|
595
|
-
_context11.next = 4;
|
|
596
|
-
return (_this$manager3 = this.manager) === null || _this$manager3 === void 0 ? void 0 : _this$manager3.onUnArchive.apply(_this$manager3, p);
|
|
597
|
-
case 4:
|
|
598
|
-
return _context11.abrupt("return", _context11.sent);
|
|
599
|
-
case 5:
|
|
600
|
-
case "end":
|
|
601
|
-
return _context11.stop();
|
|
602
|
-
}
|
|
603
|
-
}, _callee11, this);
|
|
604
|
-
}))).apply(this, arguments);
|
|
605
|
-
}
|
|
606
|
-
}, {
|
|
607
|
-
key: "onLoad",
|
|
608
|
-
value: function onLoad() {
|
|
609
|
-
return (_onLoad = _onLoad || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
610
|
-
var _this$manager4;
|
|
611
|
-
var _len4,
|
|
612
|
-
p,
|
|
613
|
-
_key4,
|
|
614
|
-
_args12 = arguments;
|
|
615
|
-
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
616
|
-
while (1) switch (_context12.prev = _context12.next) {
|
|
617
|
-
case 0:
|
|
618
|
-
this.isDeleted = false;
|
|
619
|
-
for (_len4 = _args12.length, p = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
620
|
-
p[_key4] = _args12[_key4];
|
|
621
|
-
}
|
|
622
|
-
_context12.next = 4;
|
|
623
|
-
return (_this$manager4 = this.manager) === null || _this$manager4 === void 0 ? void 0 : _this$manager4.onLoad.apply(_this$manager4, p);
|
|
624
|
-
case 4:
|
|
625
|
-
return _context12.abrupt("return", _context12.sent);
|
|
626
|
-
case 5:
|
|
627
|
-
case "end":
|
|
628
|
-
return _context12.stop();
|
|
629
|
-
}
|
|
630
|
-
}, _callee12, this);
|
|
631
|
-
}))).apply(this, arguments);
|
|
632
|
-
}
|
|
633
|
-
}, {
|
|
634
|
-
key: "onSave",
|
|
635
|
-
value: function onSave() {
|
|
636
|
-
return (_onSave = _onSave || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
637
|
-
var _this$manager6;
|
|
638
|
-
var srObject,
|
|
639
|
-
_this$manager5,
|
|
640
|
-
_len5,
|
|
641
|
-
p,
|
|
642
|
-
_key5,
|
|
643
|
-
_args13 = arguments;
|
|
644
|
-
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
645
|
-
while (1) switch (_context13.prev = _context13.next) {
|
|
646
|
-
case 0:
|
|
647
|
-
if (!this.isSaved) {
|
|
648
|
-
_context13.next = 7;
|
|
649
|
-
break;
|
|
650
|
-
}
|
|
651
|
-
this.apply_changes();
|
|
652
|
-
srObject = this.getSaveResult(true);
|
|
653
|
-
if (!this.saveResultHasID(srObject)) {
|
|
654
|
-
_context13.next = 7;
|
|
655
|
-
break;
|
|
656
|
-
}
|
|
657
|
-
/* -------------------------------------------------------------------------- */
|
|
658
|
-
WebObject.LoadIdsFromSaveResult(this, srObject);
|
|
659
|
-
_context13.next = 7;
|
|
660
|
-
return (_this$manager5 = this.manager) === null || _this$manager5 === void 0 ? void 0 : _this$manager5.event_run("on_id_change");
|
|
661
|
-
case 7:
|
|
662
|
-
for (_len5 = _args13.length, p = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
663
|
-
p[_key5] = _args13[_key5];
|
|
664
|
-
}
|
|
665
|
-
_context13.next = 10;
|
|
666
|
-
return (_this$manager6 = this.manager) === null || _this$manager6 === void 0 ? void 0 : _this$manager6.onSave.apply(_this$manager6, p);
|
|
667
|
-
case 10:
|
|
668
|
-
_context13.next = 12;
|
|
669
|
-
return this.onAfterSave();
|
|
670
|
-
case 12:
|
|
671
|
-
return _context13.abrupt("return", true);
|
|
672
|
-
case 13:
|
|
673
|
-
case "end":
|
|
674
|
-
return _context13.stop();
|
|
675
|
-
}
|
|
676
|
-
}, _callee13, this);
|
|
677
|
-
}))).apply(this, arguments);
|
|
678
|
-
}
|
|
679
|
-
}, {
|
|
680
|
-
key: "onAfterSave",
|
|
681
|
-
value: function onAfterSave() {
|
|
682
|
-
return (_onAfterSave = _onAfterSave || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
683
|
-
var _this$manager7;
|
|
684
|
-
var _len6,
|
|
685
|
-
p,
|
|
686
|
-
_key6,
|
|
687
|
-
_args14 = arguments;
|
|
688
|
-
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
689
|
-
while (1) switch (_context14.prev = _context14.next) {
|
|
690
|
-
case 0:
|
|
691
|
-
for (_len6 = _args14.length, p = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
692
|
-
p[_key6] = _args14[_key6];
|
|
693
|
-
}
|
|
694
|
-
_context14.next = 3;
|
|
695
|
-
return (_this$manager7 = this.manager) === null || _this$manager7 === void 0 ? void 0 : _this$manager7.onAfterSave.apply(_this$manager7, p);
|
|
696
|
-
case 3:
|
|
697
|
-
return _context14.abrupt("return", true);
|
|
698
|
-
case 4:
|
|
699
|
-
case "end":
|
|
700
|
-
return _context14.stop();
|
|
701
|
-
}
|
|
702
|
-
}, _callee14, this);
|
|
703
|
-
}))).apply(this, arguments);
|
|
704
|
-
}
|
|
705
|
-
}, {
|
|
706
|
-
key: "getSaveResult",
|
|
707
|
-
value: function getSaveResult() {
|
|
708
|
-
var _this3 = this;
|
|
709
|
-
var original = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
710
|
-
var srObject = _get(_getPrototypeOf(WebObject.prototype), "getSaveResult", this).call(this, original);
|
|
711
|
-
if (!srObject) return false;
|
|
712
|
-
if (Array.isArray(srObject)) {
|
|
713
|
-
var actual_sr = srObject.find(function (s) {
|
|
714
|
-
return _this3.saveResultHasID(s);
|
|
715
|
-
});
|
|
716
|
-
if (actual_sr) srObject = actual_sr;
|
|
717
|
-
}
|
|
718
|
-
return srObject;
|
|
719
|
-
}
|
|
720
|
-
}, {
|
|
721
|
-
key: "onNew",
|
|
722
|
-
value: function onNew() {
|
|
723
|
-
return (_onNew = _onNew || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
724
|
-
var _this$manager8;
|
|
725
|
-
var _len7,
|
|
726
|
-
p,
|
|
727
|
-
_key7,
|
|
728
|
-
_args15 = arguments;
|
|
729
|
-
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
730
|
-
while (1) switch (_context15.prev = _context15.next) {
|
|
731
|
-
case 0:
|
|
732
|
-
for (_len7 = _args15.length, p = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
733
|
-
p[_key7] = _args15[_key7];
|
|
734
|
-
}
|
|
735
|
-
_context15.next = 3;
|
|
736
|
-
return (_this$manager8 = this.manager) === null || _this$manager8 === void 0 ? void 0 : _this$manager8.onNew.apply(_this$manager8, p);
|
|
737
|
-
case 3:
|
|
738
|
-
return _context15.abrupt("return", _context15.sent);
|
|
739
|
-
case 4:
|
|
740
|
-
case "end":
|
|
741
|
-
return _context15.stop();
|
|
742
|
-
}
|
|
743
|
-
}, _callee15, this);
|
|
744
|
-
}))).apply(this, arguments);
|
|
745
|
-
} /* -------------------------------------------------------------------------- */
|
|
746
|
-
}, {
|
|
747
|
-
key: "saveResultHasID",
|
|
748
|
-
value: function saveResultHasID(s) {
|
|
749
|
-
return WebObject.saveResultHasID(s);
|
|
750
|
-
}
|
|
751
|
-
}], [{
|
|
752
|
-
key: "getAllUsers",
|
|
753
|
-
value: function getAllUsers(obj) {
|
|
754
|
-
if (_typeof(obj) != "object") return [];
|
|
755
|
-
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) {
|
|
756
|
-
return String(_typeof(r) === "object" ? WebObject.getID(r) : r);
|
|
757
|
-
}).filter(function (s) {
|
|
758
|
-
return s;
|
|
759
|
-
}));
|
|
760
|
-
}
|
|
761
|
-
}, {
|
|
762
|
-
key: "getMetaValue",
|
|
763
|
-
value: function getMetaValue(o, key) {
|
|
764
|
-
if (o == null) return null;
|
|
765
|
-
if (!key || typeof key != "string") return undefined;
|
|
766
|
-
var metalist = {};
|
|
767
|
-
if (_typeof(o) === "object") {
|
|
768
|
-
metalist = typeof o.getValue === "function" ? o.getValue("meta_data") : o.meta_data;
|
|
769
|
-
}
|
|
770
|
-
return metalist[key];
|
|
771
|
-
}
|
|
772
|
-
/* -------------------------------------------------------------------------- */
|
|
773
|
-
/* Save */
|
|
774
|
-
/* -------------------------------------------------------------------------- */
|
|
775
|
-
}, {
|
|
776
|
-
key: "zipSaveList",
|
|
777
|
-
value: function zipSaveList(svlist) {
|
|
778
|
-
if (_typeof(svlist) === "object") svlist = JSON.stringify(svlist);
|
|
779
|
-
return (0, _string.string_compress)(svlist);
|
|
780
|
-
}
|
|
781
|
-
}, {
|
|
782
|
-
key: "unzipSaveList",
|
|
783
|
-
value: function unzipSaveList(svlist) {
|
|
784
|
-
try {
|
|
785
|
-
if (_typeof(svlist) === "object") {
|
|
786
|
-
if (Array.isArray(svlist)) return svlist;
|
|
787
|
-
if (svlist.__save_list) return this.unzipSaveList(svlist.__save_list);
|
|
788
|
-
} else if (typeof svlist === "string") return (0, _object.wrap_array)(JSON.parse((0, _string.string_decompress)(svlist)));
|
|
789
|
-
} catch (_unused) {}
|
|
790
|
-
return (0, _object.wrap_array)(svlist);
|
|
791
|
-
}
|
|
792
|
-
}, {
|
|
793
|
-
key: "saveList",
|
|
794
|
-
value: function saveList(_x6) {
|
|
795
|
-
return (_saveList = _saveList || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(itemList) {
|
|
796
|
-
var _extraOptions$chunksi;
|
|
797
|
-
var extraOptions,
|
|
798
|
-
chunks,
|
|
799
|
-
putAddress,
|
|
800
|
-
index,
|
|
801
|
-
items_to_save,
|
|
802
|
-
save_array,
|
|
803
|
-
k,
|
|
804
|
-
item,
|
|
805
|
-
dlt,
|
|
806
|
-
resultObject,
|
|
807
|
-
_index,
|
|
808
|
-
res,
|
|
809
|
-
_item,
|
|
810
|
-
_index2,
|
|
811
|
-
_item2,
|
|
812
|
-
_args16 = arguments;
|
|
813
|
-
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
814
|
-
while (1) switch (_context16.prev = _context16.next) {
|
|
815
|
-
case 0:
|
|
816
|
-
extraOptions = _args16.length > 1 && _args16[1] !== undefined ? _args16[1] : {};
|
|
817
|
-
if (!extraOptions) extraOptions = {};
|
|
818
|
-
chunks = (0, _object.array_chunks)(itemList, (_extraOptions$chunksi = extraOptions.chunksize) !== null && _extraOptions$chunksi !== void 0 ? _extraOptions$chunksi : 50);
|
|
819
|
-
delete extraOptions.chunksize;
|
|
820
|
-
putAddress = this.get_webname();
|
|
821
|
-
index = 0;
|
|
822
|
-
case 6:
|
|
823
|
-
if (!(index < chunks.length)) {
|
|
824
|
-
_context16.next = 36;
|
|
825
|
-
break;
|
|
826
|
-
}
|
|
827
|
-
items_to_save = chunks[index];
|
|
828
|
-
save_array = [];
|
|
829
|
-
k = 0;
|
|
830
|
-
case 10:
|
|
831
|
-
if (!(k < items_to_save.length)) {
|
|
832
|
-
_context16.next = 19;
|
|
833
|
-
break;
|
|
834
|
-
}
|
|
835
|
-
item = items_to_save[k];
|
|
836
|
-
_context16.next = 14;
|
|
837
|
-
return item.get_deltaObject();
|
|
838
|
-
case 14:
|
|
839
|
-
dlt = _context16.sent;
|
|
840
|
-
save_array.push(item.isNew ? _objectSpread({}, dlt) : _objectSpread({
|
|
841
|
-
_id: item.getID()
|
|
842
|
-
}, dlt));
|
|
843
|
-
case 16:
|
|
844
|
-
k++;
|
|
845
|
-
_context16.next = 10;
|
|
846
|
-
break;
|
|
847
|
-
case 19:
|
|
848
|
-
_context16.next = 21;
|
|
849
|
-
return _global.gfunc.run_action("post", putAddress, _objectSpread({
|
|
850
|
-
__save_list: WebObject.zipSaveList(save_array)
|
|
851
|
-
}, extraOptions));
|
|
852
|
-
case 21:
|
|
853
|
-
resultObject = _context16.sent;
|
|
854
|
-
if (!Array.isArray(resultObject)) {
|
|
855
|
-
_context16.next = 33;
|
|
856
|
-
break;
|
|
857
|
-
}
|
|
858
|
-
_index = 0;
|
|
859
|
-
case 24:
|
|
860
|
-
if (!(_index < Math.min(resultObject.length, items_to_save.length))) {
|
|
861
|
-
_context16.next = 33;
|
|
862
|
-
break;
|
|
863
|
-
}
|
|
864
|
-
res = resultObject[_index];
|
|
865
|
-
_item = items_to_save[_index];
|
|
866
|
-
_item.setSaveResult(res);
|
|
867
|
-
_context16.next = 30;
|
|
868
|
-
return _item.onSave();
|
|
869
|
-
case 30:
|
|
870
|
-
_index++;
|
|
871
|
-
_context16.next = 24;
|
|
872
|
-
break;
|
|
873
|
-
case 33:
|
|
874
|
-
index++;
|
|
875
|
-
_context16.next = 6;
|
|
876
|
-
break;
|
|
877
|
-
case 36:
|
|
878
|
-
_index2 = 0;
|
|
879
|
-
case 37:
|
|
880
|
-
if (!(_index2 < itemList.length)) {
|
|
881
|
-
_context16.next = 46;
|
|
882
|
-
break;
|
|
883
|
-
}
|
|
884
|
-
_item2 = itemList[_index2];
|
|
885
|
-
if (_item2.isSaved) {
|
|
886
|
-
_context16.next = 41;
|
|
887
|
-
break;
|
|
888
|
-
}
|
|
889
|
-
return _context16.abrupt("return", false);
|
|
890
|
-
case 41:
|
|
891
|
-
if (!(_item2.getSaveResultType() != "normal")) {
|
|
892
|
-
_context16.next = 43;
|
|
893
|
-
break;
|
|
894
|
-
}
|
|
895
|
-
return _context16.abrupt("return", false);
|
|
896
|
-
case 43:
|
|
897
|
-
_index2++;
|
|
898
|
-
_context16.next = 37;
|
|
899
|
-
break;
|
|
900
|
-
case 46:
|
|
901
|
-
return _context16.abrupt("return", true);
|
|
902
|
-
case 47:
|
|
903
|
-
case "end":
|
|
904
|
-
return _context16.stop();
|
|
905
|
-
}
|
|
906
|
-
}, _callee16, this);
|
|
907
|
-
}))).apply(this, arguments);
|
|
908
|
-
}
|
|
909
|
-
}, {
|
|
910
|
-
key: "get_webname",
|
|
911
|
-
value: function get_webname() {
|
|
912
|
-
return this.__web_path || this.__web_type || this.__cache_name || "";
|
|
913
|
-
}
|
|
914
|
-
}, {
|
|
915
|
-
key: "saveResultHasID",
|
|
916
|
-
value: function saveResultHasID(s) {
|
|
917
|
-
if (_typeof(s) !== "object" || s == null || !s) return false;
|
|
918
|
-
return s.insertedId || s._id || s._index_value && !Number.isNaN(s._index_value);
|
|
919
|
-
}
|
|
245
|
+
*/
|
|
246
|
+
async get_deltaObject(p) {
|
|
247
|
+
if (!p)
|
|
248
|
+
p = {};
|
|
249
|
+
const final_object = {};
|
|
250
|
+
//@ts-ignore
|
|
251
|
+
const isChild = Boolean(p.isChild || p.ischild);
|
|
252
|
+
//@ts-ignore
|
|
253
|
+
const useDelta = this.__use_delta || Boolean(p.useDelta || p.usedelta);
|
|
254
|
+
//@ts-ignore
|
|
255
|
+
const allProperties = Boolean(p.allProperties || p.allproperties);
|
|
256
|
+
//@ts-ignore
|
|
257
|
+
const needId = Boolean(p.needId || p.needid);
|
|
258
|
+
const chkChangables = this.__changeables != null || this.__unchangeables != null;
|
|
259
|
+
const useExtraProps = Boolean(p.extraProperties);
|
|
260
|
+
//child objects usually dont update their __delta, so we read info from all of its properties
|
|
261
|
+
const dlt = allProperties || (!useDelta && isChild && chkChangables)
|
|
262
|
+
? { ...this.allproperties }
|
|
263
|
+
: { ...this.__delta };
|
|
264
|
+
const allkeys = Object.keys(dlt);
|
|
265
|
+
const changableKeys = chkChangables
|
|
266
|
+
? allkeys.filter((s) => SimpleObject.canChangeKey(this, s, {
|
|
267
|
+
useExtraProps: useExtraProps,
|
|
268
|
+
ignoreProtected: allProperties,
|
|
269
|
+
}))
|
|
270
|
+
: allkeys;
|
|
271
|
+
await FormatHelper.applyFormats({
|
|
272
|
+
inputobject: dlt,
|
|
273
|
+
formats: object_getStatic(this, "__formatList"),
|
|
274
|
+
changableKeys: changableKeys,
|
|
275
|
+
});
|
|
276
|
+
/* -------------------------------------------------------------------------- */
|
|
277
|
+
/* __functionProperties */
|
|
278
|
+
/* -------------------------------------------------------------------------- */
|
|
279
|
+
const functionProps = object_getStatic(this, "__functionProperties");
|
|
280
|
+
if (Array.isArray(functionProps)) {
|
|
281
|
+
for (let index = 0; index < functionProps.length; index++) {
|
|
282
|
+
const fp = functionProps[index];
|
|
283
|
+
if (dlt[fp])
|
|
284
|
+
dlt[fp] = fn_eval_this(this, dlt[fp]);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/* -------------------------------------------------------------------------- */
|
|
288
|
+
/* parse all changableKeys */
|
|
289
|
+
/* -------------------------------------------------------------------------- */
|
|
290
|
+
async function parseObj(obj) {
|
|
291
|
+
if (obj == null)
|
|
292
|
+
return undefined;
|
|
293
|
+
if (Array.isArray(obj))
|
|
294
|
+
return await Promise.all(obj.map(async (r) => await parseObj(r)));
|
|
295
|
+
if (obj instanceof WebObject &&
|
|
296
|
+
typeof obj.get_deltaObject === "function") {
|
|
297
|
+
//child elements have different kind of delta
|
|
298
|
+
const newobj_dlt = await obj.get_deltaObject({
|
|
299
|
+
...p,
|
|
300
|
+
isChild: true,
|
|
301
|
+
});
|
|
302
|
+
if (!object_isEmpty(newobj_dlt))
|
|
303
|
+
return newobj_dlt;
|
|
304
|
+
else
|
|
305
|
+
return obj;
|
|
306
|
+
}
|
|
307
|
+
return obj;
|
|
308
|
+
}
|
|
309
|
+
for (const key of changableKeys) {
|
|
310
|
+
final_object[key] = await parseObj(dlt[key]);
|
|
311
|
+
}
|
|
312
|
+
/* -------------------------------------------------------------------------- */
|
|
313
|
+
/* add id properties */
|
|
314
|
+
/* -------------------------------------------------------------------------- */
|
|
315
|
+
if (allProperties) {
|
|
316
|
+
final_object["_created_date"] = this["_created_date"];
|
|
317
|
+
final_object["_archived"] = this.isArchived;
|
|
318
|
+
final_object["_deleted"] = this.isDeleted;
|
|
319
|
+
}
|
|
320
|
+
if (allProperties || needId) {
|
|
321
|
+
if (this["_index_key"])
|
|
322
|
+
final_object["_index_key"] = this["_index_key"];
|
|
323
|
+
if (this.getIndex())
|
|
324
|
+
final_object["_index_value"] = this.getIndex();
|
|
325
|
+
if (this.getID())
|
|
326
|
+
final_object["_id"] = this.getID();
|
|
327
|
+
}
|
|
328
|
+
/* -------------------------------------------------------------------------- */
|
|
329
|
+
/* fix _user property */
|
|
330
|
+
/* -------------------------------------------------------------------------- */
|
|
331
|
+
if (final_object["_users"]) {
|
|
332
|
+
let tempusers = final_object["_users"];
|
|
333
|
+
if (typeof tempusers === "string")
|
|
334
|
+
tempusers = tempusers.split(",").filter((s) => s);
|
|
335
|
+
final_object["_users"] = wrap_array(tempusers);
|
|
336
|
+
}
|
|
337
|
+
return final_object;
|
|
338
|
+
}
|
|
339
|
+
/* --------------------------------- Getters -------------------------------- */
|
|
340
|
+
get __web_path() {
|
|
341
|
+
return this.constructor["__web_path"] || this.constructor["__web_type"];
|
|
342
|
+
}
|
|
343
|
+
get __web_type() {
|
|
344
|
+
return this.constructor["__web_type"] || this.constructor["__web_path"];
|
|
345
|
+
}
|
|
346
|
+
get manager() {
|
|
347
|
+
return this.get_managerClass() || undefined;
|
|
348
|
+
}
|
|
349
|
+
get_webname() {
|
|
350
|
+
return this.__web_path || this.__web_type || this.__cache_name || "";
|
|
351
|
+
}
|
|
352
|
+
static get_webname() {
|
|
353
|
+
return this.__web_path || this.__web_type || this.__cache_name || "";
|
|
354
|
+
}
|
|
355
|
+
/* -------------------------------------------------------------------------- */
|
|
356
|
+
async onDelete(...p) {
|
|
357
|
+
if (this.isSaved)
|
|
358
|
+
this.isDeleted = true;
|
|
359
|
+
return await this.manager?.onDelete(...p); //events are handled by the manager
|
|
360
|
+
}
|
|
361
|
+
async onArchive(...p) {
|
|
362
|
+
if (this.isSaved)
|
|
363
|
+
this.isArchived = true;
|
|
364
|
+
return await this.manager?.onArchive(...p); //events are handled by the manager
|
|
365
|
+
}
|
|
366
|
+
async onUnArchive(...p) {
|
|
367
|
+
if (this.isSaved)
|
|
368
|
+
this.isArchived = false;
|
|
369
|
+
return await this.manager?.onUnArchive(...p); //events are handled by the manager
|
|
370
|
+
}
|
|
371
|
+
async onLoad(...p) {
|
|
372
|
+
this.isDeleted = false;
|
|
373
|
+
return await this.manager?.onLoad(...p); //events are handled by the manager
|
|
374
|
+
}
|
|
375
|
+
async onSave(...p) {
|
|
376
|
+
if (this.isSaved) {
|
|
377
|
+
this.apply_changes();
|
|
378
|
+
var srObject = this.getSaveResult(true);
|
|
379
|
+
if (this.saveResultHasID(srObject)) {
|
|
380
|
+
/* -------------------------------------------------------------------------- */
|
|
381
|
+
WebObject.LoadIdsFromSaveResult(this, srObject);
|
|
382
|
+
await this.manager?.event_run("on_id_change");
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
await this.manager?.onSave(...p); //events are handled by the manager
|
|
386
|
+
await this.onAfterSave();
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
async onAfterSave(...p) {
|
|
390
|
+
await this.manager?.onAfterSave(...p); //events are handled by the manager
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
getSaveResult(original = false) {
|
|
394
|
+
let srObject = super.getSaveResult(original);
|
|
395
|
+
if (!srObject)
|
|
396
|
+
return false;
|
|
397
|
+
if (Array.isArray(srObject)) {
|
|
398
|
+
const actual_sr = srObject.find((s) => this.saveResultHasID(s));
|
|
399
|
+
if (actual_sr)
|
|
400
|
+
srObject = actual_sr;
|
|
401
|
+
}
|
|
402
|
+
return srObject;
|
|
403
|
+
}
|
|
404
|
+
async onNew(...p) {
|
|
405
|
+
return await this.manager?.onNew(...p); //events are handled by the manager
|
|
406
|
+
}
|
|
407
|
+
/* -------------------------------------------------------------------------- */
|
|
408
|
+
saveResultHasID(s) {
|
|
409
|
+
return WebObject.saveResultHasID(s);
|
|
410
|
+
}
|
|
411
|
+
static saveResultHasID(s) {
|
|
412
|
+
if (typeof s !== "object" || s == null || !s)
|
|
413
|
+
return false;
|
|
414
|
+
return (s.insertedId ||
|
|
415
|
+
s._id ||
|
|
416
|
+
(s._index_value && !Number.isNaN(s._index_value)));
|
|
417
|
+
}
|
|
920
418
|
/**
|
|
921
419
|
* Load Id and _index_value from the given save result into our object
|
|
922
420
|
* @param o
|
|
923
421
|
* @param srObject
|
|
924
422
|
* @returns
|
|
925
|
-
*/
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
/* -------------------------------------------------------------------------- */
|
|
423
|
+
*/
|
|
424
|
+
static LoadIdsFromSaveResult(o, srObject) {
|
|
425
|
+
if (typeof o !== "object" || typeof srObject !== "object")
|
|
426
|
+
return;
|
|
427
|
+
/* -------------------------------------------------------------------------- */
|
|
428
|
+
const srID = srObject.insertedId || srObject._id || WebObject.getID(srObject);
|
|
429
|
+
if (srID) {
|
|
430
|
+
o._id = srID;
|
|
431
|
+
}
|
|
432
|
+
/* -------------------------------------------------------------------------- */
|
|
433
|
+
if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
|
|
434
|
+
o._index_value = Number(srObject._index_value);
|
|
435
|
+
}
|
|
436
|
+
/* -------------------------------------------------------------------------- */
|
|
437
|
+
if (srObject._index_key) {
|
|
438
|
+
o._index_key = srObject._index_key;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/* -------------------------------------------------------------------------- */
|
|
945
442
|
/**
|
|
946
443
|
* get a single web object
|
|
947
444
|
* default order of parameters : search,readonly,fetchID
|
|
948
|
-
*/
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
case
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
_context17.next = 6;
|
|
973
|
-
break;
|
|
974
|
-
}
|
|
975
|
-
return _context17.abrupt("return", undefined);
|
|
976
|
-
case 6:
|
|
977
|
-
params = {};
|
|
978
|
-
params.context = readonly ? "view" : "edit";
|
|
979
|
-
_context17.t0 = _typeof(search);
|
|
980
|
-
_context17.next = _context17.t0 === "string" ? 11 : _context17.t0 === "number" ? 11 : _context17.t0 === "object" ? 19 : 19;
|
|
981
|
-
break;
|
|
982
|
-
case 11:
|
|
983
|
-
search = String(search);
|
|
984
|
-
_context17.t1 = this;
|
|
985
|
-
_context17.t2 = this;
|
|
986
|
-
_context17.next = 16;
|
|
987
|
-
return _global.gfunc.run_action("get", this.__web_path + "/" + search, params, {
|
|
988
|
-
fetchID: fetchID
|
|
989
|
-
});
|
|
990
|
-
case 16:
|
|
991
|
-
_context17.t3 = _context17.sent;
|
|
992
|
-
res = _context17.t1.ensure.call(_context17.t1, _context17.t2, _context17.t3);
|
|
993
|
-
return _context17.abrupt("break", 25);
|
|
994
|
-
case 19:
|
|
995
|
-
_context17.t4 = _object.object_first;
|
|
996
|
-
_context17.next = 22;
|
|
997
|
-
return this.get_list(search, readonly, fetchID);
|
|
998
|
-
case 22:
|
|
999
|
-
_context17.t5 = _context17.sent;
|
|
1000
|
-
res = (0, _context17.t4)(_context17.t5);
|
|
1001
|
-
return _context17.abrupt("break", 25);
|
|
1002
|
-
case 25:
|
|
1003
|
-
WebObject.setReadonly(res, readonly);
|
|
1004
|
-
return _context17.abrupt("return", res);
|
|
1005
|
-
case 27:
|
|
1006
|
-
case "end":
|
|
1007
|
-
return _context17.stop();
|
|
1008
|
-
}
|
|
1009
|
-
}, _callee17, this);
|
|
1010
|
-
}))).apply(this, arguments);
|
|
1011
|
-
}
|
|
445
|
+
*/
|
|
446
|
+
static async get_single(...p) {
|
|
447
|
+
let search = p.shift();
|
|
448
|
+
let readonly = p.shift();
|
|
449
|
+
let fetchID = p.shift();
|
|
450
|
+
if (object_isEmpty(search))
|
|
451
|
+
return undefined;
|
|
452
|
+
let res;
|
|
453
|
+
const params = {};
|
|
454
|
+
params.context = readonly ? "view" : "edit";
|
|
455
|
+
switch (typeof search) {
|
|
456
|
+
case "string":
|
|
457
|
+
case "number":
|
|
458
|
+
search = String(search);
|
|
459
|
+
res = this.ensure(this, await gfunc.run_action("get", this.__web_path + "/" + search, params, { fetchID: fetchID }));
|
|
460
|
+
break;
|
|
461
|
+
case "object":
|
|
462
|
+
default:
|
|
463
|
+
res = object_first(await this.get_list(search, readonly, fetchID));
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
WebObject.setReadonly(res, readonly);
|
|
467
|
+
return res;
|
|
468
|
+
}
|
|
1012
469
|
/**
|
|
1013
470
|
* Get a list of web objects
|
|
1014
471
|
* default order of parameters : search,readonly,fetchID
|
|
1015
|
-
*/
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
case 0:
|
|
1032
|
-
for (_len9 = _args18.length, p = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
|
|
1033
|
-
p[_key9] = _args18[_key9];
|
|
1034
|
-
}
|
|
1035
|
-
search = p.shift();
|
|
1036
|
-
readonly = p.shift();
|
|
1037
|
-
fetchID = p.shift();
|
|
1038
|
-
if (!search) search = {};
|
|
1039
|
-
_context18.next = 7;
|
|
1040
|
-
return _global.gfunc.run_action("get", this.get_webname(), search, {
|
|
1041
|
-
fetchID: fetchID
|
|
1042
|
-
});
|
|
1043
|
-
case 7:
|
|
1044
|
-
result_items = _context18.sent;
|
|
1045
|
-
// const selftype = (this.constructor ||
|
|
1046
|
-
// Object.getPrototypeOf(this)) as any;
|
|
1047
|
-
res = WebObject.map_rowindex(WebObject.mapto(this, result_items, readonly));
|
|
1048
|
-
WebObject.setReadonly(res, readonly);
|
|
1049
|
-
return _context18.abrupt("return", res);
|
|
1050
|
-
case 11:
|
|
1051
|
-
case "end":
|
|
1052
|
-
return _context18.stop();
|
|
1053
|
-
}
|
|
1054
|
-
}, _callee18, this);
|
|
1055
|
-
}))).apply(this, arguments);
|
|
1056
|
-
}
|
|
1057
|
-
}]);
|
|
1058
|
-
return WebObject;
|
|
1059
|
-
}(_index3.SimpleObject);
|
|
1060
|
-
exports.WebObject = WebObject;
|
|
1061
|
-
_defineProperty(WebObject, "__web_path", "");
|
|
1062
|
-
_defineProperty(WebObject, "__web_type", "");
|
|
1063
|
-
_defineProperty(WebObject, "__protectedProperties", ["_users"]);
|
|
1064
|
-
//you cant create a new weboject without these properties
|
|
1065
|
-
_defineProperty(WebObject, "__requiredProperties", []);
|
|
1066
|
-
var _default = WebObject;
|
|
1067
|
-
exports["default"] = _default;
|
|
472
|
+
*/
|
|
473
|
+
static async get_list(...p) {
|
|
474
|
+
let search = p.shift();
|
|
475
|
+
let readonly = p.shift();
|
|
476
|
+
let fetchID = p.shift();
|
|
477
|
+
if (!search)
|
|
478
|
+
search = {};
|
|
479
|
+
let result_items = await gfunc.run_action("get", this.get_webname(), search, { fetchID: fetchID });
|
|
480
|
+
// const selftype = (this.constructor ||
|
|
481
|
+
// Object.getPrototypeOf(this)) as any;
|
|
482
|
+
const res = WebObject.map_rowindex(WebObject.mapto(this, result_items, readonly));
|
|
483
|
+
WebObject.setReadonly(res, readonly);
|
|
484
|
+
return res;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
export default WebObject;
|