details:   /erp/devel/pi/rev/4a8874718dd6
changeset: 9656:4a8874718dd6
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Sun Jan 09 10:26:52 2011 +0100
summary:   Implemented readonly pattern

details:   /erp/devel/pi/rev/116ae4a3c7e0
changeset: 9657:116ae4a3c7e0
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Sun Jan 09 10:27:41 2011 +0100
summary:   Implemented readonly pattern

details:   /erp/devel/pi/rev/65770544fe0f
changeset: 9658:65770544fe0f
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Sun Jan 09 10:28:05 2011 +0100
summary:   Implemented readonly pattern

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/ReadOnlyTabComputationActionHandler.java
                                                            |   65 +++++++
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
                                                             |    1 -
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
                                                                              | 
  91 +++++++--
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
                                                                                
  |    7 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
                                                                                
  |    2 +-
 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/images/form/search_picker_Disabled.png
 |    0 
 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/images/form/search_picker_Down.png
     |    0 
 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/images/form/search_picker_Over.png
     |    0 
 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/ob-form-styles.js
                      |   12 +-
 
modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-selector-item.js
                                                                      |    3 +
 10 files changed, 148 insertions(+), 33 deletions(-)

diffs (truncated from 332 to 300 lines):

diff -r cc59c14c78a3 -r 65770544fe0f 
modules/org.openbravo.client.application/src/org/openbravo/client/application/ReadOnlyTabComputationActionHandler.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ReadOnlyTabComputationActionHandler.java
    Sun Jan 09 10:28:05 2011 +0100
@@ -0,0 +1,65 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2011 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.application;
+
+import java.util.Map;
+
+import javax.enterprise.context.ApplicationScoped;
+
+import org.codehaus.jettison.json.JSONObject;
+import org.openbravo.base.exception.OBException;
+import org.openbravo.client.kernel.BaseActionHandler;
+import org.openbravo.client.kernel.StaticResourceComponent;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.ui.Tab;
+import org.openbravo.model.ad.ui.Window;
+import org.openbravo.service.db.DalConnectionProvider;
+
+/**
+ * Computes which tabs are readonly and which are not readonly.
+ * 
+ * @author mtaal
+ * @see StaticResourceComponent
+ */
+...@applicationscoped
+public class ReadOnlyTabComputationActionHandler extends BaseActionHandler {
+
+  protected JSONObject execute(Map<String, Object> parameters, String data) {
+
+    try {
+      OBContext.setAdminMode();
+      final String windowId = (String) parameters.get("windowId");
+      final Window window = OBDal.getInstance().get(Window.class, windowId);
+      final JSONObject json = new JSONObject();
+      final String roleId = OBContext.getOBContext().getRole().getId();
+      final DalConnectionProvider dalConnectionProvider = new 
DalConnectionProvider();
+      for (Tab tab : window.getADTabList()) {
+        final boolean readOnlyAccess = 
org.openbravo.erpCommon.utility.WindowAccessData
+            .hasReadOnlyAccess(dalConnectionProvider, roleId, tab.getId());
+        json.put(tab.getId(), readOnlyAccess || 
tab.getUIPattern().equals("RO"));
+      }
+      return json;
+    } catch (Exception e) {
+      throw new OBException(e);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+}
diff -r cc59c14c78a3 -r 65770544fe0f 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
     Sun Jan 09 08:14:13 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
     Sun Jan 09 10:28:05 2011 +0100
@@ -340,7 +340,6 @@
           finalObject.put("readonlylogic", readonlylogics);
         }
 
-        // determine if the whole form should be opened in readonly mode
         if (mode.equals("EDIT") && row != null) {
           final String rowClientId = ((ClientEnabled) row).getClient().getId();
           final String currentClientId = 
OBContext.getOBContext().getCurrentClient().getId();
diff -r cc59c14c78a3 -r 65770544fe0f 
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
      Sun Jan 09 08:14:13 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
      Sun Jan 09 10:28:05 2011 +0100
@@ -27,6 +27,9 @@
   
   focusedView: null,
   
+  readOnlyTabDefinition: null,
+  views: [],
+  
   initWidget: function(){
     var standardWindow = this;
     
@@ -39,13 +42,40 @@
     this.addMember(this.toolBarLayout);
     
     this.viewProperties.standardWindow = this;
+    this.view = isc.OBStandardView.create(this.viewProperties);
+    this.addView(this.view);
+    this.addMember(this.view);
     
-    this.view = isc.OBStandardView.create(this.viewProperties);
-    this.addMember(this.view);
     this.Super('initWidget', arguments);
     
     // is set later after creation
     this.view.tabTitle = this.tabTitle;
+    
+    // compute the tab definition
+    if (!this.getClass().readOnlyTabDefinition) {
+      
OB.RemoteCallManager.call('org.openbravo.client.application.ReadOnlyTabComputationActionHandler',
 null, {
+        windowId: this.windowId
+      }, function(response, data, request){
+        standardWindow.setReadOnlyTabDefinition(data);
+      });
+    }
+  },
+  
+  setReadOnlyTabDefinition: function(data){
+    this.getClass().readOnlyTabDefinition = data;
+    // set the views to readonly
+    for (var i = 0; i < this.views.length; i++) {
+      this.views[i].setReadOnly(data[this.views[i].tabId]);
+    }
+  },
+  
+  addView: function(view){
+    view.standardWindow = this;
+    this.views.push(view);
+    this.toolBarLayout.addMember(view.toolBar);
+    if (this.getClass().readOnlyTabDefinition) {
+      view.setReadOnly(this.getClass().readOnlyTabDefinition[view.tabId]);
+    }
   },
   
   show: function(){
@@ -249,6 +279,8 @@
   // is selected.
   allowDefaultEditMode: true,
   
+  readOnly: false,
+  
   initWidget: function(properties){
     var isRootView = !this.parentProperty;
     
@@ -273,10 +305,6 @@
       })]
     });
     
-    if (isRootView) {
-      this.standardWindow.toolBarLayout.addMember(this.toolBar);
-    }
-    
     this.Super('initWidget', arguments);
   },
   
@@ -355,22 +383,24 @@
       },
       
       transformResponse: function(dsResponse, dsRequest, jsonData){
-        if (!dsRequest.willHandleError) {
-          if (!jsonData.response || jsonData.response.status === 'undefined' 
|| jsonData.response.status !== 0) { //0 is success
-            if (jsonData.response && jsonData.response.error) {
-              var error = jsonData.response.error;
-              if (error.type && error.type === 'user') {
-                OB.KernelUtilities.handleUserException(error.message, 
error.params);
-              } else {
-                OB.KernelUtilities.handleSystemException(error.message);
-              }
+        var errorStatus = !jsonData.response || jsonData.response.status === 
'undefined' || jsonData.response.status !== isc.RPCResponse.STATUS_SUCCESS;
+        if (errorStatus) {
+          if (jsonData.response && jsonData.response.error) {
+            var error = jsonData.response.error;
+            if (error.type && error.type === 'user') {
+              dsRequest.willHandleError = true;
+              this.view.messageBar.setLabel(isc.OBMessageBar.TYPE_ERROR, null, 
error.message, error.params);
             } else if (!dsRequest.willHandleError) {
-              OB.KernelUtilities.handleSystemException('Error occured');
-            } else if (dsResponse.status && dsResponse.status === 
isc.RPCResponse.STATUS_FAILURE) {
-              this.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, 
null, jsonData.data);
-            } else {
-              this.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, 
null, OB.I18N.getLabel('OBUIAPP_ErrorInFields'));
+              OB.KernelUtilities.handleSystemException(error.message);
             }
+          } else if (!dsRequest.willHandleError) {
+            OB.KernelUtilities.handleSystemException('Error occured');
+          } else if (dsResponse.status && dsResponse.status === 
isc.RPCResponse.STATUS_FAILURE) {
+            dsRequest.willHandleError = true;
+            this.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, 
jsonData.data);
+          } else {
+            dsRequest.willHandleError = true;
+            this.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, 
OB.I18N.getLabel('OBUIAPP_ErrorInFields'));
           }
         } else {
           // there are some cases where the jsonData is not passed, in case of 
errors
@@ -517,8 +547,7 @@
   // this
   // parent.
   addChildView: function(childView){
-    childView.standardWindow = this.standardWindow;
-    this.standardWindow.toolBarLayout.addMember(childView.toolBar);
+    this.standardWindow.addView(childView);
     
     childView.parentView = this;
     childView.parentTabSet = this.childTabSet;
@@ -541,6 +570,17 @@
     
   },
   
+  setReadOnly: function(readOnly){
+    this.readOnly = readOnly;
+    if (readOnly) {
+      this.viewForm.disable();
+      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);
+    }
+  },
+  
   setViewFocus: function(){
     var object, functionName;
     
@@ -827,6 +867,9 @@
     // clear all our selections..
     this.viewGrid.deselectAllRecords();
     
+    // hide the messagebar
+    this.messageBar.hide();
+    
     // allow default edit mode again
     this.allowDefaultEditMode = true;
     
@@ -1043,7 +1086,9 @@
           }
           
OB.RemoteCallManager.call('org.openbravo.client.application.MultipleDeleteActionHandler',
 deleteData, {
             willHandleError: true
-          }, removeCallBack, {refreshGrid: true});
+          }, removeCallBack, {
+            refreshGrid: true
+          });
         } else {
           view.viewGrid.removeData(selection[0], removeCallBack, {
             willHandleError: true
diff -r cc59c14c78a3 -r 65770544fe0f 
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
  Sun Jan 09 08:14:13 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
  Sun Jan 09 10:28:05 2011 +0100
@@ -74,8 +74,8 @@
     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, false);
-    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_REFRESH, false);
+    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_DELETE, 
this.view.readOnly || false);
+    this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_REFRESH, 
this.view.readOnly || false);
     
     this.resetFocusItem();
     var ret = this.Super('editRecord', arguments);
@@ -203,9 +203,8 @@
     if (dynamicCols) {
       this.dynamicCols = dynamicCols;
     }
-    if (!data.writable) {
+    if (!data.writable || this.view.readOnly) {
       this.disable();
-      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);
diff -r cc59c14c78a3 -r 65770544fe0f 
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
  Sun Jan 09 08:14:13 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
  Sun Jan 09 10:28:05 2011 +0100
@@ -228,7 +228,7 @@
     this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_SAVE, true);
     // enable the delete if there are records selected
     if (this.getSelection() && this.getSelection().length > 0) {
-      this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_DELETE, 
false);
+      this.view.toolBar.setLeftMemberDisabled(isc.OBToolbar.TYPE_DELETE, 
this.view.readOnly || false);
     }
     return ret;
   },
diff -r cc59c14c78a3 -r 65770544fe0f 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/images/form/search_picker_Disabled.png
Binary file 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/images/form/search_picker_Disabled.png
 has changed
diff -r cc59c14c78a3 -r 65770544fe0f 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/images/form/search_picker_Down.png
Binary file 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/images/form/search_picker_Down.png
 has changed
diff -r cc59c14c78a3 -r 65770544fe0f 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/images/form/search_picker_Over.png
Binary file 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/images/form/search_picker_Over.png
 has changed
diff -r cc59c14c78a3 -r 65770544fe0f 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/ob-form-styles.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/ob-form-styles.js
      Sun Jan 09 08:14:13 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/ob-form-styles.js
      Sun Jan 09 10:28:05 2011 +0100
@@ -49,10 +49,16 @@
   pickerIconSrc: 
'[SKINIMG]../../org.openbravo.client.application/images/form/search_picker.png',
   clearIcon: {
     height: 15,
-    width: 15,
+    width: 15,    
+    src: 
'[SKINIMG]../../org.openbravo.client.application/images/form/clear-field.png',
+    
     // note: TODO: show a helpfull text, need to be present in the messages 
table
     //prompt: 'test',

------------------------------------------------------------------------------
Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web.   Learn how to 
best implement a security strategy that keeps consumers' information secure 
and instills the confidence they need to proceed with transactions.
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