summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/router.js
blob: ebdfa780ffd92e97068621fe380ba7a1f51723cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
var SiteRouter = Router.extend({

	el: "body",
	
	routes: {
		"/":                       'login',
		"/index/:keyword":         'index',
		"/index":                  'index',
		"/login":                  'login',
		"/logout":                 'logout',
		"/signup":                 'signup',
		"/details/:id":            'details',
		"/details/:id/settings":   'threadSettings',
		"/post":                   'post',
		"/post/:keyword":          'post',
		"/comment/:id/edit":       'editComment',
		"/keywords":               'keywords',
		"/search":                 'search',
		"/mail":                   'mailbox',
		"/mail/:mailbox":          'mailbox',
		"/mail/compose":           'compose',
		"/mail/compose/:username": 'compose',
		"/mail/read/:id":          'message',
		"/mail/reply/:id":         'compose',
    "/users":                  'users',
    "/users/all":              'usersAll',
    "/profile":                'profile',
		"/profile/:username":      'profile',
		"/profile/:username/edit": 'editProfile',
    "/adminz":                 'adminz',
	},
	
	initialize: function(){
	  $(".logout").click(() => this.logout())
  },
  
  index: function(keyword){
    app.view = new IndexView ()
    app.view.load(keyword)
  },
  
  login: function(){
    app.view = new LoginView ()
  },
  
  logout: function(){
	  auth.log_out()
	  window.location.href = "/logout"
  },
  
  signup: function(){
    app.view = new SignupView ()
  },
  
  details: function(id){
    app.view = new DetailsView ()
    app.view.load(id)
  },

  threadSettings: function(id){
    app.view = new DetailsView ({ settings: true })
    app.view.load(id)
  },
  
  editComment: function(id){
    app.view = new EditCommentForm ()
    app.view.load(id)
  },

  keywords: function(){
    app.view = new KeywordsView ()
    app.view.load()
  },

  mailbox: function(box){
    app.view = new MailboxView ()
    app.view.load(box)
  },
  
  message: function(id){
    app.view = new MessageView ()
    app.view.load(id)
  },

  post: function(keyword){
    app.view = new ThreadForm ()
    app.view.load(keyword || "")
  },
  
  users: function(username){
    app.view = new UsersView ()
    app.view.load()
  },

  usersAll: function(username){
    app.view = new UsersView ({ all: true })
    app.view.load()
  },
  
  profile: function(username){
    app.view = new ProfileView ()
    app.view.load(username || auth.user.username)
  },
  
  editProfile: function(username){
    app.view = new ProfileForm ()
    app.view.load(username || auth.user.username)
  },
  
  compose: function(username){
    app.view = new ComposeView ()
    app.view.load(username)
  },

  search: function(){
    app.view = new SearchResults ()
    app.view.load()
  },

  adminz: function(){
    app.view = new AdminView ()
    app.view.load()
  },
  
  error404: function(){
    $("content").hide()
    $("#error_404").show()
    $("h1").html("404 not found")
    $("body").removeClass("loading")
    $("#error_404").append('<a href="/"><img src="/assets/img/castro.jpg"></a>')
  },

})