2015-11-17 10:34:33 +00:00
|
|
|
|
2016-09-26 09:28:47 +00:00
|
|
|
module.exports = new Class
|
2015-11-17 10:34:33 +00:00
|
|
|
({
|
|
|
|
Extends: Vn.Object
|
2015-12-10 13:48:43 +00:00
|
|
|
|
|
|
|
,isOpen: false
|
|
|
|
,uiLoaded: false
|
2015-11-17 10:34:33 +00:00
|
|
|
|
2022-05-24 10:18:44 +00:00
|
|
|
,initialize: function(gui, formInfo) {
|
2015-11-17 10:34:33 +00:00
|
|
|
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
|
2022-05-24 10:18:44 +00:00
|
|
|
*/
|
|
|
|
,$: function(objectId) {
|
2015-11-17 10:34:33 +00:00
|
|
|
if (this.builder)
|
2022-05-24 10:18:44 +00:00
|
|
|
return this.builder.getById(objectId);
|
2015-11-17 10:34:33 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2015-12-10 13:48:43 +00:00
|
|
|
|
2022-05-24 10:18:44 +00:00
|
|
|
,loadUi: function() {
|
2015-12-10 13:48:43 +00:00
|
|
|
if (!this.isOpen)
|
|
|
|
return;
|
2015-11-17 10:34:33 +00:00
|
|
|
|
2022-05-24 10:18:44 +00:00
|
|
|
var builder = new Vn.Builder();
|
2015-11-17 10:34:33 +00:00
|
|
|
builder.signalData = this;
|
2022-05-24 10:18:44 +00:00
|
|
|
builder.add('conn', this.conn);
|
|
|
|
builder.loadXml('forms/'+ this.formInfo.path +'/ui.xml');
|
2015-11-17 10:34:33 +00:00
|
|
|
|
2022-05-24 10:18:44 +00:00
|
|
|
var res = this.builder = builder.load();
|
2015-11-17 10:34:33 +00:00
|
|
|
this.node = res.$('form');
|
2022-05-24 10:18:44 +00:00
|
|
|
res.link(this);
|
2015-11-17 10:34:33 +00:00
|
|
|
|
2022-05-24 10:18:44 +00:00
|
|
|
var models = res.getByTagName('db-model');
|
2015-11-17 10:34:33 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < models.length; i++)
|
|
|
|
models[i].conn = this.conn;
|
|
|
|
|
2022-05-24 10:18:44 +00:00
|
|
|
var queries = res.getByTagName('db-query');
|
2015-11-17 10:34:33 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < queries.length; i++)
|
|
|
|
queries[i].conn = this.conn;
|
|
|
|
|
2022-05-24 10:18:44 +00:00
|
|
|
if (this.node) {
|
|
|
|
this.gui.setForm(this.node);
|
|
|
|
this.gui.setTitle(res.$('title'));
|
|
|
|
this.gui.setActions(res.$('actions'));
|
|
|
|
this.activate();
|
2015-12-10 13:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.uiLoaded = true;
|
2015-11-17 10:34:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 10:18:44 +00:00
|
|
|
,unloadUi: function() {
|
2015-12-10 13:48:43 +00:00
|
|
|
if (!this.uiLoaded)
|
|
|
|
return;
|
|
|
|
|
2022-05-24 10:18:44 +00:00
|
|
|
if (this.node) {
|
|
|
|
this.deactivate();
|
|
|
|
this.gui.setTitle(null);
|
|
|
|
this.gui.setActions(null);
|
|
|
|
Vn.Node.remove(this.node);
|
|
|
|
this.deactivate();
|
2015-11-17 10:34:33 +00:00
|
|
|
this.node = null;
|
|
|
|
}
|
2022-05-24 10:18:44 +00:00
|
|
|
if (this.builder) {
|
|
|
|
this.builder.unref();
|
2015-11-17 10:34:33 +00:00
|
|
|
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
|
|
|
*/
|
|
|
|
,open: function() {
|
|
|
|
this.close();
|
2015-12-10 13:48:43 +00:00
|
|
|
this.isOpen = true;
|
2022-05-24 10:18:44 +00:00
|
|
|
this.loadUi();
|
2015-12-10 13:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the form is closed.
|
2022-05-24 10:18:44 +00:00
|
|
|
*/
|
|
|
|
,close: function() {
|
2015-12-10 13:48:43 +00:00
|
|
|
if (!this.isOpen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.isOpen = false;
|
2022-05-24 10:18:44 +00:00
|
|
|
this.unloadUi();
|
2015-12-10 13:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the form is activated.
|
2022-05-24 10:18:44 +00:00
|
|
|
*/
|
|
|
|
,activate: function() {}
|
2015-12-10 13:48:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the form is deactivated.
|
2022-05-24 10:18:44 +00:00
|
|
|
*/
|
|
|
|
,deactivate: function() {}
|
2015-12-10 13:48:43 +00:00
|
|
|
|
2022-05-24 10:18:44 +00:00
|
|
|
,_destroy: function() {
|
|
|
|
this.close();
|
|
|
|
this.parent();
|
2015-11-17 10:34:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|