diff --git a/models/widgets_fields.py b/models/widgets_fields.py index a23facd81281571529b82a663bb3a1ce01653771..0f3bcb6dfaf658900de104202e835dac44399f33 100644 --- a/models/widgets_fields.py +++ b/models/widgets_fields.py @@ -14,12 +14,15 @@ fieldsModifier.merge_fields('year_start', 'year_end', fieldLabel=T('Year')) # new_fields # fieldsModifier = dbui.FieldsModifier('new_fields') -fieldsModifier.configure_field('dictionary', dictCfg={"string": "test", +fieldsModifier.configure_field('dictionary', height=120, + dictCfg={"string": "test", "boolean": False, "integer": 0, "float": 0.01, "date": "not implemented"}) +fieldsModifier.configure_field('list_string', height=120) + fieldsModifier.configure_field('python_code', height=120, xtype='xaceeditorfield',) diff --git a/static/plugin_dbui/locale/dbui-lang-fr.js b/static/plugin_dbui/locale/dbui-lang-fr.js index 1a216e30a775916d5ec4aff9c9a19703f9da8b2c..8d8ffa3e780756df644a8210fcdc881d291c4280 100644 --- a/static/plugin_dbui/locale/dbui-lang-fr.js +++ b/static/plugin_dbui/locale/dbui-lang-fr.js @@ -13,14 +13,20 @@ if (App.BasePanelWithSelector) { if (App.form.DictField) { Ext.apply(App.form.DictField.prototype, { textAdd: 'Ajouter', - textAddTitle: 'Entrer une clé ...', + textAddTitle: 'Ajouter ...', textAddMsg: 'Entrez le nom de la clé :', textDestroy: 'Détruire', - textDestroytitle: 'Détruire une clé ...', + textDestroytitle: 'Détruire ...', textDestroyMsg: 'Voulez-vous vraiment détruire la clé :', + textErrorTitle: 'Erreur ...', - textErrorMsg: 'Cette clé existe !' + textErrorMsg: 'Cette clé existe !', + + textUpdate: 'Modifier', + textUpdatetitle: 'Modifier ...', + textUpdateMsg: 'Modifier la clé :', + }); } diff --git a/static/plugin_dbui/src/fielddict.js b/static/plugin_dbui/src/fielddict.js index c2e31823357b212b4f19ef2701ad03596229ecab..07e02284f16374346d58fddc2a9c3cb803ec29ea 100644 --- a/static/plugin_dbui/src/fielddict.js +++ b/static/plugin_dbui/src/fielddict.js @@ -43,6 +43,12 @@ Ext.grid.Column.types.jsoncolumn = Ext.grid.JsonColumn; */ App.form.DictField = Ext.extend(Ext.form.Field, { + /** + * @cfg {boolean} autoHeight true by default + * + */ + autoHeight: false, + /** * @cfg {object} dictCfg default configuration for the dictionary * Example: @@ -56,6 +62,20 @@ App.form.DictField = Ext.extend(Ext.form.Field, { */ dictCfg: {}, + /** + * @cfg {array} headers + * label of the column display in the grid widget + */ + headers: null, + + /** + * @cfg {number} height + */ + /** + * @cfg {boolean} hideHeader false by default + */ + hideHeader: false, + /** * @cfg {boolean} modifyKeys Dictionary keys can be added or deleted. * By default false. @@ -73,13 +93,16 @@ App.form.DictField = Ext.extend(Ext.form.Field, { * private attributes for internationalization */ textAdd: 'Add', - textAddTitle: 'Enter key ...', - textAddMsg: 'Please enter the key name:', + textAddTitle: 'Add ...', + textAddMsg: 'Please enter the new key:', textDestroy: 'Delete', - textDestroytitle: 'Delete key ...', + textDestroytitle: 'Delete ...', textDestroyMsg: 'Are you sure to destroy the key:', textErrorTitle: 'Error ...', textErrorMsg: 'The key already exists!', + textUpdate: 'Update', + textUpdateTitle: 'Update ...', + textUpdateMsg: 'Modify the key:', /** * private method requests by the component model of ExtJS @@ -88,38 +111,57 @@ App.form.DictField = Ext.extend(Ext.form.Field, { "use strict"; + var cm, + i; + // property grid this.grid = new Ext.grid.PropertyGrid({ - autoHeight: true, - hideHeaders: true, + autoHeight: this.autoHeight, + hideHeaders: this.hideHeaders, source: Ext.apply({}, this.dictCfg), viewConfig : { - forceFit: true, - scrollOffset: 2 // the grid will never have scrollbars + forceFit: true } }); - // context menu to modify the keys + // set the grid height keeping a bottom margin of 5 + if (this.height) { + this.grid.setHeight(this.height); + } + + // dedicated column headers + if (this.headers) { + cm = this.grid.getColumnModel(); + + for (i = 0; i < this.headers.length; i += 1) { + cm.setColumnHeader(i, this.headers[i]); + } + } + + // context menu + this.grid.on('contextmenu', this.onContextMenu, this); + if (this.modifyKeys) { this.menu = new Ext.menu.Menu(); this.menu.add({ text: this.textAdd, iconCls: 'xaction-create', - handler: this.onAddRow, + handler: this.onAddKey, + scope: this + }, '-', { + text: this.textUpdate, + iconCls: 'xaction-update', + handler: this.onUpdateKey, scope: this }, '-', { text: this.textDestroy, iconCls: 'xaction-destroy', - handler: this.onDeleteRow, + handler: this.onDeleteKey, scope: this }); this.grid.on('rowcontextmenu', this.onRowContextMenu, this); - - // inhibit context menu - } else { - this.grid.on('contextmenu', this.onContextMenu, this); } // instantiate the underlying class @@ -133,10 +175,10 @@ App.form.DictField = Ext.extend(Ext.form.Field, { "use strict"; + this.grid.un('contextmenu', this.onContextMenu, this); + if (this.modifyKeys) { this.grid.un('rowcontextmenu', this.onRowContextMenu, this); - } else { - this.grid.un('contextmenu', this.onContextMenu, this); } Ext.destroyMembers(this, 'grid'); @@ -157,7 +199,7 @@ App.form.DictField = Ext.extend(Ext.form.Field, { /** * private handler to add a key */ - onAddRow: function () { + onAddKey: function () { "use strict"; @@ -189,12 +231,17 @@ App.form.DictField = Ext.extend(Ext.form.Field, { "use strict"; event.stopEvent(); + + if (this.modifyKeys) { + this.rowIndex = 0; + this.menu.showAt(event.getXY()); + } }, /** * private handler to delete a key */ - onDeleteRow: function () { + onDeleteKey: function () { "use strict"; @@ -234,6 +281,11 @@ App.form.DictField = Ext.extend(Ext.form.Field, { App.form.DictField.superclass.onRender.call(this, ct, position); this.wrap = this.el.wrap({cls: 'x-form-field'}); + + if (this.height) { + this.wrap.setHeight(this.height); + } + this.resizeEl = this.positionEl = this.wrap; this.grid.render(this.wrap); }, @@ -253,6 +305,39 @@ App.form.DictField = Ext.extend(Ext.form.Field, { this.menu.showAt(event.getXY()); }, + /** + * private handler to update a key + */ + onUpdateKey: function () { + + "use strict"; + + var key, + record, + value; + + record = this.grid.getStore().getAt(this.rowIndex); + key = record.get("name"); + value = record.get("value"); + + // prompt the user to modify the key + Ext.Msg.prompt(this.textUpdateTitle, this.textUpdateMsg, function (btn, text) { + + if (btn === 'ok') { + + // check that the key is unique + if (this.grid.getSource().hasOwnProperty(text)) { + Ext.Msg.alert(errorTitle, errorMsg); + return; + } + // update the key + this.grid.removeProperty(key); + this.grid.setProperty(text, value, true); + } + }, this, false, key); + + }, + /** * Set the value for this field * @param {Object} value diff --git a/static/plugin_dbui/src/fieldlist.js b/static/plugin_dbui/src/fieldlist.js index ecd50f333f4be40561d810fae9d369554414fe8e..e06c92b0a5e2635279060379bfab5acb835081a6 100644 --- a/static/plugin_dbui/src/fieldlist.js +++ b/static/plugin_dbui/src/fieldlist.js @@ -22,17 +22,38 @@ Ext.namespace('App.form'); App.form.ListField = Ext.extend(Ext.form.Field, { /** - * @cfg {boolean} autoHeight true by default - * + * @cfg {boolean} autoHeight false by default + */ + autoHeight: false, + + /** * @cfg {string} header * label of the column display in the grid widget - * - * @cfg {boolean} hideHeader false by default */ - autoHeight: true, header: 'Element', + + /** + * @cfg {number} height + */ + /** + * @cfg {boolean} hideHeader false by default + */ hideHeader: false, + /** + * @cfg{boolean} ignoreEmptyRows by default true + * Empty string are not copied in the list return by the getValue method. + */ + ignoreEmptyRows: true, + + /** + * @cfg {number} minimumRows + * The minimum number of rows displayed in the grid. + * There fill with empty string when values are not defined. + * Empty string can be ignored when getting the list using ignoreEmptyRows. + */ + minimumRows: 3, + /** * private attributes */ @@ -63,7 +84,6 @@ App.form.ListField = Ext.extend(Ext.form.Field, { // instantiate the local store store = new Ext.data.ArrayStore({ fields: [{name: 'element'}], - data: [] }); // instantiate the column model @@ -86,11 +106,17 @@ App.form.ListField = Ext.extend(Ext.form.Field, { clicksToEdit: 1, colModel: cm, store: store, + stripeRows: true, viewConfig: { forcefit: true } }); + // Set the height of the grid with a bottom margin of 10 + if (this.height) { + this.grid.setHeight(this.height - 10); + } + // instantiate the context menu this.menu = new Ext.menu.Menu(); @@ -144,6 +170,7 @@ App.form.ListField = Ext.extend(Ext.form.Field, { /** * Return the value of this field + * Empty string are not copied in the list when ignoreEmptyRows is true. */ getValue: function () { @@ -154,6 +181,11 @@ App.form.ListField = Ext.extend(Ext.form.Field, { records = this.grid.getStore().getRange(); for (i = 0; i < records.length; i += 1) { + + if (this.ignoreEmptyRows && records[i].data.element === "") { + continue; + } + li.push(records[i].data.element); } @@ -282,6 +314,10 @@ App.form.ListField = Ext.extend(Ext.form.Field, { this.wrap.setStyle('border', '1px solid'); this.wrap.setStyle('border-color', '#B5B8C8'); + if (this.height) { + this.wrap.setHeight(this.height); + } + this.resizeEl = this.positionEl = this.wrap; this.grid.render(this.wrap); }, @@ -329,15 +365,28 @@ App.form.ListField = Ext.extend(Ext.form.Field, { i; // convert the list in a list of list - // and replace the content of the store with the new data set if (value && value instanceof Array) { + for (i = 0; i < value.length; i += 1) { data.push([value[i]]); } - this.grid.getStore().loadData(data, false); + if (value.length < this.minimumRows) { + for (i = value.length; i < this.minimumRows; i += 1) { + data.push([]); + } + } + + } else { + + for (i = 0; i < this.minimumRows; i += 1) { + data.push([]); + } } + // replace the content of the store with the new data set + this.grid.getStore().loadData(data, false); + return App.form.ListField.superclass.setValue.call(this, value); } });