mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-27 06:23:41 -04:00
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/:model(/:slug_or_id)(/:subview)': 'editorModelView'
|
||||
|
||||
# user views
|
||||
'user/:nameOrID(/:subview)': 'userView'
|
||||
'user/:slugOrID': go('user/MainUserView')
|
||||
'user/:slugOrID/stats': go('user/AchievementsView')
|
||||
'user/:slugOrID/profile': go('user/JobProfileView')
|
||||
#'user/:slugOrID/code': go('user/CodeView')
|
||||
|
||||
# account views
|
||||
'account(/:subview)': 'accountView'
|
||||
'account': go('account/MainAccountView')
|
||||
'account/settings': go('account/AccountSettingsView')
|
||||
#'account/payment'
|
||||
|
||||
# Direct links
|
||||
|
||||
|
@ -83,27 +86,6 @@ module.exports = class CocoRouter extends Backbone.Router
|
|||
view.render()
|
||||
@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: {}
|
||||
openRoute: (route) ->
|
||||
route = route.split('?')[0]
|
||||
|
|
|
@ -5,7 +5,7 @@ User = require 'models/User'
|
|||
AuthModalView = require 'views/modal/auth_modal'
|
||||
RecentlyPlayedCollection = require 'collections/RecentlyPlayedCollection'
|
||||
|
||||
module.exports = class AccountHomeView extends View
|
||||
module.exports = class MainAccountView extends View
|
||||
id: 'account-home-view'
|
||||
template: template
|
||||
|
|
@ -7,7 +7,7 @@ module.exports = class UserView extends RootView
|
|||
className: 'user-view'
|
||||
viewName: null # Used for the breadcrumbs
|
||||
|
||||
constructor: (options, @userID) ->
|
||||
constructor: (@userID, options) ->
|
||||
super options
|
||||
|
||||
@listenTo @, 'userLoaded', @onUserLoaded
|
||||
|
|
|
@ -6,11 +6,11 @@ EarnedAchievement = require 'models/EarnedAchievement'
|
|||
AchievementCollection = require 'collections/AchievementCollection'
|
||||
EarnedAchievementCollection = require 'collections/EarnedAchievementCollection'
|
||||
|
||||
module.exports = class UserAchievementsView extends UserView
|
||||
module.exports = class AchievementsView extends UserView
|
||||
id: 'user-achievements-view'
|
||||
template: template
|
||||
|
||||
constructor: (options, userID) ->
|
||||
constructor: (userID, options) ->
|
||||
super options, userID
|
||||
|
||||
onUserLoaded: (user) ->
|
|
@ -54,7 +54,7 @@ module.exports = class ProfileView extends UserView
|
|||
'change #admin-contact': 'onAdminContactChanged'
|
||||
'click .session-link': 'onSessionLinkPressed'
|
||||
|
||||
constructor: (options, userID) ->
|
||||
constructor: (userID, options) ->
|
||||
@onJobProfileNotesChanged = _.debounce @onJobProfileNotesChanged, 1000
|
||||
@onRemarkChanged = _.debounce @onRemarkChanged, 1000
|
||||
@authorizedWithLinkedIn = IN?.User?.isAuthorized()
|
|
@ -2,11 +2,11 @@ UserView = require 'views/kinds/UserView'
|
|||
template = require 'templates/user/home'
|
||||
{me} = require 'lib/auth'
|
||||
|
||||
module.exports = class UserHomeView extends UserView
|
||||
module.exports = class MainUserView extends UserView
|
||||
id: 'user-home-view'
|
||||
template: template
|
||||
|
||||
constructor: (options) ->
|
||||
constructor: (userID, options) ->
|
||||
super options
|
||||
|
||||
getRenderData: ->
|
Loading…
Add table
Add a link
Reference in a new issue