details:   /erp/devel/pi/rev/8eb29441a244
changeset: 9819:8eb29441a244
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Fri Jan 14 17:28:15 2011 +0100
summary:   Moved error message handling to standard view, single record pattern 
when no records opens in grid mode

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-messagebar.js
    |  52 -------
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
 |  70 +++++++++-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
     |   3 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
     |   3 +
 4 files changed, 71 insertions(+), 57 deletions(-)

diffs (188 lines):

diff -r 99cb569eaa0d -r 8eb29441a244 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-messagebar.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-messagebar.js
 Fri Jan 14 17:25:50 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-messagebar.js
 Fri Jan 14 17:28:15 2011 +0100
@@ -111,57 +111,5 @@
         me.setMessage(type, title, text);
       }
     }, 'setLabel');
-  },
-  
-  // handles different ways by which an error can be passed from the 
-  // system, translates this to an object with a type, title and message
-  setErrorMessageFromResponse: function(resp, data, req){
-    // only handle it once
-    if (resp._errorMessageHandled) {
-      return true;
-    }
-    var msg = '', title = null, type = isc.OBMessageBar.TYPE_ERROR, isLabel = 
false, params = null;
-    if (isc.isA.String(data)) {
-      msg = data;
-    } else if (data && data.response && data.response.error) {
-      var error = data.response.error;
-      if (error.type && error.type === 'user') {
-        isLabel = true;
-        msg = error.message;
-        params = error.params;
-      } else if (error.message) {
-        type = error.messageType || type;
-        params = error.params;
-        // error.messageType can be Error
-        type = type.toLowerCase();
-        title = error.title || title;
-        msg = error.message;
-      } else {
-        // hope that someone else will handle it
-        return false;
-      }
-    } else if (data.data) {
-      // try it with data.data
-      return this.setErrorMessageFromResponse(resp, data.data, req);
-    } else {    
-      // hope that someone else will handle it
-      return false;
-    }
-
-    req.willHandleError = true;
-    resp._errorMessageHandled = true;
-    if (msg.indexOf('@') !== -1) {
-      index1 = msg.indexOf('@');
-      index2 = msg.indexOf('@', index1 + 1);
-      if (index2 !== -1) {
-        errorCode = msg.substring(index1 + 1, index2);
-        this.setLabel(type, title, errorCode, params);
-      }
-    } else if (isLabel) {
-      this.setLabel(type, title, msg, params);
-    } else {
-      this.setMessage(type, title, msg);
-    }
-    return true;
   }
 });
diff -r 99cb569eaa0d -r 8eb29441a244 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
      Fri Jan 14 17:25:50 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
      Fri Jan 14 17:28:15 2011 +0100
@@ -278,7 +278,8 @@
         
         var errorStatus = !jsonData.response || jsonData.response.status === 
'undefined' || jsonData.response.status !== isc.RPCResponse.STATUS_SUCCESS;
         if (errorStatus) {
-          var handled = 
this.view.messageBar.setErrorMessageFromResponse(dsResponse, jsonData, 
dsRequest);
+          var handled = this.view.setErrorMessageFromResponse(dsResponse, 
jsonData, dsRequest);
+          
           if (!handled && !dsRequest.willHandleError) {
             OB.KernelUtilities.handleSystemException(error.message);
           }
@@ -309,7 +310,68 @@
       this.viewForm.setDataSource(this.dataSource, this.viewForm.fields);
     }
   },
-  
+    
+  // handles different ways by which an error can be passed from the 
+  // system, translates this to an object with a type, title and message
+  setErrorMessageFromResponse: function(resp, data, req){
+    // only handle it once
+    if (resp._errorMessageHandled) {
+      return true;
+    }
+    var msg = '', title = null, type = isc.OBMessageBar.TYPE_ERROR, isLabel = 
false, params = null;
+    if (isc.isA.String(data)) {
+      msg = data;
+    } else if (data && data.response) {
+      if (data.response.errors) {
+        // give it to the form
+        this.viewForm.handleFieldErrors(data.response.errors);
+        return true;
+      } else if (data.response.error) {
+        var error = data.response.error;
+        if (error.type && error.type === 'user') {
+          isLabel = true;
+          msg = error.message;
+          params = error.params;
+        } else if (error.message) {
+          type = error.messageType || type;
+          params = error.params;
+          // error.messageType can be Error
+          type = type.toLowerCase();
+          title = error.title || title;
+          msg = error.message;
+        } else {
+          // hope that someone else will handle it
+          return false;
+        }
+      } else {
+          // hope that someone else will handle it
+          return false;
+      }
+    } else if (data.data) {
+      // try it with data.data
+      return this.setErrorMessageFromResponse(resp, data.data, req);
+    } else {    
+      // hope that someone else will handle it
+      return false;
+    }
+
+    req.willHandleError = true;
+    resp._errorMessageHandled = true;
+    if (msg.indexOf('@') !== -1) {
+      index1 = msg.indexOf('@');
+      index2 = msg.indexOf('@', index1 + 1);
+      if (index2 !== -1) {
+        errorCode = msg.substring(index1 + 1, index2);
+        this.messageBar.setLabel(type, title, errorCode, params);
+      }
+    } else if (isLabel) {
+      this.messageBar.setLabel(type, title, msg, params);
+    } else {
+      this.messageBar.setMessage(type, title, msg);
+    }
+    return true;
+  },
+
   draw: function(){
     var result = this.Super('draw', arguments);
     if (!this.viewGrid || !this.viewGrid.filterEditor) {
@@ -561,7 +623,7 @@
   shouldOpenDefaultEditMode: function(){
     // can open default edit mode if defaultEditMode is set
     // and this is the root view or a child view with a selected parent.
-    return this.allowDefaultEditMode && this.defaultEditMode && 
(this.isRootView || this.parentView.viewGrid.getSelectedRecords().length === 1);
+    return this.allowDefaultEditMode && this.viewGrid.data && 
this.viewGrid.data.getLength() > 1 && this.defaultEditMode && (this.isRootView 
|| this.parentView.viewGrid.getSelectedRecords().length === 1);
   },
   
   // opendefaultedit view for a child view is only called
@@ -580,7 +642,7 @@
     // open form in edit mode
     if (record) {
       this.editRecord(record, preventFocus);
-    } else if (!this.viewGrid.data && this.viewGrid.data.getLength() > 0) {
+    } else if (this.viewGrid.data && this.viewGrid.data.getLength() > 0) {
       // edit the first record
       this.editRecord(this.viewGrid.getRecord(0), preventFocus);
     } 
diff -r 99cb569eaa0d -r 8eb29441a244 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
  Fri Jan 14 17:25:50 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
  Fri Jan 14 17:28:15 2011 +0100
@@ -520,7 +520,8 @@
     this.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, 
OB.I18N.getLabel('OBUIAPP_ErrorInFields'));
     
     // and focus to the first error field
-    this.setFocusInErrorField(autoSave);
+    this.setFocusInErrorField(autoSave || this.inAutoSave);
+    this.inAutoSave = false;
   },
   
   setFocusInErrorField: function(autoSave){
diff -r 99cb569eaa0d -r 8eb29441a244 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
  Fri Jan 14 17:25:50 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
  Fri Jan 14 17:28:15 2011 +0100
@@ -298,6 +298,9 @@
       this.delayedHandleTargetRecord(startRow, endRow);
     } else if (this.view.shouldOpenDefaultEditMode()) {
       this.view.openDefaultEditView(this.getRecord(startRow));
+    } else if (this.data && this.data.getLength() === 1) {
+      // one record select it directly
+      this.selectRecord(0);
     }
     
     return ret;

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to