mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Making filter selectors more flexible, allowing no active-selectors to be passed in, ie. read-only
This commit is contained in:
@@ -6,10 +6,10 @@ Darkswarm.directive "activeSelector", ->
|
||||
replace: true
|
||||
templateUrl: 'active_selector.html'
|
||||
link: (scope, elem, attr)->
|
||||
scope.selector.emit = scope.emit
|
||||
elem.bind "click", ->
|
||||
scope.$apply ->
|
||||
scope.selector.active = !scope.selector.active
|
||||
# This function is a convention, e.g. a callback on the scope applied when active changes
|
||||
scope.emit() if scope.emit
|
||||
|
||||
unless scope.readOnly && scope.readOnly()
|
||||
scope.selector.emit = scope.emit
|
||||
elem.bind "click", ->
|
||||
scope.$apply ->
|
||||
scope.selector.active = !scope.selector.active
|
||||
# This function is a convention, e.g. a callback on the scope applied when active changes
|
||||
scope.emit() if scope.emit
|
||||
|
||||
@@ -5,7 +5,7 @@ Darkswarm.directive "filterSelector", (FilterSelectorsService)->
|
||||
replace: true
|
||||
scope:
|
||||
objects: "&"
|
||||
activeSelectors: "="
|
||||
activeSelectors: "=?"
|
||||
allSelectors: "=?" # Optional
|
||||
templateUrl: "filter_selector.html"
|
||||
|
||||
@@ -13,6 +13,9 @@ Darkswarm.directive "filterSelector", (FilterSelectorsService)->
|
||||
selectors_by_id = {}
|
||||
selectors = null # To get scoping/closure right
|
||||
|
||||
scope.readOnly = ->
|
||||
attr.activeSelectors?
|
||||
|
||||
scope.emit = ->
|
||||
scope.activeSelectors = selectors.filter (selector)->
|
||||
selector.active
|
||||
@@ -23,10 +26,10 @@ Darkswarm.directive "filterSelector", (FilterSelectorsService)->
|
||||
# when data has been loaded, in order to pass
|
||||
# selectors up
|
||||
scope.$on 'loadFilterSelectors', ->
|
||||
scope.allSelectors = scope.selectors()
|
||||
scope.allSelectors = scope.selectors() if attr.allSelectors?
|
||||
|
||||
scope.$watchCollection "selectors()", (newValue, oldValue) ->
|
||||
scope.allSelectors = scope.selectors()
|
||||
scope.allSelectors = scope.selectors() if attr.allSelectors?
|
||||
|
||||
# Build a list of selectors
|
||||
scope.selectors = ->
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
%active-selector{ ng: { repeat: "selector in selectors()", show: "ifDefined(selector.fits, true)" } }
|
||||
%render-svg{path: "{{selector.object.icon}}", ng: { if: "selector.object.icon"} }
|
||||
%span {{ selector.object.name }}
|
||||
%div{ style: "display: inline-block" }
|
||||
%active-selector{ ng: { repeat: "selector in selectors()", show: "ifDefined(selector.fits, true)" } }
|
||||
%render-svg{path: "{{selector.object.icon}}", ng: { if: "selector.object.icon"} }
|
||||
%span {{ selector.object.name }}
|
||||
|
||||
Reference in New Issue
Block a user