details:   /erp/devel/pi/rev/0ec469391f41
changeset: 9894:0ec469391f41
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Tue Jan 18 10:29:51 2011 +0100
summary:   Implemented Single Record pattern, refactored button 
enabling/disabling code

details:   /erp/devel/pi/rev/5228eb1c22a1
changeset: 9895:5228eb1c22a1
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Tue Jan 18 10:52:46 2011 +0100
summary:   Solved title outside of button error

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/WindowSettingsActionHandler.java
 |   7 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-action-button.js
           |   9 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
           |  73 ++++++---
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-window.js
         |   7 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js
                 |   6 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
               |  47 ++---
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
               |   9 +-
 7 files changed, 86 insertions(+), 72 deletions(-)

diffs (truncated from 382 to 300 lines):

diff -r 8cb212353eb6 -r 5228eb1c22a1 
modules/org.openbravo.client.application/src/org/openbravo/client/application/WindowSettingsActionHandler.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/WindowSettingsActionHandler.java
    Tue Jan 18 10:27:58 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/WindowSettingsActionHandler.java
    Tue Jan 18 10:52:46 2011 +0100
@@ -50,14 +50,15 @@
       final Window window = OBDal.getInstance().get(Window.class, windowId);
       final String roleId = OBContext.getOBContext().getRole().getId();
       final DalConnectionProvider dalConnectionProvider = new 
DalConnectionProvider();
-      final JSONObject jsonReadOnly = new JSONObject();
+      final JSONObject jsonUIPattern = new JSONObject();
       for (Tab tab : window.getADTabList()) {
         final boolean readOnlyAccess = 
org.openbravo.erpCommon.utility.WindowAccessData
             .hasReadOnlyAccess(dalConnectionProvider, roleId, tab.getId());
-        jsonReadOnly.put(tab.getId(), readOnlyAccess || 
tab.getUIPattern().equals("RO"));
+        String uiPattern = readOnlyAccess ? "RO" : tab.getUIPattern();
+        jsonUIPattern.put(tab.getId(), uiPattern);
       }
       final JSONObject json = new JSONObject();
-      json.put("readOnlyDefinition", jsonReadOnly);
+      json.put("uiPattern", jsonUIPattern);
       final String autoSaveStr = Preferences.getPreferenceValue("Autosave", 
false, OBContext
           .getOBContext().getCurrentClient(), 
OBContext.getOBContext().getCurrentOrganization(),
           OBContext.getOBContext().getUser(), 
OBContext.getOBContext().getRole(), window);
diff -r 8cb212353eb6 -r 5228eb1c22a1 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-action-button.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-action-button.js
      Tue Jan 18 10:27:58 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-action-button.js
      Tue Jan 18 10:52:46 2011 +0100
@@ -22,11 +22,8 @@
 
 isc.ClassFactory.defineClass('OBToolbarActionButton', isc.OBToolbarTextButton);
 
-isc.OBToolbarTextButton.addProperties( {
-  initWidget: function(properties){
-    //Hide buttons by default, they will be shown if needed by the refresh 
method
-    this.hide();
-  },
+isc.OBToolbarActionButton.addProperties( {
+  visible: false,
   
   action : function() {
     this.runProcess();
@@ -93,7 +90,7 @@
     var theView = this.view;
     this.view.refresh(function(){
         theView.getTabMessage();
-        theView.toolBar.refreshToolbarButtons();
+        theView.toolBar.refreshCustomButtons();
       });
 
     OB.ActionButton.executingProcess = null;
diff -r 8cb212353eb6 -r 5228eb1c22a1 
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
      Tue Jan 18 10:27:58 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
      Tue Jan 18 10:52:46 2011 +0100
@@ -46,7 +46,11 @@
   // isc.OBStandardView.STATE_IN_MID
   
   // the inactive state does not show an orange hat on the tab button
-  MODE_INACTIVE: 'Inactive'
+  MODE_INACTIVE: 'Inactive',
+  
+  UI_PATTERN_READONLY: 'RO',
+  UI_PATTERN_SINGLERECORD: 'SR',
+  UI_PATTERN_STANDARD: 'ST'  
 });
 
 isc.OBStandardView.addProperties({
@@ -158,6 +162,7 @@
   allowDefaultEditMode: true,
   
   readOnly: false,
+  singleRecord: false,
   
   isShowingForm: false,
   
@@ -188,14 +193,12 @@
       rightMembers: rightMemberButtons
     });
 
-    // disable new for the child views
-    if (!this.isRootView) { 
-      this.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_NEW, true);
-    } else {
-      this.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_NEW, false);
-    }
     
-    this.Super('initWidget', arguments);
+    var ret = this.Super('initWidget', arguments);
+    
+    this.setToolBarButtonState();
+
+    return ret;
   },
   
   buildStructure: function(){
@@ -548,13 +551,11 @@
   
   setReadOnly: function(readOnly){
     this.readOnly = readOnly;
-    if (readOnly) {
-      this.viewForm.readOnly = true;
-      this.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_NEW, true);
-      this.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_SAVE, true);
-      this.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_UNDO, true);
-      this.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_DELETE, true);
-    }
+    this.viewForm.readOnly = readOnly;
+  },
+  
+  setSingleRecord: function(singleRecord){
+    this.singleRecord = singleRecord;
   },
   
   setViewFocus: function(){
@@ -658,13 +659,8 @@
     }
     this.viewGrid.refreshContents();
 
-    // no parent disable new
-    if (!this.getParentId()) {
-      this.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_NEW, true);
-    } else {
-      this.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_NEW, 
this.readOnly);
-    }
-    
+    this.setToolBarButtonState();    
+
     // if not visible or the parent also needs to be refreshed
     // enable the following code if we don't automatically select the first
     // record
@@ -942,7 +938,7 @@
     }
     this.updateLastSelectedState();
         
-    this.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_DELETE, 
(!this.viewGrid.getSelection() || this.viewGrid.getSelection().length === 0));
+    this.setToolBarButtonState();
 
     var tabViewPane = null;
     
@@ -957,7 +953,32 @@
     this.updateChildCount();
     this.updateTabTitle();
     
-    this.toolBar.refreshToolbarButtons();
+    this.toolBar.refreshCustomButtons();
+  },
+  
+  setToolBarButtonState: function() {
+    // validData: this is the root or there is a parent
+    var validData = this.isRootView || this.getParentId(), toolBar = 
this.toolBar, form = this.viewForm, grid = this.viewGrid;
+    if (this.isShowingForm) {
+      // note on purpose checking form readonly
+      toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_NEW, form.isSaving || 
form.readOnly || this.singleRecord || !validData);
+      toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_SAVE, form.isSaving || 
form.readOnly || !validData || !form.hasChanged);
+      toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_UNDO,  form.isSaving || 
form.readOnly || !validData || !form.hasChanged);
+      toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_DELETE,  form.isSaving 
|| form.readOnly || this.singleRecord || !validData || form.isNew);
+      toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_REFRESH, form.isSaving 
|| form.isNew);
+    } else {
+      toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_NEW, this.readOnly || 
this.singleRecord || !validData);
+      // for a grid also the selected number is taken into account
+      toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_DELETE,  this.readOnly 
|| this.singleRecord || !validData || !grid.getSelectedRecords() || 
grid.getSelectedRecords().length === 0);
+      toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_REFRESH, !validData);
+
+      // implement in editable grid
+      toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_UNDO,  true);
+      toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_SAVE, true);      
+    }
+
+    // and refresh the process toolbar buttons
+    this.toolBar.refreshCustomButtons();
   },
   
   hasSelectionStateChanged: function() {
@@ -972,7 +993,7 @@
   },
     
   getParentId: function(){
-    if (!this.parentView || !this.parentView.viewGrid.getSelectedRecord()) {
+    if (!this.parentView || !this.parentView.viewGrid.getSelectedRecords() || 
this.parentView.viewGrid.getSelectedRecords().length !== 1) {
       return null;
     }
     return this.parentView.viewGrid.getSelectedRecord()[OB.Constants.ID];
@@ -1105,7 +1126,7 @@
         isc.ask(OB.I18N.getLabel('OBUIAPP_ConfirmRefresh'), callback);
       } else {
         var criteria = [];
-        criteria[OB.Constants.ID] = 
view.viewGrid.getSelectedRecord()[OB.Constants.ID];
+        criteria[OB.Constants.ID] = view.viewForm.getValue(OB.Constants.ID);
         view.viewForm.fetchData(criteria, refreshCallback);
       }
     }
diff -r 8cb212353eb6 -r 5228eb1c22a1 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-window.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-window.js
    Tue Jan 18 10:27:58 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-window.js
    Tue Jan 18 10:52:46 2011 +0100
@@ -99,11 +99,14 @@
       return;
     }
     this.getClass().windowSettingsRead = true;
-    this.getClass().readOnlyTabDefinition = data.readOnlyDefinition;
+    this.getClass().uiPattern = data.uiPattern;
     this.getClass().autoSave = data.autoSave;
     // set the views to readonly
     for (var i = 0; i < this.views.length; i++) {
-      this.views[i].setReadOnly(data.readOnlyDefinition[this.views[i].tabId]);
+      this.views[i].setReadOnly(data.uiPattern[this.views[i].tabId] === 
isc.OBStandardView.UI_PATTERN_READONLY);
+      this.views[i].setSingleRecord(data.uiPattern[this.views[i].tabId] === 
isc.OBStandardView.UI_PATTERN_SINGLERECORD);
+      
+      this.views[i].setToolBarButtonState();
     }
   },
   
diff -r 8cb212353eb6 -r 5228eb1c22a1 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js
    Tue Jan 18 10:27:58 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js
    Tue Jan 18 10:52:46 2011 +0100
@@ -557,11 +557,11 @@
     return;
   },
   
-  // ** {{{ refreshToolbarButtons }}} **
+  // ** {{{ refreshCustomButtons }}} **
   //
-  // Refreshes all buttons in the toolbar based on current record selection
+  // Refreshes all the custom buttons in the toolbar based on current record 
selection
   //
-  refreshToolbarButtons: function(){
+  refreshCustomButtons: function(){
     var buttons = this.getRightMembers();
     var hideAllButtons = this.view.viewGrid.getSelectedRecords().length !== 1;
     
diff -r 8cb212353eb6 -r 5228eb1c22a1 
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
  Tue Jan 18 10:27:58 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
  Tue Jan 18 10:52:46 2011 +0100
@@ -68,13 +68,12 @@
     // focus is done automatically, prevent the focus event if needed
     // the focus event will set the active view
     this.ignoreFirstFocusEvent = preventFocus;
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_SAVE, true);
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_UNDO, true);
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_DELETE, 
this.view.readOnly || false);
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_REFRESH, 
this.view.readOnly || false);
     
     var ret = this.Super('editRecord', arguments);
     this.clearErrors();
+    
+    this.view.setToolBarButtonState();
+    
     this.retrieveInitialValues(false);
     
     this.view.messageBar.hide();
@@ -95,14 +94,11 @@
 
     this.setNewState(true);
     
-    // disable relevant buttons
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_REFRESH, true);
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_SAVE, true);
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_UNDO, true);
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_DELETE, true);
-    
     var ret = this.Super('editNewRecord', arguments);
     this.clearErrors();
+    
+    this.view.setToolBarButtonState();
+    
     this.retrieveInitialValues(true);
     
     this.resetFocusItem();
@@ -253,12 +249,10 @@
     }
     if (!data.writable || this.view.readOnly) {
       this.readOnly = true;
-      this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_SAVE, true);
-      this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_UNDO, true);
-      this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_DELETE, true);
     } else {
       this.readOnly = false;
     }
+    this.view.setToolBarButtonState();
     this.focus();
   },
   
@@ -391,8 +385,7 @@
     // remove the message
     this.hasChanged = true;
     this.view.messageBar.hide();
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_SAVE, false);
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_UNDO, false);
+    this.view.setToolBarButtonState();
   },
   
   resetForm: function(){
@@ -403,10 +396,9 @@
   
   undo: function(){
     this.view.messageBar.hide();
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_SAVE, true);
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_UNDO, true);
     this.resetValues();
     this.hasChanged = false;
+    this.view.setToolBarButtonState();
   },
   
   // action defines the action to call when the save succeeds

------------------------------------------------------------------------------
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