0
1
Fork 0
hedera-web-mindshore/js/vn/lot-query.js

129 lines
1.8 KiB
JavaScript

var Lot = require ('./lot');
var LotIface = require ('./lot-iface');
var Klass = new Class ();
module.exports = Klass;
var Type =
{
INCLUDE: 1,
EXCLUDE: 2
};
Klass.extend
({
Type: Type
});
Klass.implement
({
Extends: Lot
,Tag: 'vn-lot-query'
,Properties:
{
fields:
{
type: Array
,set: function (x)
{
this._fields = x;
this._onSourceChange ();
}
,get: function ()
{
return this._fields;
}
},
source:
{
type: LotIface
,set: function (x)
{
this.link ({_source: x}, {change: this._onSourceChange});
this._onSourceChange ();
}
,get: function ()
{
return this._source;
}
},
type:
{
enumType: Type
,set: function (x)
{
this._type = x;
this._onSourceChange ();
}
,get: function ()
{
return this._type;
}
}
}
,_fields: null
,_source: null
,_type: Type.INCLUDE
,_sourceFields: null
,_onSourceChange: function ()
{
var changed = false;
var params = this._source ? this._source.params : {};
if (this._fields)
switch (this._type)
{
case Type.EXCLUDE:
changed = this.typeExclude (params);
break;
default:
changed = this.typeInclude (params);
}
else
changed = true;
if (changed)
this.changed ();
}
,typeInclude: function (params)
{
var changed = false;
var fields = this._fields;
for (var i = fields.length; i--;)
{
var field = fields[i];
if (this._params[field] !== params[field])
{
this._params[field] = params[field];
changed = true;
}
}
return changed;
}
,typeExclude: function (params)
{
var changed = false;
var sourceFields = [];
for (var field in params)
if (this._fields.indexOf (field) === -1
&& this._params[field] !== params[field])
{
this._params[field] = params[field];
sourceFields.push (field);
changed = true;
}
return changed;
}
});