app/assets/javascripts/sprangular/module.coffee in sprangular-0.0.1 vs app/assets/javascripts/sprangular/module.coffee in sprangular-0.1.0
- old
+ new
@@ -1,8 +1,15 @@
# Main Module
-window.Sprangular = angular.module "Sprangular", ['ui.bootstrap', 'ngRoute', 'ngResource', 'ngAnimate', 'underscore', 'ngSanitize', 'mgcrea.ngStrap', 'angularytics']
- .run (Env) ->
+window.Sprangular = angular.module('Sprangular', [
+ 'ngRoute'
+ 'ngAnimate'
+ 'underscore'
+ 'ngSanitize'
+ 'mgcrea.ngStrap'
+ 'angularytics'
+ 'pascalprecht.translate'
+]).run (Env) ->
paymentMethods = Env.config.payment_methods
if paymentMethods.length == 0
alert 'Gateway is not configured in Spree...'
@@ -22,44 +29,74 @@
newInstance = angular.extend(new type(), instance)
newInstance.init() if newInstance.init
newInstance
# Default Headers
-Sprangular.config ["$httpProvider", "$locationProvider", "$logProvider", "Env", ($httpProvider, $locationProvider, $logProvider, Env) ->
- $httpProvider.defaults.headers.common['Accept'] = 'application/json'
- $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
- $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded'
+Sprangular.config [
+ '$httpProvider'
+ '$locationProvider'
+ '$translateProvider'
+ '$logProvider'
+ 'Env'
+ ($httpProvider, $locationProvider, $translateProvider, $logProvider, Env) ->
+ $httpProvider.defaults.headers.common['Accept'] = 'application/json'
+ encode_as_form = 'application/x-www-form-urlencoded'
+ $httpProvider.defaults.headers.post['Content-Type'] = encode_as_form
+ $httpProvider.defaults.headers.put['Content-Type'] = encode_as_form
- $locationProvider
- .html5Mode false
- .hashPrefix '!'
+ $locationProvider
+ .html5Mode false
+ .hashPrefix '!'
- $logProvider
- .debugEnabled (Env.env isnt "production")
+ $logProvider
+ .debugEnabled (Env.env isnt "production")
+
+ # i18n Support
+ $translateProvider
+ .translations(Env.locale, Env.translations)
+ .fallbackLanguage(['en'])
+ $translateProvider.use(Env.locale)
]
-Sprangular.run ($rootScope, $location, $log, Status, Account, Cart, Flash) ->
+Sprangular.run (
+ $rootScope,
+ $location,
+ $log,
+ Status,
+ Account,
+ Cart,
+ Flash,
+ $cacheFactory
+) ->
Sprangular.startupData = {}
Status.initialized = true
+ $cacheFactory.get('$http').removeAll()
+
$rootScope.$on '$routeChangeStart', (event, next, current) ->
requirements = next.requires || {}
Status.routeChanging = true
Status.meta = {}
if requirements.user && !Account.isLogged
Status.requestedPath = next.$$route.originalPath
- Flash.error('Please sign in or register to continue.')
+ Flash.error('app.sign_in_or_register')
$location.path('/sign-in')
event.preventDefault()
- else if requirements.guest && Account.isLogged
- Flash.error("Sorry, that page is only available when you're signed out.")
+ else if requirements.guest && !Account.isLogged && !Account.isGuest
+ Status.requestedPath = next.$$route.originalPath
+ Flash.error('app.sign_in_or_register')
+ $location.path('/sign-in')
+ event.preventDefault()
+
+ else if requirements.anonymous && Account.isLogged
+ Flash.error('app.must_be_logged_out')
$location.path('/')
event.preventDefault()
else if requirements.cart && Cart.current.items.length == 0
- Flash.error('Sorry, there are no items in your cart.')
+ Flash.error('app.no_items_in_cart')
$location.path('/')
event.preventDefault()
$rootScope.$on '$routeChangeSuccess', ->
Status.routeChanging = false