/
staffplan.js.coffee
121 lines (104 loc) · 3.61 KB
/
staffplan.js.coffee
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
class StaffPlan.Routers.StaffPlan extends Support.SwappingRouter
routes:
"staffplans/:id" : "staffplanShow"
"staffplans" : "staffplanIndex"
"clients" : "clientIndex"
"clients/new" : "clientNew"
"clients/:id" : "clientShow"
"clients/:id/edit" : "clientEdit"
"users/new" : "userNew"
"users/:id" : "userShow"
"users/:id/edit" : "userEdit"
"users" : "userIndex"
"projects" : "projectIndex"
"projects/new" : "projectNew"
"projects/:id" : "projectShow"
"projects/:id/edit" : "projectEdit"
initialize: (data) ->
@users = data.users
@projects = data.projects
@clients = data.clients
@currentCompany = data.currentCompany
@currentUser = data.currentUser
@el = $('body')
window.router = @
# Staff Plans
staffplanShow: (userId) ->
user = @users.get userId
alert 'no user with that ID found' unless user?
staffplanShow = new window.StaffPlan.Views.StaffPlans.Show(router: @, user: user)
@swap staffplanShow
staffplanIndex: ->
staffplanIndex = new window.StaffPlan.Views.StaffPlans.Index(router: @, users: @users)
@swap staffplanIndex
# Clients
clientIndex: ->
clientIndex = new window.StaffPlan.Views.Clients.Index(router: @, collection: @clients, currentCompany: @currentCompany)
@swap clientIndex
clientShow: (clientId) ->
client = @clients.get clientId
clientShow = new window.StaffPlan.Views.Clients.Show(router: @, model: client)
@swap clientShow
clientNew: ->
client = new window.StaffPlan.Models.Client
clientNew = new window.StaffPlan.Views.Clients.New
router: @
model: client
collection: window.StaffPlan.clients
@swap clientNew
clientEdit: (clientId) ->
client = @clients.get clientId
clientEdit = new window.StaffPlan.Views.Clients.New
collection: window.StaffPlan.clients,
router: @,
model: client,
@swap clientEdit
# Users
userShow: (userId) ->
user = @users.get userId
userShow = new window.StaffPlan.Views.Users.Show(router: @, model: user)
@swap userShow
userNew: ->
userNew = new window.StaffPlan.Views.Users.New
router: @
collection: window.StaffPlan.users
@swap userNew
userIndex: ->
userIndex = new window.StaffPlan.Views.Users.Index
router: @
collection: window.StaffPlan.users
currentCompany: window.StaffPlan.currentCompany
@swap userIndex
userEdit: (userId) ->
user = window.StaffPlan.users.get userId
userEdit = new window.StaffPlan.Views.Users.Edit
router: @
model: user
@swap userEdit
projectNew: ->
projectNew = new window.StaffPlan.Views.Projects.New
router: @
clients: window.StaffPlan.clients
collection: window.StaffPlan.projects
currentUser: window.StaffPlan.users.get(@currentUser.id)
@swap projectNew
projectEdit: (projectId) ->
project = window.StaffPlan.projects.get projectId
projectEdit = new window.StaffPlan.Views.Projects.Edit
router: @
clients: window.StaffPlan.clients
currentUser: window.StaffPlan.users.get(@currentUser.id)
model: project
collection: window.StaffPlan.projects
@swap projectEdit
projectShow: (projectId) ->
project = window.StaffPlan.projects.get projectId
projectShow = new window.StaffPlan.Views.Projects.Show
model: project
router: @
@swap projectShow
projectIndex: ->
projectIndex = new window.StaffPlan.Views.Projects.Index
router: @
collection: window.StaffPlan.projects
@swap projectIndex