Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. define(['backbone', 'cs!app/Controller', 'cs!utils/Layers', 'cs!utils/Router', 'cs!models/User',]
  2.  
  3.     (Backbone, Controller, Layers, Router, user) ->
  4.  
  5.         RouterProxy = () ->
  6.  
  7.         RouterProxy:: = (() ->
  8.  
  9.             # private
  10.  
  11.             registerRoute = (route, callback, context, restrictedTo) ->
  12.                 wrappedCallback = () ->
  13.                     checkAccess route, callback, context, restrictedTo, arguments
  14.                 @appRouter.on "route:#{route}", wrappedCallback
  15.  
  16.             checkAccess = (route, callback, context, restrictedTo, args) ->
  17.                 if restrictedTo
  18.                     loginRequired = $.inArray(restrictedTo, ['user', 'admin']) != -1
  19.                     if loginRequired and not user.isLoggedIn()
  20.                         return Layers.showLoginLayer()
  21.                     if restrictedTo == 'admin' and not user.isAdmin()
  22.                         alert 'Admin area access is restricted'
  23.                         return Router.navigate ''
  24.                 callback(args).apply context, args
  25.  
  26.             # public
  27.  
  28.             constructor: RouterProxy
  29.  
  30.             initialize: () ->
  31.                 Controller.initialize()
  32.                 AppRouter = Backbone.Router.extend
  33.                     routes:
  34.                         'coredata': 'showCoreData'
  35.                         'whereabouts': 'showWhereabouts'
  36.                         '*path': 'defaultAction'
  37.                 @appRouter = new AppRouter
  38.                 (@_ registerRoute) 'showCoreData', Controller.showCoreDataView, Controller
  39.                 (@_ registerRoute) 'showWhereabouts', Controller.showWhereaboutsView, Controller
  40.                 (@_ registerRoute) 'defaultAction', Controller.showHomeView, Controller
  41.                 Router.router = @appRouter
  42.                 Backbone.history.start
  43.                     pushState: true
  44.  
  45.             _: (callback) ->
  46.                 () =>
  47.                     callback.apply @, arguments
  48.  
  49.         )()
  50.                
  51. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement