mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-27 06:23:41 -04:00
Start of new user routing and views are there
This commit is contained in:
parent
51bc8e5a7c
commit
e33bb44ffc
5 changed files with 46 additions and 0 deletions
app
lib
templates
views
|
@ -16,6 +16,9 @@ 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'
|
||||
|
||||
# Direct links
|
||||
'test/*subpath': go('TestView')
|
||||
'demo/*subpath': go('DemoView')
|
||||
|
@ -46,6 +49,15 @@ 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()
|
||||
|
||||
cache: {}
|
||||
openRoute: (route) ->
|
||||
route = route.split('?')[0]
|
||||
|
|
3
app/templates/kinds/user.jade
Normal file
3
app/templates/kinds/user.jade
Normal file
|
@ -0,0 +1,3 @@
|
|||
extends /templates/base
|
||||
|
||||
// User pages might have some user page specific header, if not remove this
|
1
app/templates/user/achievements.jade
Normal file
1
app/templates/user/achievements.jade
Normal file
|
@ -0,0 +1 @@
|
|||
extends /templates/base
|
19
app/views/kinds/UserView.coffee
Normal file
19
app/views/kinds/UserView.coffee
Normal file
|
@ -0,0 +1,19 @@
|
|||
RootView = require 'views/kinds/RootView'
|
||||
template = require 'templates/kinds/user'
|
||||
User = require 'models/User'
|
||||
|
||||
module.exports = class UserView extends RootView
|
||||
template: template
|
||||
className: 'user-view'
|
||||
|
||||
constructor: (options, nameOrID) ->
|
||||
# TODO Ruben Assume ID for now
|
||||
user = new User nameOrID
|
||||
user.fetch
|
||||
success: ->
|
||||
console.log 'helabaaa'
|
||||
error: (model, response, options) ->
|
||||
console.log response
|
||||
console.log options
|
||||
|
||||
super options
|
11
app/views/user/achievements.coffee
Normal file
11
app/views/user/achievements.coffee
Normal file
|
@ -0,0 +1,11 @@
|
|||
UserView = require 'views/kinds/UserView'
|
||||
template = require 'templates/user/achievements'
|
||||
{me} = require 'lib/auth'
|
||||
|
||||
module.exports = class UserAchievementsViewe extends UserView
|
||||
id: 'user-achievements-view'
|
||||
template: template
|
||||
|
||||
constructor: (options, @nameOrID) ->
|
||||
super options, @nameOrID
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue