Added new context menu entries, enter key starts new row
authorMartin Taal <martin.taal@openbravo.com>
Thu, 03 Mar 2011 13:49:09 +0100
changeset 10992 1cd103b3bf2a
parent 10991 8fe8a3602973
child 10993 8fa360d7c861
Added new context menu entries, enter key starts new row
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Mar 03 13:18:26 2011 +0100
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Mar 03 13:49:09 2011 +0100
@@ -116,7 +116,7 @@
 <!--2052DF26669F4864B295C17502F53E38-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--2052DF26669F4864B295C17502F53E38-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--2052DF26669F4864B295C17502F53E38-->  <VALUE><![CDATA[OBUIAPP_EditInGrid]]></VALUE>
-<!--2052DF26669F4864B295C17502F53E38-->  <MSGTEXT><![CDATA[Edit in Grid]]></MSGTEXT>
+<!--2052DF26669F4864B295C17502F53E38-->  <MSGTEXT><![CDATA[Edit in grid ]]></MSGTEXT>
 <!--2052DF26669F4864B295C17502F53E38-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
 <!--2052DF26669F4864B295C17502F53E38-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--2052DF26669F4864B295C17502F53E38--></AD_MESSAGE>
@@ -1124,4 +1124,48 @@
 <!--FF8081812E0F2FB1012E0F3248D5000B-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--FF8081812E0F2FB1012E0F3248D5000B--></AD_MESSAGE>
 
+<!--FF8081812E7BA4E8012E7BABECB30008--><AD_MESSAGE>
+<!--FF8081812E7BA4E8012E7BABECB30008-->  <AD_MESSAGE_ID><![CDATA[FF8081812E7BA4E8012E7BABECB30008]]></AD_MESSAGE_ID>
+<!--FF8081812E7BA4E8012E7BABECB30008-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081812E7BA4E8012E7BABECB30008-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081812E7BA4E8012E7BABECB30008-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081812E7BA4E8012E7BABECB30008-->  <VALUE><![CDATA[OBUIAPP_Delete]]></VALUE>
+<!--FF8081812E7BA4E8012E7BABECB30008-->  <MSGTEXT><![CDATA[Delete]]></MSGTEXT>
+<!--FF8081812E7BA4E8012E7BABECB30008-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF8081812E7BA4E8012E7BABECB30008-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081812E7BA4E8012E7BABECB30008--></AD_MESSAGE>
+
+<!--FF8081812E7BA4E8012E7BAD022D001A--><AD_MESSAGE>
+<!--FF8081812E7BA4E8012E7BAD022D001A-->  <AD_MESSAGE_ID><![CDATA[FF8081812E7BA4E8012E7BAD022D001A]]></AD_MESSAGE_ID>
+<!--FF8081812E7BA4E8012E7BAD022D001A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081812E7BA4E8012E7BAD022D001A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081812E7BA4E8012E7BAD022D001A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081812E7BA4E8012E7BAD022D001A-->  <VALUE><![CDATA[OBUIAPP_EditInForm]]></VALUE>
+<!--FF8081812E7BA4E8012E7BAD022D001A-->  <MSGTEXT><![CDATA[Edit in form]]></MSGTEXT>
+<!--FF8081812E7BA4E8012E7BAD022D001A-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF8081812E7BA4E8012E7BAD022D001A-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081812E7BA4E8012E7BAD022D001A--></AD_MESSAGE>
+
+<!--FF8081812E7BA4E8012E7BAD74830021--><AD_MESSAGE>
+<!--FF8081812E7BA4E8012E7BAD74830021-->  <AD_MESSAGE_ID><![CDATA[FF8081812E7BA4E8012E7BAD74830021]]></AD_MESSAGE_ID>
+<!--FF8081812E7BA4E8012E7BAD74830021-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081812E7BA4E8012E7BAD74830021-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081812E7BA4E8012E7BAD74830021-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081812E7BA4E8012E7BAD74830021-->  <VALUE><![CDATA[OBUIAPP_CreateRecordInGrid]]></VALUE>
+<!--FF8081812E7BA4E8012E7BAD74830021-->  <MSGTEXT><![CDATA[New record in grid]]></MSGTEXT>
+<!--FF8081812E7BA4E8012E7BAD74830021-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF8081812E7BA4E8012E7BAD74830021-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081812E7BA4E8012E7BAD74830021--></AD_MESSAGE>
+
+<!--FF8081812E7BA4E8012E7BADC6FE0028--><AD_MESSAGE>
+<!--FF8081812E7BA4E8012E7BADC6FE0028-->  <AD_MESSAGE_ID><![CDATA[FF8081812E7BA4E8012E7BADC6FE0028]]></AD_MESSAGE_ID>
+<!--FF8081812E7BA4E8012E7BADC6FE0028-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081812E7BA4E8012E7BADC6FE0028-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081812E7BA4E8012E7BADC6FE0028-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081812E7BA4E8012E7BADC6FE0028-->  <VALUE><![CDATA[OBUIAPP_CreateRecordInForm]]></VALUE>
+<!--FF8081812E7BA4E8012E7BADC6FE0028-->  <MSGTEXT><![CDATA[New record in form]]></MSGTEXT>
+<!--FF8081812E7BA4E8012E7BADC6FE0028-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--FF8081812E7BA4E8012E7BADC6FE0028-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--FF8081812E7BA4E8012E7BADC6FE0028--></AD_MESSAGE>
+
 </data>
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js	Thu Mar 03 13:18:26 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-view-grid.js	Thu Mar 03 13:49:09 2011 +0100
@@ -202,6 +202,24 @@
       filterEditorType: 'StaticTextItem'
     });
     
+    var grid = this;
+    var menuItems = [{
+        title: OB.I18N.getLabel('OBUIAPP_CreateRecordInGrid'),
+        click: function(){
+          grid.deselectAllRecords();
+          grid.startEditingNew();
+        }
+      }, {
+        title: OB.I18N.getLabel('OBUIAPP_CreateRecordInForm'),
+        click: function(){
+          grid.deselectAllRecords();
+          grid.view.newDocument();
+        }
+      }
+    ];
+    
+    this.contextMenu = this.getMenuConstructor().create({items: menuItems});
+    
     var ret = this.Super('initWidget', arguments);
     
     this.noDataEmptyMessage = OB.I18N.getLabel('OBUISC_ListGrid.loadingDataMessage'); // OB.I18N.getLabel('OBUIAPP_GridNoRecords')
@@ -313,6 +331,17 @@
     }
     return this.Super('headerClick', arguments);
   },
+
+  // overridden to set the enterkeyaction to nextrowstart in cases the current row
+  // is the last being edited  
+  getNextEditCell : function (rowNum, colNum, editCompletionEvent) {
+    // past the last row
+    if (editCompletionEvent === isc.ListGrid.ENTER_KEYPRESS && rowNum === (this.getTotalRows() - 1)) {
+      // move to the next row
+      return this.findNextEditCell(rowNum +1, 0, 1, true, true);
+    }
+    return this.Super('getNextEditCell', arguments);
+  },
   
   deselectAllRecords: function(preventUpdateSelectInfo, autoSaveDone){
     if (!autoSaveDone) {
@@ -769,15 +798,23 @@
   makeCellContextItems: function(record, rowNum, colNum){
     var sourceWindow = this.view.standardWindow.windowId;
     var menuItems = [];
+    var recordsSelected = this.getSelectedRecords().length > 0;
+    var singleSelected = this.getSelectedRecords().length === 1;
     var field = this.getField(colNum);
     var grid = this;
     menuItems.add({
-      title: OB.I18N.getLabel('OBUIAPP_CreateNewRecord'),
+      title: OB.I18N.getLabel('OBUIAPP_CreateRecordInGrid'),
       click: function(){
         grid.startEditingNew(rowNum);
       }
     });
-    if (this.canEdit && this.isWritable(record) && !this.view.readOnly) {
+    menuItems.add({
+      title: OB.I18N.getLabel('OBUIAPP_CreateRecordInForm'),
+      click: function(){
+        grid.view.newDocument();
+      }
+    });
+    if (singleSelected && this.canEdit && this.isWritable(record) && !this.view.readOnly) {
       menuItems.add({
         title: OB.I18N.getLabel('OBUIAPP_EditInGrid'),
         click: function(){
@@ -785,8 +822,15 @@
           grid.startEditing(rowNum, colNum);
         }
       });
+      menuItems.add({
+        title: OB.I18N.getLabel('OBUIAPP_EditInForm'),
+        click: function(){
+          grid.endEditing();
+          grid.view.editRecord(record);
+        }
+      });
     }
-    if (field.canFilter) {
+    if (singleSelected && field.canFilter) {
       menuItems.add({
         title: OB.I18N.getLabel('OBUIAPP_UseAsFilter'),
         click: function(){
@@ -806,7 +850,7 @@
         }
       });
     }
-    if (field.foreignKeyField) {
+    if (singleSelected && field.foreignKeyField) {
       menuItems.add({
         title: OB.I18N.getLabel('OBUIAPP_OpenOnTab'),
         click: function(){
@@ -819,6 +863,14 @@
         }
       });
     }
+    if (recordsSelected && !this.view.readOnly && this.allSelectedRecordsWritable()) {
+      menuItems.add({
+        title: OB.I18N.getLabel('OBUIAPP_Delete'),
+        click: function(){
+          grid.view.deleteSelectedRows();
+        }
+      });
+    }
     
     return menuItems;
   },
@@ -1499,6 +1551,16 @@
     return !record._readOnly;
   },
   
+  allSelectedRecordsWritable: function() {
+    for (var i = 0; i < this.getSelectedRecords().length; i++) {
+      var record = this.getSelectedRecords()[i];
+      if (!this.isWritable(record)) {
+        return false;
+      }
+    }
+    return true;    
+  },
+  
   setRecordErrorMessage: function(rowNum, msg){
     var record = this.getRecord(rowNum);
     if (!record) {