details:   https://code.openbravo.com/erp/devel/pi/rev/7d3eaa3a17c4
changeset: 13840:7d3eaa3a17c4
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Tue Sep 27 09:55:42 2011 +0200
summary:   Fixes issue 18072: Focus handling in form and grid editing needs to 
be cleaned up, results in unpredictable behavior
Make use of standard smartclient functionality for focus handling, fixes:
Fixes issue 18072: Focus handling in form and grid editing needs to be cleaned 
up, results in unpredictable behavior
Fixes issue 18500: "Sales Forecast" -> "Lines" -> "Planned Date" calendar date 
picker doesn't work always
Fixes issue 18086: When pressing tab in suggestion box, field displayed through 
displaylogic is skipped

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
 |  156 +++------
 1 files changed, 49 insertions(+), 107 deletions(-)

diffs (truncated from 303 to 300 lines):

diff -r 61b5386aec1c -r 7d3eaa3a17c4 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
     Tue Sep 27 09:52:32 2011 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
     Tue Sep 27 09:55:42 2011 +0200
@@ -81,6 +81,8 @@
   // is set in the OBAttachmentsSectionItem.initWidget
   attachmentsSection: null,
 
+  selectOnFocus: true,
+  
   initWidget: function() {
     this._preventFocusChanges = true;
 
@@ -170,17 +172,6 @@
     
     delete this.validateAfterFicReturn;
     
-    // only compute a new focus item if the form is active
-    if (this.view.isActiveView()) {
-      this.computeFocusItem();
-    }
-    
-    // if the focus item is not really enabled
-    // then find a new one, even if the form is not active
-    if (this.getFocusItem() && !this.getFocusItem().isFocusable(true)) {
-      this.computeFocusItem(this.getFocusItem());
-    }
-
     // sometimes if an error occured we stay disabled
     // prevent this
     this.setDisabled(false);
@@ -188,26 +179,26 @@
     this.setHasChanged(false);
 
     this.setNewState(isNew);
-    
+
+    // errors are cleared anyway
+    delete this.validateAfterFicReturn;
+
     // focus is done automatically, prevent the focus event if needed
     // the focus event will set the active view
     if (!isNew) {
-      this.validateAfterFicReturn = true;
       // If editing a document set to recent documents
       this.view.setRecentDocument(this.getValues());
     }
     
     this.ignoreFirstFocusEvent = preventFocus;
+    
+    // retrieveinitialvalues does focus and clear of errors
     this.retrieveInitialValues(isNew);
     
     if (isNew) {
       this.view.statusBar.mode = 'NEW';
       this.view.statusBar.setContentLabel(this.view.statusBar.newIcon, 
'OBUIAPP_New');
     }
-
-    // do at the end because during initial form drawing
-    // fields get blurred and will show an error
-    this.clearErrors();
   },
   
   editNewRecord: function(preventFocus){
@@ -299,7 +290,6 @@
   setNewState: function(isNew){
     // showing the sections will change the focus item
     // restore that
-    this.storeFocusItem();
     this.isNew = isNew;
     this.view.statusBar.setNewState(isNew);
     this.view.updateTabTitle();
@@ -308,9 +298,6 @@
     this.enableLinkedItemSection(!isNew);
     this.enableAttachmentsSection(!isNew);
     
-    // and restore
-    this.restoreFocusItem();
-    
     if (isNew) {
       this.view.statusBar.newIcon.prompt = 
OB.I18N.getLabel('OBUIAPP_NewIconPrompt');
     } else {
@@ -411,16 +398,32 @@
     if (focusItem && focusItem.isFocusable()) {
       focusItem.focusInItem();
       this.view.lastFocusedItem = focusItem;
+      this.selectFocusItemValue();
     } else {      
       // find a new one
       this.computeFocusItem(focusItem);
       if (this.getFocusItem() !== focusItem && this.getFocusItem()) {
         focusItem.focusInItem();
+        this.selectFocusItemValue();
         this.view.lastFocusedItem = focusItem;
       }
     }
   },
   
+  selectFocusItemValue: function() {
+    if (!this.getFocusItem() || !this.view.isActiveView()) {
+      return;
+    }
+    // if not explicitly set to false, select its value
+    if (this.getFocusItem().selectOnFocus !== false) {
+      if (isc.Browser.isIE) {
+        this.getFocusItem().delayCall('selectValue', [], 100);
+      } else {
+        this.getFocusItem().selectValue();
+      }
+    }    
+  },
+  
   getFieldFromInpColumnName: function(inpColumnName) {
     var i, length;
     
@@ -543,13 +546,28 @@
         me.rememberValues();
       }
       me.initializing = false;
+
+      // do here because during initial form drawing
+      // fields get blurred and will show an error
+      me.clearErrors(true);
       
+      // only compute a new focus item if the form is active
+      if (me.view.isActiveView()) {
+        me.computeFocusItem();
+      }
+      
+      // if the focus item is not really enabled
+      // then find a new one, even if the form is not active
+      if (me.getFocusItem() && !me.getFocusItem().isFocusable(true)) {
+        me.computeFocusItem(me.getFocusItem());
+      }
+      // note the focus is set in the field when the FIC call
+      // returns
+
       // at this point select the focused value      
       if (me.getFocusItem()) {
         me.setFocusInForm();
-        me.selectFocusItemValue();
       }
-
     });
   },
   
@@ -727,7 +745,7 @@
       }
     }
 
-    this.markForRedraw();
+    this.redraw();
 
     delete this.inFicCall;
     this.view.toolBar.updateButtonState(true);
@@ -765,7 +783,6 @@
     if (previousAllItemsDisabled !== this.allItemsDisabled) {
       if (this.getFocusItem()) {
         if (this.allItemsDisabled) {
-          this.storeFocusItem();
           if (this.getFocusItem() && !this.initializing) {
             this.getFocusItem().blurItem();
           }
@@ -779,13 +796,6 @@
           for (i = 0; i < length; i++) {
             delete this.getFields()[i].canFocus;
           }
-          
-          // do restore focus in a delayed manner for ie
-          if (isc.Browser.isIE) {
-            this.delayCall('restoreFocusItem', [true], 100);
-          } else {
-            this.restoreFocusItem();
-          }
           delete this.ignoreFirstFocusEvent;
         }
       } else {
@@ -1124,7 +1134,10 @@
       }
 
       me.processFICReturn(response, data, request, editValues, editRow);
-
+ 
+      if (me.getFocusItem()) {
+        me.setFocusInForm();
+      }
     });
     this.view.toolBar.updateButtonState(true);
   },
@@ -1159,7 +1172,7 @@
   
   resetForm: function(){
     this.resetValues();
-    this.clearErrors();
+    this.clearErrors(true);
     this.setHasChanged(false);
   },
   
@@ -1205,8 +1218,6 @@
   saveRow: function(){
     var savingNewRecord = this.isNew;
     
-    this.storeFocusItem();
-    
     // store the value of the current focus item
     if (this.getFocusItem() && this.saveFocusItemChanged !== 
this.getFocusItem()) {
       this.getFocusItem().blur(this, this.getFocusItem());
@@ -1327,7 +1338,6 @@
 
       form.isSaving = false;
       view.toolBar.updateButtonState(true);
-      this.restoreFocusItem();
       return false;
     };
     
@@ -1370,23 +1380,8 @@
     this.computeFocusItem(this.getField(currentItemName));
     if (this.getFocusItem()) {
       this.getFocusItem().focusInItem();
-      this.selectFocusItemValue();
     }
   },
-
-  selectFocusItemValue: function() {
-    if (!this.getFocusItem() || !this.view.isActiveView()) {
-      return;
-    }
-    // if not explicitly set to false, select its value
-    if (this.getFocusItem().selectOnFocus !== false) {
-      if (isc.Browser.isIE) {
-        this.getFocusItem().delayCall('selectValue', [], 100);
-      } else {
-        this.getFocusItem().selectValue();
-      }
-    }    
-  },
   
   // overridden to prevent focus setting when autoSaving  
   showErrors: function(errors, hiddenErrors, suppressAutoFocus){
@@ -1593,62 +1588,9 @@
     this.Super('showFieldErrors', [fieldName, true]);
   },
   
-  // overridden because Smartclient looses the selection when redrawing
-  // this was not reproducable in standard smartclient
-  // therefore this hack
-  redraw: function() {
-    var hasFocus;
-    if (this.getFocusItem() && this.getFocusItem().hasFocus) {
-      this.storeFocusItem();
-      // don't let the native SC code do store/restore of the focus item
-      hasFocus = this.getFocusItem().hasFocus;
-      this.getFocusItem().hasFocus = false;
-    }
-    this.Super('redraw', arguments);
-    if (hasFocus) {
-      if (isc.Browser.isIE) {
-        this.delayCall('restoreFocusItem', [true], 100);
-      } else {
-        this.restoreFocusItem();
-      }
-    }
-  },
-  
-  storeFocusItem: function() {
-    delete this.storedFocusItem;
-    delete this.storedSelectionRange;
-    if (this.getFocusItem()) {
-      this.storedFocusItem = this.getFocusItem();
-      this.storedSelectionRange = this.getFocusItem().getSelectionRange();
-    }
-  },
-  
-  restoreFocusItem: function() {
-    var storedSelectionRange = this.storedSelectionRange;
-    if (this.isVisible() && this.storedFocusItem) {
-      if (!this.storedFocusItem.isFocusable(true)) {
-        this.focusInNextItem(this.getFocusItem().name);
-      } else {
-        this.setFocusItem(this.storedFocusItem);
-        this.setFocusInForm();
-        if (storedSelectionRange) {
-          if (isc.Browser.isIE && storedSelectionRange[0] !== 
storedSelectionRange[1]) {
-            // we have overridden selectvalue to not use selection ranges
-            // but direct element.select, see ob-smartclient.js
-            this.selectFocusItemValue();
-          } else {
-            this.getFocusItem().setSelectionRange(storedSelectionRange[0], 
storedSelectionRange[1]);
-          }
-        }
-      }
-    }
-    
-    delete this.storedFocusItem;
-    delete this.storedSelectionRange;    
-  },
-
   destroy: function () {
-    var i, items = this.getItems(), len = items.length, ds, dataSources = [];
+    var i, item, items = this.getItems(), len = items.length, 
+      ds, dataSources = [];

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to