0
1
Fork 0
hedera-web-mindshore/js/htk/field.js

135 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-05-27 13:38:06 +00:00
var Widget = require('./widget');
2016-09-26 09:28:47 +00:00
2019-05-27 13:38:06 +00:00
module.exports = new Class({
2016-09-26 09:28:47 +00:00
Extends: Widget
,Tag: 'htk-field'
,Child: 'param'
,Properties:
{
2019-05-27 13:38:06 +00:00
value: {
2015-07-03 05:49:45 +00:00
type: String
2019-05-27 13:38:06 +00:00
,set: function(x) {
if (Vn.Value.compare(x, this._value))
return;
if (x instanceof Date)
2019-05-27 13:38:06 +00:00
x = x.clone();
2019-05-27 13:38:06 +00:00
this.valueChanged(x);
this.putValue(x);
}
2019-05-27 13:38:06 +00:00
,get: function(x) {
return this._value;
}
},
2019-05-27 13:38:06 +00:00
param: {
type: Vn.Param
2019-05-27 13:38:06 +00:00
,set: function(x) {
this.link({_param: x}, {'changed': this.onParamChange});
this.onParamChange();
}
2019-05-27 13:38:06 +00:00
,get: function() {
return this._param;
}
},
2019-05-27 13:38:06 +00:00
editable: {
type: Boolean
2019-05-27 13:38:06 +00:00
,set: function(x) {
if (x != this._editable) {
this._editable = x;
2019-05-27 13:38:06 +00:00
this.setEditable(x);
}
}
2019-05-27 13:38:06 +00:00
,get: function() {
return this._editable;
}
},
2019-05-27 13:38:06 +00:00
form: {
2015-11-19 13:57:23 +00:00
type: Db.Iterator
2019-05-27 13:38:06 +00:00
,set: function(x) {
this._form = x;
2019-05-27 13:38:06 +00:00
this.bindToForm();
}
,get: function() {
return this._form;
}
},
2019-05-27 13:38:06 +00:00
column: {
type: String
2019-05-27 13:38:06 +00:00
,set: function(x) {
this._paramName = x;
2019-05-27 13:38:06 +00:00
this.bindToForm();
}
,get: function() {
return this._paramName;
}
},
2019-05-27 13:38:06 +00:00
conditionalFunc: {
type: Function
,value: null
}
}
,_value: undefined
,_param: null
,_editable: true
,_blockParamChange: false
,_blockValueChange: false
2019-05-27 13:38:06 +00:00
,onParamChange: function() {
if (!this._blockValueChange) {
this._blockParamChange = true;
this.value = this._param.value;
this._blockParamChange = false;
}
}
2019-05-27 13:38:06 +00:00
,bindToForm: function() {
if (this._form && this._paramName)
2016-09-26 09:28:47 +00:00
this.param = new Db.Param
({
form: this._form
,column: this._paramName
});
}
/**
* Virtual method that must be implemented by class childs to set the entry
* editable.
*
* @param {Boolean} editable Whether the user is allowed to edit the entry
**/
2019-05-27 13:38:06 +00:00
,setEditable: function(editable) {}
/**
* Virtual method that must be implemented by class childs to put the value
* on the associated entry.
*
* @param {Object} value The new value for the entry
**/
2019-05-27 13:38:06 +00:00
,putValue: function(value) {}
/**
* Protected method that should be called from class childs when the value
* on the associated entry changes.
*
* @param {Object} value The new entry value
**/
2019-05-27 13:38:06 +00:00
,valueChanged: function(value) {
this._value = value;
if (this.conditionalFunc)
2019-05-27 13:38:06 +00:00
this.conditionalFunc(this, value);
2019-05-27 13:38:06 +00:00
if (this._param && !this._blockParamChange) {
this._blockValueChange = true;
this._param.value = value;
this._blockValueChange = false;
}
2019-05-27 13:38:06 +00:00
this.signalEmit('changed');
}
});