summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/_router.js
blob: 2b2c7c0d905c09806874580ed0ca441521fd28ef (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
var SiteRouter = Router.extend({
	el: "body",
	
	events: {
		"click [data-role='show-signup-modal']": 'signup',
		"click [data-role='show-signin-modal']": 'signin',
		"click [data-role='forgot-password']": 'passwordForgot',
		"click [data-role='new-project-modal']": 'newProject',
		"click [data-role='edit-project-modal']": 'editProject',
		"click [data-role='edit-profile-modal']": 'editProfile',
		"click [data-role='new-document-modal']": 'newDocument',
		"click [data-role='edit-document-modal']": 'editDocument',
		"click [data-role='destroy-document-modal']": 'destroyDocument',
		"click [data-role='show-layouts-modal']": 'layoutPicker',
		"click [data-role='show-projects-modal']": 'projectPicker',
	},
	
	routes: {
		"/login":               'signin',
		"/signup":              'signup',

		"/auth/usernameTaken":  'usernameTaken',
		"/auth/password":       'passwordReset',
		"/auth/forgotPassword": 'passwordForgot',

		"/profile":             'profile',
		"/profile/edit":        'editProfile',
		"/about/:name/edit":    'editDocument',
		"/about/new":           'newDocument',

		"/layout":              'layoutPicker',
		"/layout/:name":        'layoutEditor',

		"/project":             'projectPicker',
		"/project/new":         'newProject',
		"/project/new/:layout": 'projectNewWithLayout',
		"/project/:name":       'project',
		"/project/:name/view":  'projectViewer',
	},

	initialize: function(){
		this.signUpModal = new SignUpModal()
		this.signInModal = new SignInModal()
		this.layoutsModal = new LayoutsModal()
		this.projectsModal = new ProjectsModal()
		this.newProjectModal = new NewProjectModal()
		this.editProjectModal = new EditProjectModal()
		this.editProfileModal = new EditProfileModal()
		this.passwordForgotModal = new PasswordForgot()
		this.documentModal = new DocumentModal()
		this.profileView = new ProfileView()
		
		this.route()
		
		$("body").removeClass("loading")
	},


	layoutEditor: function(e, name){
		app.mode.builder = true
		app.launch()

		this.builderView = app.controller = new BuilderView()
		this.builderView.load(name)
	},
	
	layoutPicker: function(e){
		e && e.preventDefault()
		window.history.pushState(null, document.title, "/layout")
		this.layoutsModal.load()
	},

	projectPicker: function(e){
		e && e.preventDefault()
		window.history.pushState(null, document.title, "/project")
		this.projectsModal.load()
	},

	newProject: function(e){
		e && e.preventDefault()
		window.history.pushState(null, document.title, "/project/new")
		this.newProjectModal.load()
	},

	projectNewWithLayout: function(e, layout){
		e && e.preventDefault()

		app.mode.editor = true
		app.launch()

		layout = slugify(layout)
		
		window.history.pushState(null, document.title, "/project/new/" + layout)
		this.editorView = app.controller = new EditorView()
		this.editorView.loadLayout(layout)
	},

	project: function(e, name){
		if ($(".aboutRoom").length) {
			this.projectViewer(e, name)
		}
		else {
			this.projectEditor(e, name)
		}
	},

	projectEditor: function(e, name){
		app.mode.editor = true
		app.launch()

		this.editorView = app.controller = new EditorView()
		this.editorView.load(name)
	},
	
	projectViewer: function(e, name){
		app.mode.editor = true
		app.launch()

		this.readerView = app.controller = new ReaderView()
		this.readerView.load(name)
	},

/*
	editProject: function(e){
		e && e.preventDefault()
		window.history.pushState(null, document.title, "/project/edit")	
		this.editProjectModal.load()
	},
*/

	signup: function(e){
		e && e.preventDefault()
		window.history.pushState(null, document.title, "/signup")
		this.signUpModal.load()
	},

	signin: function(e){
		e && e.preventDefault()
		window.history.pushState(null, document.title, "/login")
		this.signInModal.load()
	},
	
	usernameTaken: function(e){
		this.usernameTakenModal = new UsernameTaken ()
		this.usernameTakenModal.load()
	},
	passwordForgot: function(e){
		e && e.preventDefault()
		window.history.pushState(null, document.title, "/auth/forgotPassword")
		this.passwordForgotModal.load()
	},
	passwordReset: function(e){
		this.passwordResetModal = new PasswordReset ()
		this.passwordResetModal.load()
	},
	
	profile: function(e){
		this.profileView.load()
	},
	
	editProfile: function(e){
		e && e.preventDefault()
		window.history.pushState(null, document.title, "/profile/edit")	

		this.editProfileModal.load()
	},


	newDocument: function(e){
		e && e.preventDefault()

		var name = e ? $(e.currentTarget).data("name") : "new"

		window.history.pushState(null, document.title, "/about/new")	
		this.documentModal.load(name, true)
	},
	
	editDocument: function(e, name){
		e && e.preventDefault()
		
		var name = e ? $(e.currentTarget).data("name") : name
		window.history.pushState(null, document.title, "/about/" + name + "/edit")
		this.documentModal.load(name, false)
	},

	destroyDocument: function(e, name){
		e && e.preventDefault()
		
		var name = e ? $(e.currentTarget).data("name") : name
		
		ConfirmModal.confirm("Are you sure you want to delete " + name + "?", function(){
			this.documentModal.destroy(name, function(){
				AlertModal.alert("Document deleted!", function(){
					window.location.href = "/about"
				}.bind(this))
			}.bind(this))
		}.bind(this))
		
		// this.documentModal.destroy(name)
	},

})