hedera-web/js/db/param.js

116 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
var Form = require ('./form');
module.exports = new Class
({
Extends: Vn.Param
,Tag: 'db-param'
,Parent: 'form'
,Properties:
{
/**
* The form field referenced by this param.
2016-12-20 09:32:17 +00:00
*/
column:
{
type: String
,set: function (x)
{
this._columnName = x;
this.refresh ();
}
,get: function ()
{
this._columnName;
}
},
/**
* The form referenced by this param.
2016-12-20 09:32:17 +00:00
*/
form:
{
2016-09-26 09:28:47 +00:00
type: Form
,set: function (x)
{
this.link ({_form: x},
{
'status-changed': this.onFormChange
,'iter-changed': this.onIterChange
});
this.refresh ();
}
,get: function ()
{
return this._form;
}
2015-07-03 05:49:45 +00:00
},
/**
* Determines whether the link to the form is unidirectional, ie, a
* change in the form updates the parameter but not vice versa.
2016-12-20 09:32:17 +00:00
*/
2015-07-03 05:49:45 +00:00
oneWay:
{
type: Boolean
,set: function (x)
{
this._oneWay = x;
}
,get: function ()
{
return this._oneWay;
}
}
}
,_columnName: null
,_form: null
2015-07-03 05:49:45 +00:00
,_formLock: false
,_columnIndex: -1
,_oneWay: false
,_formValue: null
,initialize: function (props)
{
this.parent (props);
this.on ('changed', this.onChange, this);
}
,refresh: function ()
{
if (this._form)
{
this.onFormChange ();
this.onIterChange ();
}
}
,onFormChange: function ()
{
if (this._columnName != null)
2015-07-03 05:49:45 +00:00
this._columnIndex = this._form.getColumnIndex (this._columnName);
}
,onIterChange: function ()
{
2015-07-03 05:49:45 +00:00
this._formLock = true;
var formValue;
2015-12-10 13:48:43 +00:00
if (this._columnIndex !== -1)
2015-07-03 05:49:45 +00:00
formValue = this._form.getByIndex (this._columnIndex);
else
2015-12-10 13:48:43 +00:00
formValue = undefined;
2015-12-10 13:48:43 +00:00
this.value = formValue;
2015-07-03 05:49:45 +00:00
this._formLock = false;
}
,onChange: function ()
{
2015-07-03 05:49:45 +00:00
if (!this._formLock && this._columnIndex != -1 && !this.oneWay)
this._form.setByIndex (this._columnIndex, this._value);
}
});