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

Update UserDataMultiDefault with a new design to ease the maintenance.

parent 01e0e067
......@@ -9,11 +9,13 @@
#-------------------------------------------------------------------------------
fieldsModifier = dbui.FieldsModifier('history')
fieldsModifier.configure_field('id_events', itemId='keyid_events')
fieldsModifier.configure_field('data',
comboBoxItemId='keyid_events',
dictField='EventsData',
dictFieldData='EventsData',
dictFieldEvent='EventsEvent',
dictFieldIdEvent='EventsId',
formFieldIdEvent='HistoryId_events',
store='eventsStore',
trUndefined=undef,
xtype='xuserdatamultidefault')
fieldsModifier.configure_field('start_date', flex=1)
......
/**
* A dictionary handling several user data block definition.
* It is linked to a ComboBox allowing to select the event and
* its user data block.
* It is linked to a ComboBox and to a store. The ComboBox allows to select
* the event while the definition of its data block is found in the store.
*
* The user data block is rendered as a Ext.grid.property.Grid.
* It is seen as a series of properties with their values.
......@@ -14,9 +14,75 @@
*/
Ext.define('TrackEvents.form.field.UserDataMultiDefault', {
extend: 'Dbui.form.field.DictMultiDefault',
extend: 'Dbui.form.field.Dict',
alias: 'widget.xuserdatamultidefault',
/**
* @cfg {Ext.data.Store/String} store (required)
* the store contains the definition of the event, namely a key
* and the configuration of the data block
*
*/
/**
* @cfg {String} formFieldIdEvent (required)
* The form containing this widget is loaded with a record.
* It contains the key associated to the select event.
* The formFieldEvent is the field containing this key.
* This also the name of the ComboBox field in the form.
*/
/**
* @cfg {String} dictFieldData (required)
* The field in the store which contains the data block configuration.
*/
/**
* @cfg {String} dictFieldEvent (required)
* The field in the store whihch contains the event name.
*/
/**
* @cfg {String} dictFieldIdEvent (required)
* The field in the store whihch contains the event key.
*/
/**
* @cfg {String} trUndefined (required)
* transaltion of the keyword "undefined" used in the database
*/
// private attributes
combo: null,
lastKey: undefined,
lastEvent: undefined,
// jshint strict: false
// private method requests by the component model of ExtJS
initComponent: function () {
var me = this;
// instantiate the base class
me.callParent(arguments);
// instantiate the store containing the relation
// between the key and the data block configuration
me.store = Dbui.getStore(me.store);
},
// private method requests by the component model of ExtJS
beforeDestroy: function () {
var me = this;
me.combo.un('select', me.onComboBoxSelect, me);
me.callParent(arguments);
},
// jshint strict: true
//
// build the source configuration for the Ext.grid.property.Grid.
// It defined the type for each property and the editor widget.
......@@ -37,7 +103,7 @@ Ext.define('TrackEvents.form.field.UserDataMultiDefault', {
"use strict";
var me = this,
model = record.get(me.dictField) || null,
model = record.get(me.dictFieldData) || null,
defaultValues = {},
sourceConfig = {};
......@@ -162,8 +228,9 @@ Ext.define('TrackEvents.form.field.UserDataMultiDefault', {
},
//
// supersede the base class method in order to deal with the
// data type of the user data block
// Load the value in the field.
// It is usualy call when the form is loaded.
// Reference key and data block are determined.
//
setValue: function (value) {
......@@ -171,38 +238,68 @@ Ext.define('TrackEvents.form.field.UserDataMultiDefault', {
var me = this,
combo = me.combo || null,
cfg,
record;
previousEvent = me.lastEvent,
undef = me.trUndefined,
cfg, form, formRecord, rawValue, record;
// link me to the ComboBox
if (value && !combo) {
if (!combo) {
combo = me.up('xform, form').down('#' + me.comboBoxItemId);
}
// The comboBox field is identidied by its name, e.g HistororyId_events
if (!combo) {
form = me.up('xform, form').getForm();
me.combo = form.findField(me.formFieldIdEvent);
me.combo.on('select', me.onComboBoxSelect, me);
}
// keep track of the value load in the ComboBox
// replace empty string by empty dictionary
if (combo) {
me.lastKey = combo.getValue();
// protection
// in the initialization phase rawValue is an empty string
rawValue = me.combo.getRawValue();
if (rawValue.length === 0) {
return;
}
if (!value) {
value = {};
}
formRecord = me.up('xform, form').getForm().getRecord();
// get the configuration for the Ext.grid.property.Grid
record = combo.findRecordByValue(combo.getValue());
// rather complicated logic to find the correct grid configuration
//
// NOTE ExtJS 6
// The ComboBox behave strangely in that configuration
// The method ComboBox.getValue() always return 1
// The property value and rawValue refer to was have been select previously
// Therefore a complexe logic is required to solve all case
//
if ((previousEvent === undef && rawValue === undef) || formRecord === undefined) {
me.lastKey = 1;
value = {};
if (record !== false) {
cfg = me.buildSourceConfig(record);
} else if (previousEvent !== undefined && rawValue === undef) {
me.lastKey = 1;
value = {};
// fill the property grid
// NOTE: let the editor take care of the data type conversion
// when the user data block definition change
me.grid.setSource(value, cfg.sourceConfig);
}
} else if (previousEvent === rawValue) {
me.lastKey = formRecord.get(me.formFieldIdEvent);
} else if (previousEvent === undefined && formRecord !== null) {
me.lastKey = formRecord.get(me.formFieldIdEvent);
} else if (previousEvent !== undefined && rawValue !== undefined) {
me.lastKey = formRecord.get(me.formFieldIdEvent);
} else {
me.lastKey = 1;
value = {};
}
record = me.store.findRecord(me.dictFieldIdEvent, me.lastKey);
me.lastEvent = record.get(me.dictFieldEvent);
// build the configuration of the Ext.grid.property.Grid
cfg = me.buildSourceConfig(record);
// fill the property grid
// NOTE: let the editor take care of the data type conversion
// when the user data block definition change
me.grid.setSource(value, cfg.sourceConfig);
// the standard way to set the value for a field
// extract from Ext.form.field.Base
return me.mixins.field.setValue.call(me, value);
......
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