From c0d8c062bb479bfdbe3171aa9a94a1f0fe270bc7 Mon Sep 17 00:00:00 2001
From: Renaud Le Gac <legac@cppm.in2p3.fr>
Date: Wed, 20 Nov 2013 21:25:20 +0100
Subject: [PATCH] ExtJS 4.2: Add the onResize for fielddict, fieldlist and
 fieldeditor.

---
 models/widgets_fields.py              |  7 ++-----
 models/widgets_forms.py               | 13 +++++++-----
 models/widgets_viewport.py            |  4 +---
 static/plugin_dbui/src/fielddict.js   | 19 ++++++++++++-----
 static/plugin_dbui/src/fieldeditor.js | 30 +++++++++++++++++++++++++--
 static/plugin_dbui/src/fieldlist.js   | 30 +++++++++++++++++++--------
 6 files changed, 74 insertions(+), 29 deletions(-)

diff --git a/models/widgets_fields.py b/models/widgets_fields.py
index 7c6682ff..a60b71a8 100644
--- a/models/widgets_fields.py
+++ b/models/widgets_fields.py
@@ -6,7 +6,6 @@
 #
 # harvest selector (merge)
 #
-#-------------------------------------------------------------------------------
 fieldsModifier = dbui.FieldsModifier('harvester_selector')
 fieldsModifier.configure_field('year_start', flex=1)
 fieldsModifier.configure_field('year_end', flex=1)
@@ -16,7 +15,6 @@ fieldsModifier.merge_fields('year_start', 'year_end', fieldLabel=T('Year'))
 #
 # new_fields
 #
-#-------------------------------------------------------------------------------
 fieldsModifier = dbui.FieldsModifier('new_fields')
 fieldsModifier.configure_field('dictionary', headers=['foo', 'faa'],
                                              modifyKeys=True,
@@ -25,14 +23,13 @@ fieldsModifier.configure_field('dictionary', headers=['foo', 'faa'],
                                                       "integer": 0,
                                                       "float": 0.01,
                                                       "date": "not implemented"})
-
-fieldsModifier.configure_field('python_code', xtype='xaceeditorfield',)
+    
+fieldsModifier.configure_field('python_code', xtype='xaceeditorfield')
 
 #-------------------------------------------------------------------------------
 #
 # publications
 #
-#-------------------------------------------------------------------------------
 fieldsModifier = dbui.FieldsModifier('publications')
 fieldsModifier.configure_field('conference_start', format='Y-m-d')
 fieldsModifier.configure_field('conference_end', format='Y-m-d')
diff --git a/models/widgets_forms.py b/models/widgets_forms.py
index 9ef41346..8084cec4 100644
--- a/models/widgets_forms.py
+++ b/models/widgets_forms.py
@@ -2,11 +2,13 @@
 """ widgets forms
 
 """
+#-------------------------------------------------------------------------------
 #
 # add plugin to all forms
 #
 dbui.configure_forms(db, plugins=['pFormToolTip'])
 
+#-------------------------------------------------------------------------------
 #
 # link comboboxes in foo1 selector
 #
@@ -19,6 +21,7 @@ dbui.configure_forms(db, plugins=['pFormToolTip'])
 #                             displayFieldSlaves='granularity_local',
 #                             valueFieldSlaves='granularity')
 
+#-------------------------------------------------------------------------------
 #
 # link several comboboxes in harvester selector
 #
@@ -32,14 +35,14 @@ formModifier.link_comboboxes(master=virtdb.harvester_selector.id_projects,
                              slave=virtdb.harvester_selector.id_teams,
                              masterHasSlaveData='harvesters')
 
-#
-# new fields
+#-------------------------------------------------------------------------------
+# 
+# new_fields
 #
 formModifier = dbui.FormModifier('new_fields')
-formModifier.configure(width=400,
-                       defaults={'width': 270})
-
+formModifier.configure(width=400)
 
+#-------------------------------------------------------------------------------
 #
 # Create fieldSet for the publication form
 #
diff --git a/models/widgets_viewport.py b/models/widgets_viewport.py
index ae668ba4..fbd0374a 100644
--- a/models/widgets_viewport.py
+++ b/models/widgets_viewport.py
@@ -17,9 +17,7 @@ for tablename in ('categories', 'harvesters', 'publications', 'new_fields'):
                        items=[dbui.to_formPanel(db[tablename])],
                        layout='fit',
                        title="Add %s ..." % tablename,
-                       modal=True,
-                       autoHeight=True,
-                       widht=500)
+                       modal=True)
 
     formNode.add_child(T(tablename), leaf)
 
diff --git a/static/plugin_dbui/src/fielddict.js b/static/plugin_dbui/src/fielddict.js
index 497f8317..080388a7 100644
--- a/static/plugin_dbui/src/fielddict.js
+++ b/static/plugin_dbui/src/fielddict.js
@@ -58,10 +58,6 @@ Ext.define('App.form.DictField', {
      */
     headers: null,
 
-    /**
-     * @cfg {Number} height
-     * The height of the widget.
-     */
     /**
      * @cfg {Boolean}
      * The columns header is hidden when true.
@@ -98,7 +94,6 @@ Ext.define('App.form.DictField', {
 
         // property grid
         this.grid = Ext.create('Ext.grid.property.Grid', {
-            height: this.height,
             hideHeaders: this.hideHeaders,
             source: Ext.apply({}, this.dictCfg),
         });
@@ -152,6 +147,7 @@ Ext.define('App.form.DictField', {
     beforeDestroy: function () {
 
         this.grid.un('cellcontextmenu', this.onCellContextMenu, this);
+        this.grid.un('containercontextmenu', this.onContainerContextMenu, this);
         this.grid.un('headercontextmenu', this.onHeaderContextMenu, this);
 
         Ext.destroyMembers(this, 'grid');
@@ -295,6 +291,19 @@ Ext.define('App.form.DictField', {
         this.bodyEl.setVisibilityMode(Ext.dom.Element.DISPLAY).hide();
     },
 
+    /**
+     * Resize the component
+     *
+     * @param {Number} w
+     * @param {Number} h
+     *
+     */
+    onResize: function (w, h) {
+
+        this.grid.setSize(w - this.getLabelWidth(), h);
+        this.callParent(arguments);
+    },
+
     /**
      * Update a key.
      */
diff --git a/static/plugin_dbui/src/fieldeditor.js b/static/plugin_dbui/src/fieldeditor.js
index e1ec9fca..deddad36 100644
--- a/static/plugin_dbui/src/fieldeditor.js
+++ b/static/plugin_dbui/src/fieldeditor.js
@@ -25,7 +25,7 @@ Ext.define('App.form.AceEditorField', {
     language: 'python',
 
     /**
-     * @cfg {Number}
+     * @cfg {Number} [required]
      * The height of the editor widget
      */
     editorHeight: 150,
@@ -38,6 +38,16 @@ Ext.define('App.form.AceEditorField', {
     // private property
     editor: null,
 
+    // private method requests by the component model of ExtJS
+    initComponent: function (config) {
+
+        // Hack to get the size of the editor render properly
+        // The width is to small when it is not specified.
+        this.minWidth = this.minWidth || 258;
+
+        this.callParent(arguments);
+    },
+
     // private method requests by the component model of ExtJS
     beforeDestroy: function () {
 
@@ -77,7 +87,6 @@ Ext.define('App.form.AceEditorField', {
         // wrap an element around the input field
         this.resizeEl = this.positionEl = this.wrap = this.bodyEl.wrap();
 
-
         // the editor require that the width an height are defined
         this.wrap.setWidth(this.wrap.getWidth());
         this.wrap.setHeight(this.editorHeight);
@@ -95,6 +104,23 @@ Ext.define('App.form.AceEditorField', {
         this.bodyEl.setVisibilityMode(Ext.dom.Element.DISPLAY).hide();
     },
 
+    /**
+     * Resize the component
+     *
+     * @param {Number} w
+     * @param {Number} h
+     *
+     */
+    onResize: function (w, h) {
+
+        this.wrap.setSize(w - this.getLabelWidth(), h);
+        if (this.editor) {
+            this.editor.resize();
+        }
+
+        this.callParent(arguments);
+    },
+
     /**
      * Set the value for this field.
      *
diff --git a/static/plugin_dbui/src/fieldlist.js b/static/plugin_dbui/src/fieldlist.js
index 44dd27ab..095f3b04 100644
--- a/static/plugin_dbui/src/fieldlist.js
+++ b/static/plugin_dbui/src/fieldlist.js
@@ -4,6 +4,10 @@
  *
  * **Note** :The list can only contains string.
  *
+ * **Note** : The onRender handle can be removed using the approach
+ * describe in the url (see rixo):
+ * http://stackoverflow.com/questions/6153362/how-to-create-custom-extjs-form-field-component
+ *
  * @experimental
  * @since 0.4.15.0
  *
@@ -19,10 +23,6 @@ Ext.define('App.form.ListField', {
      */
     header: 'Element',
 
-    /**
-     * @cfg {number} height
-     * The height of the widget.
-     */
     /**
      * @cfg {boolean}
      * Hide the column header when true.
@@ -64,6 +64,10 @@ Ext.define('App.form.ListField', {
 
         var cellEditing;
 
+        // Hack to get the size of the grid render properly.
+        // The width is to small when it is not specified.
+        this.minWidth = this.minWidth || 258;
+
         // instantiate the local store
         this.store = Ext.create('Ext.data.ArrayStore', {
             fields: [{name: 'element'}]
@@ -90,11 +94,6 @@ Ext.define('App.form.ListField', {
             store: this.store,
         });
 
-        // Set the height of the grid with a bottom margin of 10
-        if (this.height) {
-            this.grid.setHeight(this.height);
-        }
-
         // instantiate the context menu
         this.menu = Ext.create('Ext.menu.Menu', {
             items: [{
@@ -322,6 +321,19 @@ Ext.define('App.form.ListField', {
         this.bodyEl.setVisibilityMode(Ext.dom.Element.DISPLAY).hide();
     },
 
+    /**
+     * Resize the component
+     *
+     * @param {Number} w
+     * @param {Number} h
+     *
+     */
+    onResize: function (w, h) {
+
+        this.grid.setSize(w - this.getLabelWidth(), h);
+        this.callParent(arguments);
+    },
+
     /**
      * Set the value for this field.
      *
-- 
GitLab