From a87ced2646d2fba206cd1b6b5d5ffdd3c6235fbf Mon Sep 17 00:00:00 2001 From: Julius Date: Tue, 24 Sep 2013 21:21:08 +0200 Subject: [PATCH] Hide article category if no article matches the search --- app/assets/javascripts/list.customized.js | 8 ++++---- app/assets/javascripts/list.unlist.js | 25 +++++++++++++++++++++++ app/views/group_orders/_form.html.haml | 2 +- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/list.customized.js b/app/assets/javascripts/list.customized.js index 96ca9793..da79cbe1 100644 --- a/app/assets/javascripts/list.customized.js +++ b/app/assets/javascripts/list.customized.js @@ -45,21 +45,21 @@ var CustomizedList = function(id, options, values) { var resetSearchButton = h.getByClass(options.resetSearchClass, self.list.listContainer); $(resetSearchButton).removeClass(options.highlightClass); - } + }; this.searchDelayEnd = function(searchString, columns) { self.list.search(searchString, columns); - } + }; this.highlightResetButton = function() { var resetSearchButton = h.getByClass(options.resetSearchClass, self.list.listContainer); $(resetSearchButton).toggleClass(options.highlightClass, self.list.searched); - } + }; this.resetSearch = function() { $('.' + options.delayedSearchClass + ', .' + options.searchClass, self.list.listContainer).val(''); self.list.search(''); - } + }; init.start(id, options, values); } diff --git a/app/assets/javascripts/list.unlist.js b/app/assets/javascripts/list.unlist.js index dc7101ed..16600077 100644 --- a/app/assets/javascripts/list.unlist.js +++ b/app/assets/javascripts/list.unlist.js @@ -62,6 +62,19 @@ List.prototype.templateEngines.unlist = function(list, settings) { itemSource = getItemSource(settings.item), templater = this; + var init = { + start: function(options) { + this.defaults(options); + this.callbacks(options); + }, + defaults: function(options) { + options.listHeadingsClass = options.listHeadingsClass || 'list-heading'; + }, + callbacks: function(options) { + list.on('updated', templater.updateListHeadings); + } + }; + function getItemSource(item) { if (item === undefined) { var nodes = listSource.childNodes, @@ -143,6 +156,18 @@ List.prototype.templateEngines.unlist = function(list, settings) { this.clear = function() { $(listSource.childNodes).addClass('unlisted'); }; + + this.updateListHeadings = function() { + var headSel = '.' + settings.listHeadingsClass; + + $(headSel, listSource).each(function() { + if( $(this).nextUntil(headSel, ':not(.unlisted)').length ) { + $(this).removeClass('unlisted'); + } + }); + }; + + init.start(settings); }; /******************************************************************************* diff --git a/app/views/group_orders/_form.html.haml b/app/views/group_orders/_form.html.haml index bab7cad7..fbb4da00 100644 --- a/app/views/group_orders/_form.html.haml +++ b/app/views/group_orders/_form.html.haml @@ -73,7 +73,7 @@ %th{style: "width:15px;"}= t '.sum' %tbody.list - @order.articles_grouped_by_category.each do |category, order_articles| - %tr.no-unlist.article-category + %tr.list-heading.article-category %td = category %i.icon-tag