mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Dereferencing groups and adding modals to page
This commit is contained in:
@@ -6,7 +6,7 @@ Darkswarm.directive "activeTableHubLink", (CurrentHub, CurrentOrder) ->
|
||||
link: (scope, elm, attr)->
|
||||
# Swap out the text of the hub link depending on whether it'll change current hub
|
||||
# To be used with ofnEmptiesCart
|
||||
if CurrentHub.hub.id and CurrentHub.hub.id isnt scope.hub.id
|
||||
if CurrentHub.hub?.id and CurrentHub.hub.id isnt scope.hub.id
|
||||
scope.action = attr.change
|
||||
else
|
||||
scope.action = attr.shop
|
||||
|
||||
@@ -3,7 +3,7 @@ Darkswarm.directive "ofnEmptiesCart", (CurrentHub, CurrentOrder, Navigation, sto
|
||||
link: (scope, elm, attr)->
|
||||
hub = scope.$eval(attr.ofnEmptiesCart)
|
||||
# A hub is selected, we're changing to a different hub, and the cart isn't empty
|
||||
if CurrentHub.hub.id and CurrentHub.hub.id isnt hub.id
|
||||
if CurrentHub.hub?.id and CurrentHub.hub.id isnt hub.id
|
||||
unless CurrentOrder.empty()
|
||||
elm.bind 'click', (ev)->
|
||||
ev.preventDefault()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
Darkswarm.directive "hubModal", ($modal)->
|
||||
restrict: 'E'
|
||||
replace: true
|
||||
template: "<a>{{enterprise.name}}</a>"
|
||||
link: (scope, elem, attrs, ctrl)->
|
||||
elem.on "click", =>
|
||||
scope.modalInstance = $modal.open(controller: ctrl, templateUrl: 'hub_modal.html', scope: scope)
|
||||
@@ -0,0 +1,6 @@
|
||||
Darkswarm.factory 'Dereferencer', ->
|
||||
new class Dereferencer
|
||||
dereference: (array, data)->
|
||||
if array
|
||||
for object, i in array
|
||||
array[i] = data[object.id]
|
||||
@@ -1,4 +1,4 @@
|
||||
Darkswarm.factory 'Enterprises', (enterprises, CurrentHub)->
|
||||
Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Dereferencer)->
|
||||
new class Enterprises
|
||||
enterprises_by_id: {} # id/object pairs for lookup
|
||||
constructor: ->
|
||||
@@ -10,12 +10,6 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub)->
|
||||
dereference: ->
|
||||
if CurrentHub.hub?.id
|
||||
CurrentHub.hub = @enterprises_by_id[CurrentHub.hub.id]
|
||||
|
||||
for enterprise in @enterprises
|
||||
if enterprise.hubs
|
||||
for hub, i in enterprise.hubs
|
||||
enterprise.hubs[i] = @enterprises_by_id[hub.id]
|
||||
|
||||
if enterprise.producers
|
||||
for producer, i in enterprise.producers
|
||||
enterprise.producers[i] = @enterprises_by_id[producer.id]
|
||||
Dereferencer.dereference enterprise.hubs, @enterprises_by_id
|
||||
Dereferencer.dereference enterprise.producers, @enterprises_by_id
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
Darkswarm.factory 'Groups', (groups) ->
|
||||
Darkswarm.factory 'Groups', (groups, Enterprises, Dereferencer) ->
|
||||
new class Groups
|
||||
groups: groups
|
||||
groups_by_id: {}
|
||||
constructor: ->
|
||||
@groups = groups
|
||||
for group in @groups
|
||||
@groups_by_id[group.id] = group
|
||||
@dereference()
|
||||
dereference: ->
|
||||
for group in @groups
|
||||
Dereferencer.dereference group.enterprises, Enterprises.enterprises_by_id
|
||||
for enterprise in Enterprises.enterprises
|
||||
Dereferencer.dereference enterprise.groups, @groups_by_id
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ Darkswarm.factory "MapModal", ($modal, $rootScope)->
|
||||
scope.enterprise = enterprise
|
||||
if enterprise.is_distributor
|
||||
scope.hub = enterprise
|
||||
$modal.open(templateUrl: "map_modal_hub.html", scope: scope)
|
||||
$modal.open(templateUrl: "hub_modal.html", scope: scope)
|
||||
else
|
||||
scope.producer = enterprise
|
||||
$modal.open(templateUrl: "map_modal_producer.html", scope: scope)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
%p.right
|
||||
{{ [enterprise.address.city, enterprise.address.state] | printArray}}
|
||||
%h3
|
||||
%i.ofn-i_036-producers
|
||||
%i.ofn-i_036-producers{"ng-show" => "!enterprise.is_distributor"}
|
||||
%i.ofn-i_040-hub{"ng-show" => "enterprise.is_distributor"}
|
||||
{{ enterprise.name }}
|
||||
%img.hero-img{"ng-src" => "{{enterprise.promo_image}}"}
|
||||
|
||||
Reference in New Issue
Block a user