commit 51d84e29e395bdade7ae78e51bc28d6345abb88a
parent c3a9c2c8a39af6c5377998685a56e93cdedf84d1
Author: Felicitus <felicitus@felicitus.org>
Date: Wed, 24 Jun 2015 17:22:29 +0200
Refactored special key bindings to ExtJS5, implemented ESC as "Reset Field and Search"
Diffstat:
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Ext.ux/SearchField.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Ext.ux/SearchField.js
@@ -29,17 +29,19 @@ Ext.define('Ext.ux.form.SearchField', {
targetField : 'query',
filter: null,
+
+ listeners: {
+ 'specialkey': {
+ fn: 'keyHandler',
+ scope: 'this'
+ }
+ },
/**
* Initializes the component. Binds the enter key to startSearch.
*/
initComponent: function(){
this.callParent(arguments);
- this.on('specialkey', function(f, e){
- if(e.getKey() == e.ENTER){
- this.startSearch();
- }
- }, this);
this.filter = Ext.create("Ext.util.Filter", {
property: this.targetField,
@@ -47,6 +49,22 @@ Ext.define('Ext.ux.form.SearchField', {
operator: 'like'
});
},
+ /**
+ * Handles special keys used in this field.
+ *
+ * Enter: Starts the search
+ * Escape: Removes the search and clears the field contents
+ */
+ keyHandler: function (field, e) {
+ switch (e.getKey()) {
+ case e.ENTER:
+ this.startSearch();
+ break;
+ case e.ESC:
+ this.resetSearch();
+ break;
+ }
+ },
/**
* Resets the search field to empty and re-triggers the store to load the matching records.
*/
@@ -55,9 +73,11 @@ Ext.define('Ext.ux.form.SearchField', {
store = me.store,
proxy = store.getProxy(),
val;
-
+
+ me.setValue('');
+
if (me.hasSearch) {
- me.setValue('');
+
store.removeFilter(this.filter);
store.currentPage = 1;