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

Add the singleton Event with the method getHistoryDataConfig.

parent e4e15d71
......@@ -43,7 +43,7 @@ class Event(object):
dbui.plugins_paths["event"] = {
"css": "static/plugin_event/resources/css/",
"debug": None,
"debug": "static/plugin_event/src/Event.js",
"lg": "static/plugin_event/locale/event-lang-%s.js" % lg,
"libmin": "static/plugin_event/event-min.js"}
......
......@@ -24,17 +24,6 @@ Ext.require("Ext.direct.RemotingProvider");
Ext.require("Ext.EventManager");
Ext.require("Ext.tip.QuickTipManager");
Ext.require("Event.form.field.Graph");
Ext.require("Event.form.field.UserData");
Ext.require("Event.form.field.UserDataMultiDefault");
Ext.require("Event.form.field.Summary");
Ext.require("Event.form.plugin.UserDataConsistency");
Ext.require("Event.grid.plugin.RowWidget");
Ext.require("Event.grid.HistoryFilter");
Ext.require("Event.grid.plugin.HistoryContextMenu");
Ext.require("Event.grid.RowEventData");
Ext.require("Event.grid.RowHistoryData");
Ext.onReady(function(){
"use strict";
......
/**
* Common utilities.
*/
Ext.define('Event', {
singleton: true,
uses: [
"Event.form.field.Graph",
"Event.form.field.UserData",
"Event.form.field.UserDataMultiDefault",
"Event.form.field.Summary",
"Event.form.plugin.UserDataConsistency",
"Event.grid.plugin.RowWidget",
"Event.grid.HistoryFilter",
"Event.grid.plugin.HistoryContextMenu",
"Event.grid.RowEventData",
"Event.grid.RowHistoryData"],
/**
*
* The history.data field can be manipulated by an Ext.grid.property.Grid.
* The configuration of the property grid depend on the event.
*
* This helper function return the configuration of the property grid
* using the event definition.
*
* @param {Ext.data.Store} events
* contains definitions for all events.
*
* @param {Number} idEvent
* the event identifier
*
* @return {Object}
*
*/
getHistoryDataConfig: function (events, idEvent) {
"use strict";
var record = events.findRecord("EventsId", idEvent),
eventData = record.get("EventsData"),
defaultValues = {},
sourceConfig = {};
Ext.Object.each(eventData, function (property) {
var defaultValue = eventData[property].value || null,
type = eventData[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 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