diff --git a/forms/ecomerce/catalog/catalog.js b/forms/ecomerce/catalog/catalog.js index 740fb2df..03db68a8 100644 --- a/forms/ecomerce/catalog/catalog.js +++ b/forms/ecomerce/catalog/catalog.js @@ -132,7 +132,7 @@ Hedera.Catalog = new Class var shouldRefresh = params.search || params.category && params.type; - Vn.Node.removeChilds (this.$.tagFilters); + Vn.Node.removeChilds (this.$.suggestedFilters); if (shouldRefresh) { @@ -163,14 +163,9 @@ Hedera.Catalog = new Class this.tagFilter = {}; } - ,tagFilter: {} - - ,onTagFilterAdd: function () - { - tagFilter[tag.id] = tag.value; - } + ,filters: {} - ,buildQuery: function (query, params) + ,buildQuery: function (query, params, excludeTag) { var query = new Sql.MultiStmt ({ stmts: [ @@ -180,7 +175,7 @@ Hedera.Catalog = new Class ] }); var qParams = { - joins: this.buildTagFilter (), + joins: this.buildTagFilter (excludeTag), filter: this.buildMainFilter () }; Object.assign (qParams, params); @@ -228,11 +223,12 @@ Hedera.Catalog = new Class var i = -1; - for (var tagId in this.tagFilter) + for (var tagId in this.filters) { - var tagValue = this.tagFilter[tagId]; + var tagId = parseInt (tagId); + var tagValue = this.filters[tagId].field.value; - if (tagId == excludeTag) + if (tagId === excludeTag) continue; i++; @@ -296,35 +292,73 @@ Hedera.Catalog = new Class ,onTagsReady: function (resultSet) { - var filters = this.$.tagFilters; var tags = resultSet.results[2].data; tags.forEach (function (tag) { + if (this.filters[tag.id] !== undefined) + return; + var query = this.buildQuery ( - 'CALL catalogGetTagValues (#tag)', {tag: tag.id}); + 'CALL catalogGetTagValues (#tag)', {tag: tag.id}, tag.id); + + var filter = this.createElement ('div'); + this.$.suggestedFilters.appendChild (filter); var label = this.createElement ('label'); label.appendChild (this.createTextNode (tag.name)); - filters.appendChild (label); + filter.appendChild (label); var combo = new Htk.Combo ({ valueField: 'value', - showField: 'value', - model: new Db.Model ({ - autoLoad: true, - resultIndex: 2, - query: query, - conn: this.conn - }) + showField: 'value' }); - combo.on ('changed', this.onComboChange, this); - filters.appendChild (combo.node); + filter.appendChild (combo.node); + + var model = new Db.Model ({ + autoLoad: false, + resultIndex: 2, + query: query, + conn: this.conn + }); + combo.model = model; + + var filterData = { + filter: filter, + tagId: tag.id, + field: combo, + model: model + }; + combo.on ('changed', + this.onComboChange.bind (this, filterData), this); }, this); } - ,onComboChange: function (combo) + ,onComboChange: function (filterData, _, value) { - console.log (combo.value); + var filter = filterData.filter; + var tagId = filterData.tagId; + + if (value == null) + { + this.$.currentFilters.removeChild (filter); + delete this.filters[tagId]; + } + else if (this.filters[tagId] === undefined) + { + this.filters[tagId] = filterData; + this.$.suggestedFilters.removeChild (filter); + this.$.currentFilters.appendChild (filter); + } + + for (var tid in this.filters) + if (parseInt (tid) !== tagId) + { + var query = this.buildQuery ( + 'CALL catalogGetTagValues (#tag)', {tag: tid}, tid); + this.filters[tid].model.query = query; + } + + this.onParamsChange (); } ,onCategoryChange: function () diff --git a/forms/ecomerce/catalog/style.css b/forms/ecomerce/catalog/style.css index 3a560503..05a89b3f 100644 --- a/forms/ecomerce/catalog/style.css +++ b/forms/ecomerce/catalog/style.css @@ -101,32 +101,6 @@ width: 90%; display: block; } -.vn-filter > ul -{ - margin: 0; - list-style-type: none; - text-align: left; - color: #666; - padding-left: .8em; -} -.vn-filter li -{ - margin: 0; - margin-top: .3em; - line-height: 2em; - max-width: 90%; - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; -} -.vn-filter li > button -{ - vertical-align: middle; - text-align: center; - padding: .2em; - margin: 0; - margin-right: .2em; -} .right-panel .filters > button { display: block; diff --git a/forms/ecomerce/catalog/ui.xml b/forms/ecomerce/catalog/ui.xml index 8d3574d4..9857eb3f 100755 --- a/forms/ecomerce/catalog/ui.xml +++ b/forms/ecomerce/catalog/ui.xml @@ -227,7 +227,9 @@ ORDER BY name -
+
+
+