Refactored router and views to anticipate the renameViews feature
This commit is contained in:
parent
0d87209fa8
commit
972d231ff5
7 changed files with 14 additions and 32 deletions
|
@ -47,11 +47,14 @@ module.exports = class CocoRouter extends Backbone.Router
|
||||||
# editor views tend to have the same general structure
|
# editor views tend to have the same general structure
|
||||||
'editor/:model(/:slug_or_id)(/:subview)': 'editorModelView'
|
'editor/:model(/:slug_or_id)(/:subview)': 'editorModelView'
|
||||||
|
|
||||||
# user views
|
'user/:slugOrID': go('user/MainUserView')
|
||||||
'user/:nameOrID(/:subview)': 'userView'
|
'user/:slugOrID/stats': go('user/AchievementsView')
|
||||||
|
'user/:slugOrID/profile': go('user/JobProfileView')
|
||||||
|
#'user/:slugOrID/code': go('user/CodeView')
|
||||||
|
|
||||||
# account views
|
'account': go('account/MainAccountView')
|
||||||
'account(/:subview)': 'accountView'
|
'account/settings': go('account/AccountSettingsView')
|
||||||
|
#'account/payment'
|
||||||
|
|
||||||
# Direct links
|
# Direct links
|
||||||
|
|
||||||
|
@ -83,27 +86,6 @@ module.exports = class CocoRouter extends Backbone.Router
|
||||||
view.render()
|
view.render()
|
||||||
@openView if view then view else @notFoundView()
|
@openView if view then view else @notFoundView()
|
||||||
|
|
||||||
userView: (nameOrID, subview) ->
|
|
||||||
modulePrefix = 'views/user/'
|
|
||||||
suffix = subview or 'home'
|
|
||||||
ViewClass = @tryToLoadModule modulePrefix + suffix
|
|
||||||
if ViewClass
|
|
||||||
view = new ViewClass {}, nameOrID
|
|
||||||
view.render()
|
|
||||||
@openView if view then view else @notFoundView()
|
|
||||||
|
|
||||||
# TODO Ruben There should be a uniform way to define these routes. This is backwards compatible
|
|
||||||
accountView: (subview) ->
|
|
||||||
modulePrefix = 'views/account/'
|
|
||||||
suffix = subview or 'home'
|
|
||||||
suffix2 = suffix + '_view'
|
|
||||||
ViewClass = @tryToLoadModule modulePrefix + suffix
|
|
||||||
ViewClass = @tryToLoadModule modulePrefix + suffix2 unless ViewClass
|
|
||||||
if ViewClass
|
|
||||||
view = new ViewClass
|
|
||||||
view.render()
|
|
||||||
@openView if view then view else @notFoundView()
|
|
||||||
|
|
||||||
cache: {}
|
cache: {}
|
||||||
openRoute: (route) ->
|
openRoute: (route) ->
|
||||||
route = route.split('?')[0]
|
route = route.split('?')[0]
|
||||||
|
|
|
@ -5,7 +5,7 @@ User = require 'models/User'
|
||||||
AuthModalView = require 'views/modal/auth_modal'
|
AuthModalView = require 'views/modal/auth_modal'
|
||||||
RecentlyPlayedCollection = require 'collections/RecentlyPlayedCollection'
|
RecentlyPlayedCollection = require 'collections/RecentlyPlayedCollection'
|
||||||
|
|
||||||
module.exports = class AccountHomeView extends View
|
module.exports = class MainAccountView extends View
|
||||||
id: 'account-home-view'
|
id: 'account-home-view'
|
||||||
template: template
|
template: template
|
||||||
|
|
|
@ -7,7 +7,7 @@ module.exports = class UserView extends RootView
|
||||||
className: 'user-view'
|
className: 'user-view'
|
||||||
viewName: null # Used for the breadcrumbs
|
viewName: null # Used for the breadcrumbs
|
||||||
|
|
||||||
constructor: (options, @userID) ->
|
constructor: (@userID, options) ->
|
||||||
super options
|
super options
|
||||||
|
|
||||||
@listenTo @, 'userLoaded', @onUserLoaded
|
@listenTo @, 'userLoaded', @onUserLoaded
|
||||||
|
|
|
@ -6,11 +6,11 @@ EarnedAchievement = require 'models/EarnedAchievement'
|
||||||
AchievementCollection = require 'collections/AchievementCollection'
|
AchievementCollection = require 'collections/AchievementCollection'
|
||||||
EarnedAchievementCollection = require 'collections/EarnedAchievementCollection'
|
EarnedAchievementCollection = require 'collections/EarnedAchievementCollection'
|
||||||
|
|
||||||
module.exports = class UserAchievementsView extends UserView
|
module.exports = class AchievementsView extends UserView
|
||||||
id: 'user-achievements-view'
|
id: 'user-achievements-view'
|
||||||
template: template
|
template: template
|
||||||
|
|
||||||
constructor: (options, userID) ->
|
constructor: (userID, options) ->
|
||||||
super options, userID
|
super options, userID
|
||||||
|
|
||||||
onUserLoaded: (user) ->
|
onUserLoaded: (user) ->
|
|
@ -54,7 +54,7 @@ module.exports = class ProfileView extends UserView
|
||||||
'change #admin-contact': 'onAdminContactChanged'
|
'change #admin-contact': 'onAdminContactChanged'
|
||||||
'click .session-link': 'onSessionLinkPressed'
|
'click .session-link': 'onSessionLinkPressed'
|
||||||
|
|
||||||
constructor: (options, userID) ->
|
constructor: (userID, options) ->
|
||||||
@onJobProfileNotesChanged = _.debounce @onJobProfileNotesChanged, 1000
|
@onJobProfileNotesChanged = _.debounce @onJobProfileNotesChanged, 1000
|
||||||
@onRemarkChanged = _.debounce @onRemarkChanged, 1000
|
@onRemarkChanged = _.debounce @onRemarkChanged, 1000
|
||||||
@authorizedWithLinkedIn = IN?.User?.isAuthorized()
|
@authorizedWithLinkedIn = IN?.User?.isAuthorized()
|
|
@ -2,11 +2,11 @@ UserView = require 'views/kinds/UserView'
|
||||||
template = require 'templates/user/home'
|
template = require 'templates/user/home'
|
||||||
{me} = require 'lib/auth'
|
{me} = require 'lib/auth'
|
||||||
|
|
||||||
module.exports = class UserHomeView extends UserView
|
module.exports = class MainUserView extends UserView
|
||||||
id: 'user-home-view'
|
id: 'user-home-view'
|
||||||
template: template
|
template: template
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (userID, options) ->
|
||||||
super options
|
super options
|
||||||
|
|
||||||
getRenderData: ->
|
getRenderData: ->
|
Reference in a new issue