summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/site/LayoutsModal.js
blob: 0a038787894d69990003cb6757226e15f207c901 (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
var LayoutsIndex = View.extend({

	initialize: function(){
		this.$templates = this.$(".templates")
	},

	load: function(type){
		this.$templates.children("span").remove()
		
		$.get("/api/layouts", $.proxy(function(data){

			data.forEach($.proxy(function(room){
				var $span = $("<span>")
				// $span.html(JSON.stringify(room))
				$span.data("slug", room.slug)
				$span.css("background-image", "url(" + room.photo + ")")
				
				this.$templates.append($span)
			}, this))

			this.show()
		}, this))

	}
})


var LayoutsModal = ModalView.extend(LayoutsIndex.prototype).extend({
	el: ".mediaDrawer.layouts",

	events: {
		"click .templates span": 'toggleActive',
		"submit form": 'newBuilder',
	},
	
	toggleActive: function(e){
		e.preventDefault()
		this.$(".templates .active").removeClass("active")
		var $layout = $(e.currentTarget)
		$layout.addClass("active")
		
		// actually do
		window.location.pathname = "/builder/" + $layout.data("slug")
	},
	
	newBuilder: function(e){
		e && e.preventDefault()
		window.location.pathname = "/builder/new"
	}

})


var NewProjectModal = ModalView.extend(LayoutsIndex.prototype).extend({
	el: ".mediaDrawer.newProject",

	events: {
		"click .templates span": 'toggleActive',
		"submit form": 'choose',
	},
	
	toggleActive: function(e){
		e.preventDefault()
		this.$(".templates .active").removeClass("active")
		$(e.currentTarget).addClass("active")
	},
	
	choose: function(e){
		e && e.preventDefault()
	}
	
})