hedera-web/js/sql/batch.js

145 lines
2.5 KiB
JavaScript
Raw Normal View History

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