Compacting down our flash messages

This commit is contained in:
Will Marshall
2014-06-04 16:38:49 +10:00
parent 874afb2d7e
commit cd09f70ed3
7 changed files with 25 additions and 9 deletions

View File

@@ -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 = ->

View File

@@ -2,6 +2,5 @@ Darkswarm.factory 'CurrentOrder', (currentOrder) ->
new class CurrentOrder
constructor: ->
@[k] = v for k, v of currentOrder
empty: =>
@line_items.length == 0

View File

@@ -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

View File

@@ -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: ->

View File

@@ -0,0 +1,2 @@
%alert{close: "closeAlert($index)", "ng-repeat" => "flash in flashes", type: "flash.type"}
{{ flash.message }}

View File

@@ -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"

View File

@@ -23,7 +23,7 @@
.inner-wrap
= render partial: "shared/menu/menu"
= display_flash_messages
-#= display_flash_messages
%ofn-flash
%section{ role: "main" }