hedera-web/js/vn/param.js

158 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
2017-04-05 14:06:07 +00:00
var VnObject = require ('./object');
var Lot = require ('./lot');
var Type = require ('./type');
2016-09-26 09:28:47 +00:00
module.exports = new Class
({
2017-04-05 14:06:07 +00:00
Extends: VnObject
,Tag: 'vn-param'
2017-04-05 14:06:07 +00:00
,Child: 'param'
,Properties:
{
2017-04-05 14:06:07 +00:00
param:
{
type: Object
,set: function (x)
{
this.link ({_param: x}, {'changed': this._onParamChange});
this._refreshParam ();
}
,get: function ()
{
return this._param;
}
},
2017-04-07 11:00:33 +00:00
name:
{
2015-07-03 05:49:45 +00:00
type: String
,set: function (x)
{
2017-04-07 11:00:33 +00:00
this._name = x;
2017-04-05 14:06:07 +00:00
this._onLotChange ();
}
,get: function ()
{
2017-04-07 11:00:33 +00:00
return this._name;
2017-04-05 14:06:07 +00:00
}
},
value:
{
type: Object
,set: function (x)
{
this._setValue (x, true);
}
,get: function ()
{
return this._value;
}
},
2017-04-05 14:06:07 +00:00
type:
{
type: Type
,set: function (x)
{
this._type = x;
this._onLotChange ();
}
,get: function ()
{
return this._type;
}
},
lot:
{
2017-04-05 14:06:07 +00:00
type: Lot
,set: function (x)
{
2017-04-05 14:06:07 +00:00
this.link ({_lot: x}, {'change': this._onLotChange});
this._onLotChange ();
}
,get: function ()
{
2017-04-05 14:06:07 +00:00
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;
}
}
}
2017-04-05 14:06:07 +00:00
,_lotLock: false
,_paramLock: false
,_value: undefined
2017-04-05 14:06:07 +00:00
,_lot: null
2017-04-07 11:00:33 +00:00
,_name: null
2017-04-05 14:06:07 +00:00
,_type: null
,_oneWay: false
2017-04-05 14:06:07 +00:00
,_onLotChange: function ()
{
2017-04-07 11:00:33 +00:00
if (this._lotLock || !this._name || !this._lot)
2017-04-05 14:06:07 +00:00
return;
2017-04-07 11:00:33 +00:00
var newValue = this._lot.get (this._name, this._type);
2017-04-05 14:06:07 +00:00
this._lotLock = true;
this._setValue (newValue, true);
this._lotLock = false;
}
,_setValue: function (newValue, signal)
{
if (newValue == this._value)
return;
2017-04-05 14:06:07 +00:00
if (newValue instanceof Date)
newValue = newValue.clone ();
this._value = newValue;
2017-04-07 11:00:33 +00:00
if (this._lot && this._name && !this._lotLock && !this._oneWay)
2017-04-05 14:06:07 +00:00
{
this._lotLock = true;
2017-04-07 11:00:33 +00:00
this._lot.set (this._name, newValue);
2017-04-05 14:06:07 +00:00
this._lotLock = false;
}
this._refreshParam ();
if (signal)
this.signalEmit ('changed', newValue);
}
2016-09-26 09:28:47 +00:00
2017-04-05 14:06:07 +00:00
,_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;
}
});