fixed issue 16576: OPTIMIZE-09: Extend "not being able to save" message
authorAsier Lostalé <asier.lostale@openbravo.com>
Fri, 22 Jul 2011 17:30:45 +0200
changeset 13254 24a53bbf75a2
parent 13253 675b247f895d
child 13255 43e38631f444
fixed issue 16576: OPTIMIZE-09: Extend "not being able to save" message
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_PREFERENCE.xml
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-messagebar.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Fri Jul 22 12:21:21 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Fri Jul 22 17:30:45 2011 +0200
@@ -1378,6 +1378,17 @@
 <!--FF808081314C76B401314D0A2A240082-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--FF808081314C76B401314D0A2A240082--></AD_MESSAGE>
 
+<!--FF80808131517E5F0131523F2F9000C1--><AD_MESSAGE>
+<!--FF80808131517E5F0131523F2F9000C1-->  <AD_MESSAGE_ID><![CDATA[FF80808131517E5F0131523F2F9000C1]]></AD_MESSAGE_ID>
+<!--FF80808131517E5F0131523F2F9000C1-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF80808131517E5F0131523F2F9000C1-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF80808131517E5F0131523F2F9000C1-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF80808131517E5F0131523F2F9000C1-->  <VALUE><![CDATA[OBUIAPP_ErrorInFieldsGrid]]></VALUE>
+<!--FF80808131517E5F0131523F2F9000C1-->  <MSGTEXT><![CDATA[One or more rows could not be saved. Fix the problem or <a href="#" style="color: green;" onclick="window['%0'].undo();">cancel all pending changes</a> to return to the last saved state.]]></MSGTEXT>
+<!--FF80808131517E5F0131523F2F9000C1-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF80808131517E5F0131523F2F9000C1-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF80808131517E5F0131523F2F9000C1--></AD_MESSAGE>
+
 <!--FF8081812D6761CF012D676DF2A70045--><AD_MESSAGE>
 <!--FF8081812D6761CF012D676DF2A70045-->  <AD_MESSAGE_ID><![CDATA[FF8081812D6761CF012D676DF2A70045]]></AD_MESSAGE_ID>
 <!--FF8081812D6761CF012D676DF2A70045-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -1813,7 +1824,7 @@
 <!--FF8081812E867351012E867555F90008-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--FF8081812E867351012E867555F90008-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--FF8081812E867351012E867555F90008-->  <VALUE><![CDATA[OBUIAPP_UndoChanges]]></VALUE>
-<!--FF8081812E867351012E867555F90008-->  <MSGTEXT><![CDATA[Undo changes]]></MSGTEXT>
+<!--FF8081812E867351012E867555F90008-->  <MSGTEXT><![CDATA[Cancel changes]]></MSGTEXT>
 <!--FF8081812E867351012E867555F90008-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
 <!--FF8081812E867351012E867555F90008-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--FF8081812E867351012E867555F90008--></AD_MESSAGE>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_PREFERENCE.xml	Fri Jul 22 12:21:21 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_PREFERENCE.xml	Fri Jul 22 17:30:45 2011 +0200
@@ -42,7 +42,9 @@
   {"id": "StatusBar_Maximize-Restore", "keyComb": {"alt": true, "shift": true, "key": "Enter"}},
   {"id": "StatusBar_Close", "keyComb": {"key": "Escape"}},
   {"id": "Grid_EditInForm", "keyComb": {"ctrl": true, "alt": false, "key": "f2"}},
-  {"id": "Grid_EditInGrid", "keyComb": {"ctrl": false, "alt": false, "key": "f2"}}
+  {"id": "Grid_EditInGrid", "keyComb": {"ctrl": false, "alt": false, "key": "f2"}},
+  {"id": "Grid_EditInGrid", "keyComb": {"ctrl": false, "alt": false, "key": "f2"}},
+  {"id": "Grid_CancelChanges", "keyComb": {"ctrl": false, "alt": false, "key": "Escape"}}
 ]]]></VALUE>
 <!--5EE6D055A7FE4C4DA7EB557F6C61D0EA-->  <PROPERTY><![CDATA[OBUIAPP_KeyboardShortcuts]]></PROPERTY>
 <!--5EE6D055A7FE4C4DA7EB557F6C61D0EA-->  <ISPROPERTYLIST><![CDATA[Y]]></ISPROPERTYLIST>
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Fri Jul 22 12:21:21 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Fri Jul 22 17:30:45 2011 +0200
@@ -1305,8 +1305,14 @@
   },
   
   handleFieldErrors: function(errors){
-    var msg = OB.I18N.getLabel('OBUIAPP_ErrorInFields'),
-        additionalMsg = '', err;
+    var msg, additionalMsg = '', err;
+
+    if (this.view.isEditingGrid) {
+      msg = OB.I18N.getLabel('OBUIAPP_ErrorInFieldsGrid', [this.view.ID]);
+    } else {
+      msg = OB.I18N.getLabel('OBUIAPP_ErrorInFields');
+    }
+
     if (errors) {
       this.setErrors(errors, true);
       for (err in errors) {
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js	Fri Jul 22 12:21:21 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js	Fri Jul 22 17:30:45 2011 +0200
@@ -525,6 +525,22 @@
       this.frozenBody.showEmptyMessage = false;
     }
     return ret;
+  },
+
+  //= getErrorRows =
+  // Returns all the rows that have errors.
+  getErrorRows: function(){
+    var editRows, errorRows = [], i;
+
+    if (this.hasErrors()) {
+      editRows = this.getAllEditRows(true);
+      for (i = 0; i < editRows.length; i++) {
+        if (this.rowHasErrors(editRows[i])) {
+          errorRows.push(editRows[i]);
+        }
+      }
+    }
+    return errorRows;
   }
 });
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Fri Jul 22 12:21:21 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Fri Jul 22 17:30:45 2011 +0200
@@ -553,6 +553,12 @@
       return false; //To avoid keyboard shortcut propagation
     };
     OB.KeyboardManager.KS.set('Grid_EditInForm', editInFormAction);
+
+    OB.KeyboardManager.KS.set('Grid_CancelChanges',
+       function(){
+         grid.view.undo();
+         return false;
+       });
   },
   
   deselectAllRecords: function(preventUpdateSelectInfo, autoSaveDone){
@@ -1117,23 +1123,14 @@
     var singleSelected = this.getSelectedRecords().length === 1;
     var field = this.getField(colNum);
     var grid = this;
-    if (recordsSelected) {
-      var allSelectedHaveErrors = true, i;
-      for (i = 0; i < this.getSelectedRecords().length; i++) {
-        var localRowNum = this.getRecordIndex(this.getSelectedRecords()[i]);
-        if (!this.rowHasErrors(localRowNum)) {
-          allSelectedHaveErrors = false;
-          break;
+    if (!this.view.hasNotChanged() || this.view.viewGrid.hasErrors()) {
+      menuItems.add({
+        title: OB.I18N.getLabel('OBUIAPP_UndoChanges'),
+        keyTitle: OB.KeyboardManager.KS.getProperty('keyComb.text','Grid_CancelChanges','id'),
+        click: function(){
+          grid.view.undo();
         }
-      }
-      if (allSelectedHaveErrors) {
-        menuItems.add({
-          title: OB.I18N.getLabel('OBUIAPP_UndoChanges'),
-          click: function(){
-            grid.view.undo();
-          }
-        });
-      }
+      });
     }
 
     if (singleSelected && this.canEdit && this.isWritable(record) && !this.view.readOnly) {
@@ -1577,6 +1574,8 @@
     if (record) {
       if (!record[isc.OBViewGrid.ERROR_MESSAGE_PROP]) {
         this.setRecordErrorMessage(rowNum, OB.I18N.getLabel('OBUIAPP_ErrorInFields'));
+        // do not automatically remove this message
+        this.view.messageBar.keepOnAutomaticRefresh = true;
       } else {
         record[this.recordBaseStyleProperty] = this.recordStyleError;
       }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-messagebar.js	Fri Jul 22 12:21:21 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-messagebar.js	Fri Jul 22 17:30:45 2011 +0200
@@ -25,7 +25,7 @@
 isc.OBMessageBarCloseIcon.addProperties({
   messageBar: null,
   action: function(){
-    this.messageBar.hide();
+    this.messageBar.hide(true);
   }
 });
 
@@ -117,5 +117,13 @@
         me.setMessage(type, title, text);
       }
     }, 'setLabel');
+  },
+
+  hide: function(force) {
+    // if hide is not forced, keep the message if marked as keepOnAutomaticRefresh
+    if (force || !this.keepOnAutomaticRefresh) {
+      delete this.keepOnAutomaticRefresh;
+      this.Super('hide', arguments);
+    }
   }
 });
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Fri Jul 22 12:21:21 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Fri Jul 22 17:30:45 2011 +0200
@@ -1451,12 +1451,23 @@
     };
     this.standardWindow.doActionAfterAutoSave(actionObject, false);
   },
-  
+
   undo: function(){
-    var view = this, callback, form, grid;
+    var view = this, callback, form, grid, errorRows, i;
+    view.messageBar.hide(true);
     if (this.isEditingGrid) {
+      grid = view.viewGrid;
       // the editing grid will take care of the confirmation
-      view.viewGrid.cancelEditing();
+      grid.cancelEditing();
+
+      // undo edit in all records with errors
+      if (grid.hasErrors()) {
+        errorRows = grid.getErrorRows();
+        for (i = 0; i < errorRows.length; i++){
+          grid.selectRecord(grid.getRecord(errorRows[i]));
+        }
+        grid.undoEditSelectedRows();
+      }
       return;
     } else if (this.isShowingForm) {
       form = this.viewForm;
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js	Fri Jul 22 12:21:21 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js	Fri Jul 22 17:30:45 2011 +0200
@@ -190,7 +190,7 @@
     buttonType: 'undo',
     prompt: OB.I18N.getLabel('OBUIAPP_CancelEdit'),
     updateState: function() {
-      this.setDisabled(this.view.hasNotChanged());
+      this.setDisabled(this.view.hasNotChanged() && !this.view.viewGrid.hasErrors());
     },
     keyboardShortcutId: 'ToolBar_Undo'
   },