Do not fetch products JSON on every shopping page

This commit is contained in:
Rohan Mitchell
2014-05-29 10:54:08 +10:00
parent 2a630a855a
commit fdff442ec6
6 changed files with 23 additions and 22 deletions

View File

@@ -1,15 +1,17 @@
Darkswarm.controller "OrderCycleCtrl", ($scope, $rootScope, OrderCycle, $timeout) ->
Darkswarm.controller "OrderCycleCtrl", ($scope, OrderCycle, $timeout) ->
$scope.order_cycle = OrderCycle.order_cycle
$scope.OrderCycle = OrderCycle
$scope.changeOrderCycle = ->
OrderCycle.push_order_cycle()
$timeout ->
$("#order_cycle_id").trigger("closeTrigger")
# Timeout forces this to be evaluated after everything is loaded
# This is a hack. We should probably write our own "popover" directive
# That takes an expression instead of a trigger, and binds to that
$timeout =>
if !$scope.OrderCycle.selected()
$("#order_cycle_id").trigger("openTrigger")
Darkswarm.controller "OrderCycleChangeCtrl", ($scope, OrderCycle, Product, $timeout) ->
$scope.changeOrderCycle = ->
OrderCycle.push_order_cycle Product.update
$timeout ->
$("#order_cycle_id").trigger("closeTrigger")

View File

@@ -1,4 +1,4 @@
Darkswarm.factory 'Order', ($resource, Product, order, $http, CheckoutFormState, flash, Navigation)->
Darkswarm.factory 'Order', ($resource, order, $http, CheckoutFormState, flash, Navigation)->
new class Order
errors: {}

View File

@@ -1,10 +1,10 @@
Darkswarm.factory 'OrderCycle', ($resource, Product, orderCycleData) ->
Darkswarm.factory 'OrderCycle', ($resource, orderCycleData) ->
class OrderCycle
@order_cycle = orderCycleData # Object or {} due to RABL
@push_order_cycle: ->
@push_order_cycle: (callback) ->
new $resource("/shop/order_cycle").save {order_cycle_id: @order_cycle.order_cycle_id}, (order_data)->
OrderCycle.order_cycle.orders_close_at = order_data.orders_close_at
Product.update()
callback()
@orders_close_at: ->
@order_cycle.orders_close_at if @selected()

View File

@@ -9,7 +9,7 @@ Darkswarm.factory 'Product', ($resource) ->
products: null
loading: true
update: ->
update: =>
@data.products = $resource("/shop/products").query =>
@data.loading = false
@data

View File

@@ -1,19 +1,20 @@
%shop.darkswarm
- content_for :order_cycle_form do
%strong.avenir Ready for
%select.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id",
"ng-change" => "changeOrderCycle()",
"ng-options" => "oc.id as oc.time for oc in #{@order_cycles.map {|oc| {time: pickup_time(oc), id: oc.id}}.to_json}",
"popover-placement" => "bottom", "popover" => "When do you want to get your order?", "popover-trigger" => "openTrigger"}
%div{"ng-controller" => "OrderCycleChangeCtrl"}
%strong.avenir Ready for
%select.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id",
"ng-change" => "changeOrderCycle()",
"ng-options" => "oc.id as oc.time for oc in #{@order_cycles.map {|oc| {time: pickup_time(oc), id: oc.id}}.to_json}",
"popover-placement" => "bottom", "popover" => "When do you want to get your order?", "popover-trigger" => "openTrigger"}
%closing{"ng-if" => "OrderCycle.selected()"}
Orders close
%strong {{ OrderCycle.orders_close_at() | date_in_words }}
%closing{"ng-if" => "OrderCycle.selected()"}
Orders close
%strong {{ OrderCycle.orders_close_at() | date_in_words }}
= render partial: "shopping_shared/details"
.row
= render partial: "shop/products/form"
= render partial: "shared/footer"
= render partial: "shared/footer"

View File

@@ -14,5 +14,3 @@
- else
%form.custom
= yield :order_cycle_form