Added recent docs functionality
authorMartin Taal <martin.taal@openbravo.com>
Thu, 10 Mar 2011 11:47:22 +0100
changeset 11171 e36b3ca87880
parent 11170 bcdcdbfc5590
child 11172 d5ed03e73444
Added recent docs functionality
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_REF_LIST.xml
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-recent-utilities.js
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-utilities.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-manager.js
modules/org.openbravo.client.myob/src-db/database/sourcedata/AD_MESSAGE.xml
modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-myopenbravo.js
modules/org.openbravo.client.myob/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.myob/images/management/IconRecentDocs.png
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_REF_LIST.xml	Thu Mar 10 11:46:34 2011 +0100
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_REF_LIST.xml	Thu Mar 10 11:47:22 2011 +0100
@@ -175,4 +175,16 @@
 <!--FF8081812E7BEED8012E7C2FCFB30063-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--FF8081812E7BEED8012E7C2FCFB30063--></AD_REF_LIST>
 
+<!--FF8081812E9F4334012E9F4855820012--><AD_REF_LIST>
+<!--FF8081812E9F4334012E9F4855820012-->  <AD_REF_LIST_ID><![CDATA[FF8081812E9F4334012E9F4855820012]]></AD_REF_LIST_ID>
+<!--FF8081812E9F4334012E9F4855820012-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081812E9F4334012E9F4855820012-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081812E9F4334012E9F4855820012-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081812E9F4334012E9F4855820012-->  <VALUE><![CDATA[OBUIAPP_RecentDocumentsList]]></VALUE>
+<!--FF8081812E9F4334012E9F4855820012-->  <NAME><![CDATA[OBUIAPP_RecentDocumentsList]]></NAME>
+<!--FF8081812E9F4334012E9F4855820012-->  <DESCRIPTION><![CDATA[Recent documents opened by the user]]></DESCRIPTION>
+<!--FF8081812E9F4334012E9F4855820012-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--FF8081812E9F4334012E9F4855820012-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081812E9F4334012E9F4855820012--></AD_REF_LIST>
+
 </data>
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-recent-utilities.js	Thu Mar 10 11:46:34 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-recent-utilities.js	Thu Mar 10 11:47:22 2011 +0100
@@ -93,15 +93,18 @@
         return;
       }
       var currentRecentValue = this.getRecentValue(propertyName);
+      // check if there is already an entry for the new recent
       var currentIndex = -1;
       for (var i = 0; i < currentRecentValue.length; i++) {
-        // if the title is the same then assume they are the same
-        if (currentRecentValue[i].tabTitle && 
+        // if the title is the same then assume they are the same, only 
+        // check this if there is no recentId being used
+        if (!currentRecentValue[i].recentId && currentRecentValue[i].tabTitle && 
             choiceObject.tabTitle && choiceObject.tabTitle === currentRecentValue[i].tabTitle) {
           currentIndex = i;
-        } else if (currentRecentValue[i] &&
-        currentRecentValue[i].id === choiceObject.id) {
-          // found it
+        } else  if (currentRecentValue[i].recentId && 
+              choiceObject.recentId && choiceObject.recentId === currentRecentValue[i].recentId) {
+            currentIndex = i;
+        } else if (currentRecentValue[i].id && currentRecentValue[i].id === choiceObject.id) {
           currentIndex = i;
         }
       }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js	Thu Mar 10 11:46:34 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js	Thu Mar 10 11:47:22 2011 +0100
@@ -485,12 +485,10 @@
     }
     
     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;
-      }
+    if (this.isShowingForm && this.viewForm.isNew && this.isRootView) {      
+        url = url + '&command=NEW';      
+    } else if (this.viewGrid.getSelectedRecords() && this.viewGrid.getSelectedRecords().length === 1) {
+      url = url + '&recordId=' + this.viewGrid.getSelectedRecord().id;
     }
 
     return url;
@@ -592,6 +590,15 @@
     }
   },
   
+  setRecentDocument: function(record) {
+    var params = this.standardWindow.getBookMarkParams();
+    params.targetTabId = this.tabId;
+    params.targetRecordId = record.id;
+    params.recentId = this.tabId + '_' + record.id;
+    params.recentTitle = record[OB.Constants.IDENTIFIER];
+    OB.Layout.ViewManager.addRecentDocument(params);
+  },
+  
   setActiveViewProps: function(state){
     if (state) {
       this.toolBar.show();
@@ -1182,11 +1189,10 @@
       tab.prompt = title;
       tab.showPrompt = true;
       tab.hoverWidth = 150;
-
-      if (title.length > 30) {
-        title = title.substring(0, 30) + "...";
-      }
-
+      
+      // trunc the title if it too large 
+      title = OB.Utilities.truncTitle(title);
+      
       // add the prefix/suffix here to prevent cutoff on that
       title = prefix + title + suffix;
       tabSet.setTabTitle(tab, title);
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js	Thu Mar 10 11:46:34 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-utilities.js	Thu Mar 10 11:47:22 2011 +0100
@@ -21,6 +21,21 @@
 // are related to opening views, opening popups, displaying yes/no, etc. 
 OB.Utilities = {};
 
+// ** {{{OB.Utilities.truncTitle}}} **
+// Truncs a string after a specific length. Initial implementation is 
+// simple (just cuts of at the specified length). Returns the trunced title
+// if no cutLength is set then the default length of 30 is chosen. If no
+// suffix is set then ... is appended
+// TODO: more advanced implementations can cut of at a space or dash for 
+// example
+OB.Utilities.truncTitle = function(title, cutLength, suffix){
+  cutLength = cutLength || 30;
+  if (!title || title.length < cutLength) {
+    return title;
+  }
+  return title.substring(0, cutLength) + (suffix || '...');
+};
+
 // ** {{{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 
@@ -246,6 +261,11 @@
 // is not set then the tab is opened in grid mode. If command is not set then default is
 // used.
 OB.Utilities.openDirectTab = function(tabId, recordId, command){
+  
+  tabId = OB.Utilities.removeFragment(tabId);
+  recordId = OB.Utilities.removeFragment(recordId);
+  command = OB.Utilities.removeFragment(command);
+  
   var callback = function(response, data, request){
     command = command || 'DEFAULT';
     var view = {
@@ -272,6 +292,19 @@
   }, callback);
 };
 
+// ** {{{OB.Utilities.removeFragment}}} **
+// remove a # and the rest from a string
+OB.Utilities.removeFragment = function(str) {
+  if (!str) {
+    return str;
+  }
+  var index = str.indexOf('#');
+  if (index !== -1) {
+    return str.substring(0, index);
+  }
+  return str;
+};
+
 // ** {{{OB.Utilities.openView}}} **
 // Open a view taking into account if a specific window should be opened in classic mode or not.
 // Returns the object used to open the window.
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js	Thu Mar 10 11:46:34 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-form.js	Thu Mar 10 11:47:22 2011 +0100
@@ -816,6 +816,8 @@
         //view.messageBar.setMessage(isc.OBMessageBar.TYPE_SUCCESS, null, OB.I18N.getLabel('OBUIAPP_SaveSuccess'));
         view.statusBar.setStateLabel('OBUIAPP_Saved', view.statusBar.checkedIcon);
         
+        view.setRecentDocument(this.getValues());
+        
         // force a fetch to place the grid on the correct location
         if (form.isNew) {
           view.viewGrid.targetRecordId = data.id;
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-manager.js	Thu Mar 10 11:46:34 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-manager.js	Thu Mar 10 11:47:22 2011 +0100
@@ -132,6 +132,12 @@
       var request = rpcMgr.sendRequest(reqObj);
     },
     
+    addRecentDocument: function(params) {
+      vmgr.recentManager.addRecent('OBUIAPP_RecentDocumentsList', 
+          isc.addProperties({icon: '[SKINIMG]../../org.openbravo.client.application/images/application-menu/iconWindow.png'}, 
+              params));
+    },
+    
     createTab: function(viewName, viewTabId, viewInstance, params) {
       if (params.i18nTabTitle) {
         // note call to I18N is done below after the tab
--- a/modules/org.openbravo.client.myob/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Mar 10 11:46:34 2011 +0100
+++ b/modules/org.openbravo.client.myob/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Mar 10 11:47:22 2011 +0100
@@ -605,4 +605,15 @@
 <!--FF8081812E14E58B012E14F2ED5300B4-->  <AD_MODULE_ID><![CDATA[2758CD25B2704AF6BBAD10365FC82C06]]></AD_MODULE_ID>
 <!--FF8081812E14E58B012E14F2ED5300B4--></AD_MESSAGE>
 
+<!--FF8081812E9F4334012E9F4645BF0007--><AD_MESSAGE>
+<!--FF8081812E9F4334012E9F4645BF0007-->  <AD_MESSAGE_ID><![CDATA[FF8081812E9F4334012E9F4645BF0007]]></AD_MESSAGE_ID>
+<!--FF8081812E9F4334012E9F4645BF0007-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081812E9F4334012E9F4645BF0007-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081812E9F4334012E9F4645BF0007-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081812E9F4334012E9F4645BF0007-->  <VALUE><![CDATA[OBKMO_RecentDocuments]]></VALUE>
+<!--FF8081812E9F4334012E9F4645BF0007-->  <MSGTEXT><![CDATA[Recent Documents]]></MSGTEXT>
+<!--FF8081812E9F4334012E9F4645BF0007-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF8081812E9F4334012E9F4645BF0007-->  <AD_MODULE_ID><![CDATA[2758CD25B2704AF6BBAD10365FC82C06]]></AD_MODULE_ID>
+<!--FF8081812E9F4334012E9F4645BF0007--></AD_MESSAGE>
+
 </data>
--- a/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-myopenbravo.js	Thu Mar 10 11:46:34 2011 +0100
+++ b/modules/org.openbravo.client.myob/web/org.openbravo.client.myob/js/ob-myopenbravo.js	Thu Mar 10 11:47:22 2011 +0100
@@ -90,15 +90,10 @@
   adminMode: false,
   adminLevel: '',
   adminLevelValue: '',
-
+    
   initWidget: function(args){
-    var me = this, i, widgetInstance, recentViewsLayout, addWidgetLayout, adminOtherMyOBLayout, refreshLayout;
+    var me = this, i, widgetInstance, recentViewsLayout, recentViewsLinksLayout, recentDocumentsLayout, recentDocumentsLinksLayout, addWidgetLayout, adminOtherMyOBLayout, refreshLayout;
     
-    // TODO: styling
-    // the recent view links copied from the quick launch/quick create
-    // and menu
-    // TODO: should this be updated every time the user makes a selection
-    // in the quick launch/create and menu?
     recentViewsLayout = isc.VLayout.create({});
     recentViewsLayout.addMember(isc.Label.create({
       height: 1,
@@ -120,6 +115,27 @@
       }
     });
 
+    recentDocumentsLayout = isc.VLayout.create({});
+    recentDocumentsLayout.addMember(isc.Label.create({
+      height: 1,
+      overflow: 'visible',
+      baseStyle: 'OBMyOBRecentViews',
+      contents: OB.I18N.getLabel('OBKMO_RecentDocuments')
+    }));
+
+    recentDocumentsLinksLayout = isc.VLayout.create({
+      height: 1,
+      overflow: 'visible'
+    });
+    recentDocumentsLayout.addMember(recentDocumentsLinksLayout);
+    this.setRecentDocumentsList(recentDocumentsLinksLayout);
+
+    OB.PropertyStore.addListener(function(propertyName, currentValue, newValue){
+      if (propertyName === 'OBUIAPP_RecentDocumentsList') {
+        me.setRecentDocumentsList(recentDocumentsLinksLayout);
+      }
+    });
+    
     var actionTitle = isc.VLayout.create({
       height: 1,
       overflow: 'visible'
@@ -198,7 +214,7 @@
       width: '15%',
       height: 1,
       overflow: 'visible',
-      members: [recentViewsLayout, isc.LayoutSpacer.create({
+      members: [recentViewsLayout, recentDocumentsLayout, isc.LayoutSpacer.create({
         height: 5
       }), actionTitle, refreshLayout, addWidgetLayout]
     });
@@ -418,6 +434,52 @@
       layout.markForRedraw();
     }
   },
+  
+  setRecentDocumentsList: function(layout){
+    var recentList, newRecent, recentIndex = 0, recent, lbl, newIcon, entryLayout, icon;
+    // start with a fresh content
+    layout.removeMembers(layout.members);
+    
+    // reads the list of recents and displays them
+    recentList = OB.Layout.ViewManager.recentManager.getRecentValue('OBUIAPP_RecentDocumentsList');
+    if (recentList && recentList.length > 0) {
+    
+      handleClickFunction = function(){
+        OB.Layout.ViewManager.openView(this.recent.viewId, this.recent);
+      };
+
+      for (; recentIndex < recentList.length; recentIndex++) {
+        if (recentList[recentIndex]) {
+          recent = recentList[recentIndex];
+          recent.command = 'DEFAULT';
+          
+          lbl = isc.Label.create({
+            contents: OB.Utilities.truncTitle(recent.recentTitle, 20),
+            recent: recent,
+            wrap: false,
+            width: '100%',
+            showHover: true,
+            showPrompt: true,
+            prompt: recent.tabTitle + ' - ' + recent.recentTitle,            
+            baseStyle: 'OBMyOBRecentViewsEntry',
+            handleClick: handleClickFunction,
+            iconOrientation: 'left',
+            icon: '[SKINIMG]../../org.openbravo.client.myob/images/management/IconRecentDocs.png',
+            iconWidth: 13,
+            iconHeight: 15
+          });
+
+          entryLayout = isc.HLayout.create({
+            defaultLayoutAlign: 'center',
+            width: '100%'
+          });
+          entryLayout.addMember(lbl);
+          layout.addMember(entryLayout);
+        }
+      }
+      layout.markForRedraw();
+    }
+  },
 
   // ** {{{ OBMyOpenbravo.addWidget(widgetProperties) }}} **
   //
Binary file modules/org.openbravo.client.myob/web/org.openbravo.userinterface.smartclient/openbravo/skins/3.00/org.openbravo.client.myob/images/management/IconRecentDocs.png has changed