mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Adapting taxon autocompleter to allow multiple selection of taxons
This commit is contained in:
@@ -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()
|
||||
taxon.name
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user