2016-09-26 09:28:47 +00:00
|
|
|
|
|
|
|
var Object = require ('./object');
|
|
|
|
var Value = require ('./value');
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* A map container for many Sql.Object
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2016-09-26 09:28:47 +00:00
|
|
|
module.exports = new Class
|
2015-01-23 13:09:30 +00:00
|
|
|
({
|
2016-09-26 09:28:47 +00:00
|
|
|
Extends: Object
|
2015-01-23 13:09:30 +00:00
|
|
|
,Tag: 'sql-batch'
|
2015-07-07 15:27:47 +00:00
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
blocked:
|
|
|
|
{
|
|
|
|
type: Boolean
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._blocked = x;
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._blocked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-07-28 19:14:26 +00:00
|
|
|
,objects: {}
|
2015-07-07 15:27:47 +00:00
|
|
|
,_blocked: false
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,loadXml: function (builder, node)
|
|
|
|
{
|
|
|
|
this.parent (builder, node);
|
|
|
|
|
|
|
|
var childs = node.childNodes;
|
|
|
|
|
|
|
|
for (var i = 0; i < childs.length; i++)
|
|
|
|
if (childs[i].tagName && childs[i].tagName.toLowerCase () == 'item')
|
|
|
|
{
|
|
|
|
var object;
|
|
|
|
var id = childs[i].getAttribute ('name');
|
|
|
|
|
|
|
|
if (id)
|
|
|
|
{
|
2015-11-09 08:14:33 +00:00
|
|
|
if (object = builder.getById (childs[i].getAttribute ('param')))
|
2015-01-23 13:09:30 +00:00
|
|
|
this.addParam (id, object);
|
2015-11-09 08:14:33 +00:00
|
|
|
else if (object = builder.getById (childs[i].getAttribute ('object')))
|
2015-01-23 13:09:30 +00:00
|
|
|
this.addObject (id, object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,get: function (id)
|
|
|
|
{
|
2015-07-28 19:14:26 +00:00
|
|
|
if (this.objects[id])
|
|
|
|
return this.objects[id];
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
,add: function (id)
|
|
|
|
{
|
2015-07-28 19:14:26 +00:00
|
|
|
if (!this.objects[id])
|
|
|
|
this.objects[id] = null;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-07-28 19:14:26 +00:00
|
|
|
,_addObject: function (id, object)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-07-28 19:14:26 +00:00
|
|
|
this.remove (id);
|
|
|
|
this.objects[id] = object;
|
|
|
|
object.on ('changed', this.emitChanged, this);
|
|
|
|
this.emitChanged ();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,addObject: function (id, object)
|
|
|
|
{
|
2015-07-28 19:14:26 +00:00
|
|
|
this._addObject (id, object.ref ());
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,addValue: function (id, value)
|
|
|
|
{
|
2015-07-28 19:14:26 +00:00
|
|
|
this._addObject (id,
|
2016-09-26 09:28:47 +00:00
|
|
|
new Value ({value: value}));
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-11-05 07:30:19 +00:00
|
|
|
|
|
|
|
,addValues: function (values)
|
|
|
|
{
|
|
|
|
for (var id in values)
|
|
|
|
this.addValue (id, values[id]);
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,addParam: function (id, param)
|
|
|
|
{
|
2015-07-28 19:14:26 +00:00
|
|
|
this._addObject (id,
|
2016-09-26 09:28:47 +00:00
|
|
|
new Value ({param: param}));
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2015-11-19 13:57:23 +00:00
|
|
|
,getValue: function (id)
|
|
|
|
{
|
|
|
|
var object = this.objects[id];
|
|
|
|
|
2016-09-26 09:28:47 +00:00
|
|
|
if (object instanceof Value)
|
2015-11-19 13:57:23 +00:00
|
|
|
return object.value;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-11-05 07:30:19 +00:00
|
|
|
,addParams: function (params)
|
|
|
|
{
|
|
|
|
for (var id in params)
|
|
|
|
this.addParam (id, params[id]);
|
|
|
|
}
|
|
|
|
|
2015-07-28 19:14:26 +00:00
|
|
|
,remove: function (id)
|
|
|
|
{
|
|
|
|
if (this.objects[id])
|
|
|
|
{
|
|
|
|
this._unrefObject (this.objects[id]);
|
|
|
|
delete this.objects[id];
|
|
|
|
}
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-02-08 15:38:38 +00:00
|
|
|
,block: function ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-07-07 15:27:47 +00:00
|
|
|
this._blocked = true;
|
2015-02-08 15:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,unblock: function ()
|
|
|
|
{
|
2015-07-07 15:27:47 +00:00
|
|
|
this._blocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
,emitChanged: function ()
|
|
|
|
{
|
|
|
|
if (!this._blocked)
|
|
|
|
this.signalEmit ('changed');
|
2015-02-08 15:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,changed: function ()
|
|
|
|
{
|
2015-07-07 15:27:47 +00:00
|
|
|
this.signalEmit ('changed');
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,isReady: function ()
|
|
|
|
{
|
2015-07-28 19:14:26 +00:00
|
|
|
for (var id in this.objects)
|
|
|
|
if (!(this.objects[id] && this.objects[id].isReady ()))
|
2015-01-23 13:09:30 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-07-28 19:14:26 +00:00
|
|
|
|
|
|
|
,_unrefObject: function (object)
|
|
|
|
{
|
|
|
|
if (object)
|
|
|
|
{
|
|
|
|
object.disconnect ('changed', this.emitChanged, this);
|
|
|
|
object.unref ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-17 18:02:14 +00:00
|
|
|
,_destroy: function ()
|
2015-07-28 19:14:26 +00:00
|
|
|
{
|
|
|
|
for (var id in this.objects)
|
|
|
|
this._unrefObject (this.objects[id]);
|
2015-08-17 18:02:14 +00:00
|
|
|
|
2015-07-28 19:14:26 +00:00
|
|
|
this.parent ();
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
});
|