Skip to content

Commit

Permalink
Fix drag drop, not great though
Browse files Browse the repository at this point in the history
  • Loading branch information
samwan committed Oct 12, 2012
1 parent 5e267c4 commit 8fb7606
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@
dragstart : function(o) {
start = Point.fromCss(self.$item.position());
self.$item.appendTo('body');
app.detachMapItem(recordId);
},
dragmove : function(o) {
current = start.add(o.dragVector);
self.$item.css({ left:o.currentPosition.x, top:o.currentPosition.y });
},
dragend : function(o) {
app.dropMapItemOntoScreen(recordId, o.releasePosition);
app.dropListItemOntoScreen(recordId, o.releasePosition);
self.destroy();
}
});
};
Expand Down Expand Up @@ -175,7 +177,8 @@
this.$item.find('.icon_image').attr('src', record.imgurl);
}

var App = function() {
var App = function(url) {
this.url = url;
this.data = null;
this.$viewport = $('#viewport');
this.$mapcontainer = $('#mapcontainer');
Expand All @@ -194,6 +197,7 @@
setInterval(function() {
self.load();
}, 3000);
self.load();
};
// UI
App.prototype.initCommandBar = function() {
Expand Down Expand Up @@ -226,19 +230,11 @@
App.prototype.toggleSensorList = function() {
this.$sensorlist.toggle();
};
App.prototype.dropMapItemOntoScreen = function(recordId, position) {
// If release outside of map or release over listitem, then remove, otherwise re-add
App.prototype.detachMapItem = function(recordId) {
var self = this;
if (self.__hittestOnMap(position)) {
self.mappedItems[recordId].destroy();
delete self.mappedItems[recordId];
self.listedItems[recordId].setDraggingEnabled(true);
} else {
var localPoint = self.globalToLocal(position);
self.mappedItems[recordId].appendTo(self.$mapcontainer).css({ left:localPoint.x, top:localPoint.y });
self.setRecordXY(recordId, localPoint.x, localPoint.y);
}
}
delete self.mappedItems[recordId];
self.listedItems[recordId].setDraggingEnabled(true);
};
App.prototype.__hittestOnMap = function(position) {
var self = this;
return self.__hittest(position, self.$sensorlist) == true || self.__hittest(position, self.$viewport) == false;
Expand Down Expand Up @@ -283,7 +279,7 @@
App.prototype.load = function(continuation) {
var self = this;
$.ajax({
url : '/spatialize/api/floorplan.json',
url : self.url,
type : 'GET',
dataType : 'json',
data : {},
Expand All @@ -304,20 +300,21 @@
var self = this;
self.$status.text('Saving...').fadeIn();
$.ajax({
url : '/spatialize/api/floorplan.json',
url : self.url,
type : 'POST',
dataType : 'json',
data : {jsonstring:JSON.stringify(this.data)},
success : function(responseData, textStatus, xhr) {
continuation && continuation(responseData);
self.$status.text('Saved');
console.log('saved', responseData);
setTimeout(function() { self.$status.fadeOut(); }, 300);
}
});
};
$(window).load(function() {
var app = new App();
var url = '/spatialize/api/floorplan.json';
var url = 'floorplan.json';
var app = new App(url);
});
</script>
</head>
Expand Down

0 comments on commit 8fb7606

Please sign in to comment.