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

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

		var resolution
		switch (data.units) {
		  case 'ft':
		    resolution = app.defaults.footResolution
		    break
		  case 'm':
		    resolution = app.defaults.meterResolution
		    break
		  case 'px':
		  default:
		    resolution = 1
		    break
		}
    this.$blueprintScaleDisplay.html( ((1/data.scale) * resolution).toFixed(1) )
		this.show()
	},

	toggle: function(state){
		this.$el.toggleClass("active", state)
    this.$viewHeight.unitVal( window.viewHeight )
	},
	
	openScaler: function(){
	  this.parent.scaler.pick( this.parent.data, true )
	  this.parent.scaler.show()
	},
	
	show: function(){	
		this.toggle(true)
	},
	
	hide: function(){
		this.toggle(false)
	},
	
	deselect: function(){
	  this.toggle(true)
	},

	enterHeight: function(e){
	  if (e.keyCode == 13) this.changeHeight(e)
	},
	changeHeight: function(e){
		e.stopPropagation()
		window.wallHeight = this.$height.unitVal()
		shapes.forEach(function(line){
      line.mx.set_height( window.wallHeight )
    })
	},
	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()
	}

})