hedera-web/js/vn/param.js

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;
}
},
name:
{
type: String
,set: function (x)
{
this._name = x;
this._onLotChange ();
}
,get: function ()
{
return this._name;
}
},
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
,_name: null
,_type: null
,_oneWay: false
,_onLotChange: function ()
{
if (this._lotLock || !this._name || !this._lot)
return;
var newValue = this._lot.get (this._name, 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._name && !this._lotLock && !this._oneWay)
{
this._lotLock = true;
this._lot.set (this._name, 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;
}
});