158 lines
2.5 KiB
JavaScript
158 lines
2.5 KiB
JavaScript
|
|
var VnObject = require ('./object');
|
|
var Lot = require ('./lot');
|
|
var Type = require ('./type');
|
|
|
|
module.exports = new Class
|
|
({
|
|
Extends: VnObject
|
|
,Tag: 'vn-param'
|
|
,Child: 'param'
|
|
,Properties:
|
|
{
|
|
param:
|
|
{
|
|
type: Object
|
|
,set: function (x)
|
|
{
|
|
this.link ({_param: x}, {'changed': this._onParamChange});
|
|
this._refreshParam ();
|
|
}
|
|
,get: function ()
|
|
{
|
|
return this._param;
|
|
}
|
|
},
|
|
key:
|
|
{
|
|
type: String
|
|
,set: function (x)
|
|
{
|
|
this._key = x;
|
|
this._onLotChange ();
|
|
}
|
|
,get: function ()
|
|
{
|
|
return this._key;
|
|
}
|
|
},
|
|
value:
|
|
{
|
|
type: Object
|
|
,set: function (x)
|
|
{
|
|
this._setValue (x, true);
|
|
}
|
|
,get: function ()
|
|
{
|
|
return this._value;
|
|
}
|
|
},
|
|
type:
|
|
{
|
|
type: Type
|
|
,set: function (x)
|
|
{
|
|
this._type = x;
|
|
this._onLotChange ();
|
|
}
|
|
,get: function ()
|
|
{
|
|
return this._type;
|
|
}
|
|
},
|
|
lot:
|
|
{
|
|
type: Lot
|
|
,set: function (x)
|
|
{
|
|
this.link ({_lot: x}, {'change': this._onLotChange});
|
|
this._onLotChange ();
|
|
}
|
|
,get: function ()
|
|
{
|
|
return this._lot;
|
|
}
|
|
},
|
|
/**
|
|
* Determines whether the link to the form is unidirectional, ie, a
|
|
* change in the lot updates the parameter but not vice versa.
|
|
*/
|
|
oneWay:
|
|
{
|
|
type: Boolean
|
|
,set: function (x)
|
|
{
|
|
this._oneWay = x;
|
|
}
|
|
,get: function ()
|
|
{
|
|
return this._oneWay;
|
|
}
|
|
}
|
|
}
|
|
|
|
,_lotLock: false
|
|
,_paramLock: false
|
|
,_value: undefined
|
|
,_lot: null
|
|
,_key: null
|
|
,_type: null
|
|
,_oneWay: false
|
|
|
|
,_onLotChange: function ()
|
|
{
|
|
if (this._lotLock || !this._key || !this._lot)
|
|
return;
|
|
|
|
var newValue = this._lot.get (this._key, this._type);
|
|
|
|
this._lotLock = true;
|
|
this._setValue (newValue, true);
|
|
this._lotLock = false;
|
|
}
|
|
|
|
,_setValue: function (newValue, signal)
|
|
{
|
|
if (newValue == this._value)
|
|
return;
|
|
|
|
if (newValue instanceof Date)
|
|
newValue = newValue.clone ();
|
|
|
|
this._value = newValue;
|
|
|
|
if (this._lot && this._key && !this._lotLock && !this._oneWay)
|
|
{
|
|
this._lotLock = true;
|
|
this._lot.set (this._key, newValue);
|
|
this._lotLock = false;
|
|
}
|
|
|
|
this._refreshParam ();
|
|
|
|
if (signal)
|
|
this.signalEmit ('changed', newValue);
|
|
}
|
|
|
|
,_refreshParam: function ()
|
|
{
|
|
if (this._param && !this._paramLock)
|
|
{
|
|
this._paramLock = true;
|
|
this._param.value = this._value;
|
|
this._paramLock = false;
|
|
}
|
|
}
|
|
|
|
,_onParamChange: function ()
|
|
{
|
|
if (this._paramLock)
|
|
return;
|
|
|
|
this._paramLock = true;
|
|
this._setValue (this._param.value);
|
|
this._paramLock = false;
|
|
}
|
|
});
|