From: Jaroslav Kysela Date: Thu, 4 Jan 2018 19:44:33 +0000 (+0100) Subject: lovcombo: add Ext.ux.form.ComboAny X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=884d447c69bdbb04a4a39c6d6d9a5340480c3b6f;p=thirdparty%2Ftvheadend.git lovcombo: add Ext.ux.form.ComboAny --- diff --git a/src/webui/static/app/epg.js b/src/webui/static/app/epg.js index 622453aa3..a75cd2491 100644 --- a/src/webui/static/app/epg.js +++ b/src/webui/static/app/epg.js @@ -273,7 +273,7 @@ tvheadend.epgDetails = function(event) { })); } - var confcombo = new Ext.form.ComboBox({ + var confcombo = new Ext.ux.form.ComboAny({ store: store, triggerAction: 'all', mode: 'local', @@ -762,7 +762,7 @@ tvheadend.epg = function() { // Channels, uses global store - var epgFilterChannels = new Ext.form.ComboBox({ + var epgFilterChannels = new Ext.ux.form.ComboAny({ loadingText: _('Loading...'), width: 200, displayField: 'val', @@ -785,7 +785,7 @@ tvheadend.epg = function() { // Tags, uses global store - var epgFilterChannelTags = new Ext.form.ComboBox({ + var epgFilterChannelTags = new Ext.ux.form.ComboAny({ loadingText: _('Loading...'), width: 200, displayField: 'val', @@ -811,7 +811,7 @@ tvheadend.epg = function() { /// We have to pass the name, not the field, since the /// field is deleted and re-created inside clear filter. function createFilterCat(clearFilter, cat) { - var filter = new Ext.form.ComboBox({ + var filter = new Ext.ux.form.ComboAny({ loadingText: _('Loading...'), width: 200, displayField: 'val', @@ -862,7 +862,7 @@ tvheadend.epg = function() { // Content groups - var epgFilterContentGroup = new Ext.form.ComboBox({ + var epgFilterContentGroup = new Ext.ux.form.ComboAny({ loadingText: _('Loading...'), width: 200, displayField: 'val', @@ -883,7 +883,7 @@ tvheadend.epg = function() { } }); - var epgFilterDuration = new Ext.form.ComboBox({ + var epgFilterDuration = new Ext.ux.form.ComboAny({ loadingText: _('Loading...'), width: 150, displayField: 'label', diff --git a/src/webui/static/app/idnode.js b/src/webui/static/app/idnode.js index 3761c6aa7..538de570d 100644 --- a/src/webui/static/app/idnode.js +++ b/src/webui/static/app/idnode.js @@ -412,7 +412,6 @@ tvheadend.IdNodeField = function(conf) this.editor = function(conf) { var cons = null; - var combo = false; /* Editable? */ var d = this.rdonly; @@ -447,7 +446,7 @@ tvheadend.IdNodeField = function(conf) c['fromLegend'] = _('Available'); } else { - cons = Ext.form.ComboBox; + cons = Ext.ux.form.ComboAny; if (this.list) { cons = Ext.ux.form.LovCombo; c['checkField'] = 'checked_' + this.id; @@ -460,8 +459,6 @@ tvheadend.IdNodeField = function(conf) c['forceSelection'] = false; c['triggerAction'] = 'all'; c['emptyText'] = _('Select {0} ...').replace('{0}', this.text); - - combo = true; } /* Single */ @@ -509,10 +506,7 @@ tvheadend.IdNodeField = function(conf) } } - var r = new cons(c); - if (combo) - r.doQuery = tvheadend.doQueryAnyMatch; - return r; + return new cons(c); }; }; @@ -694,7 +688,7 @@ tvheadend.idnode_editor_field = function(f, conf) /* Enumerated (combobox) type */ } else if (f['enum']) { - var cons = Ext.form.ComboBox; + var cons = Ext.ux.form.ComboAny; if (f.list) cons = Ext.ux.form.LovCombo; var st = tvheadend.idnode_enum_store(f); @@ -720,8 +714,6 @@ tvheadend.idnode_editor_field = function(f, conf) } }); - r.doQuery = tvheadend.doQueryAnyMatch; - if (st.on) { var fn = function() { st.un('load', fn); diff --git a/src/webui/static/app/tvheadend.js b/src/webui/static/app/tvheadend.js index 760c56819..40c41a4bb 100644 --- a/src/webui/static/app/tvheadend.js +++ b/src/webui/static/app/tvheadend.js @@ -694,53 +694,9 @@ tvheadend.PagingToolbarConf = function(conf, title, auto, count) return conf; } -/* - * 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(); - } - } -} - /* * Replace one entry */ - tvheadend.replace_entry = function(r, d) { if (!r) return; var dst = r.data; @@ -858,7 +814,7 @@ tvheadend.VideoPlayer = function(channelId) { initialChannelName = record.data.val; } - var selectChannel = new Ext.form.ComboBox({ + var selectChannel = new Ext.ux.form.ComboAny({ loadingText: _('Loading...'), width: 200, displayField: 'val', @@ -897,7 +853,7 @@ tvheadend.VideoPlayer = function(channelId) { }); } - var selectProfile = new Ext.form.ComboBox({ + var selectProfile = new Ext.ux.form.ComboAny({ loadingText: _('Loading...'), width: 150, displayField: 'val', diff --git a/src/webui/static/lovcombo/lovcombo-all.js b/src/webui/static/lovcombo/lovcombo-all.js index 9cb155dbf..cc596df91 100644 --- a/src/webui/static/lovcombo/lovcombo-all.js +++ b/src/webui/static/lovcombo/lovcombo-all.js @@ -29,13 +29,75 @@ if('function' !== typeof RegExp.escape) { // create namespace Ext.ns('Ext.ux.form'); + +/** + * + * @class Ext.ux.form.ComboAny + * @extends Ext.form.ComboBox + */ +Ext.ns('Ext.ux.form'); +Ext.ux.form.ComboAny = Ext.extend(Ext.form.ComboBox, { + + 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 { + /* 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(); + } + } + }, + + onTypeAhead: function() { + if (this.store.getCount() > 0) { + var r = this.store.getAt(0); + var newValue = r.data[this.displayField]; + var len = newValue.length; + var olen = this.getRawValue().length; + if (olen != len) { + this.setRawValue(newValue); + this.selectText(0, len); + } + } + } + +}); + /** * * @class Ext.ux.form.LovCombo * @extends Ext.form.ComboBox */ -Ext.ux.form.LovCombo = Ext.extend(Ext.form.ComboBox, { +Ext.ux.form.LovCombo = Ext.extend(Ext.ux.form.ComboAny, { // {{{ // configuration options