0
1
Fork 0
hedera-web-mindshore/js/hedera/form.js

109 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2022-05-24 21:11:12 +00:00
module.exports = new Class({
Extends: Vn.Object
2015-12-10 13:48:43 +00:00
,isOpen: false
,uiLoaded: false
2022-11-16 01:46:44 +00:00
,initialize(gui) {
this.gui = gui;
this.conn = gui.conn;
this.hash = gui.hash;
}
2015-12-10 13:48:43 +00:00
2022-11-28 08:51:31 +00:00
,async loadUi() {
2015-12-10 13:48:43 +00:00
if (!this.isOpen)
return;
2022-05-30 01:30:33 +00:00
const conn = this.conn;
const hash = this.hash;
2022-05-30 01:30:33 +00:00
const builder = new Vn.Builder();
2022-11-16 01:44:39 +00:00
builder.compileString(this.$constructor.Template.default);
const scope = this.scope = this.builder = builder.load(null, this);
2022-05-28 01:18:06 +00:00
this.$ = scope.$;
2022-06-18 21:04:34 +00:00
scope.link({conn, hash});
2022-05-28 01:18:06 +00:00
this.node = scope.$.form;
2022-07-15 05:55:18 +00:00
this.node.$ctrl = this;
2022-05-24 21:11:12 +00:00
2022-05-30 01:30:33 +00:00
const paramsLot = this.$.params;
if (paramsLot) {
paramsLot.source = hash;
this.params = paramsLot;
}
2022-05-30 01:30:33 +00:00
function setConnection(tagName) {
const objects = scope.getByTagName(tagName);
for (let i = 0; i < objects.length; i++)
objects[i].conn = conn;
}
2022-05-30 01:30:33 +00:00
const tags = ['db-model', 'db-query', 'db-lot'];
for (let i = 0; i < tags.length; i++)
setConnection(tags[i]);
2022-05-24 10:18:44 +00:00
if (this.node) {
this.gui.setForm(this.node);
2022-05-28 01:18:06 +00:00
this.gui.setTitle(scope.$.title);
this.gui.setActions(scope.$.actions);
2022-11-28 08:51:31 +00:00
await this.activate();
2015-12-10 13:48:43 +00:00
}
this.uiLoaded = true;
}
2022-11-28 08:51:31 +00:00
,async unloadUi() {
2015-12-10 13:48:43 +00:00
if (!this.uiLoaded)
return;
2022-05-24 10:18:44 +00:00
if (this.node) {
2022-11-28 08:51:31 +00:00
await this.deactivate();
2022-05-24 10:18:44 +00:00
this.gui.setTitle(null);
this.gui.setActions(null);
Vn.Node.remove(this.node);
2022-11-28 08:51:31 +00:00
await this.deactivate();
this.node = null;
}
2022-05-24 10:18:44 +00:00
if (this.builder) {
this.builder.unref();
this.builder = null;
}
}
2015-12-10 13:48:43 +00:00
/**
* Called when the form is opened.
2022-05-24 10:18:44 +00:00
*/
2022-11-28 08:51:31 +00:00
,async open() {
await this.close();
2015-12-10 13:48:43 +00:00
this.isOpen = true;
2022-11-28 08:51:31 +00:00
await this.loadUi();
2015-12-10 13:48:43 +00:00
}
/**
* Called when the form is closed.
2022-05-24 10:18:44 +00:00
*/
2022-11-28 08:51:31 +00:00
,async close() {
if (!this.isOpen) return;
2015-12-10 13:48:43 +00:00
this.isOpen = false;
2022-11-28 08:51:31 +00:00
await this.unloadUi();
2015-12-10 13:48:43 +00:00
}
/**
* Called when the form is activated.
2022-05-24 10:18:44 +00:00
*/
2022-11-28 08:51:31 +00:00
,async activate() {}
2015-12-10 13:48:43 +00:00
/**
* Called when the form is deactivated.
2022-05-24 10:18:44 +00:00
*/
2022-11-28 08:51:31 +00:00
,async deactivate() {}
2015-12-10 13:48:43 +00:00
2022-11-16 01:46:44 +00:00
,_destroy() {
2022-05-24 10:18:44 +00:00
this.close();
if (this.scope) this.scope._destroy();
2022-06-06 16:02:17 +00:00
Vn.Object.prototype._destroy.call(this);
}
});