mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Restoring my clever flash refactoring
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
Darkswarm.directive "ofnFlash", (flash, $timeout)->
|
||||
Darkswarm.directive "ofnFlash", (flash, $timeout, RailsFlashLoader)->
|
||||
# Mappings between flash types (left) and Foundation classes
|
||||
typePairings =
|
||||
info: "standard"
|
||||
info: "info"
|
||||
error: "alert"
|
||||
success: "success"
|
||||
scope: {}
|
||||
restrict: 'AE'
|
||||
restrict: 'E'
|
||||
templateUrl: "flash.html"
|
||||
controller: ($scope)->
|
||||
$scope.closeAlert = (index)->
|
||||
@@ -21,3 +22,4 @@ Darkswarm.directive "ofnFlash", (flash, $timeout)->
|
||||
$scope.flashes.shift()
|
||||
|
||||
flash.subscribe(show)
|
||||
RailsFlashLoader.initFlash()
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
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
|
||||
@@ -6,11 +6,7 @@ Darkswarm.factory "OfnMap", (enterprisesForMap, MapModal)->
|
||||
# Adding methods to each enterprise
|
||||
extend: (enterprise)->
|
||||
new class MapMarker
|
||||
icon: "/test.opng"
|
||||
constructor: ->
|
||||
@[k] = v for k, v of enterprise
|
||||
|
||||
reveal: =>
|
||||
|
||||
console.log @
|
||||
MapModal.open @
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Darkswarm.factory 'Order', ($resource, order, $http, flash, Navigation, storage, CurrentHub)->
|
||||
Darkswarm.factory 'Order', ($resource, order, $http, Navigation, storage, CurrentHub, RailsFlashLoader)->
|
||||
new class Order
|
||||
errors: {}
|
||||
secrets: {}
|
||||
@@ -24,8 +24,8 @@ 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
|
||||
RailsFlashLoader.loadFlash(response.flash)
|
||||
|
||||
|
||||
# Rails wants our Spree::Address data to be provided with _attributes
|
||||
preprocess: ->
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
Darkswarm.factory 'RailsFlashLoader', (flash, railsFlash)->
|
||||
new class RailsFlashLoader
|
||||
initFlash: ->
|
||||
@loadFlash railsFlash
|
||||
loadFlash: (rails_flash)->
|
||||
for type, message of rails_flash
|
||||
flash[type] = message
|
||||
@@ -2,7 +2,8 @@
|
||||
.small-12.columns.producer-hero
|
||||
%h3.producer-name
|
||||
%i.ofn-i_036-producers
|
||||
{{ producer.name }}
|
||||
{{ enterprise.name }}
|
||||
{{ enterprise.id }}
|
||||
%img.producer-hero-img{"ng-src" => "{{enterprise.promo_image}}"}
|
||||
|
||||
.row
|
||||
|
||||
@@ -37,7 +37,7 @@ class ApplicationController < ActionController::Base
|
||||
session[:expired_order_cycle_id] = current_order_cycle.id
|
||||
current_order.empty!
|
||||
current_order.set_order_cycle! nil
|
||||
flash[:notice] = "The order cycle you've selected has just closed. Please try again!"
|
||||
flash[:info] = "The order cycle you've selected has just closed. Please try again!"
|
||||
redirect_to root_url
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@ class CheckoutController < Spree::CheckoutController
|
||||
end
|
||||
end
|
||||
if @order.state == "complete" || @order.completed?
|
||||
flash.notice = t(:order_processed_successfully)
|
||||
flash[:success] = t(:order_processed_successfully)
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
respond_with(@order, :location => order_path(@order))
|
||||
|
||||
@@ -5,7 +5,7 @@ class UserPasswordsController < Spree::UserPasswordsController
|
||||
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
|
||||
|
||||
if resource.errors.empty?
|
||||
set_flash_message(:notice, :send_instructions) if is_navigational_format?
|
||||
set_flash_message(:success, :send_instructions) if is_navigational_format?
|
||||
respond_with resource, :location => spree.login_path
|
||||
else
|
||||
respond_to do |format|
|
||||
|
||||
@@ -4,7 +4,7 @@ class UserRegistrationsController < Spree::UserRegistrationsController
|
||||
def create
|
||||
@user = build_resource(params[:spree_user])
|
||||
if resource.save
|
||||
set_flash_message(:notice, :signed_up)
|
||||
set_flash_message(:success, :signed_up)
|
||||
sign_in(:spree_user, @user)
|
||||
session[:spree_user_signup] = true
|
||||
associate_user
|
||||
|
||||
2
app/views/json/_flash.rabl
Normal file
2
app/views/json/_flash.rabl
Normal file
@@ -0,0 +1,2 @@
|
||||
object OpenStruct.new(flash)
|
||||
attributes :info, :success, :error
|
||||
@@ -21,12 +21,12 @@
|
||||
= inject_json "currentHub", "current_hub"
|
||||
= inject_json "currentOrder", "current_order"
|
||||
= inject_json "user", "current_user"
|
||||
= inject_json "railsFlash", "flash"
|
||||
|
||||
.off-canvas-wrap{offcanvas: true}
|
||||
.inner-wrap
|
||||
= render partial: "shared/menu/menu"
|
||||
|
||||
= display_flash_messages
|
||||
%ofn-flash
|
||||
|
||||
%section{ role: "main" }
|
||||
|
||||
@@ -16,6 +16,6 @@ describe BaseController do
|
||||
oc.stub(:closed?).and_return true
|
||||
get :index
|
||||
response.should redirect_to root_url
|
||||
flash[:notice].should == "The order cycle you've selected has just closed. Please try again!"
|
||||
flash[:info].should == "The order cycle you've selected has just closed. Please try again!"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user