2016-09-26 09:28:47 +00:00
|
|
|
|
|
|
|
var Form = require ('./form');
|
|
|
|
|
|
|
|
module.exports = new Class
|
2015-01-23 13:09:30 +00:00
|
|
|
({
|
|
|
|
Extends: Vn.Param
|
|
|
|
,Tag: 'db-param'
|
|
|
|
,Parent: 'form'
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The form field referenced by this param.
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-01-23 13:09:30 +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
|
|
|
*/
|
2015-01-23 13:09:30 +00:00
|
|
|
form:
|
|
|
|
{
|
2016-09-26 09:28:47 +00:00
|
|
|
type: Form
|
2015-01-23 13:09:30 +00:00
|
|
|
,set: function (x)
|
|
|
|
{
|
2017-03-30 11:44:53 +00:00
|
|
|
this.link ({_set: x},
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2017-03-30 11:44:53 +00:00
|
|
|
'change': this.onSetChange
|
2015-01-23 13:09:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.refresh ();
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
2017-03-30 11:44:53 +00:00
|
|
|
return this._set;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,_columnName: null
|
2017-03-30 11:44:53 +00:00
|
|
|
,_set: null
|
|
|
|
,_setLock: false
|
2015-07-03 05:49:45 +00:00
|
|
|
,_oneWay: false
|
2017-03-30 11:44:53 +00:00
|
|
|
,_setValue: null
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,initialize: function (props)
|
|
|
|
{
|
|
|
|
this.parent (props);
|
|
|
|
this.on ('changed', this.onChange, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
,refresh: function ()
|
|
|
|
{
|
2017-03-30 11:44:53 +00:00
|
|
|
if (this._set)
|
|
|
|
this.onSetChange ();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 11:44:53 +00:00
|
|
|
,onSetChange: function ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2017-03-30 11:44:53 +00:00
|
|
|
this._setLock = true;
|
|
|
|
var formValue = this._set.get (this._columnName);
|
|
|
|
this.value = formValue;
|
|
|
|
this._setLock = false;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,onChange: function ()
|
|
|
|
{
|
2017-03-30 11:44:53 +00:00
|
|
|
if (!this._setLock && this._columnName && !this.oneWay)
|
|
|
|
this._set.set (this._columnName, this._value);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|