0
1
Fork 0
hedera-web-mindshore/js/vn/hash-param.js

151 lines
2.4 KiB
JavaScript
Raw Normal View History

2015-08-17 18:02:14 +00:00
2016-09-26 09:28:47 +00:00
var Object = require ('./object');
var Param = require ('./param');
var Hash = require ('./hash');
module.exports = new Class
2015-08-17 18:02:14 +00:00
({
2016-09-26 09:28:47 +00:00
Extends: Object
2015-08-17 18:02:14 +00:00
,Tag: 'vn-hash-param'
2015-10-14 11:51:43 +00:00
,Child: 'param'
2015-08-17 18:02:14 +00:00
,Properties:
{
param:
{
2016-09-26 09:28:47 +00:00
type: Param
2015-08-17 18:02:14 +00:00
,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._onHashChange ();
}
,get: function ()
{
return this._key;
}
2015-12-10 13:48:43 +00:00
},
value:
{
type: Object
,set: function (x)
{
this._setValue (x, true);
2015-12-10 13:48:43 +00:00
}
,get: function ()
{
return this._value;
}
},
type:
{
type: Object
,set: function (x)
{
this._type = x;
this._onHashChange ();
}
,get: function ()
{
return this._type;
}
2015-08-17 18:02:14 +00:00
}
}
,_hashLock: false
,_paramLock: false
2015-12-10 13:48:43 +00:00
,_value: undefined
2015-08-17 18:02:14 +00:00
,_key: null
2015-12-10 13:48:43 +00:00
,_type: null
2015-08-17 18:02:14 +00:00
,initialize: function (props)
{
this.parent (props);
2016-09-26 09:28:47 +00:00
var listener = Hash.getListener ();
2015-08-17 18:02:14 +00:00
this.link ({_listener: listener}, {'changed': this._onHashChange});
this._onHashChange ();
}
,_onHashChange: function ()
{
if (this._hashLock || !this._key || !this._listener)
2015-08-17 18:02:14 +00:00
return;
2016-09-26 09:28:47 +00:00
var newValue = Hash.get (this._key);
2015-12-10 13:48:43 +00:00
if (newValue === '')
newValue = null;
if (this._type && newValue !== undefined && newValue !== null)
2015-12-10 13:48:43 +00:00
switch (this._type)
{
case Boolean:
newValue = (/^(true|1)$/i).test (newValue);
break;
case Number:
newValue = 0 + new Number (newValue);
break;
}
2015-08-17 18:02:14 +00:00
this._hashLock = true;
this._setValue (newValue, true);
this._hashLock = false;
}
,_setValue: function (newValue, signal)
{
if (newValue == this._value)
return;
this._value = newValue;
if (this._key && !this._hashLock)
2015-08-17 18:02:14 +00:00
{
this._hashLock = true;
var map = {};
map[this._key] = newValue;
2016-09-26 09:28:47 +00:00
Hash.add (map);
this._hashLock = false;
2015-08-17 18:02:14 +00:00
}
this._refreshParam ();
if (signal)
this.signalEmit ('changed', newValue);
2015-08-17 18:02:14 +00:00
}
2015-08-17 18:02:14 +00:00
,_refreshParam: function ()
{
if (this._param && !this._paramLock)
2015-08-17 18:02:14 +00:00
{
this._paramLock = true;
2015-12-10 13:48:43 +00:00
this._param.value = this._value;
this._paramLock = false;
2015-08-17 18:02:14 +00:00
}
}
,_onParamChange: function ()
{
if (this._paramLock)
2015-08-17 18:02:14 +00:00
return;
this._paramLock = true;
this._setValue (this._param.value);
this._paramLock = false;
2015-08-17 18:02:14 +00:00
}
});