Commit d62aeda0 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update UserDataMultiDefault in order to use Event.getHistoryDataConfig.

parent 8840eb54
......@@ -32,6 +32,11 @@ Ext.define('Event', {
*
* @return {Object}
*
* {
* sourceConfig: Object,
* defaultValues: Object
* }
*
*/
getHistoryDataConfig: function (events, idEvent) {
......@@ -39,7 +44,8 @@ Ext.define('Event', {
var record = events.findRecord("EventsId", idEvent),
eventData = record.get("EventsData"),
defaultValues = {},
sourceConfig = {};
sourceConfig = {},
obj;
Ext.Object.each(eventData, function (property) {
......@@ -128,6 +134,11 @@ Ext.define('Event', {
defaultValues[property] = defaultValue;
});
return sourceConfig;
obj = {
"defaultValues": defaultValues,
"sourceConfig": sourceConfig
};
return obj;
}
});
......@@ -55,7 +55,6 @@ Ext.define('Event.form.field.UserDataMultiDefault', {
// private attributes
combo: null,
lastKey: undefined,
lastEvent: undefined,
// jshint strict: false
......@@ -83,141 +82,21 @@ Ext.define('Event.form.field.UserDataMultiDefault', {
// jshint strict: true
//
// build the source configuration for the Ext.grid.property.Grid.
// It defined the type for each property and the editor widget.
//
// @param {Ext.data.Model} record
// The record associated to the selected event.
// The attribute EventsData contains the definition of the user data block.
//
// @return {Object} the grid property configuration and default values
// @return {Object} return.sourceConfig
// the editor for each property.
//
// @return {Object} return.defaultValues
// the default value for each property.
//
buildSourceConfig: function (record) {
"use strict";
var me = this,
model = record.get(me.dictFieldData) || null,
defaultValues = {},
sourceConfig = {};
if (!model) {
return {defaultValues: {}, sourceConfig: {}};
}
Ext.Object.each(model, function (property) {
var defaultValue = model[property].value || null,
type = model[property].type || null,
editor,
li,
map;
sourceConfig[property] = {type: type};
switch (type) {
case 'boolean':
defaultValue = Boolean(defaultValue);
break;
case 'date':
defaultValue = new Date(defaultValue);
editor = Ext.create('Ext.form.field.Date', {
anchor: "100%",
format: 'Y-m-dTH:i:s',
useStrict: true
});
sourceConfig[property].editor = editor;
break;
case 'float':
defaultValue = Number(defaultValue);
editor = Ext.create('Ext.form.field.Number', {
decimalPrecision: 3,
decimalSeparator: '.'
});
sourceConfig[property].editor = editor;
break;
case 'integer':
defaultValue = Number(defaultValue);
editor = Ext.create('Ext.form.field.Number', {
allowDecimals: false,
allowExponential: false
});
sourceConfig[property].editor = editor;
break;
case 'reference':
map = defaultValue.split('.');
editor = Ext.create('Dbui.form.field.ComboBoxUserReset', {
store: map[0] + 'Store',
displayField: Dbui.encodeField(map[0], map[1]),
valueField: Dbui.encodeField(map[0], map[1])
});
defaultValue = null;
sourceConfig[property].editor = editor;
break;
case 'string':
//
// the editor is a combobox when the default
// is a list of values.
//
li = Ext.JSON.decode(defaultValue, true);
if (Ext.isArray(li)) {
defaultValue = li.length ? li[0] : null;
li.forEach(function (value, index) {
li[index] = {key: value, value: value};
});
editor = Ext.create('Ext.form.field.ComboBox', {
store: {
fields: ['key', 'value'],
data: li,
xtype: 'store'
},
displayField: 'key',
valueField: 'value'
});
sourceConfig[property].editor = editor;
}
break;
}
defaultValues[property] = defaultValue;
});
return {defaultValues: defaultValues, sourceConfig: sourceConfig};
},
//
// supersede the base class method to deal with the data type
//
// @param {Ext.form.field.ComboBox} combo
// @param {Ext.data.Model} record
//
//
onComboBoxSelect: function (combo, record) {
onComboBoxSelect: function (combo) {
"use strict";
var me = this,
cfg;
cfg = me.buildSourceConfig(record);
currentKey = combo.getValue(),
cfg = Event.getHistoryDataConfig(me.store, currentKey);
// load the current value if the key is back to the original one
if (combo.getValue() === me.lastKey) {
if (currentKey === me.lastKey) {
me.grid.setSource(me.value, cfg.sourceConfig);
// load a new set of values
......@@ -239,7 +118,7 @@ Ext.define('Event.form.field.UserDataMultiDefault', {
var me = this,
combo = me.combo || null,
form = me.up('xform, form').getForm(),
cfg, formRecord, rawValue, record;
cfg, formRecord, rawValue;
// is the form ready
if (!form) {
......@@ -291,11 +170,9 @@ Ext.define('Event.form.field.UserDataMultiDefault', {
value = {};
}
record = me.store.findRecord(me.dictFieldIdEvent, me.lastKey);
me.lastEvent = record.get(me.dictFieldEvent);
// get the configuration for the Ext.grid.property.Grid
cfg = me.buildSourceConfig(record);
// for the selected event
cfg = Event.getHistoryDataConfig(me.store, me.lastKey);
// fill the property grid
// NOTE: let the editor take care of the data type conversion
......
......@@ -161,8 +161,8 @@ Ext.define("Event.grid.RowHistoryData", {
var me = this,
events = me.eventStore,
idEvent= me.historyId_events,
sourceConfig = Event.getHistoryDataConfig(events, idEvent);
cfg = Event.getHistoryDataConfig(events, idEvent);
me.setSource(value, sourceConfig);
me.setSource(value, cfg.sourceConfig);
}
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment