mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Compacting down our flash messages
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
Darkswarm.directive "ofnFlash", (flash, $timeout)->
|
||||
typePairings =
|
||||
info: "standard"
|
||||
error: "alert"
|
||||
success: "success"
|
||||
scope: {}
|
||||
restrict: 'AE'
|
||||
template: "<alert ng-repeat='flash in flashes' type='flash.type'>{{flash.message}}</alert>"
|
||||
templateUrl: "flash.html"
|
||||
controller: ($scope)->
|
||||
$scope.closeAlert = (index)->
|
||||
$scope.flashes.splice(index, 1)
|
||||
|
||||
link: ($scope, element, attr) ->
|
||||
$scope.flashes = []
|
||||
show = (message, type)->
|
||||
show = (message, type)=>
|
||||
if message
|
||||
$scope.flashes.push({message: message, type: type})
|
||||
$scope.flashes.push({message: message, type: typePairings[type]})
|
||||
$timeout($scope.delete, 5000)
|
||||
|
||||
$scope.delete = ->
|
||||
|
||||
@@ -2,6 +2,5 @@ Darkswarm.factory 'CurrentOrder', (currentOrder) ->
|
||||
new class CurrentOrder
|
||||
constructor: ->
|
||||
@[k] = v for k, v of currentOrder
|
||||
|
||||
empty: =>
|
||||
@line_items.length == 0
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
Darkswarm.factory 'Flash', (flash)->
|
||||
new class Flash
|
||||
loadFlash: (rails_flash)->
|
||||
for type, message of rails_flash
|
||||
switch type
|
||||
when "notice"
|
||||
flash.info = message
|
||||
else
|
||||
flash[type] = message
|
||||
@@ -1,4 +1,4 @@
|
||||
Darkswarm.factory 'Order', ($resource, order, $http, flash, Navigation, storage)->
|
||||
Darkswarm.factory 'Order', ($resource, order, $http, Flash, Navigation, storage)->
|
||||
new class Order
|
||||
errors: {}
|
||||
secrets: {}
|
||||
@@ -24,8 +24,7 @@ Darkswarm.factory 'Order', ($resource, order, $http, flash, Navigation, storage)
|
||||
Navigation.go data.path
|
||||
.error (response, status)=>
|
||||
@errors = response.errors
|
||||
flash.error = response.flash?.error
|
||||
flash.success = response.flash?.notice
|
||||
Flash.loadFlash(response.flash)
|
||||
|
||||
# Rails wants our Spree::Address data to be provided with _attributes
|
||||
preprocess: ->
|
||||
|
||||
2
app/assets/javascripts/templates/flash.html.haml
Normal file
2
app/assets/javascripts/templates/flash.html.haml
Normal file
@@ -0,0 +1,2 @@
|
||||
%alert{close: "closeAlert($index)", "ng-repeat" => "flash in flashes", type: "flash.type"}
|
||||
{{ flash.message }}
|
||||
@@ -15,7 +15,6 @@ class CheckoutController < Spree::CheckoutController
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
if @order.update_attributes(params[:order])
|
||||
fire_event('spree.checkout.update')
|
||||
while @order.state != "complete"
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
.inner-wrap
|
||||
= render partial: "shared/menu/menu"
|
||||
|
||||
= display_flash_messages
|
||||
-#= display_flash_messages
|
||||
%ofn-flash
|
||||
|
||||
%section{ role: "main" }
|
||||
|
||||
Reference in New Issue
Block a user