From a38e27e504e2158127e8e82f6d2277aeed35c1ab Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 18 Dec 2014 15:47:20 +1100 Subject: [PATCH] Adapting taxon autocompleter to allow multiple selection of taxons --- .../directives/taxon_autocomplete.js.coffee | 21 +++++++++++-------- .../bulk_edit/_products_product.html.haml | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee b/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee index 6830bd7d22..9c5197121a 100644 --- a/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee +++ b/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee @@ -1,19 +1,22 @@ angular.module("ofn.admin").directive "ofnTaxonAutocomplete", (Taxons) -> # Adapted from Spree's existing taxon autocompletion - require: "ngModel" - link: (scope,element,attrs,ngModel) -> + scope: true + link: (scope,element,attrs) -> + multiple = scope.$eval attrs.multipleSelection + placeholder = attrs.placeholder + setTimeout -> element.select2 - placeholder: "Category" - multiple: false + placeholder: placeholder + multiple: multiple initSelection: (element, callback) -> - callback Taxons.findByID(scope.product.category_id) + if multiple + callback Taxons.findByIDs(scope.product.category_id) + else + callback Taxons.findByID(scope.product.category_id) query: (query) -> query.callback { results: Taxons.findByTerm(query.term) } formatResult: (taxon) -> taxon.name formatSelection: (taxon) -> - taxon.name - element.on "change", -> - scope.$apply -> - ngModel.$setViewValue element.val() \ No newline at end of file + taxon.name \ No newline at end of file diff --git a/app/views/spree/admin/products/bulk_edit/_products_product.html.haml b/app/views/spree/admin/products/bulk_edit/_products_product.html.haml index ed41532a11..bf527ba507 100644 --- a/app/views/spree/admin/products/bulk_edit/_products_product.html.haml +++ b/app/views/spree/admin/products/bulk_edit/_products_product.html.haml @@ -19,7 +19,7 @@ %span{ 'ng-bind' => 'product.on_hand', :name => 'on_hand', 'ng-show' => '!hasOnDemandVariants(product) && (hasVariants(product) || product.on_demand)' } %input.field{ 'ng-model' => 'product.on_hand', :name => 'on_hand', 'ofn-track-product' => 'on_hand', 'ng-hide' => 'hasVariants(product) || product.on_demand', :type => 'number' } %td.category{ 'ng-if' => 'columns.category.visible' } - %input.fullwidth{ :type => 'text', id: "p{{product.id}}_category_id", 'ng-model' => 'product.category_id', 'ofn-taxon-autocomplete' => '', 'ofn-track-product' => 'category_id' } + %input.fullwidth{ :type => 'text', id: "p{{product.id}}_category_id", 'ng-model' => 'product.category_id', 'ofn-taxon-autocomplete' => '', 'ofn-track-product' => 'category_id', 'multiple-selection' => 'false', placeholder: 'Category' } %td.available_on{ 'ng-show' => 'columns.available_on.visible' } %input{ 'ng-model' => 'product.available_on', :name => 'available_on', 'ofn-track-product' => 'available_on', 'datetimepicker' => 'product.available_on', type: "text" } %td.actions