Working reloading of products, changing order cycles, sticky state

This commit is contained in:
Will Marshall
2013-12-11 13:36:12 +11:00
parent 04d8949177
commit 3903173848
5 changed files with 20 additions and 7 deletions

View File

@@ -1,9 +1,10 @@
Shop.factory 'OrderCycle', ($resource, Product) ->
new class OrderCycle
@order_cycle:
class OrderCycle
@order_cycle = {
order_cycle_id: null
}
set_order_cycle: (id = null)->
new $resource("/shop/order_cycle").save {order_cycle_id: id}, ->
@set_order_cycle: ->
new $resource("/shop/order_cycle").save {order_cycle_id: @order_cycle.order_cycle_id}, ->
Product.update()

View File

@@ -3,5 +3,7 @@ Shop.factory 'Product', ($resource) ->
@products: null
update: ->
@products = $resource("/shop/products").query()
console.log @products
@products
all: ->
@products || @update()

View File

@@ -1 +1,2 @@
window.Shop = angular.module("Shop", ["ngResource"])
window.Shop = angular.module("Shop", ["ngResource"]).config ($httpProvider) ->
$httpProvider.defaults.headers.post['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content')

View File

@@ -1,7 +1,9 @@
%ordercycle{"ng-controller" => "OrderCycleCtrl"}
- if @order_cycles.empty?
Orders are currently closed for this hub
%p Please contact your hub directly to see if they accept late orders, or wait until the next cycle opens.
%p
Please contact your hub directly to see if they accept late orders,
or wait until the next cycle opens.
= render partial: "shop/next_order_cycle"
= render partial: "shop/last_order_cycle"
@@ -9,6 +11,6 @@
- else
Ready for:
%select{"ng-model" => "order_cycle.order_cycle_id",
"ng-init" => "order_cycle.order_cycle_id = #{current_order_cycle.id}",
"ng-change" => "changeOrderCycle()",
"ng-options" => "c for c in #{@order_cycles.map {|oc| oc.id}.to_json}"}

View File

@@ -13,6 +13,13 @@ describe ShopController do
controller.stub(:current_distributor).and_return d
end
describe "Fetching products" do
it "should return products for the current order cycle" do
spree_get :products
end
it "should not return other products"
end
describe "Selecting order cycles" do
it "should select an order cycle when only one order cycle is open" do
oc1 = create(:order_cycle, distributors: [d])