mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Rewriting shopfront alert regarding changeable orders to be dynamic
This commit is contained in:
@@ -10,7 +10,7 @@ Darkswarm.controller "OrderCycleCtrl", ($scope, $timeout, OrderCycle) ->
|
||||
$("#order_cycle_id").trigger("openTrigger")
|
||||
|
||||
|
||||
Darkswarm.controller "OrderCycleChangeCtrl", ($scope, $timeout, OrderCycle, Products, Variants, Cart) ->
|
||||
Darkswarm.controller "OrderCycleChangeCtrl", ($scope, $timeout, OrderCycle, Products, Variants, Cart, ChangeableOrdersAlert) ->
|
||||
# Track previous order cycle id for use with revertOrderCycle()
|
||||
$scope.previous_order_cycle_id = OrderCycle.order_cycle.order_cycle_id
|
||||
$scope.$watch 'order_cycle.order_cycle_id', (newValue, oldValue)->
|
||||
@@ -31,3 +31,4 @@ Darkswarm.controller "OrderCycleChangeCtrl", ($scope, $timeout, OrderCycle, Prod
|
||||
Cart.clear()
|
||||
Products.update()
|
||||
Cart.reloadFinalisedLineItems()
|
||||
ChangeableOrdersAlert.reload()
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
Darkswarm.directive "changeableOrdersAlert", (ChangeableOrdersAlert) ->
|
||||
restrict: "C"
|
||||
scope: true
|
||||
link: (scope, element, attrs) ->
|
||||
scope.alert = ChangeableOrdersAlert
|
||||
@@ -0,0 +1,14 @@
|
||||
Darkswarm.factory 'ChangeableOrdersAlert', ($http) ->
|
||||
new class ChangeableOrdersAlert
|
||||
html: ''
|
||||
visible: true
|
||||
|
||||
constructor: ->
|
||||
@reload()
|
||||
|
||||
reload: ->
|
||||
$http.get('/shop/changeable_orders_alert').then (response) =>
|
||||
@html = response.data.trim()
|
||||
|
||||
close: =>
|
||||
@visible = false
|
||||
@@ -110,6 +110,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
.alert-box.changeable-orders-alert {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
.alert-box.shopfront-message {
|
||||
border: 2px solid $clr-turquoise;
|
||||
border-radius: 5px;
|
||||
|
||||
@@ -37,6 +37,10 @@ class ShopController < BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def changeable_orders_alert
|
||||
render layout: false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def filtered_json(products_json)
|
||||
|
||||
@@ -19,9 +19,10 @@ module Spree
|
||||
|
||||
def changeable_orders
|
||||
# Only returns open order for the current user + shop + oc combo
|
||||
return [] unless spree_current_user && current_distributor && current_order_cycle
|
||||
return [] unless current_distributor.allow_order_changes?
|
||||
Spree::Order.complete.where(
|
||||
return @changeable_orders unless @changeable_orders.nil?
|
||||
return @changeable_orders = [] unless spree_current_user && current_distributor && current_order_cycle
|
||||
return @changeable_orders = [] unless current_distributor.allow_order_changes?
|
||||
@changeable_orders = Spree::Order.complete.where(
|
||||
state: 'complete',
|
||||
user_id: spree_current_user.id,
|
||||
distributor_id: current_distributor.id,
|
||||
@@ -33,6 +34,7 @@ module Spree
|
||||
end
|
||||
|
||||
def shop_changeable_orders_alert_html
|
||||
return "" unless changeable_orders.any?
|
||||
t(:shop_changeable_orders_alert_html,
|
||||
count: changeable_orders.count,
|
||||
path: changeable_orders_link_path,
|
||||
|
||||
@@ -8,10 +8,9 @@
|
||||
= inject_shop_enterprises
|
||||
|
||||
%shop.darkswarm
|
||||
- if changeable_orders.any?
|
||||
.alert-box.info{ "ofn-inline-alert" => true, ng: { show: "visible" } }
|
||||
= shop_changeable_orders_alert_html
|
||||
%a.close{ ng: { click: "close()" } } ×
|
||||
.alert-box.changeable-orders-alert.info.animate-show{ ng: { show: "alert.visible && alert.html" } }
|
||||
%span{ ng: { bind: { html: "alert.html" } } }
|
||||
%a.close{ ng: { click: "alert.close()" } } ×
|
||||
|
||||
- content_for :order_cycle_form do
|
||||
|
||||
|
||||
1
app/views/shop/changeable_orders_alert.html.haml
Normal file
1
app/views/shop/changeable_orders_alert.html.haml
Normal file
@@ -0,0 +1 @@
|
||||
= shop_changeable_orders_alert_html
|
||||
@@ -28,6 +28,7 @@ Openfoodnetwork::Application.routes.draw do
|
||||
get :products
|
||||
post :order_cycle
|
||||
get :order_cycle
|
||||
get :changeable_orders_alert
|
||||
end
|
||||
|
||||
resources :producers, only: [:index] do
|
||||
|
||||
Reference in New Issue
Block a user