CallBackery
view release on metacpan or search on metacpan
lib/CallBackery/qooxdoo/callbackery/source/class/callbackery/ui/form/Auto.js view on Meta::CPAN
},
/**
* load new data into the data main model
*
* @param data {var} TODOC
* @param relax {var} TODOC
*/
setData : function(data, relax) {
this._setData(this._model, data, relax);
},
/**
* set the data in a selectbox
*
* @param box {var} TODOC
* @param data {var} TODOC
*/
setSelectBoxData : function(box, data) {
let model;
if (data.length == 0) {
model = qx.data.marshal.Json.createModel([ {
title : '',
key : null
}]);
}
else {
data.forEach((item,i) => {
item.title = item.title != null
? this.xtr(item.title)
: null;
});
model = qx.data.marshal.Json.createModel(data);
}
let lookup = {};
model.forEach((item,idx) => {
lookup[item.getKey()] = item;
});
this._selectBoxKeyToItem[box] = lookup;
let ctrl = this._boxCtrl[box];
let oldItem = ctrl.getValue();
let newItem = null;
if (oldItem){
if (oldItem.getKey) {
newItem = lookup[oldItem.getKey()];
}
if (!newItem){
console.warn(`SelectBox ${box} has no entry for ${oldItem.getKey()} selecting first item.`);
}
}
this._settingData++;
ctrl.setModel(model);
ctrl.setValue(newItem);
this._settingData--;
},
/**
* set the data in a combobox
*
* @param box {var} TODOC
* @param widget {var} TODOC
* @param data {var} TODOC
*/
setComboBoxData : function(box, data) {
let ctrl = this._boxCtrl[box];
this._settingData++;
ctrl.setModel(qx.data.marshal.Json.createModel(data));
this._settingData--;
},
/**
* load new data into a model
* if relax is set unknown properties will be ignored
*
* @param model {var} TODOC
* @param data {var} TODOC
* @param relax {var} TODOC
*/
_setData : function(model, data, relax) {
this._settingData++;
for (var key in data) {
var formKey = this._keyToFormKey[key];
if (!formKey) {
continue;
}
var upkey = qx.lang.String.firstUp(formKey);
var setter = 'set' + upkey;
var getter = 'get' + upkey;
var value = data[key];
if (relax && !model[setter]) {
continue;
}
switch(this._typeMap[key])
{
case 'text':
model[setter]((value !== undefined && value !== null) ? String(value) : null);
break;
case 'bool':
if (value === null) {
value = false;
}
model[setter](qx.lang.Type.isBoolean(value) ? value : parseInt(value) != 0);
break;
case 'dateTime':
case 'date':
model[setter](value);
break;
case 'selectBox':
let newItem = this._selectBoxKeyToItem[key][value];
if (!newItem) {
console.warn(`SelectBox ${key} has no entry for ${value} selecting first Item.`);
}
this._boxCtrl[key].setValue(newItem);
( run in 1.951 second using v1.01-cache-2.11-cpan-39bf76dae61 )