summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/MasterView.js
blob: 5aca4e04f4f9317fef25e2468f1f0dd6e09d5eae (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
var MasterView = View.extend({
	el: "body",
	
	events: {
		"click [data-role='show-signup-modal']": 'signup',
		"click [data-role='show-signin-modal']": 'signin',
		"click [data-role='new-project-modal']": 'newProject',
		"click [data-role='edit-project-modal']": 'editProject',
		"click [data-role='edit-profile-modal']": 'editProfile',
	},
	
	routes: {
		"/login":          'signin',
		"/signup":         'signup',
		"/project/new":    'newProject',
		"/profile/edit":   'editProfile',
		"/app":            'launch',
	},

	initialize: function(){
		this.signUpModal = new SignUpModal()
		this.signInModal = new SignInModal()
		this.newProjectModal = new NewProjectModal()
		this.editProjectModal = new EditProjectModal()
		this.editProfileModal = new EditProfileModal()
		
		this.originalPath = window.location.pathname
		
		for (var route in this.routes) {
			if (window.location.pathname.indexOf(route) === 0) {
				this[this.routes[route]]()
				break;
			}
		}

		$("body").removeClass("loading")
	},
	
	launch: function(){
		app.launch()
	},
	
	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()
	},
	
	newProject: function(e){
		e && e.preventDefault()
		window.history.pushState(null, document.title, "/project/new")	

		this.newProjectModal.load()
	},

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

		this.editProfileModal.load()
	},

})