Added deep link button and popup window and deep link logic
authorMartin Taal <martin.taal@openbravo.com>
Wed, 09 Mar 2011 09:59:28 +0100
changeset 11129 7b499d87c794
parent 11128 78bdd4129fe5
child 11131 362e1eb87492
Added deep link button and popup window and deep link logic
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/ob-form-styles.js
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/ob-toolbar-styles.css
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/ob-toolbar-styles.js
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Wed Mar 09 00:28:31 2011 +0100
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Wed Mar 09 09:59:28 2011 +0100
@@ -1542,4 +1542,37 @@
 <!--FF8081812E912BB3012E9144BF08009F-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--FF8081812E912BB3012E9144BF08009F--></AD_MESSAGE>
 
+<!--FF8081812E99943C012E99C86806004D--><AD_MESSAGE>
+<!--FF8081812E99943C012E99C86806004D-->  <AD_MESSAGE_ID><![CDATA[FF8081812E99943C012E99C86806004D]]></AD_MESSAGE_ID>
+<!--FF8081812E99943C012E99C86806004D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081812E99943C012E99C86806004D-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081812E99943C012E99C86806004D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081812E99943C012E99C86806004D-->  <VALUE><![CDATA[OBUIAPP_URL]]></VALUE>
+<!--FF8081812E99943C012E99C86806004D-->  <MSGTEXT><![CDATA[URL]]></MSGTEXT>
+<!--FF8081812E99943C012E99C86806004D-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF8081812E99943C012E99C86806004D-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081812E99943C012E99C86806004D--></AD_MESSAGE>
+
+<!--FF8081812E99943C012E99C8B0500050--><AD_MESSAGE>
+<!--FF8081812E99943C012E99C8B0500050-->  <AD_MESSAGE_ID><![CDATA[FF8081812E99943C012E99C8B0500050]]></AD_MESSAGE_ID>
+<!--FF8081812E99943C012E99C8B0500050-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081812E99943C012E99C8B0500050-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081812E99943C012E99C8B0500050-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081812E99943C012E99C8B0500050-->  <VALUE><![CDATA[OBUIAPP_Document_Link]]></VALUE>
+<!--FF8081812E99943C012E99C8B0500050-->  <MSGTEXT><![CDATA[Document Link]]></MSGTEXT>
+<!--FF8081812E99943C012E99C8B0500050-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF8081812E99943C012E99C8B0500050-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081812E99943C012E99C8B0500050--></AD_MESSAGE>
+
+<!--FF8081812E99943C012E99C9668A0055--><AD_MESSAGE>
+<!--FF8081812E99943C012E99C9668A0055-->  <AD_MESSAGE_ID><![CDATA[FF8081812E99943C012E99C9668A0055]]></AD_MESSAGE_ID>
+<!--FF8081812E99943C012E99C9668A0055-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081812E99943C012E99C9668A0055-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081812E99943C012E99C9668A0055-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081812E99943C012E99C9668A0055-->  <VALUE><![CDATA[OBUIAPP_GetDirectLink]]></VALUE>
+<!--FF8081812E99943C012E99C9668A0055-->  <MSGTEXT><![CDATA[Get a direct link to this view or record]]></MSGTEXT>
+<!--FF8081812E99943C012E99C9668A0055-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF8081812E99943C012E99C9668A0055-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081812E99943C012E99C9668A0055--></AD_MESSAGE>
+
 </data>
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js	Wed Mar 09 00:28:31 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js	Wed Mar 09 09:59:28 2011 +0100
@@ -207,6 +207,8 @@
         leftMemberButtons.push(isc.OBToolbarIconButton.create(this.iconToolbarButtons[i]));
       }
     }
+    // and add the direct link at the end
+    leftMemberButtons.push(isc.OBToolbarIconButton.create(isc.OBToolbar.LINK_BUTTON_PROPERTIES));
     
     this.toolBar = isc.OBToolbar.create({
       view: this,
@@ -462,6 +464,38 @@
     }
   },
   
+  getDirectLinkUrl: function() {
+    var url = window.location.href;
+    var qIndex = url.indexOf('?');
+    var dIndex = url.indexOf('#');
+    var index = -1;
+    if (dIndex != -1 && qIndex != -1) {
+      if (dIndex < qIndex) {
+        index = dIndex;
+      } else {
+        index = qIndex;
+      }
+    } else if (qIndex != -1) {
+      index = qIndex;
+    } else if (dIndex != -1) {
+      index = dIndex;
+    }
+    if (index != -1) {
+      url = url.substring(0, index);
+    }
+    
+    url = url + '?tabId=' + this.tabId;
+    if (this.isShowingForm) {
+      if (this.viewForm.isNew && this.isRootView) {
+        url = url + '&command=NEW';
+      } else if (!this.viewForm.isNew) {
+        url = url + '&recordId=' + this.viewGrid.getSelectedRecord().id;
+      }
+    }
+
+    return url;
+  },
+  
   // ** {{{ addChildView }}} **
   // The addChildView creates the child tab and sets the pointer back to
   // this
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js	Wed Mar 09 00:28:31 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js	Wed Mar 09 09:59:28 2011 +0100
@@ -222,6 +222,38 @@
     },
     keyboardShortcutId: 'ToolBar_Export'
   },
+  LINK_BUTTON_PROPERTIES: {
+    action: function(){
+      var url = this.view.getDirectLinkUrl();
+      var form = isc.OBViewForm.create({
+        width: 390,
+        height: 1,
+        overflow: 'visible',
+        fields: [{
+          type: 'OBTextAreaItem', selectOnFocus: true, 
+          width: 390, height: 50, canFocus: true, 
+          name:'url', 
+          title: OB.I18N.getLabel('OBUIAPP_URL'), value: url}
+        ],
+        show: function() {
+          var fld = this.getFields()[0];
+          this.setFocusItem(fld);
+          this.Super('show', arguments);
+          // do the focus with a delay to give the popup time to draw
+          this.fireOnPause('link_button_show', this.focus, 50, this);
+        }
+      });
+      var dialog = OB.Utilities.createDialog(OB.I18N.getLabel('OBUIAPP_Document_Link'));
+      dialog.setContent(form);
+      dialog.show();
+    },
+    disabled: false,
+    buttonType: 'link',
+    prompt: OB.I18N.getLabel('OBUIAPP_GetDirectLink'),
+    updateState: function(){
+    },
+    keyboardShortcutId: 'ToolBar_Link'    
+  },
   // This offers a mechanism to add properties at runtime to buttons created through
   // templates and java
   BUTTON_PROPERTIES: {
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js	Wed Mar 09 00:28:31 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js	Wed Mar 09 09:59:28 2011 +0100
@@ -21,6 +21,83 @@
 // are related to opening views, opening popups, displaying yes/no, etc. 
 OB.Utilities = {};
 
+// ** {{{OB.Utilities.createDialog}}} **
+// Creates a dialog with a title, an ok button and a layout in the middle.
+// The dialog is not shown but returned. The caller needs to call setContent to 
+// set the content in the dialog and show it.
+OB.Utilities.createDialog = function(title, focusOnOKButton, properties){
+  var dialog = isc.Dialog.create({
+    title: title,
+    toolbarButtons: [isc.Dialog.OK],
+    isModal: true,
+    canDragReposition: true,
+    keepInParentRect: true,
+    autoSize: true,
+    autoCenter: true,
+    
+    contentLayout: 'horizontal',
+    autoChildParentMap: isc.addProperties({}, isc.Window.getInstanceProperty("autoChildParentMap"), {
+      stack: 'body',
+      layout: 'stack',
+      toolbar: 'stack'
+    }),
+    
+    stackDefaults: {
+      height: 1
+    },
+
+    toolbarDefaults: isc.addProperties({}, isc.Dialog.getInstanceProperty("toolbarDefaults"), {
+      layoutAlign: 'center',
+      buttonConstructor: isc.OBFormButton
+    }),
+    
+    createChildren: function(){
+      this.showToolbar = false;
+      this.Super('createChildren');
+      this.addAutoChild('stack', null, isc.VStack);
+      this.addAutoChild('layout', {
+        height: 1,
+        width: '100%',
+        overflow: 'visible'
+      }, isc.VLayout);
+      this.showToolbar = true;
+      this.makeToolbar();
+      
+      // can't be done via defaults because policy and direction are dynamically determined
+      this.body.hPolicy = 'fill';
+    },
+    
+    // will set the content and show it
+    setContent: function(content){
+      
+      // Note: we lazily create children on draw, so verify that the items have been
+      // initialized before manipulating the label
+      if (!this._isInitialized) {
+        this.createChildren();
+      }
+      
+      // Update the content in the body        
+      this.layout.addMember(content);
+      this.toolbar.layoutChildren();
+      if (this.isDrawn()) {
+        this.stack.layoutChildren();
+        this.body.layoutChildren();
+        this.layoutChildren();
+      }
+      
+      this.show();
+      
+      // focus in the first button so you can hit Enter to do the default thing
+      if (this.toolbar && focusOnOKButton) {
+        var firstButton = this.toolbar.getMember(0);
+        firstButton.focus();
+      }
+    }
+    
+  }, properties);
+  return dialog;
+};
+
 // ** {{{OB.Utilities.createLoadingLayout}}} **
 // Creates a layout with the loading image.
 OB.Utilities.createLoadingLayout = function(){
@@ -182,7 +259,7 @@
     if (command !== 'NEW') {
       view.targetTabId = tabId;
     }
-      
+    
     if (recordId) {
       view.targetRecordId = recordId;
     }
--- a/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/ob-form-styles.js	Wed Mar 09 00:28:31 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	Wed Mar 09 09:59:28 2011 +0100
@@ -34,7 +34,6 @@
   cellPadding: 0
 });
 
-
 isc.OBFormButton.addProperties({
   baseStyle: 'OBFormButton',
   titleStyle: 'OBFormButtonTitle'
--- a/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/ob-toolbar-styles.css	Wed Mar 09 00:28:31 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/ob-toolbar-styles.css	Wed Mar 09 09:59:28 2011 +0100
@@ -130,6 +130,12 @@
   background-image: url(./images/toolbar/iconButton-savecloseX.png);
 }
 
+.OBToolbarIconButton_icon_link {
+  background-repeat: no-repeat;
+  background-position: center center;
+  background-image: url(./images/toolbar/iconButton-link.png);
+}
+
 .OBToolbarIconButton_icon_createCopy {
   background-repeat: no-repeat;
   background-position: center center;
--- a/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/ob-toolbar-styles.js	Wed Mar 09 00:28:31 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.application/ob-toolbar-styles.js	Wed Mar 09 09:59:28 2011 +0100
@@ -17,7 +17,6 @@
  ************************************************************************
 */
 
-
 isc.OBToolbar.addProperties({
   width: '100%',
   height: 45,
@@ -27,14 +26,12 @@
   rightMembersMargin: 12
 });
 
-
 isc.OBToolbarIconButton.addProperties({
   width: 30,
   height: 28,
   menuButtonImage: '[SKIN]/../../org.openbravo.client.application/images/toolbar/iconButton-menu-unfold.png'  /** There is a CSS hack to avoid showing it when no menu available. this.menuButtonImage inside initWidget doesn't run **/
 });
 
-
 isc.OBToolbarTextButton.addProperties({
   height: 30,
   autoFit: true