2017-04-19 06:16:37 +00:00
|
|
|
|
|
|
|
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
|
2017-04-21 10:53:15 +00:00
|
|
|
,_sourceFields: null
|
2017-04-19 06:16:37 +00:00
|
|
|
|
|
|
|
,_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;
|
2017-04-21 10:53:15 +00:00
|
|
|
var sourceFields = [];
|
2017-04-19 06:16:37 +00:00
|
|
|
|
|
|
|
for (var field in params)
|
|
|
|
if (this._fields.indexOf (field) === -1
|
|
|
|
&& this._params[field] !== params[field])
|
|
|
|
{
|
|
|
|
this._params[field] = params[field];
|
2017-04-21 10:53:15 +00:00
|
|
|
sourceFields.push (field);
|
2017-04-19 06:16:37 +00:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|