react-antd-admin-panel
Version:
Easy prototyping admin panel using React and Antd
49 lines • 1.77 kB
JavaScript
import Value from "./Value";
export default class Formula {
constructor(post) {
this._values = {};
this._hidden = [];
this._post = post;
}
// Only registered if the defaultValue-method is set on the .tsx and a default value is set on the .ts
value(model, value) {
if (value === undefined) {
return;
}
if (!model._key) {
this._hidden.push(new Value().model(model));
return;
}
if (this._values[model._key]) {
this._values[model._key].set(value);
this._values[model._key].model(model);
}
else {
this._values[model._key] = new Value();
this.value(model, value);
}
}
action(action) { this._action = action; return this; }
post(post) { this._post = post; return this; }
submit(args, action) {
this._post.submit(args, action, this);
}
onComplete() {
var _a;
(_a = this._action) === null || _a === void 0 ? void 0 : _a.callCompletes();
}
onError() {
var _a;
(_a = this._action) === null || _a === void 0 ? void 0 : _a.callErrors();
}
params() {
let form = {};
Object.keys(this._values).forEach((r) => form[r] = this._values[r].get());
return form;
}
valuesOnReset() {
Object.keys(this._values).forEach((r) => { var _a, _b; return (_b = (_a = this._values[r]._model).clearSelf) === null || _b === void 0 ? void 0 : _b.call(_a); });
this._hidden.forEach((r) => { var _a, _b; return (_b = (_a = r._model).clearSelf) === null || _b === void 0 ? void 0 : _b.call(_a); });
}
}
//# sourceMappingURL=Formula.js.map