details:   /erp/devel/pi/rev/ce6986db003f
changeset: 10526:ce6986db003f
user:      Stefan Hühner <stefan.huehner <at> openbravo.com>
date:      Thu Feb 10 13:34:07 2011 +0100
summary:   Speedup login process by moving some request to a widget using it.
Move isInternetAvailable call which is used only inside one widget into that
widget and out of the normal login process (application-js.ftl) to not delay
the login itself.
This also adds a seperate loading spinner to this widget to give user feedback
about the extra loading happening thee.

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-remote-call-manager.js
 |    8 +-
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/ApplicationComponent.java
              |    4 +
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl
           |    1 -
 
modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoActionHandler.java
              |    3 +
 
modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-community-branding-widget.js
         |  106 ++++++---
 src/index.jsp                                                                  
                            |    1 -
 6 files changed, 78 insertions(+), 45 deletions(-)

diffs (224 lines):

diff -r e88f79cba1a7 -r ce6986db003f 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-remote-call-manager.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-remote-call-manager.js
        Thu Feb 10 12:10:58 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-remote-call-manager.js
        Thu Feb 10 13:34:07 2011 +0100
@@ -42,8 +42,8 @@
     //
     // Calls the remote action on the server. The response is processed by
     // calling the callBack function.
-    // The callback function gets three parameters: rpcResponse (the
-    // original request), data (the resulting content), rpcRequest.
+    // The callback function gets three parameters: rpcResponse,
+    // data (the resulting content), rpcRequest.
     // See the Smartclient RPCCallback type for more information.
     //
     // Parameters:
@@ -53,8 +53,8 @@
     // * {{{requestParams}}}: request parameters send to the action.
     // * {{{callback}}}: is the function which is called after receiving the
     // result.
-    // * {{{callerContext}}}: a context object which is available when the
-    // callback gets called.
+    // * {{{callerContext}}}: a context object which is available
+    // (as rpcRequest.clientContext) when the callback gets called
     //
     call : function(/* String */actionName, /* Object */data, /* Object */
     requestParams, /* Function */callback, /* Object */callerContext) {
diff -r e88f79cba1a7 -r ce6986db003f 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/ApplicationComponent.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/ApplicationComponent.java
     Thu Feb 10 12:10:58 2011 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/ApplicationComponent.java
     Thu Feb 10 13:34:07 2011 +0100
@@ -131,6 +131,10 @@
     return result;
   }
 
+  /**
+   * @deprecated the value is retrieved asynchronously via the 
MyOpenbravoActionHandler instead
+   */
+  @Deprecated
   public String getCommunityBrandingUrl() {
     return Utility.getCommunityBrandingUrl(MYOB_UIMODE);
   }
diff -r e88f79cba1a7 -r ce6986db003f 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl
  Thu Feb 10 12:10:58 2011 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl
  Thu Feb 10 13:34:07 2011 +0100
@@ -23,7 +23,6 @@
         language : '${data.languageId?js_string}',
         systemVersion : '${data.systemVersion?js_string}', // global version 
used in all hyperlinks
         contextUrl: '${data.contextUrl}',
-        communityBrandingUrl: '${data.communityBrandingUrl?js_string}',
         communityBrandingStaticUrl: 
'${data.communityBrandingStaticUrl?js_string}',
         butlerUtilsUrl: '${data.butlerUtilsUrl?js_string}',
         purpose: '${data.instancePurpose?js_string}',
diff -r e88f79cba1a7 -r ce6986db003f 
modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoActionHandler.java
--- 
a/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoActionHandler.java
     Thu Feb 10 12:10:58 2011 +0100
+++ 
b/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/MyOpenbravoActionHandler.java
     Thu Feb 10 13:34:07 2011 +0100
@@ -58,6 +58,7 @@
   private static final String WIDGET_REMOVED = "WIDGET_REMOVED";
   private static final String PUBLISH_CHANGES = "PUBLISH_CHANGES";
   private static final String RELOAD_WIDGETS = "RELOAD_WIDGETS";
+  private static final String GET_COMMUNITY_BRANDING_URL = 
"GET_COMMUNITY_BRANDING_URL";
   private static final String GET_AVAILABLE_WIDGET_CLASSES = 
"GET_AVAILABLE_WIDGET_CLASSES";
 
   @Inject
@@ -108,6 +109,8 @@
           o.put("widgets", widgets);
         } else if (strEventType.equals(GET_AVAILABLE_WIDGET_CLASSES)) {
           addAvailableWidgetClasses(o);
+        } else if (strEventType.equals(GET_COMMUNITY_BRANDING_URL)) {
+          o.put("url", Utility.getCommunityBrandingUrl("MyOB"));
         } else {
           message.setType("Error");
           message.setMessage("@OBKMO_UnknownEventType@");
diff -r e88f79cba1a7 -r ce6986db003f 
modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-community-branding-widget.js
--- 
a/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-community-branding-widget.js
        Thu Feb 10 12:10:58 2011 +0100
+++ 
b/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-community-branding-widget.js
        Thu Feb 10 13:34:07 2011 +0100
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010 Openbravo SLU
+ * All portions are Copyright (C) 2010-2011 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -26,41 +26,85 @@
   headerLabel: null,
 
   createWindowContents: function(){
-    var layout = isc.VStack.create({height:'100%', width:'100%', 
styleName:''}),
-        url, params = {};
+    var layout = isc.VStack.create({height:'100%', width:'100%', 
styleName:''});
 
     if(!OB.Application.brandingWidget) {
       // set a global pointer to ourselves
       OB.Application.brandingWidget = this;
     }
-    
-    this.versionLabel = isc.Label.create({contents: this.versionText,
-                                         height: '36px',
-                                         width:'100%',
-                                         styleName: 
this.getPurposeStyleClass(),
-                                         align: 'center'});
 
-    layout.addMember(this.versionLabel);
+    layout.addMember(OB.Utilities.createLoadingLayout());
 
-    // note internetConnection is a global var set by a call to
-    // the butler service
-    if (typeof internetConnection !== 'undefined') {
-      url = document.location.protocol + OB.Application.communityBrandingUrl;
+    var post = {
+      'eventType': 'GET_COMMUNITY_BRANDING_URL',
+      'context' : {
+        'adminMode' : 'false'
+      },
+      'widgets' : []
+    }
+
+    var me = this;
+    var haveInternet = false;
+    /*
+     * The following LAB.wait(callback) call does not reliably call the 
callout in case no
+     * internet connection is present (so schedule timeout to use local 
fallback content after 10s)
+     */
+    var timerNoInternet = setTimeout(function() {
+      me.setOBContent(false);
+    }, 10000);
+    $LAB.script(document.location.protocol + 
OB.Application.butlerUtilsUrl).wait(function() {
+       haveInternet = (typeof internetConnection !== 'undefined');
+       // callback did fire so clear timer as its no longer needed
+       clearTimeout(timerNoInternet);
+
+       if (haveInternet) {
+        
OB.RemoteCallManager.call('org.openbravo.client.myob.MyOpenbravoActionHandler', 
post, {}, function(response, data, request) {
+               var communityBrandingUrl = data.url;
+               me.setOBContent(haveInternet, communityBrandingUrl);
+        });
+       } else {
+          me.setOBContent(false);
+        }
+    });
+
+    return layout;
+  },
+
+  setOBContent: function(haveInternet, communityBrandingUrl) {
+    var url, params = {};
+
+    if (haveInternet) {
+      url = document.location.protocol + communityBrandingUrl;
     } else {
       url = OB.Application.contextUrl + 
OB.Application.communityBrandingStaticUrl;
       params = {'uimode': 'MyOB'};
     }
 
-    layout.addMember(isc.HTMLFlow.create({
-      contentsType: 'page',
-      contentsURL: url,
-      contentsURLParams: params,
-      height: '324px',
-      width: '100%'
-    }));
-    return layout;
+    var layout = this.windowContents;
+
+    // remove Loading...
+    var loadingBar = layout.members[this.windowContents.members.length-1];
+
+    this.versionLabel = isc.Label.create({contents: this.versionText,
+      height: '36px',
+      width:'100%',
+      styleName: this.getPurposeStyleClass(),
+      align: 'center'
+    });
+
+    var content = isc.HTMLFlow.create({
+        contentsType: 'page',
+        contentsURL: url,
+        contentsURLParams: params,
+        height: '324px',
+        width: '100%'
+      });
+
+    layout.removeMember(loadingBar);
+    layout.addMember(this.versionLabel);
+    layout.addMember(content);
   },
-  
+
   update: function() {
     //FIXME: too expensive
     OB.MyOB.reloadWidgets();
@@ -70,22 +114,6 @@
 //    this.versionLabel.draw();
   },
   
-  getBrandingHtml: function() {
-    var html = this.brandingHtml;
-    
-    html = html.replace('{versionText}', this.versionText);
-    html = html.replace('{brandingUrl}', url);
-    html = html.replace('{purposeClass}', this.getPurposeStyleClass());
-    return html;
-  },
-  
-  brandingHtml: '<DIV id="communityBranding" class="OBWidgetCommunityBranding" 
border="0">' +
-  '<DIV class="OBWidgetCommunityBrandingTitle">' +
-  '<DIV class="{purposeClass}" alt="" title=""></DIV>' +
-  '<DIV class="OBWidgetCommunityBrandingVersion">{versionText}</DIV>' +
-  '</DIV>' +
-  '</DIV>',
-  
   getPurposeStyleClass: function(){
     var purposeCode = OB.Application.purpose;
     if (purposeCode === 'D') {
diff -r e88f79cba1a7 -r ce6986db003f src/index.jsp
--- a/src/index.jsp     Thu Feb 10 12:10:58 2011 +0100
+++ b/src/index.jsp     Thu Feb 10 13:34:07 2011 +0100
@@ -118,7 +118,6 @@
 // starts the application is called as the last statement in the 
StaticResources part
 function OBStartApplication() {
   OB.Layout.draw();
-  $LAB.script(document.location.protocol + 
OB.Application.butlerUtilsUrl).wait();
   OB.Layout.ViewManager.createAddStartTab();
   // get rid of the loading stuff
   document.body.removeChild(document.getElementById('OBLoadingDiv'));

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to