CallBackery
view release on metacpan or search on metacpan
lib/CallBackery/qooxdoo/callbackery/source/class/callbackery/ui/form/Auto.js view on Meta::CPAN
* The following widgets are supported: date, text, selectbox
*
* text: { },
* selectBox: { cfg { structure: [ {key: x, title: y}, ...] } },
* date: { }, // following unix tradition, dates are represented in epoc seconds
*
* Populate the new form using the setData method, providing a map
* with the required data.
*
*/
qx.Class.define("callbackery.ui.form.Auto", {
extend : qx.ui.core.Widget,
/**
* @param structure {Array} form structure
* @param layout {Instance} qooxdoo layout for this widget
* @param formRenderer {Class} qooxdoo form render class
* @param plugin {Object} CallBackery (parent) widget this widget is added to
*/
construct : function(structure, layout, formRenderer, plugin) {
this.base(arguments);
this._settingData = 0;
this._setLayout(layout || new qx.ui.layout.Grow());
var form = this._form = new qx.ui.form.Form();
if (plugin) {
plugin.addOwnedQxObject(form, 'Form');
}
this._ctrl = {};
var formCtrl = new qx.data.controller.Form(null, form);
this._boxCtrl = {};
this._keyToFormKey = {};
this._formKeyToKey = {};
this._selectBoxKeyToItem = {};
var tm = this._typeMap = {};
var that = this;
var formKeyIdx = 0;
structure.forEach(s => {
var options = {};
// value binding in qooxdoo does not like keys
// with strange characters ... (like -)
if (s.key) {
formKeyIdx++;
var formKey = s.key.replace(/[^_a-z]/ig,'');
if (this._formKeyToKey[formKey]) {
formKey += String(formKeyIdx);
}
this._keyToFormKey[s.key] = formKey;
this._formKeyToKey[formKey] = s.key;
}
['note','copyOnTap','copyFailMsg','copySuccessMsg'].forEach(prop => {
if (s[prop]){
options[prop] = qx.lang.Type.isString(s[prop])
|| qx.lang.Type.isArray(s[prop]) ?
that.xtr(s[prop]) : s[prop];
}
});
if (s.widget == 'header') {
var header = options.widget =
new qx.ui.basic.Label().set({
font: 'bold'
});
if (s.key) {
form.addOwnedQxObject(header, s.key || s.label);
this._ctrl[s.key] = header;
}
if (s.set){
header.set(s.set);
}
form.addGroupHeader(s.label != null ? this.xtr(s.label) : '', options);
return;
}
if (s.key == null) {
throw new Error('the key property is required');
}
var cfg = s.cfg || {};
var control;
var textWidget = false;
switch(s.widget)
{
case 'date':
control = new qx.ui.form.DateField().set({
dateFormat : new qx.util.format.DateFormat(this.tr("dd.MM.yyyy"))
});
tm[s.key] = 'date';
break;
case 'dateTime':
control = new callbackery.ui.form.DateTime().set({
dateFormat : new qx.util.format.DateFormat(this.tr("dd.MM.yyyy"))
});
tm[s.key] = 'dateTime';
break;
case 'text':
textWidget = true;
case 'time':
control = new qx.ui.form.TextField();
tm[s.key] = 'text';
break;
case 'password':
control = new qx.ui.form.PasswordField();
tm[s.key] = 'text';
break;
case 'textArea':
textWidget = true;
control = new qx.ui.form.TextArea();
tm[s.key] = 'text';
break;
case 'hiddenText':
control = new qx.ui.form.TextField();
control.exclude();
tm[s.key] = 'text';
break;
case 'checkBox':
control = new qx.ui.form.CheckBox();
( run in 0.904 second using v1.01-cache-2.11-cpan-ceb78f64989 )