summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/builder
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/ui/builder')
-rw-r--r--public/assets/javascripts/ui/builder/BuilderInfo.js160
-rw-r--r--public/assets/javascripts/ui/builder/BuilderSettings.js15
-rw-r--r--public/assets/javascripts/ui/builder/BuilderView.js9
3 files changed, 175 insertions, 9 deletions
diff --git a/public/assets/javascripts/ui/builder/BuilderInfo.js b/public/assets/javascripts/ui/builder/BuilderInfo.js
new file mode 100644
index 0000000..9bbd385
--- /dev/null
+++ b/public/assets/javascripts/ui/builder/BuilderInfo.js
@@ -0,0 +1,160 @@
+
+var BuilderInfo = View.extend({
+ el: "#builderInfo",
+
+ events: {
+ "keydown": 'stopPropagation',
+ "change [name=x]": 'changePosition',
+ "change [name=y]": 'changePosition',
+ "change [name=width]": 'changeDimensions',
+ "change [name=depth]": 'changeDimensions',
+ "change [name=height]": 'changeDimensions',
+ "change [name=units]": 'changeUnits',
+ "change [name=resolution]": 'changeResolution',
+ "change [name=viewHeight]": 'changeViewHeight',
+ },
+
+ initialize: function(opt){
+ this.parent = opt.parent
+ this.$x = this.$("[name=x]")
+ this.$y = this.$("[name=y]")
+ this.$width = this.$("[name=width]")
+ this.$depth = this.$("[name=depth]")
+ this.$height = this.$("[name=height]")
+ this.$units = this.$("[name=units]")
+ this.$viewHeight = this.$("[name=viewHeight]")
+ this.$unitName = this.$(".unitName")
+ app.on("builder-pick-room", this.pick.bind(this))
+ app.on("builder-destroy-room", this.destroy.bind(this))
+ },
+
+ load: function(data){
+ this.$viewHeight.unitVal( data.viewHeight || app.defaults.viewHeight )
+ this.$units.val( "ft" )
+ this.$unitName.html( "ft" )
+ this.$resolution.val( app.defaults.footResolution )
+ },
+
+ toggle: function(state){
+ this.$el.toggleClass("active", state)
+ },
+
+ show: function(){
+ this.toggle(true)
+ },
+
+ hide: function(){
+ this.toggle(false)
+ },
+
+ room: null,
+
+ pick: function(room){
+ this.room = room
+ this.$width.unitVal( room.rect.x.length() )
+ this.$depth.unitVal( room.rect.y.length() )
+ this.$height.unitVal( room.height )
+ this.$x.unitVal( room.rect.x.a )
+ this.$y.unitVal( room.rect.y.a )
+
+ console.log(room)
+ },
+
+ destroy: function(room){
+ this.room = null
+ this.hide()
+ },
+
+ changeDimensions: function(){
+// this.$width.unitVal( room.rect.x.length() )
+// this.$depth.unitVal( room.rect.y.length() )
+// this.$height.unitVal( room.height )
+ },
+
+ changeUnits: function(){
+ app.units = this.$units.val()
+ this.$('.units').resetUnitVal()
+ },
+
+ changeViewHeight: function(){
+ window.viewHeight = this.$viewHeight.unitVal( )
+ },
+
+})
+
+$.fn.resetUnitVal = function(){
+ this.each(function(){
+ var n = $(this).data("px")
+ $(this).unitVal(n)
+ });
+}
+
+$.fn.unitVal = function(n){
+ var s
+ if (typeof n === "undefined") {
+ s = $(this).val()
+ n = stringToMeasurement( s )
+ }
+ s = measurementToString( n )
+ $(this).val( s ).data("px", n)
+ return n
+}
+
+function measurementToString( n ) {
+ var s, ft, inch
+ switch (app.units) {
+ case 'm':
+ s = round(n/36 * 0.3048 * 100) / 100 + " m"
+ break
+ case 'ft':
+ ft = floor(n / 36)
+ inch = abs(round((n % 36) / 3))
+ s = ft + "'"
+ if (inch > 0) {
+ s += " " + inch + '"'
+ }
+ break
+ case 'px':
+ default:
+ s = round(n) + " px"
+ break
+ }
+ return s
+}
+function stringToMeasurement( s ) {
+ var ft, inch, ft_in, type
+ if (s.indexOf("'") !== -1 || s.indexOf('"') !== -1 || s.indexOf('ft') !== -1) {
+ ft_in = s.match(/[0-9.]+/g)
+ if (ft_in.length >= 2) {
+ ft = parseFloat( ft_in[0] )
+ inch = parseFloat( ft_in[1] )
+ }
+ else if (ft_in.length == 1) {
+ if (s.indexOf('"') !== -1) {
+ ft = 0
+ inch = parseFloat( ft_in[0] )
+ }
+ else {
+ ft = parseFloat( ft_in[0] )
+ inch = 0
+ }
+ }
+ else {
+ ft = inch = 0
+ }
+ n = ft * 36 + inch * 3
+ }
+ else if (type === "m") {
+ n = parseFloat(s.match(/[0-9.]+/)) * 36 / 0.3048
+ }
+ else if (s.indexOf("px") !== -1) {
+ n = parseFloat(s.match(/[0-9.]+/))
+ }
+ else {
+ n = abs( stringToMeasurement( s + app.units ) )
+ }
+ if (s.indexOf('-') !== -1) {
+ n *= -1
+ }
+ return n
+} \ No newline at end of file
diff --git a/public/assets/javascripts/ui/builder/BuilderSettings.js b/public/assets/javascripts/ui/builder/BuilderSettings.js
index 9b2f753..c551f95 100644
--- a/public/assets/javascripts/ui/builder/BuilderSettings.js
+++ b/public/assets/javascripts/ui/builder/BuilderSettings.js
@@ -2,11 +2,12 @@
var BuilderSettings = FormView.extend({
el: "#builderSettings",
- createAction: "/api/layouts/new",
- updateAction: "/api/layouts/edit",
- destroyAction: "/api/layouts/destroy",
+ createAction: "/api/layout/new",
+ updateAction: "/api/layout/edit",
+ destroyAction: "/api/layout/destroy",
events: {
+ "keydown": 'stopPropagation',
"keydown [name=name]": 'enterSubmit',
"click [data-role='save-layout']": 'save',
"click [data-role='clone-layout']": 'clone',
@@ -57,7 +58,7 @@ var BuilderSettings = FormView.extend({
destroy: function(){
var msg = "Are you sure you want to delete the layout " + sanitize(this.$name.val()) + "?"
- ConfirmModal.confirm(msg, $.proxy(function(){
+ ConfirmModal.confirm(msg, function(){
$.ajax({
url: this.destroyAction,
type: "delete",
@@ -66,11 +67,11 @@ var BuilderSettings = FormView.extend({
window.location.href = "/layout"
}
})
- }, this))
+ }.bind(this))
},
- toggle: function(){
- this.$el.toggleClass("active")
+ toggle: function(state){
+ this.$el.toggleClass("active", state)
},
enterSubmit: function (e) {
diff --git a/public/assets/javascripts/ui/builder/BuilderView.js b/public/assets/javascripts/ui/builder/BuilderView.js
index 33aface..555cd58 100644
--- a/public/assets/javascripts/ui/builder/BuilderView.js
+++ b/public/assets/javascripts/ui/builder/BuilderView.js
@@ -2,12 +2,13 @@
var BuilderView = View.extend({
el: "#builderView",
- action: "/api/layouts/",
+ action: "/api/layout/",
events: {
},
initialize: function(){
+ this.info = new BuilderInfo ({ parent: this })
this.toolbar = new BuilderToolbar ({ parent: this })
this.settings = new BuilderSettings ({ parent: this })
},
@@ -20,11 +21,15 @@ var BuilderView = View.extend({
name = sanitize(name)
- $.get(this.action + name, $.proxy(this.ready, this))
+ $.get(this.action + name, this.ready.bind(this))
},
ready: function(data){
this.settings.load(data)
+ this.info.load(data)
},
+
+ hideExtras: function(){
+ }
})