summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/blueprint/BlueprintInfo.js
blob: ad462ae0e3e792fa9b436bd5778a91509b5713b9 (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
var BlueprintInfo = View.extend({
	el: "#blueprintInfo",

	events: {
	  "mousedown": "stopPropagation",
		"keydown": 'stopPropagation',
		"keydown [name=height]": 'enterHeight',
		"change [name=units]": 'changeUnits',
		"keydown [name=viewHeight]": 'enterViewHeight',
		"change [name=viewHeight]": 'changeViewHeight',
		"click [data-role=destroy-room]": 'destroy',
	},
	
	initialize: function(opt){
		this.parent = opt.parent
		this.$units = this.$("[name=units]")
		this.$viewHeight = this.$("[name=viewHeight]")
		this.$unitName = this.$(".unitName")
	},
	
	load: function(data){
		this.$viewHeight.unitVal( window.viewHeight = data.viewHeight || app.defaults.viewHeight )
		this.$units.val( data.units )
		this.$unitName.html( data.units )
	},

	toggle: function(state){
		this.$el.toggleClass("active", state)
    this.$viewHeight.unitVal( window.viewHeight )
	},
	
	show: function(){	
		this.toggle(true)
	},
	
	hide: function(){
	  this.room = null
		this.toggle(false)
	},

	room: null,
	
	pick: function(room){
	},
	
	deselect: function(){
	  this.room = null
	  this.toggle(true)
	},

	enterHeight: function(e){
	  if (e.keyCode == 13) this.changeHeight(e)
	},
	changeHeight: function(e){
		e.stopPropagation()
		var height = this.room.height = this.$height.unitVal()
		if (window.heightIsGlobal) {
		  Rooms.forEach(function(room){
		    room.height = height
		  })
		}
    Rooms.rebuild()
	},
	changeUnits: function(){
		app.units = this.$units.val()
		this.$('.units').resetUnitVal()
	},
	enterViewHeight: function(e){
	  if (e.keyCode == 13) this.changeViewHeight(e)
	},
  changeViewHeight: function(){
 		window.viewHeight = this.$viewHeight.unitVal()
	}

})