Commit 70087bc1 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Render list of value using combobox.

parent f2b53c41
...@@ -18,23 +18,37 @@ An event contains *meta-data* linking the event to: ...@@ -18,23 +18,37 @@ An event contains *meta-data* linking the event to:
The events are stored in the ``history`` table and the meta-data in the foreign The events are stored in the ``history`` table and the meta-data in the foreign
tables ``fundings``, ``people``, ``people_categories``, ``projects`` and tables ``fundings``, ``people``, ``people_categories``, ``projects`` and
``teams``. The organization of the table can not be changed. All the fields of ``teams``. The organization of these tables can not be modified by the user
these tables are standard database field which can be used in SQL request or in since all their fields are standard database field.
reports.
An event contains also the *user data block*. It is stored in one database An event contains also the *user data block*. It is stored in one database
field. The user data block is a python dictionary serialized as a JSON_ string. field. The user data block is a python dictionary serialized as a JSON_ string.
The structure of the dictionary, *the keys*, are defined by the user, once, for The structure of the dictionary, *the keys*, are defined by the user, once, for
each event type. The structure of the dictionary can be modified at any each event type. The structure of the dictionary can be modified at any
time by the user. Mechanisms are in placed to guaranty the consistency across time by the user. Mechanisms are in placed to guaranty the consistency across
the database. The SQL request are limited to string operations. the database. Although it is powerful, there is limitation on that field.
Individual key of the dictionary can not be used in SQL request. But, any key The SQL request are limited to string operations. Individual key of the
can be manipulated in reports. dictionary can not be used. However, any key can be manipulated in reports.
Define an event Define an event
---------------- ----------------
The event definitions are stored in the ``events`` table. The event definitions are stored in the ``events`` table.
It mainly contains the a model defining the structure of the user data block.
The model is a series of *property* defined by a name, a data type and
possibly a default value. Possible types are *boolean*, *date*, *integer*,
*float*, *reference* and *string*.
.. note::
The reference type allows the user to select value within those
available for a given database field. The address of the database
field is defined in the *default* column. It is equal to
``tablename.fieldname``.
.. note::
For sting, the user can also select the value among a predefined set.
The set is defined in the *default* column. It is equal to a
JSON_-type array, *e.g* `["foo", "faa"]`.
In order to create a new event definition: In order to create a new event definition:
...@@ -50,17 +64,21 @@ In order to create a new event definition: ...@@ -50,17 +64,21 @@ In order to create a new event definition:
The form to enter an event definition in the database. The form to enter an event definition in the database.
4. Enter the event type in the ``event`` entry. 4. Enter the event type in the ``event`` entry.
5. Enter the python dictionary structure in the ``model`` field. 5. Enter the the model.
Add the first key by right clicking on ``property`` label. Later on, Add the first property by right clicking on ``property``, ``type`` or
key can be ``Add``, ``Modify`` or ``Delete`` using the ``default`` label. Later on, others properties can be ``Add``,
contextual menu. ``Modify`` or ``Delete`` using the contextual menu.
.. warning:: .. warning::
the data user block of the existing events are updated when the Modifying the definiton of the user block is a tricky operation
python dictionary structure is modified. since consistency with existing events store in the history table
has to be preserved.
Mechanisms are in place to preserve the consistency when a property
is added, deleted or renamed. However, the user has to take care of
the consistency when the property type as well as the default value
are changed.
A good practice is to enter the type of key (``boolean``,
``date``, ``string``, ``number``) or a default value.
Enter an event in the history Enter an event in the history
------------------------------ ------------------------------
......
...@@ -26,11 +26,14 @@ Ext.define('MyApp.form.field.UserDataMultiDefault', { ...@@ -26,11 +26,14 @@ Ext.define('MyApp.form.field.UserDataMultiDefault', {
properties = Ext.Object.getKeys(model), properties = Ext.Object.getKeys(model),
value = {}, value = {},
sourceConfig = {}, sourceConfig = {},
defaultValue, editor, map, type; defaultValue,
editor,
// generate the configuration data for the property grid li,
Ext.Array.each(properties, function(property) { map,
type;
// create the configuration data for the property grid
Ext.Array.each(properties, function (property) {
defaultValue = model[property].value || null; defaultValue = model[property].value || null;
type = model[property].type; type = model[property].type;
...@@ -81,6 +84,32 @@ Ext.define('MyApp.form.field.UserDataMultiDefault', { ...@@ -81,6 +84,32 @@ Ext.define('MyApp.form.field.UserDataMultiDefault', {
break; break;
case 'string': 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; break;
} }
......
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