2015-11-17 10:34:33 +00:00
|
|
|
|
|
|
|
Vn.Form = new Class
|
|
|
|
({
|
|
|
|
Extends: Vn.Object
|
2015-12-10 13:48:43 +00:00
|
|
|
|
|
|
|
,isOpen: false
|
|
|
|
,uiLoaded: false
|
2015-11-17 10:34:33 +00:00
|
|
|
|
|
|
|
,initialize: function (gui, formInfo)
|
|
|
|
{
|
|
|
|
this.gui = gui;
|
|
|
|
this.conn = gui.conn;
|
|
|
|
this.hash = gui.hash;
|
|
|
|
this.formInfo = formInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an object from the builder associated to this form.
|
|
|
|
*
|
|
|
|
* @param {string} objectId The object identifier
|
|
|
|
* @return {Object} The object, or %null if not found
|
|
|
|
**/
|
|
|
|
,$: function (objectId)
|
|
|
|
{
|
|
|
|
if (this.builder)
|
|
|
|
return this.builder.getById (objectId);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2015-12-10 13:48:43 +00:00
|
|
|
|
|
|
|
,loadUi: function ()
|
2015-11-17 10:34:33 +00:00
|
|
|
{
|
2015-12-10 13:48:43 +00:00
|
|
|
if (!this.isOpen)
|
|
|
|
return;
|
2015-11-17 10:34:33 +00:00
|
|
|
|
|
|
|
var builder = new Vn.Builder ();
|
|
|
|
builder.signalData = this;
|
2015-11-19 13:57:23 +00:00
|
|
|
builder.add ('conn', this.conn);
|
2015-11-17 10:34:33 +00:00
|
|
|
builder.loadXml ('forms/'+ this.formInfo.path +'/ui.xml');
|
|
|
|
|
|
|
|
var res = this.builder = builder.load ();
|
|
|
|
this.node = res.$('form');
|
|
|
|
res.link ();
|
|
|
|
|
|
|
|
var models = res.getByTagName ('db-model');
|
|
|
|
|
|
|
|
for (var i = 0; i < models.length; i++)
|
|
|
|
models[i].conn = this.conn;
|
|
|
|
|
|
|
|
var queries = res.getByTagName ('db-query');
|
|
|
|
|
|
|
|
for (var i = 0; i < queries.length; i++)
|
|
|
|
queries[i].conn = this.conn;
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
if (this.node)
|
|
|
|
{
|
|
|
|
this.gui.formHolder.appendChild (this.node);
|
|
|
|
this.gui.setTitle (res.$('title'));
|
|
|
|
this.gui.setActions (res.$('actions'));
|
|
|
|
this.activate ();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.uiLoaded = true;
|
2015-11-17 10:34:33 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
,unloadUi: function ()
|
2015-11-17 10:34:33 +00:00
|
|
|
{
|
2015-12-10 13:48:43 +00:00
|
|
|
if (!this.uiLoaded)
|
|
|
|
return;
|
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
if (this.node)
|
|
|
|
{
|
2015-12-10 13:48:43 +00:00
|
|
|
this.deactivate ();
|
2015-11-17 10:34:33 +00:00
|
|
|
this.gui.setTitle (null);
|
|
|
|
this.gui.setActions (null);
|
|
|
|
Vn.Node.remove (this.node);
|
2015-12-10 13:48:43 +00:00
|
|
|
this.deactivate ();
|
2015-11-17 10:34:33 +00:00
|
|
|
this.node = null;
|
|
|
|
}
|
|
|
|
if (this.builder)
|
|
|
|
{
|
|
|
|
this.builder.unref ();
|
|
|
|
this.builder = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
/**
|
|
|
|
* Called when the form is opened.
|
|
|
|
**/
|
|
|
|
,open: function ()
|
|
|
|
{
|
|
|
|
this.close ();
|
|
|
|
this.isOpen = true;
|
|
|
|
this.loadUi ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the form is closed.
|
|
|
|
**/
|
|
|
|
,close: function ()
|
|
|
|
{
|
|
|
|
if (!this.isOpen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.isOpen = false;
|
|
|
|
this.unloadUi ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the form is activated.
|
|
|
|
**/
|
|
|
|
,activate: function () {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the form is deactivated.
|
|
|
|
**/
|
|
|
|
,deactivate: function () {}
|
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
,_destroy: function ()
|
|
|
|
{
|
|
|
|
this.close ();
|
|
|
|
this.parent ();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|