Fixed issue 26776: Re-added KS capabilities to filters
authorDavid Baz Fayos <david.baz@openbravo.com>
Mon, 05 Jan 2015 16:27:55 +0100
changeset 25722 17607c72e7c5
parent 25721 aafc50f0ea12
child 25723 c64817b82a3e
Fixed issue 26776: Re-added KS capabilities to filters
More info at http://wiki.openbravo.com/wiki/Projects:FK_Filter_Keyboard_Shortcuts
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list-filter.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js	Mon Jan 05 16:26:06 2015 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js	Mon Jan 05 16:27:55 2015 +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) 2011-2014 Openbravo SLU
+ * All portions are Copyright (C) 2011-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -77,6 +77,11 @@
     }
 
     this.pickListProperties = {
+      // 'showOverAsSelected' and 'bodyKeyPress' defined here until issue 28475 be fixed.
+      // After the fix the following two lines must be removed, since it will be inherited from
+      // OBListFilterItem  as usual
+      showOverAsSelected: this.pickListProperties.showOverAsSelected,
+      bodyKeyPress: this.pickListProperties.bodyKeyPress,
 
       // make sure that we send the same parameters as the grid
       onFetchData: function (criteria, requestProperties) {
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list-filter.js	Mon Jan 05 16:26:06 2015 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-list-filter.js	Mon Jan 05 16:27:55 2015 +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) 2011-2014 Openbravo SLU
+ * All portions are Copyright (C) 2011-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -74,5 +74,55 @@
       isc.Page.setEvent(isc.EH.IDLE, this.form.grid, isc.Page.FIRE_ONCE, 'performAction');
     }
     this.Super('change', arguments);
+  },
+
+  handleKeyPress: function () {
+    if (isc.EH.getKey() === 'Space') {
+      if (this.isPickListShown() && !this.pickList.bodyKeyPress('Space')) {
+        return false;
+      }
+    }
+    return this.Super('handleKeyPress', arguments);
+  }
+});
+
+isc.OBListFilterItem.changeDefaults('pickListProperties', {
+  showOverAsSelected: false,
+
+  bodyKeyPress: function (event, eventInfo) {
+    var focusedRecord = this.getRecord(this.getFocusRow()),
+        selectedRecords = this.getSelectedRecords(),
+        isSelectedRecord = false,
+        recordIdentifier = (this.fields && this.fields[1] && this.fields[1].name ? this.fields[1].name : ''),
+        i;
+    for (i = 0; i < selectedRecords.length; i++) {
+      if (focusedRecord[recordIdentifier] === selectedRecords[i][recordIdentifier]) {
+        isSelectedRecord = true;
+        break;
+      }
+    }
+    if (event === 'Space') {
+      // bodyKeyPress doesn't capture 'Space' key press, so used this workaround
+      // to obtain it from the 'handleKeyPress' of the parent item
+      if (focusedRecord) {
+        if (isSelectedRecord) {
+          this.deselectRecord(focusedRecord);
+        } else {
+          this.selectRecord(focusedRecord);
+        }
+        this.multiSelectChanged();
+        // Return false to avoid propagation in the parent item
+        return false;
+      } else {
+        // Return true to ensure propagation in the parent item
+        return true;
+      }
+    }
+    if (isc.EH.getKey() === 'Enter') {
+      if (!isSelectedRecord) {
+        this.selectRecord(focusedRecord);
+      }
+    }
+    return this.Super('bodyKeyPress', arguments);
   }
 });
\ No newline at end of file