Commit 2110e578 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Bugs fixed and imporvement in UserData, UserDataMultiDefault and the related controller.

parent 70087bc1
......@@ -6,8 +6,8 @@ A collection of tools specific to the applications
import json
import plugin_dbui
USER_DATA_TYPES = ('boolean', 'date', 'number', 'string')
MSG = T(" - %s entry(ies) modified in the history table. <br>"
" - DO NOT FORGET TO MODIFIED THE REPORT CONFIGURATION.")
def userModelConsistency():
""" A user data block is associated to each event.
......@@ -23,14 +23,6 @@ def userModelConsistency():
event = request.vars.fieldEvent
model = json.loads(request.vars.fieldData)
# keep in model default values but remove type definition
for key in model:
if not isinstance(model[key], (str, unicode)):
continue
if model[key].lower().strip() in USER_DATA_TYPES:
model[key] = None
# build a map of the modified keys.
# each operation is a list containing (action, old key, new key).
# the action is equal to: add, destroy, update
......@@ -68,26 +60,38 @@ def userModelConsistency():
if id_event == None:
return
# setup the default values
# string using set and reference need a special treatment
for key in model:
value = model[key]['value']
type = model[key]['type']
if value:
if type == "string" and value[0] == "[" and value[-1] == "]":
li = json.loads(value)
model[key]['value'] = (li[0] if li else None)
elif type == "reference":
model[key]['value'] = None
# scan and modify the history table
# NOTE: the delete of old key is implicit
# the delete of old key is implicit since they are not copied
query = db.history.id_events == id_event
rows = db(query).select()
for row in rows:
data = {}
rd = row.data
# copy existing key or add new key
for key in model:
# copy existing key
if key in row.data:
data[key] = row.data[key]
# add new key
else:
data[key] = model[key]
data[key] = (rd[key] if key in rd else model[key]['value'])
# modify key name
for oldkey, newkey in update_keys.iteritems():
if oldkey in row.data:
data[newkey] = row.data[oldkey]
if oldkey in rd:
data[newkey] = rd[oldkey]
db(db.history.id == row.id).update(data=data)
return T('%s entries modified in the history table.') % len(rows)
\ No newline at end of file
return MSG % len(rows)
\ No newline at end of file
# -*- coding: utf-8 -*-
{
'': '',
' - %s entry(ies) modified in the history table. <br> - DO NOT FORGET TO MODIFIED THE REPORT CONFIGURATION.': " - %s entrée(s) modifiée(s) dans l'historique. <br> - N'OUBLIEZ PAS DE MODIFIER LES RAPPORTS.",
'%s between %s and %s': '%s du %s au %s',
'%s entries modified in the history table.': "%s entrés ont été modifié dans l'historique.",
'%s in %s': '%s en %s',
......
......@@ -7,7 +7,6 @@ Ext.define('MyApp.locale.form.field.UserData', {
override : "MyApp.form.field.UserData",
textAddMenu: "ajouter",
textAddTitle: "Entrer une nouvelle propriété",
textDefault: "défault",
textDestroyMenu: "Détruire",
textDestroyTitle: "Etes vous certain de détruire la propriété",
textErrorTitle: "Erreur ...",
......@@ -17,7 +16,8 @@ Ext.define('MyApp.locale.form.field.UserData', {
textReTitle: "La propriété est mal formée...",
textReMsg: "Le nom doit contenir les caractères [A-Za-z0-9_]",
textUpdateMenu: "Modifier",
textUpdateTitle: "Modifier la propriété"
textUpdateTitle: "Modifier la propriété",
textValue: "valeur"
});
Ext.define('MyApp.locale.form.plugin.UserDataConsistency', {
......
......@@ -28,7 +28,6 @@ Ext.define('MyApp.form.field.UserData', {
// private properties for internationalization
textAddMenu: 'Add',
textAddTitle: 'Please enter the new property',
textDefault: 'default',
textDestroyMenu: 'Delete',
textDestroyTitle: 'Are you sure to destroy the property',
textErrorTitle: 'Error ...',
......@@ -39,13 +38,13 @@ Ext.define('MyApp.form.field.UserData', {
textType: 'type',
textUpdateMenu: 'Update',
textUpdateTitle: 'Modify the property name',
textValue: 'value',
// private method requests by the component model of ExtJS
initComponent: function () {
var me = this,
grid,
menu,
store;
// the store used by the grid
......@@ -75,7 +74,7 @@ Ext.define('MyApp.form.field.UserData', {
menuDisabled: true,
sortable: false
}, {
text: me.textDefault,
text: me.textValue,
dataIndex: 'value',
editor: 'textfield',
flex: 1,
......@@ -167,7 +166,7 @@ Ext.define('MyApp.form.field.UserData', {
var me = this,
data = {};
me.store.each(function(record) {
me.store.each(function (record) {
data[record.get('property')] = {
type: record.get('type'),
value: record.get('value')
......@@ -201,7 +200,7 @@ Ext.define('MyApp.form.field.UserData', {
}
// check that the property is unique
if (store.find('property', text) !== -1) {
if (store.findExact('property', text) !== -1) {
Ext.Msg.alert(me.textErrorTitle, me.textErrorMsg);
return;
}
......@@ -307,7 +306,7 @@ Ext.define('MyApp.form.field.UserData', {
if (btn === 'ok') {
// check that the property is unique
if (store.find('property', text) !== -1) {
if (store.findExact('property', text) !== -1) {
Ext.Msg.alert(me.textErrorTitle, me.textErrorMsg);
return;
}
......@@ -324,12 +323,11 @@ Ext.define('MyApp.form.field.UserData', {
//
// build the editor configuration for the type column
//
typeEditor: function() {
typeEditor: function () {
"use strict";
var me = this,
editor,
var editor,
store;
store = {
......@@ -393,7 +391,7 @@ Ext.define('MyApp.form.field.UserData', {
// load the grid with fresh value
if (value) {
Object.getOwnPropertyNames(data).forEach(function(property) {
Ext.Object.each(data, function (property) {
record = model.create();
record.set('property', property);
record.set('type', data[property].type);
......
/**
* Handle the different setting for the user data block.
* The data type and conversion are set up properly.
* A dictionary handling several user data block definition.
* It is linked to a ComboBox allowing to select the event and
* its user data block.
*
* The user data block is rendered as a Ext.grid.property.Grid.
* It is seen as a series of properties with their values.
*
* Each property has a type, boolean, date, float, integer, reference
* or string. The widget to enter or to modify a value depends on the type.
* It can also convert data when the definition of the user data block
* change. Value is equal to null when the conversion failed.
*
*/
// require to load the base class when running in debug mode
Ext.Loader.setPath('App', '../static/plugin_dbui/src');
Ext.define('MyApp.form.field.UserDataMultiDefault', {
......@@ -11,32 +21,40 @@ Ext.define('MyApp.form.field.UserDataMultiDefault', {
alias: 'widget.xuserdatamultidefault',
//
// supersede the base class method
// handle properly the data type setup in the used data block
// build the source configuration for the Ext.grid.property.Grid.
// It defined the type for each property and the editor widget.
//
// @param {Ext.form.field.ComboBox} combo
// @param {Ext.data.Model[]} records
// @param {Object} eOpts
// @param {Ext.data.Model} record
// The record associated to the selected event.
// The attribute EventsData contains the definition of the user data block.
//
onComboBoxSelect: function (combo, records, eOpts) {
// @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 = records.length ? records[0].get(me.dictField) : null,
properties = Ext.Object.getKeys(model),
value = {},
sourceConfig = {},
defaultValue,
editor,
li,
map,
type;
// create the configuration data for the property grid
Ext.Array.each(properties, function (property) {
defaultValue = model[property].value || null;
type = model[property].type;
model = record.get(me.dictField) || 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) {
......@@ -48,8 +66,8 @@ Ext.define('MyApp.form.field.UserDataMultiDefault', {
defaultValue = new Date(defaultValue);
editor = Ext.create('Ext.form.field.Date', {
anchor: "100%",
format: 'Y-m-d',
submitFormat: 'Y-m-d'
format: 'Y-m-dTH:i:s',
useStrict: true
});
sourceConfig[property].editor = editor;
break;
......@@ -113,19 +131,80 @@ Ext.define('MyApp.form.field.UserDataMultiDefault', {
break;
}
value[property] = defaultValue;
defaultValues[property] = defaultValue;
});
me.originalValue = value;
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[]} records
// @param {Object} eOpts
//
onComboBoxSelect: function (combo, records, eOpts) {
"use strict";
var me = this,
record = records.length ? records[0] : null,
cfg;
cfg = me.buildSourceConfig(record);
// load the current value if the key is back to the original one
if (combo.getValue() === me.lastKey) {
me.grid.setSource(me.value, sourceConfig);
me.grid.setSource(me.value, cfg.sourceConfig);
// load a new set of values
} else {
me.grid.setSource(value, sourceConfig);
me.originalValue = cfg.defaultValues;
me.grid.setSource(cfg.defaultValues, cfg.sourceConfig);
}
},
//
// supersede the base class method in order to deal with the
// data type of the user data block
//
setValue: function (value) {
"use strict";
var me = this,
combo = me.combo || null,
cfg,
record;
// link me to the ComboBox
if (value && !combo) {
if (!combo) {
combo = me.up('xform, form').down('#' + me.comboBoxItemId);
}
}
// keep track of the value load in the ComboBox
// replace empty string by empty dictionary
if (combo) {
me.lastKey = combo.getValue();
if (!value) {
value = {};
}
// get the configuration for the Ext.grid.property.Grid
record = combo.findRecordByValue(combo.getValue());
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);
}
});
\ No newline at end of file
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