Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define(['backbone', 'cs!app/Controller', 'cs!utils/Layers', 'cs!utils/Router', 'cs!models/User',]
- (Backbone, Controller, Layers, Router, user) ->
- RouterProxy = () ->
- RouterProxy:: = (() ->
- # private
- registerRoute = (route, callback, context, restrictedTo) ->
- wrappedCallback = () ->
- checkAccess route, callback, context, restrictedTo, arguments
- @appRouter.on "route:#{route}", wrappedCallback
- checkAccess = (route, callback, context, restrictedTo, args) ->
- if restrictedTo
- loginRequired = $.inArray(restrictedTo, ['user', 'admin']) != -1
- if loginRequired and not user.isLoggedIn()
- return Layers.showLoginLayer()
- if restrictedTo == 'admin' and not user.isAdmin()
- alert 'Admin area access is restricted'
- return Router.navigate ''
- callback(args).apply context, args
- # public
- constructor: RouterProxy
- initialize: () ->
- Controller.initialize()
- AppRouter = Backbone.Router.extend
- routes:
- 'coredata': 'showCoreData'
- 'whereabouts': 'showWhereabouts'
- '*path': 'defaultAction'
- @appRouter = new AppRouter
- (@_ registerRoute) 'showCoreData', Controller.showCoreDataView, Controller
- (@_ registerRoute) 'showWhereabouts', Controller.showWhereaboutsView, Controller
- (@_ registerRoute) 'defaultAction', Controller.showHomeView, Controller
- Router.router = @appRouter
- Backbone.history.start
- pushState: true
- _: (callback) ->
- () =>
- callback.apply @, arguments
- )()
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement