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

145 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-04-19 06:16:37 +00:00
var Gui = require ('./gui');
2016-09-26 09:28:47 +00:00
module.exports = new Class
({
2017-10-18 16:01:21 +00:00
Extends: Vn.Component
2017-04-19 06:16:37 +00:00
,Properties: {
gui:
{
type: Gui
,set: function (x)
{
this._gui = x;
this.conn = x.conn;
this.hash = x.hash;
}
,get: function ()
{
return this._gui;
}
},
formInfo:
{
type: Object,
value: null
}
}
2015-12-10 13:48:43 +00:00
,isOpen: false
,uiLoaded: false
,loadUi: function ()
{
2015-12-10 13:48:43 +00:00
if (!this.isOpen)
return;
var builder = new Vn.Builder ();
2017-10-18 16:01:21 +00:00
builder.compileFile ('forms/'+ this.formInfo.path +'/ui.xml');
2017-03-23 16:20:51 +00:00
2017-10-22 00:25:57 +00:00
var conn = this.conn;
var hash = this.hash;
2017-10-18 16:01:21 +00:00
var extraObjects = {
2017-10-22 00:25:57 +00:00
conn: conn,
hash: hash
2017-10-18 16:01:21 +00:00
};
2017-10-22 00:25:57 +00:00
var scope = builder.load (this.doc, this, null, extraObjects, hash);
2017-10-18 16:01:21 +00:00
this.scope = scope;
2017-10-20 17:09:06 +00:00
this.$ = scope.$;
this._node = this.$.main;
2017-10-20 17:09:06 +00:00
var paramsLot = this.$.params;
2017-07-05 09:50:42 +00:00
if (paramsLot)
2017-09-12 11:31:15 +00:00
{
2017-10-22 00:25:57 +00:00
paramsLot.source = hash;
2017-09-12 11:31:15 +00:00
this.params = paramsLot;
}
2017-10-16 07:58:12 +00:00
2017-10-18 16:01:21 +00:00
scope.link ();
2017-07-05 09:50:42 +00:00
2017-10-22 00:25:57 +00:00
function setConnection (tagName)
{
var objects = scope.getByTagName (tagName);
for (var i = 0; i < objects.length; i++)
objects[i].conn = conn;
}
2017-10-22 00:25:57 +00:00
var tags = ['db-model', 'db-query', 'db-lot'];
for (var i = 0; i < tags.length; i++)
setConnection (tags[i]);
2017-03-23 16:20:51 +00:00
2015-12-10 13:48:43 +00:00
if (this.node)
{
this.gui.setForm (this.node);
2017-10-20 17:45:11 +00:00
this.gui.setTitle (this.$.title);
this.gui.setActions (this.$.actions);
2015-12-10 13:48:43 +00:00
this.activate ();
}
this.uiLoaded = true;
}
2015-12-10 13:48:43 +00:00
,unloadUi: function ()
{
2015-12-10 13:48:43 +00:00
if (!this.uiLoaded)
return;
if (this.node)
{
2015-12-10 13:48:43 +00:00
this.deactivate ();
2017-10-18 16:01:21 +00:00
this.scope.unref ();
this.gui.setTitle (null);
this.gui.setActions (null);
2017-03-17 12:42:10 +00:00
this.gui.setForm (null);
this.node = null;
2017-09-12 11:31:15 +00:00
this.params = null;
}
2017-10-18 16:01:21 +00:00
if (this.scope)
{
2017-10-18 16:01:21 +00:00
this.scope.unref ();
this.scope = null;
}
}
2015-12-10 13:48:43 +00:00
/**
* Called when the form is opened.
2016-12-20 09:32:17 +00:00
*/
2015-12-10 13:48:43 +00:00
,open: function ()
{
this.close ();
this.isOpen = true;
this.loadUi ();
}
/**
* Called when the form is closed.
2016-12-20 09:32:17 +00:00
*/
2015-12-10 13:48:43 +00:00
,close: function ()
{
if (!this.isOpen)
return;
this.isOpen = false;
this.unloadUi ();
}
/**
* Called when the form is activated.
2016-12-20 09:32:17 +00:00
*/
2015-12-10 13:48:43 +00:00
,activate: function () {}
/**
* Called when the form is deactivated.
2016-12-20 09:32:17 +00:00
*/
2015-12-10 13:48:43 +00:00
,deactivate: function () {}
,_destroy: function ()
{
this.close ();
this.parent ();
}
});