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.
|
|
|
|
**/
|
|
|
|
column:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._columnName = x;
|
|
|
|
this.refresh ();
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
this._columnName;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The form referenced by this param.
|
|
|
|
**/
|
|
|
|
form:
|
|
|
|
{
|
2016-09-26 09:28:47 +00:00
|
|
|
type: Form
|
2015-01-23 13:09:30 +00:00
|
|
|
,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.
|
|
|
|
**/
|
|
|
|
oneWay:
|
|
|
|
{
|
|
|
|
type: Boolean
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._oneWay = x;
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._oneWay;
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,_columnName: null
|
|
|
|
,_form: null
|
2015-07-03 05:49:45 +00:00
|
|
|
,_formLock: false
|
|
|
|
,_columnIndex: -1
|
|
|
|
,_oneWay: false
|
|
|
|
,_formValue: null
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,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);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,onIterChange: function ()
|
|
|
|
{
|
2018-05-16 15:21:15 +00:00
|
|
|
if (this._oneWay && this.value != null)
|
|
|
|
return;
|
|
|
|
|
2015-07-03 05:49:45 +00:00
|
|
|
this._formLock = true;
|
|
|
|
|
|
|
|
var formValue;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
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);
|
2015-01-23 13:09:30 +00:00
|
|
|
else
|
2015-12-10 13:48:43 +00:00
|
|
|
formValue = undefined;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-12-10 13:48:43 +00:00
|
|
|
this.value = formValue;
|
2015-07-03 05:49:45 +00:00
|
|
|
this._formLock = false;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,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);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|