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

157 lines
2.7 KiB
JavaScript

var Component = require('vn/component');
module.exports = new Class({
Extends: Component
,Implements: Vn.ParamIface
,Tag: 'htk-field'
,Child: 'param'
,Properties: {
value: {
type: String
,set: function(x) {
if (Vn.Value.compare(x, this._value))
return;
if (x instanceof Date)
x = x.clone();
this.valueChanged(x);
this.putValue(x);
this._notifyChanges();
}
,get: function() {
return this._value;
}
},
param: {
type: Vn.ParamIface
,set: function(x) {
this._setParam(x);
}
,get: function() {
return this._param;
}
},
lot: {
type: Vn.LotIface
,set: function(x) {
this._setLot(x);
}
,get: function() {
return this._lot;
}
},
name: {
type: String
,set: function(x) {
this._setName(x);
}
,get: function() {
return this._name;
}
},
oneWay: {
type: Boolean
,set: function(x) {
this._oneWay = x;
}
,get: function() {
return this._oneWay;
}
},
oneTime: {
type: Boolean
,set: function(x) {
this._oneTime = x;
}
,get: function() {
return this._oneTime;
}
},
editable: {
type: Boolean
,set: function(x) {
if (x != this._editable) {
this._editable = x;
this.setEditable(x);
}
}
,get: function() {
return this._editable;
}
},
form: {
type: Db.Iterator
,set: function(x) {
this.lot = x;
}
,get: function() {
return this._lot;
}
},
column: {
type: String
,set: function(x) {
this.name = x;
}
,get: function() {
return this._name;
}
},
conditionalFunc: {
type: Function
,value: null
}
}
,_editable: true
,_lockField: false
,_setValue: function(newValue) {
if (!this._putValue(newValue))
return;
if (!this._lockField)
this.putValue(newValue);
if (this.conditionalFunc)
this.conditionalFunc(this, newValue);
const node = this.node;
if (node && node.nodeType === Node.ELEMENT_NODE)
node.classList.toggle('filled', newValue !== undefined);
this._notifyChanges();
}
/**
* 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
*/
,setEditable: function() {}
/**
* 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
*/
,putValue: function() {}
/**
* Protected method that should be called from class childs when the value
* on the associated entry changes.
*
* @param {Object} value The new entry value
*/
,valueChanged: function(value) {
this._lockField = true;
this._setValue(value);
this._lockField = false;
}
});