Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
WEBUI JS: fix the any match query for comboboxes
  • Loading branch information
perexg committed Sep 8, 2014
1 parent df01566 commit ba01c10
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 46 deletions.
56 changes: 11 additions & 45 deletions src/webui/static/app/idnode.js
Expand Up @@ -239,6 +239,7 @@ tvheadend.IdNodeField = function(conf)
this.editor = function(conf)
{
var cons = null;
var combo = false;

/* Editable? */
var d = this.rdonly;
Expand Down Expand Up @@ -269,6 +270,8 @@ tvheadend.IdNodeField = function(conf)
c['forceSelection'] = false;
c['triggerAction'] = 'all';
c['emptyText'] = 'Select ' + this.text + ' ...';

combo = true;

/* Single */
} else {
Expand Down Expand Up @@ -302,7 +305,10 @@ tvheadend.IdNodeField = function(conf)
}
}

return new cons(c);
var r = new cons(c);
if (combo)
r.doQuery = tvheadend.doQueryAnyMatch;
return r;
};
};

Expand Down Expand Up @@ -410,57 +416,17 @@ tvheadend.idnode_editor_field = function(f, create)
}
}
});

r.doQuery = tvheadend.doQueryAnyMatch;

if (st.on) {
var fn = function() {
st.un('load', fn);
r.setValue(value); // HACK: to get extjs to display properly
};
st.on('load', fn);
}

// any match mode
r.doQuery = function(q, forceAll){
q = Ext.isEmpty(q) ? '' : q;
var qe = {
query: q,
forceAll: forceAll,
combo: this,
cancel:false
};

if (this.fireEvent('beforequery', qe) === false || qe.cancel)
return false;

q = qe.query;
forceAll = qe.forceAll;
if (forceAll === true || (q.length >= this.minChars)) {
if (this.lastQuery !== q) {
this.lastQuery = q;
if (this.mode == 'local') {
this.selectedIndex = -1;
if (forceAll) {
this.store.clearFilter();
}
else {
this.store.filter(this.displayField, q, true); // supply the anyMatch option
}
this.onLoad();
}
else {
this.store.baseParams[this.queryParam] = q;
this.store.load({
params: this.getParams(q)
});
this.expand();
}
}
else {
this.selectedIndex = -1;
this.onLoad();
}
}
};


return r;
/* TODO: listeners for regexp?
listeners : {
Expand Down
44 changes: 43 additions & 1 deletion src/webui/static/app/tvheadend.js
Expand Up @@ -90,6 +90,49 @@ tvheadend.loading = function(on) {
Ext.getBody().unmask();
};

/*
* Any Match option in ComboBox queries
* This query is identical as in extjs-all.js
* except one
*/
tvheadend.doQueryAnyMatch = function(q, forceAll) {
q = Ext.isEmpty(q) ? '' : q;
var qe = {
query: q,
forceAll: forceAll,
combo: this,
cancel:false
};

if (this.fireEvent('beforequery', qe) === false || qe.cancel)
return false;

q = qe.query;
forceAll = qe.forceAll;
if (forceAll === true || (q.length >= this.minChars)) {
if (this.lastQuery !== q) {
this.lastQuery = q;
if (this.mode == 'local') {
this.selectedIndex = -1;
if (forceAll) {
this.store.clearFilter();
} else {
/* supply the anyMatch option (last param) */
this.store.filter(this.displayField, q, true);
}
this.onLoad();
} else {
this.store.baseParams[this.queryParam] = q;
this.store.load({ params: this.getParams(q) });
this.expand();
}
} else {
this.selectedIndex = -1;
this.onLoad();
}
}
}

/*
* General capabilities
*/
Expand Down Expand Up @@ -494,4 +537,3 @@ tvheadend.app = function() {

};
}(); // end of app

0 comments on commit ba01c10

Please sign in to comment.