details:   /erp/devel/pi/rev/fb6a3fd8ed6b
changeset: 9660:fb6a3fd8ed6b
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Mon Jan 10 08:23:20 2011 +0100
summary:   Added closeclick and tabdeselect event handling

details:   /erp/devel/pi/rev/ffb5bef381b5
changeset: 9661:ffb5bef381b5
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Mon Jan 10 08:26:35 2011 +0100
summary:   First implementation of auto-save, added new icons, changed css for 
disabled labels, changed activeview setting behavior

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/WindowSettingsActionHandler.java
 |   72 +++
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/layout.js.ftl
          |   18 +
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-formitem-widgets.js
        |   42 ++-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
           |  184 +++++++--
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-statusbar.js
               |   83 ++-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
               |  116 +++++-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
               |    4 +-
 7 files changed, 412 insertions(+), 107 deletions(-)

diffs (truncated from 904 to 300 lines):

diff -r 2b85c2a65ed3 -r ffb5bef381b5 
modules/org.openbravo.client.application/src/org/openbravo/client/application/WindowSettingsActionHandler.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/WindowSettingsActionHandler.java
    Mon Jan 10 08:26:35 2011 +0100
@@ -0,0 +1,72 @@
+/*
+ *************************************************************************
+ * 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.erpCommon.businessUtility.Preferences;
+import org.openbravo.model.ad.ui.Tab;
+import org.openbravo.model.ad.ui.Window;
+import org.openbravo.service.db.DalConnectionProvider;
+
+/**
+ * Computes different settings which may be user/role specific for a certain 
window.
+ * 
+ * @author mtaal
+ * @see StaticResourceComponent
+ */
+...@applicationscoped
+public class WindowSettingsActionHandler 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 String roleId = OBContext.getOBContext().getRole().getId();
+      final DalConnectionProvider dalConnectionProvider = new 
DalConnectionProvider();
+      final JSONObject jsonReadOnly = 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"));
+      }
+      final JSONObject json = new JSONObject();
+      json.put("readOnlyDefinition", jsonReadOnly);
+      final String autoSaveStr = Preferences.getPreferenceValue("Autosave", 
false, OBContext
+          .getOBContext().getCurrentClient(), 
OBContext.getOBContext().getCurrentOrganization(),
+          OBContext.getOBContext().getUser(), 
OBContext.getOBContext().getRole(), window);
+      json.put("autoSave", "Y".equals(autoSaveStr));
+      return json;
+    } catch (Exception e) {
+      throw new OBException(e);
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+}
diff -r 2b85c2a65ed3 -r ffb5bef381b5 
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/layout.js.ftl
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/layout.js.ftl
     Mon Jan 10 08:22:01 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/layout.js.ftl
     Mon Jan 10 08:26:35 2011 +0100
@@ -165,6 +165,24 @@
       tabPane.tabSelected(tabNum, tabPane, ID, tab);
     }
   },
+  
+  tabDeselected: function (tabNum, tabPane, ID, tab, newTab) {
+    if (tabPane.tabDeselected) {
+      tabPane.tabDeselected(tabNum, tabPane, ID, tab, newTab);
+    }
+  },
+  
+  closeClick: function(tab) {
+    if (tab.pane && tab.pane.closeClick) {
+      tab.pane.closeClick(tab, this);
+    } else {
+      doCloseClick(tab);
+    }   
+  },
+  
+  doCloseClick: function(tab) {
+    return this.Super('closeClick', arguments);
+  },
 
   initWidget: function() {
     this.tabBarProperties.tabSet = this;
diff -r 2b85c2a65ed3 -r ffb5bef381b5 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-formitem-widgets.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-formitem-widgets.js
   Mon Jan 10 08:22:01 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-formitem-widgets.js
   Mon Jan 10 08:26:35 2011 +0100
@@ -101,8 +101,31 @@
   
   init: function(){
     this.instanceClearIcon = isc.shallowClone(this.clearIcon);
+    this.instanceClearIcon.formItem = this;
+    
+    this.instanceClearIcon.showIf= function(form, item){
+      if (item.disabled) {
+        return false;
+      }
+      if (item.required) {
+        return false;
+      }
+      if (form && form.view && form.view.readOnly) {
+        return false;
+      }
+      if (item.getValue()) {
+        return true;
+      }
+      return false;
+    };
+    
+    this.instanceClearIcon.click = function(){
+      this.formItem.setValue(null);
+      this.formItem.form.itemChangeActions();
+    };
+
     this.icons = [this.instanceClearIcon];
-    this.icons[0].formItem = this;
+    
     return this.Super('init', arguments);
   },
   
@@ -249,6 +272,17 @@
 // Form sections
 isc.ClassFactory.defineClass('OBSectionItem', SectionItem);
 
+isc.OBSectionItem.addProperties({
+  // revisit when/if we allow disabling of section items
+  // visual state of disabled or non-disabled stays the same now
+  showDisabled: false,
+  
+  // never disable a section item
+  isDisabled: function() {
+    return false;
+  }
+});
+
 // == OBListItem ==
 // Combo box for list references
 isc.ClassFactory.defineClass('OBListItem', SelectItem);
@@ -908,14 +942,14 @@
   focus: function(form, item){
     if (form.view) {
       form.view.lastFocusedItem = this;
-      form.view.setActiveView(true);
+      form.view.setAsActiveView();
     } else if (form.grid) {
       if (form.grid.view) {
         form.grid.view.lastFocusedItem = this;
-        form.grid.view.setActiveView(true);
+        form.grid.view.setAsActiveView();
       } else if (isc.isA.RecordEditor(form.grid) && form.grid.sourceWidget && 
form.grid.sourceWidget.view) {
         form.grid.sourceWidget.view.lastFocusedItem = this;
-        form.grid.sourceWidget.view.setActiveView(true);
+        form.grid.sourceWidget.view.setAsActiveView();
       }
     }
   },
diff -r 2b85c2a65ed3 -r ffb5bef381b5 
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
      Mon Jan 10 08:22:01 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
      Mon Jan 10 08:26:35 2011 +0100
@@ -25,9 +25,8 @@
   
   viewProperties: null,
   
-  focusedView: null,
+  activeView: null,
   
-  readOnlyTabDefinition: null,
   views: [],
   
   initWidget: function(){
@@ -51,24 +50,38 @@
     // 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, {
+    // retrieve user specific window settings from the server
+    // they are stored at class level to only do the call once
+    if (!this.getClass().windowSettingsRead) {
+      
OB.RemoteCallManager.call('org.openbravo.client.application.WindowSettingsActionHandler',
 null, {
         windowId: this.windowId
       }, function(response, data, request){
-        standardWindow.setReadOnlyTabDefinition(data);
+        standardWindow.setWindowSettings(data);
       });
     }
   },
   
-  setReadOnlyTabDefinition: function(data){
-    this.getClass().readOnlyTabDefinition = data;
+  // set window specific user settings, purposely set on class level
+  setWindowSettings: function(data){
+    if (this.getClass().windowSettingsRead) {
+      return;
+    }
+    this.getClass().windowSettingsRead = true;
+    this.getClass().readOnlyTabDefinition = data.readOnlyDefinition;
+    this.getClass().autoSave = data.autoSave;
     // set the views to readonly
     for (var i = 0; i < this.views.length; i++) {
-      this.views[i].setReadOnly(data[this.views[i].tabId]);
+      this.views[i].setReadOnly(data.readOnlyDefinition[this.views[i].tabId]);
     }
   },
   
+  isAutoSave: function(){
+    if (this.getClass().autoSave) {
+      return true;
+    }
+    return false;
+  },
+  
   addView: function(view){
     view.standardWindow = this;
     this.views.push(view);
@@ -84,10 +97,41 @@
     return ret;
   },
   
+  // is called from the main app tabset
+  tabDeselected: function(tabNum, tabPane, ID, tab, newTab){
+    if (this.activeView) {
+      this.activeView.viewForm.autoSave();
+    }
+  },
+  
+  closeClick: function(tab, tabSet){
+    var actionObject = {
+      target: tabSet,
+      method: tabSet.doCloseClick,
+      parameters: [tab]
+    };
+    this.view.viewForm.autoSave(actionObject);
+  },
+  
+  setActiveView: function(view){
+    if (!this.isDrawn()) {
+      return;
+    }
+    var currentActiveView = this.activeView;
+    if (this.activeView === view) {
+      return;
+    }
+    if (currentActiveView) {
+      currentActiveView.setActiveViewVisualState(false);
+    }
+    this.activeView = view;
+    view.setActiveViewVisualState(true);
+  },
+  
   setFocusInView: function(){
-    var currentView = this.focusedView || this.view;
+    var currentView = this.activeView || this.view;
     currentView.setViewFocus();
-    currentView.setActiveView(true, true);
+    currentView.setAsActiveView(true);
   },
   
   draw: function(){
@@ -339,7 +383,11 @@
     isc.defineClass(obDsClassname, ds.getClass());
     
     var modifiedDs = isc.addProperties({}, ds, {
+      view: this,
+      
       fetchData: function(criteria, callback, requestProperties){
+//        isc.Dialog.Prompt.modalTarget = this.view.standardWindow;
+        
         var newRequestProperties = 
OB.Utilities._getTabInfoRequestProperties(this.view, requestProperties);
         var additionalPara = {
           _operationType: 'fetch',
@@ -350,6 +398,7 @@
       },
       
       updateData: function(updatedRecord, callback, requestProperties){
+        
         var newRequestProperties = 
OB.Utilities._getTabInfoRequestProperties(this.view, requestProperties);
         //standard update is not sent with operationType
         var additionalPara = {

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