Commit 8840eb54 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update RowHistoryData, the user can modify values.

parent c7327a48
...@@ -209,9 +209,10 @@ class CoreUi(object): ...@@ -209,9 +209,10 @@ class CoreUi(object):
"widget": { "widget": {
"xtype": "xrowhistorydata", "xtype": "xrowhistorydata",
"bind": { "bind": {
"historyData": "{record.HistoryData}" "historyData": "{record.HistoryData}",
"historyId_events": "{record.HistoryId_events}"
}, },
"padding": "10 0 12 50" "padding": "10 100 12 50"
} }
} }
......
...@@ -11,70 +11,136 @@ ...@@ -11,70 +11,136 @@
*/ */
Ext.define("Event.grid.RowHistoryData", { Ext.define("Event.grid.RowHistoryData", {
extend: "Ext.grid.Panel", extend: "Ext.grid.property.Grid",
alias: "widget.xrowhistorydata", alias: "widget.xrowhistorydata",
uses: "Ext.data.Store",
config: {
/**
* @cfg {Object}
* Contains the user data block which will be displayed in a grid:
*
* {
* property1: val1,
* property2: val2
* }
*
* This configuration has to be bind to the grid by the RowWidget plugin:
*
* historyData = "{record.HistoryData}"
*
*/
historyData: null,
/**
* @cfg {Number}
* The identifier of the event
*
* This configuration has to be bind to the grid by the RowWidget plugin:
*
* historyId_events = "{record.HistoryId_events}"
*
*/
historyId_events: undefined,
/**
* @cfg {Boolean}
* Activate the read only mode when it is true.
* In that case, the user cannot modify the value anymore.
*
*/
readOnly: false
},
// pivate property
eventStore: "eventsStore",
// jshint strict: false
// private method requests by the component model of ExtJS
initComponent: function () {
var me = this;
me.callParent(arguments);
// link to the event store
me.eventStore = Dbui.getStore(me.eventStore);
// to deal with readonly mode at any time
me.on("beforeedit", me.onBeforeEdit, me);
// activate the two way binding
// the history.data field is updated when the user modifies a value
// in the property grid. Here we mimic the behaviour of a spreadsheet.
if (!me.readOnly) {
me.on("propertychange", me.onPropertyChange, me);
}
},
// private method requests by the component model of ExtJS
beforeDestroy: function () {
var me = this;
me.un("beforeedit", me.onBeforeEdit, me);
if (!me.readOnly) {
me.un("propertychange", me.onPropertyChange, me);
}
me.callParent(arguments);
},
// jshint strict: true
/** /**
* @cfg {Object} * Setter for the historyData property.
* Contains the user data block which will be displayed in a grid: * Method required by the binding model.
*
* @return {Object}
* *
* { * {
* property1: val1, * property1: val1,
* property2: val2 * property2: val2
* } * }
*
* This configuration has to be bind to the grid by the RowWidget plugin:
*
* historyData = "{record.HistoryData}"
* *
*/ */
historyData: null, getHistoryData: function () {
// Predefined configuration options "use strict";
forceFit: true, var me = this,
value = {};
// private properties for internationalization me.getStore().each(function(record) {
textProperty: "property", value[record.get("name")] = record.get("value");
textValue: "value", });
// jshint strict: false return value;
},
// private method requests by the component model of ExtJS /**
initComponent: function () { * Handler to activate / desactivate the readonly mode
*
*/
onBeforeEdit: function () {
"use strict";
var me = this; var me = this;
// the store for the grid return !me.readOnly;
me.store = Ext.create("Ext.data.Store", { },
fields: [
{name: "property", type: "string"},
{name: "value", type: "string"}
],
proxy: "memory"
});
// the columns of the grid /**
me.columns =[{ * Handler to update the database
dataIndex: "property", *
flex: 0.5, */
sortable: true, onPropertyChange: function () {
text: me.textProperty
}, {
dataIndex: "value",
flex: 4,
sortable: true,
text: me.textValue
}];
// instantiate the base class
me.callParent(arguments);
// hide the dirty flag when a cell is modified "use strict";
me.getView().markDirty = false; var me = this;
},
// jshint strict: true me.publishState("historyData", me.getHistoryData());
},
/** /**
* Setter for the historyData property. * Setter for the historyData property.
...@@ -92,30 +158,11 @@ Ext.define("Event.grid.RowHistoryData", { ...@@ -92,30 +158,11 @@ Ext.define("Event.grid.RowHistoryData", {
setHistoryData: function (value) { setHistoryData: function (value) {
"use strict"; "use strict";
var me = this, var me = this,
store = me.getStore(), events = me.eventStore,
model = store.getProxy().getModel(), idEvent= me.historyId_events,
records = [], sourceConfig = Event.getHistoryDataConfig(events, idEvent);
record;
me.eventData = value;
if (value) {
Ext.Object.each(value, function (prop, val) {
record = model.create();
record.set("property", prop);
record.set("value", val);
records.push(record);
});
store.loadData(records, false);
} else {
store.removeAll(true);
}
me.getView().refresh(); me.setSource(value, 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