Making filter selectors more flexible, allowing no active-selectors to be passed in, ie. read-only

This commit is contained in:
Rob Harrington
2015-04-23 12:31:06 +10:00
parent 0251d8962d
commit 3df2720b31
3 changed files with 17 additions and 13 deletions

View File

@@ -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

View File

@@ -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 = ->

View File

@@ -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 }}