@azrico/webobject 1.3.21 → 1.3.22
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 +20 -51
- package/dist/src/WebObjects/WebObject.js +269 -657
- package/dist/src/WebObjects/WebObjectManager.js +125 -386
- package/dist/src/index.js +9 -104
- package/dist/src/structs/DummyObject.js +8 -35
- package/dist/src/structs/MapableObject.js +74 -113
- package/dist/src/structs/MetaObject.js +35 -125
- package/dist/src/structs/ObjectArray.js +43 -71
- package/dist/src/structs/ObjectManager.js +210 -529
- package/dist/src/structs/SimpleObject.d.ts +0 -1
- package/dist/src/structs/SimpleObject.js +670 -958
- package/package.json +1 -1
|
@@ -1,680 +1,292 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
_defineProperty(_assertThisInitialized(_this), "_created_date", "");
|
|
49
|
-
_defineProperty(_assertThisInitialized(_this), "get_webtype", function () {
|
|
50
|
-
return _this.__web_type || _this.get_webpath();
|
|
51
|
-
});
|
|
52
|
-
_defineProperty(_assertThisInitialized(_this), "get_webpath", function () {
|
|
53
|
-
return _this.__web_path;
|
|
54
|
-
});
|
|
55
|
-
_defineProperty(_assertThisInitialized(_this), "get_managerClass", function () {
|
|
56
|
-
return null;
|
|
57
|
-
});
|
|
58
|
-
_this.meta_data = [];
|
|
59
|
-
return _this;
|
|
60
|
-
}
|
|
61
|
-
/* -------------------------------------------------------------------------- */
|
|
62
|
-
/* Meta data */
|
|
63
|
-
/* -------------------------------------------------------------------------- */
|
|
64
|
-
/**
|
|
65
|
-
* Update meta value of this object , meta data is stored in meta_data variable
|
|
66
|
-
* @param key
|
|
67
|
-
* @param value
|
|
68
|
-
* @param createIfNotExists should we create a new meta if key does not exist
|
|
69
|
-
* @param sendChange
|
|
70
|
-
* @returns
|
|
71
|
-
*/
|
|
72
|
-
_createClass(WebObject, [{
|
|
73
|
-
key: "setMetaValue",
|
|
74
|
-
value: function setMetaValue(key, value) {
|
|
75
|
-
var createIfNotExists = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
76
|
-
var sendChange = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "auto";
|
|
77
|
-
if (!this.canModify) {
|
|
78
|
-
if (this.__throw_errors !== false) throw Error("Cant use setMetaValue on ".concat(key, " when on readonly mode"));else return false;
|
|
79
|
-
}
|
|
80
|
-
if (!key || typeof key != "string") {
|
|
81
|
-
if (this.__throw_errors !== false) throw Error("Bad key at setMetaValue");else return false;
|
|
82
|
-
}
|
|
83
|
-
var old_value = WebObject.getMetaValue(this, key);
|
|
84
|
-
if ((0, _object.object_equals)(old_value, value)) return false; //same value, no changes
|
|
85
|
-
var old_metalist = (0, _object.to_array)(this.getValue("meta_data")).map(function (s) {
|
|
86
|
-
return (0, _object.object_shallow_clone)(s);
|
|
87
|
-
});
|
|
88
|
-
var new_metalist = (0, _object.setInArray)(old_metalist, "key", key, "value", value, createIfNotExists);
|
|
89
|
-
this.setValue("meta_data", new_metalist);
|
|
90
|
-
if (sendChange !== false) this.notifyChanged("meta", key, value);
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
1
|
+
import SimpleObject from "../structs/SimpleObject";
|
|
2
|
+
import { getInArray, object_equals, object_first, object_isEmpty, object_isTrue, object_shallow_clone, setInArray, to_array, } from "@azrico/object";
|
|
3
|
+
import { gfunc } from "@azrico/global";
|
|
4
|
+
export class WebObject extends SimpleObject {
|
|
5
|
+
static __web_path = "";
|
|
6
|
+
static __web_type = "";
|
|
7
|
+
meta_data;
|
|
8
|
+
_id = "";
|
|
9
|
+
_created_date = "";
|
|
10
|
+
constructor(is_readonly = false) {
|
|
11
|
+
super(is_readonly);
|
|
12
|
+
this.meta_data = [];
|
|
13
|
+
}
|
|
14
|
+
/* -------------------------------------------------------------------------- */
|
|
15
|
+
/* Meta data */
|
|
16
|
+
/* -------------------------------------------------------------------------- */
|
|
17
|
+
/**
|
|
18
|
+
* Update meta value of this object , meta data is stored in meta_data variable
|
|
19
|
+
* @param key
|
|
20
|
+
* @param value
|
|
21
|
+
* @param createIfNotExists should we create a new meta if key does not exist
|
|
22
|
+
* @param sendChange
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
setMetaValue(key, value, createIfNotExists = true, sendChange = "auto") {
|
|
26
|
+
if (!this.canModify) {
|
|
27
|
+
if (this.__throw_errors !== false)
|
|
28
|
+
throw Error(`Cant use setMetaValue on ${key} when on readonly mode`);
|
|
29
|
+
else
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (!key || typeof key != "string") {
|
|
33
|
+
if (this.__throw_errors !== false)
|
|
34
|
+
throw Error(`Bad key at setMetaValue`);
|
|
35
|
+
else
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const old_value = WebObject.getMetaValue(this, key);
|
|
39
|
+
if (object_equals(old_value, value))
|
|
40
|
+
return false; //same value, no changes
|
|
41
|
+
const old_metalist = to_array(this.getValue("meta_data")).map((s) => object_shallow_clone(s));
|
|
42
|
+
const new_metalist = setInArray(old_metalist, "key", key, "value", value, createIfNotExists);
|
|
43
|
+
this.setValue("meta_data", new_metalist);
|
|
44
|
+
if (sendChange !== false)
|
|
45
|
+
this.notifyChanged("meta", key, value);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
93
48
|
/**
|
|
94
49
|
* Get meta object by key
|
|
95
50
|
* @param key
|
|
96
51
|
* @returns meta object
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return WebObject.getMeta(this, key);
|
|
102
|
-
}
|
|
52
|
+
*/
|
|
53
|
+
getMeta(key) {
|
|
54
|
+
return WebObject.getMeta(this, key);
|
|
55
|
+
}
|
|
103
56
|
/**
|
|
104
57
|
* Get meta value by key
|
|
105
58
|
* @param key
|
|
106
59
|
* @returns value or undefined
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return WebObject.getMetaValue(this, key);
|
|
112
|
-
}
|
|
60
|
+
*/
|
|
61
|
+
getMetaValue(key) {
|
|
62
|
+
return WebObject.getMetaValue(this, key);
|
|
63
|
+
}
|
|
113
64
|
/**
|
|
114
65
|
* Get meta object by key
|
|
115
66
|
* @param o
|
|
116
67
|
* @param key
|
|
117
68
|
* @returns meta object
|
|
118
|
-
*/
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
}, {
|
|
178
|
-
key: "canSave",
|
|
179
|
-
value: function canSave(deltaObj) {
|
|
180
|
-
var deltaRes = this.deltaIsValid(deltaObj);
|
|
181
|
-
if (deltaRes !== true) return deltaRes;
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
}, {
|
|
185
|
-
key: "deltaIsValid",
|
|
186
|
-
value: function deltaIsValid(d) {
|
|
187
|
-
return true;
|
|
188
|
-
}
|
|
189
|
-
}, {
|
|
190
|
-
key: "get_deltaObject",
|
|
191
|
-
value:
|
|
69
|
+
*/
|
|
70
|
+
static getMeta(o, key) {
|
|
71
|
+
if (o == null)
|
|
72
|
+
return null;
|
|
73
|
+
if (!key || typeof key != "string")
|
|
74
|
+
return undefined;
|
|
75
|
+
let metalist = [];
|
|
76
|
+
if (typeof o === "object") {
|
|
77
|
+
metalist =
|
|
78
|
+
typeof o.getValue === "function"
|
|
79
|
+
? o.getValue("meta_data")
|
|
80
|
+
: o.meta_data;
|
|
81
|
+
}
|
|
82
|
+
return getInArray(metalist, "key", key);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get meta value by key
|
|
86
|
+
* @param o
|
|
87
|
+
* @param key
|
|
88
|
+
* @returns value or undefined
|
|
89
|
+
*/
|
|
90
|
+
static getMetaValue(o, key) {
|
|
91
|
+
return WebObject.getMeta(o, key)?.value;
|
|
92
|
+
}
|
|
93
|
+
/* -------------------------------------------------------------------------- */
|
|
94
|
+
/* Save */
|
|
95
|
+
/* -------------------------------------------------------------------------- */
|
|
96
|
+
async Save() {
|
|
97
|
+
if (this.__throw_errors !== false)
|
|
98
|
+
throw new Error("Save not implented");
|
|
99
|
+
WebObject.addError(this, "Save not implented", "NOSAVE", true);
|
|
100
|
+
this.setSaveResult(false, "canceled");
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
async Delete() {
|
|
104
|
+
if (this.__throw_errors !== false)
|
|
105
|
+
throw new Error("Delete not implented");
|
|
106
|
+
WebObject.addError(this, "Delete not implented", "NOSAVE", true);
|
|
107
|
+
this.setSaveResult(false, "canceled");
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
/* -------------------------------------------------------------------------- */
|
|
111
|
+
canSave(deltaObj) {
|
|
112
|
+
const deltaRes = this.deltaIsValid(deltaObj);
|
|
113
|
+
if (deltaRes !== true)
|
|
114
|
+
return deltaRes;
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
deltaIsValid(d) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
static isResultValid(result_object) {
|
|
121
|
+
if (object_isEmpty(result_object))
|
|
122
|
+
return false;
|
|
123
|
+
if (object_isTrue(result_object.acknowledged)) {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
192
128
|
/**
|
|
193
129
|
* You will post this to the server for saving
|
|
194
130
|
* automatically removes unchangable fields
|
|
195
131
|
* @returns
|
|
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
|
-
case 30:
|
|
313
|
-
if (allProperties) {
|
|
314
|
-
final_object["_id"] = this.getID();
|
|
315
|
-
final_object["_index_value"] = this.getIndex();
|
|
316
|
-
final_object["_index_key"] = this["_index_key"];
|
|
317
|
-
final_object["_created_date"] = this["_created_date"];
|
|
318
|
-
}
|
|
319
|
-
return _context5.abrupt("return", final_object);
|
|
320
|
-
case 32:
|
|
321
|
-
case "end":
|
|
322
|
-
return _context5.stop();
|
|
323
|
-
}
|
|
324
|
-
}, _callee5, this, [[13, 24, 27, 30]]);
|
|
325
|
-
}));
|
|
326
|
-
function get_deltaObject(_x) {
|
|
327
|
-
return _get_deltaObject.apply(this, arguments);
|
|
328
|
-
}
|
|
329
|
-
return get_deltaObject;
|
|
330
|
-
}() /* --------------------------------- Getters -------------------------------- */
|
|
331
|
-
}, {
|
|
332
|
-
key: "__web_path",
|
|
333
|
-
get: function get() {
|
|
334
|
-
return this.constructor["__web_path"];
|
|
335
|
-
}
|
|
336
|
-
}, {
|
|
337
|
-
key: "__web_type",
|
|
338
|
-
get: function get() {
|
|
339
|
-
return this.constructor["__web_type"];
|
|
340
|
-
}
|
|
341
|
-
}, {
|
|
342
|
-
key: "manager",
|
|
343
|
-
get: function get() {
|
|
344
|
-
return this.get_managerClass();
|
|
345
|
-
}
|
|
346
|
-
}, {
|
|
347
|
-
key: "set_managerClass",
|
|
348
|
-
value: function set_managerClass(mng) {
|
|
349
|
-
this.get_managerClass = function () {
|
|
350
|
-
return mng;
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
/* -------------------------------------------------------------------------- */
|
|
354
|
-
}, {
|
|
355
|
-
key: "onDelete",
|
|
356
|
-
value: function () {
|
|
357
|
-
var _onDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
358
|
-
var _this$manager;
|
|
359
|
-
var _len,
|
|
360
|
-
p,
|
|
361
|
-
_key,
|
|
362
|
-
_args6 = arguments;
|
|
363
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
364
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
365
|
-
case 0:
|
|
366
|
-
this.isDeleted = true;
|
|
367
|
-
for (_len = _args6.length, p = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
368
|
-
p[_key] = _args6[_key];
|
|
369
|
-
}
|
|
370
|
-
_context6.next = 4;
|
|
371
|
-
return (_this$manager = this.manager) === null || _this$manager === void 0 ? void 0 : _this$manager.onDelete.apply(_this$manager, p);
|
|
372
|
-
case 4:
|
|
373
|
-
return _context6.abrupt("return", _context6.sent);
|
|
374
|
-
case 5:
|
|
375
|
-
case "end":
|
|
376
|
-
return _context6.stop();
|
|
377
|
-
}
|
|
378
|
-
}, _callee6, this);
|
|
379
|
-
}));
|
|
380
|
-
function onDelete() {
|
|
381
|
-
return _onDelete.apply(this, arguments);
|
|
382
|
-
}
|
|
383
|
-
return onDelete;
|
|
384
|
-
}()
|
|
385
|
-
}, {
|
|
386
|
-
key: "onLoad",
|
|
387
|
-
value: function () {
|
|
388
|
-
var _onLoad = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
389
|
-
var _this$manager2;
|
|
390
|
-
var _len2,
|
|
391
|
-
p,
|
|
392
|
-
_key2,
|
|
393
|
-
_args7 = arguments;
|
|
394
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
395
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
396
|
-
case 0:
|
|
397
|
-
this.isDeleted = false;
|
|
398
|
-
for (_len2 = _args7.length, p = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
399
|
-
p[_key2] = _args7[_key2];
|
|
400
|
-
}
|
|
401
|
-
_context7.next = 4;
|
|
402
|
-
return (_this$manager2 = this.manager) === null || _this$manager2 === void 0 ? void 0 : _this$manager2.onLoad.apply(_this$manager2, p);
|
|
403
|
-
case 4:
|
|
404
|
-
return _context7.abrupt("return", _context7.sent);
|
|
405
|
-
case 5:
|
|
406
|
-
case "end":
|
|
407
|
-
return _context7.stop();
|
|
408
|
-
}
|
|
409
|
-
}, _callee7, this);
|
|
410
|
-
}));
|
|
411
|
-
function onLoad() {
|
|
412
|
-
return _onLoad.apply(this, arguments);
|
|
413
|
-
}
|
|
414
|
-
return onLoad;
|
|
415
|
-
}()
|
|
416
|
-
}, {
|
|
417
|
-
key: "onSave",
|
|
418
|
-
value: function () {
|
|
419
|
-
var _onSave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
420
|
-
var _this3 = this,
|
|
421
|
-
_this$manager4;
|
|
422
|
-
var srObject,
|
|
423
|
-
actual_sr,
|
|
424
|
-
_this$manager3,
|
|
425
|
-
_len3,
|
|
426
|
-
p,
|
|
427
|
-
_key3,
|
|
428
|
-
_args8 = arguments;
|
|
429
|
-
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
430
|
-
while (1) switch (_context8.prev = _context8.next) {
|
|
431
|
-
case 0:
|
|
432
|
-
if (!this.isSaved) {
|
|
433
|
-
_context8.next = 10;
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
this.apply_changes();
|
|
437
|
-
srObject = this.getSaveResult(true);
|
|
438
|
-
if (!(srObject != null)) {
|
|
439
|
-
_context8.next = 10;
|
|
440
|
-
break;
|
|
441
|
-
}
|
|
442
|
-
//we may have some extra data in the save result.
|
|
443
|
-
//try to find the main data
|
|
444
|
-
if (Array.isArray(srObject)) {
|
|
445
|
-
actual_sr = srObject.find(function (s) {
|
|
446
|
-
return _classPrivateMethodGet(_this3, _isValidSR, _isValidSR2).call(_this3, s);
|
|
447
|
-
});
|
|
448
|
-
if (actual_sr) srObject = actual_sr;
|
|
449
|
-
}
|
|
450
|
-
if (!_classPrivateMethodGet(this, _isValidSR, _isValidSR2).call(this, srObject)) {
|
|
451
|
-
_context8.next = 10;
|
|
452
|
-
break;
|
|
453
|
-
}
|
|
454
|
-
if (srObject.insertedId || srObject._id) {
|
|
455
|
-
this._id = srObject.insertedId || srObject._id;
|
|
456
|
-
}
|
|
457
|
-
if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
|
|
458
|
-
this._index_value = Number(srObject._index_value);
|
|
459
|
-
}
|
|
460
|
-
_context8.next = 10;
|
|
461
|
-
return (_this$manager3 = this.manager) === null || _this$manager3 === void 0 ? void 0 : _this$manager3.event_run("on_id_change");
|
|
462
|
-
case 10:
|
|
463
|
-
for (_len3 = _args8.length, p = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
464
|
-
p[_key3] = _args8[_key3];
|
|
465
|
-
}
|
|
466
|
-
_context8.next = 13;
|
|
467
|
-
return (_this$manager4 = this.manager) === null || _this$manager4 === void 0 ? void 0 : _this$manager4.onSave.apply(_this$manager4, p);
|
|
468
|
-
case 13:
|
|
469
|
-
return _context8.abrupt("return", _context8.sent);
|
|
470
|
-
case 14:
|
|
471
|
-
case "end":
|
|
472
|
-
return _context8.stop();
|
|
473
|
-
}
|
|
474
|
-
}, _callee8, this);
|
|
475
|
-
}));
|
|
476
|
-
function onSave() {
|
|
477
|
-
return _onSave.apply(this, arguments);
|
|
478
|
-
}
|
|
479
|
-
return onSave;
|
|
480
|
-
}()
|
|
481
|
-
}, {
|
|
482
|
-
key: "onNew",
|
|
483
|
-
value: function () {
|
|
484
|
-
var _onNew = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
485
|
-
var _this$manager5;
|
|
486
|
-
var _len4,
|
|
487
|
-
p,
|
|
488
|
-
_key4,
|
|
489
|
-
_args9 = arguments;
|
|
490
|
-
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
491
|
-
while (1) switch (_context9.prev = _context9.next) {
|
|
492
|
-
case 0:
|
|
493
|
-
for (_len4 = _args9.length, p = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
494
|
-
p[_key4] = _args9[_key4];
|
|
495
|
-
}
|
|
496
|
-
_context9.next = 3;
|
|
497
|
-
return (_this$manager5 = this.manager) === null || _this$manager5 === void 0 ? void 0 : _this$manager5.onNew.apply(_this$manager5, p);
|
|
498
|
-
case 3:
|
|
499
|
-
return _context9.abrupt("return", _context9.sent);
|
|
500
|
-
case 4:
|
|
501
|
-
case "end":
|
|
502
|
-
return _context9.stop();
|
|
503
|
-
}
|
|
504
|
-
}, _callee9, this);
|
|
505
|
-
}));
|
|
506
|
-
function onNew() {
|
|
507
|
-
return _onNew.apply(this, arguments);
|
|
508
|
-
}
|
|
509
|
-
return onNew;
|
|
510
|
-
}()
|
|
511
|
-
/* -------------------------------------------------------------------------- */
|
|
132
|
+
*/
|
|
133
|
+
async get_deltaObject(p) {
|
|
134
|
+
if (!p)
|
|
135
|
+
p = {};
|
|
136
|
+
const final_object = {};
|
|
137
|
+
//@ts-ignore
|
|
138
|
+
const isChild = Boolean(p.isChild || p.ischild);
|
|
139
|
+
//@ts-ignore
|
|
140
|
+
const useDelta = this.__use_delta || Boolean(p.useDelta || p.usedelta);
|
|
141
|
+
//@ts-ignore
|
|
142
|
+
const allProperties = Boolean(p.allProperties || p.allproperties);
|
|
143
|
+
const chkChangables = this.__changeables != null || this.__unchangeables != null;
|
|
144
|
+
const useExtraProps = Boolean(p.extraProperties);
|
|
145
|
+
//child objects usually dont update their __delta, so we read info from all of its properties
|
|
146
|
+
const dlt = allProperties || (!useDelta && isChild && chkChangables)
|
|
147
|
+
? { ...this.allproperties }
|
|
148
|
+
: { ...this.__delta };
|
|
149
|
+
const allkeys = Object.keys(dlt);
|
|
150
|
+
const changableKeys = chkChangables
|
|
151
|
+
? allkeys.filter((s) => SimpleObject.canChangeKey(this, s, useExtraProps))
|
|
152
|
+
: allkeys;
|
|
153
|
+
async function parseObj(obj) {
|
|
154
|
+
if (obj == null)
|
|
155
|
+
return undefined;
|
|
156
|
+
if (Array.isArray(obj))
|
|
157
|
+
return await Promise.all(obj.map(async (r) => await parseObj(r)));
|
|
158
|
+
if (obj instanceof WebObject &&
|
|
159
|
+
typeof obj.get_deltaObject === "function") {
|
|
160
|
+
//child elements have different kind of delta
|
|
161
|
+
const newobj_dlt = await obj.get_deltaObject({
|
|
162
|
+
...p,
|
|
163
|
+
isChild: true,
|
|
164
|
+
});
|
|
165
|
+
if (!object_isEmpty(newobj_dlt))
|
|
166
|
+
return newobj_dlt;
|
|
167
|
+
else
|
|
168
|
+
return obj;
|
|
169
|
+
}
|
|
170
|
+
return obj;
|
|
171
|
+
}
|
|
172
|
+
for (const key of changableKeys) {
|
|
173
|
+
final_object[key] = await parseObj(dlt[key]);
|
|
174
|
+
}
|
|
175
|
+
if (allProperties) {
|
|
176
|
+
final_object["_id"] = this.getID();
|
|
177
|
+
final_object["_index_value"] = this.getIndex();
|
|
178
|
+
final_object["_index_key"] = this["_index_key"];
|
|
179
|
+
final_object["_created_date"] = this["_created_date"];
|
|
180
|
+
}
|
|
181
|
+
return final_object;
|
|
182
|
+
}
|
|
183
|
+
/* --------------------------------- Getters -------------------------------- */
|
|
184
|
+
get __web_path() {
|
|
185
|
+
return this.constructor["__web_path"];
|
|
186
|
+
}
|
|
187
|
+
get __web_type() {
|
|
188
|
+
return this.constructor["__web_type"];
|
|
189
|
+
}
|
|
190
|
+
get_webtype = () => this.__web_type || this.get_webpath();
|
|
191
|
+
get_webpath = () => this.__web_path;
|
|
192
|
+
static get_webname() {
|
|
193
|
+
return this.__web_path || this.__web_type || this.__cache_name;
|
|
194
|
+
}
|
|
195
|
+
get manager() {
|
|
196
|
+
return this.get_managerClass();
|
|
197
|
+
}
|
|
198
|
+
get_managerClass = () => null;
|
|
199
|
+
set_managerClass(mng) {
|
|
200
|
+
this.get_managerClass = () => mng;
|
|
201
|
+
}
|
|
202
|
+
/* -------------------------------------------------------------------------- */
|
|
203
|
+
async onDelete(...p) {
|
|
204
|
+
this.isDeleted = true;
|
|
205
|
+
return await this.manager?.onDelete(...p); //events are handled by the manager
|
|
206
|
+
}
|
|
207
|
+
async onLoad(...p) {
|
|
208
|
+
this.isDeleted = false;
|
|
209
|
+
return await this.manager?.onLoad(...p); //events are handled by the manager
|
|
210
|
+
}
|
|
211
|
+
async onSave(...p) {
|
|
212
|
+
if (this.isSaved) {
|
|
213
|
+
this.apply_changes();
|
|
214
|
+
var srObject = this.getSaveResult(true);
|
|
215
|
+
if (srObject != null) {
|
|
216
|
+
//we may have some extra data in the save result.
|
|
217
|
+
//try to find the main data
|
|
218
|
+
if (Array.isArray(srObject)) {
|
|
219
|
+
const actual_sr = srObject.find((s) => this.#isValidSR(s));
|
|
220
|
+
if (actual_sr)
|
|
221
|
+
srObject = actual_sr;
|
|
222
|
+
}
|
|
223
|
+
if (this.#isValidSR(srObject)) {
|
|
224
|
+
if (srObject.insertedId || srObject._id) {
|
|
225
|
+
this._id = srObject.insertedId || srObject._id;
|
|
226
|
+
}
|
|
227
|
+
if (srObject._index_value &&
|
|
228
|
+
!Number.isNaN(srObject._index_value)) {
|
|
229
|
+
this._index_value = Number(srObject._index_value);
|
|
230
|
+
}
|
|
231
|
+
await this.manager?.event_run("on_id_change");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return await this.manager?.onSave(...p); //events are handled by the manager
|
|
236
|
+
}
|
|
237
|
+
#isValidSR(s) {
|
|
238
|
+
if (typeof s !== "object" && s == null)
|
|
239
|
+
return false;
|
|
240
|
+
return (s.insertedId ||
|
|
241
|
+
s._id ||
|
|
242
|
+
(s._index_value && !Number.isNaN(s._index_value)));
|
|
243
|
+
}
|
|
244
|
+
async onNew(...p) {
|
|
245
|
+
return await this.manager?.onNew(...p); //events are handled by the manager
|
|
246
|
+
}
|
|
247
|
+
/* -------------------------------------------------------------------------- */
|
|
512
248
|
/**
|
|
513
249
|
* get a single web object
|
|
514
250
|
* default order of parameters : search,readonly,fetchID
|
|
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
|
-
key: "isResultValid",
|
|
541
|
-
value: function isResultValid(result_object) {
|
|
542
|
-
if ((0, _object.object_isEmpty)(result_object)) return false;
|
|
543
|
-
if ((0, _object.object_isTrue)(result_object.acknowledged)) {
|
|
544
|
-
return true;
|
|
545
|
-
}
|
|
546
|
-
return false;
|
|
547
|
-
}
|
|
548
|
-
}, {
|
|
549
|
-
key: "get_webname",
|
|
550
|
-
value: function get_webname() {
|
|
551
|
-
return this.__web_path || this.__web_type || this.__cache_name;
|
|
552
|
-
}
|
|
553
|
-
}, {
|
|
554
|
-
key: "get_single",
|
|
555
|
-
value: function () {
|
|
556
|
-
var _get_single = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
557
|
-
var _len5,
|
|
558
|
-
p,
|
|
559
|
-
_key5,
|
|
560
|
-
search,
|
|
561
|
-
readonly,
|
|
562
|
-
fetchID,
|
|
563
|
-
res,
|
|
564
|
-
params,
|
|
565
|
-
_args10 = arguments;
|
|
566
|
-
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
567
|
-
while (1) switch (_context10.prev = _context10.next) {
|
|
568
|
-
case 0:
|
|
569
|
-
for (_len5 = _args10.length, p = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
570
|
-
p[_key5] = _args10[_key5];
|
|
571
|
-
}
|
|
572
|
-
search = p.shift();
|
|
573
|
-
readonly = p.shift();
|
|
574
|
-
fetchID = p.shift();
|
|
575
|
-
if (!(0, _object.object_isEmpty)(search)) {
|
|
576
|
-
_context10.next = 6;
|
|
577
|
-
break;
|
|
578
|
-
}
|
|
579
|
-
return _context10.abrupt("return", undefined);
|
|
580
|
-
case 6:
|
|
581
|
-
params = {};
|
|
582
|
-
params.context = readonly ? "view" : "edit";
|
|
583
|
-
_context10.t0 = _typeof(search);
|
|
584
|
-
_context10.next = _context10.t0 === "string" ? 11 : _context10.t0 === "number" ? 11 : _context10.t0 === "object" ? 19 : 19;
|
|
585
|
-
break;
|
|
586
|
-
case 11:
|
|
587
|
-
search = String(search);
|
|
588
|
-
_context10.t1 = this;
|
|
589
|
-
_context10.t2 = this;
|
|
590
|
-
_context10.next = 16;
|
|
591
|
-
return _global.gfunc.run_action("get", this.__web_path + "/" + search, params, {
|
|
592
|
-
fetchID: fetchID
|
|
593
|
-
});
|
|
594
|
-
case 16:
|
|
595
|
-
_context10.t3 = _context10.sent;
|
|
596
|
-
res = _context10.t1.ensure.call(_context10.t1, _context10.t2, _context10.t3);
|
|
597
|
-
return _context10.abrupt("break", 25);
|
|
598
|
-
case 19:
|
|
599
|
-
_context10.t4 = _object.object_first;
|
|
600
|
-
_context10.next = 22;
|
|
601
|
-
return this.get_list(search, readonly, fetchID);
|
|
602
|
-
case 22:
|
|
603
|
-
_context10.t5 = _context10.sent;
|
|
604
|
-
res = (0, _context10.t4)(_context10.t5);
|
|
605
|
-
return _context10.abrupt("break", 25);
|
|
606
|
-
case 25:
|
|
607
|
-
WebObject.setReadonly(res, readonly);
|
|
608
|
-
return _context10.abrupt("return", res);
|
|
609
|
-
case 27:
|
|
610
|
-
case "end":
|
|
611
|
-
return _context10.stop();
|
|
612
|
-
}
|
|
613
|
-
}, _callee10, this);
|
|
614
|
-
}));
|
|
615
|
-
function get_single() {
|
|
616
|
-
return _get_single.apply(this, arguments);
|
|
617
|
-
}
|
|
618
|
-
return get_single;
|
|
619
|
-
}()
|
|
251
|
+
*/
|
|
252
|
+
static async get_single(...p) {
|
|
253
|
+
let search = p.shift();
|
|
254
|
+
let readonly = p.shift();
|
|
255
|
+
let fetchID = p.shift();
|
|
256
|
+
if (object_isEmpty(search))
|
|
257
|
+
return undefined;
|
|
258
|
+
let res;
|
|
259
|
+
const params = {};
|
|
260
|
+
params.context = readonly ? "view" : "edit";
|
|
261
|
+
switch (typeof search) {
|
|
262
|
+
case "string":
|
|
263
|
+
case "number":
|
|
264
|
+
search = String(search);
|
|
265
|
+
res = this.ensure(this, await gfunc.run_action("get", this.__web_path + "/" + search, params, { fetchID: fetchID }));
|
|
266
|
+
break;
|
|
267
|
+
case "object":
|
|
268
|
+
default:
|
|
269
|
+
res = object_first(await this.get_list(search, readonly, fetchID));
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
WebObject.setReadonly(res, readonly);
|
|
273
|
+
return res;
|
|
274
|
+
}
|
|
620
275
|
/**
|
|
621
276
|
* Get a list of web objects
|
|
622
277
|
* default order of parameters : search,readonly,fetchID
|
|
623
|
-
*/
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
639
|
-
while (1) switch (_context11.prev = _context11.next) {
|
|
640
|
-
case 0:
|
|
641
|
-
for (_len6 = _args11.length, p = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
642
|
-
p[_key6] = _args11[_key6];
|
|
643
|
-
}
|
|
644
|
-
search = p.shift();
|
|
645
|
-
readonly = p.shift();
|
|
646
|
-
fetchID = p.shift();
|
|
647
|
-
if (!search) search = {};
|
|
648
|
-
_context11.next = 7;
|
|
649
|
-
return _global.gfunc.run_action("get", this.__web_path, search, {
|
|
650
|
-
fetchID: fetchID
|
|
651
|
-
});
|
|
652
|
-
case 7:
|
|
653
|
-
result_items = _context11.sent;
|
|
654
|
-
selftype = this.prototype;
|
|
655
|
-
res = WebObject.map_rowindex(WebObject.mapto(selftype, result_items, readonly));
|
|
656
|
-
WebObject.setReadonly(res, readonly);
|
|
657
|
-
return _context11.abrupt("return", res);
|
|
658
|
-
case 12:
|
|
659
|
-
case "end":
|
|
660
|
-
return _context11.stop();
|
|
661
|
-
}
|
|
662
|
-
}, _callee11, this);
|
|
663
|
-
}));
|
|
664
|
-
function get_list() {
|
|
665
|
-
return _get_list.apply(this, arguments);
|
|
666
|
-
}
|
|
667
|
-
return get_list;
|
|
668
|
-
}()
|
|
669
|
-
}]);
|
|
670
|
-
return WebObject;
|
|
671
|
-
}(_SimpleObject2["default"]);
|
|
672
|
-
exports.WebObject = WebObject;
|
|
673
|
-
function _isValidSR2(s) {
|
|
674
|
-
if (_typeof(s) !== "object" && s == null) return false;
|
|
675
|
-
return s.insertedId || s._id || s._index_value && !Number.isNaN(s._index_value);
|
|
676
|
-
}
|
|
677
|
-
_defineProperty(WebObject, "__web_path", "");
|
|
678
|
-
_defineProperty(WebObject, "__web_type", "");
|
|
679
|
-
var _default = WebObject;
|
|
680
|
-
exports["default"] = _default;
|
|
278
|
+
*/
|
|
279
|
+
static async get_list(...p) {
|
|
280
|
+
let search = p.shift();
|
|
281
|
+
let readonly = p.shift();
|
|
282
|
+
let fetchID = p.shift();
|
|
283
|
+
if (!search)
|
|
284
|
+
search = {};
|
|
285
|
+
let result_items = await gfunc.run_action("get", this.__web_path, search, { fetchID: fetchID });
|
|
286
|
+
const selftype = this.prototype;
|
|
287
|
+
const res = WebObject.map_rowindex(WebObject.mapto(selftype, result_items, readonly));
|
|
288
|
+
WebObject.setReadonly(res, readonly);
|
|
289
|
+
return res;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
export default WebObject;
|