Crude offline Freezing

This commit is contained in:
Curtis SerVaas
2014-09-29 13:00:44 -04:00
parent 56d174d7e6
commit 18731566d9
7 changed files with 108 additions and 96 deletions
+4
View File
@@ -13,6 +13,10 @@ $(function(){
});
function createPathMenu(event){
//console.log($(event.target).attr("data-id"));
var pathDiv = $(event.target).parent().children("#pathDiv")
+95 -87
View File
@@ -1,111 +1,119 @@
var socket = null;
var AppRouter = Backbone.Router.extend({
var socket = null;
socketEvents: _.extend({}, Backbone.Events),
var AppRouter = Backbone.Router.extend({
routes: {
'': 'initialize',
':id': "viewRoot"
},
socketEvents: _.extend({}, Backbone.Events),
initialize: function(){
routes: {
'': 'initialize',
':id': "viewRoot"
},
if(socket){ return; }//prevents double-initialization.
socket = io.connect();
this.setUpSocket();
initialize: function(){
this.socketInitialize();
},
$.ajax({
url: "/ajaxlogin",
type: "POST",
socketInitialize: function(){
if(socket){ return; }//prevents double-initialization.
socket = io.connect();
this.setUpSocket();
$.ajax({
url: "/ajaxlogin",
type: "POST",
complete: function(){
},
success: function(data){
console.log("AjaxLoginDATA");
if(typeof data == "string"){
$("textarea").attr("disabled", true);
} //User is not logged in.
if(typeof data == "object"){//we've got the userObject.
$("#googleButton").parent().html("<a href='logout'>Logout</a> ");
socket.emit("logIn", data); //logs the user into the socket.
complete: function(){
},
success: function(data){
console.log("AjaxLoginDATA");
if(typeof data == "string"){
$("textarea").attr("disabled", true);
} //User is not logged in.
if(typeof data == "object"){//we've got the userObject.
$("#googleButton").parent().html("<a href='logout'>Logout</a> ");
socket.emit("logIn", data); //logs the user into the socket.
data.google.id = null;
data.google.token = null;
data.google.email = null;
CurrentUser = data;
data.google.id = null;
data.google.token = null;
data.google.email = null;
CurrentUser = data;
console.log("CURRENT USER");
console.log(CurrentUser);
}
},
error: function(data){
console.log("ERROR- AjaxLoginDATA");
console.log("CURRENT USER");
console.log(CurrentUser);
}
});
},
},
// index: function(otherID){
// var that = this;
// otherID = otherID ||
// },
viewRoot: function(id, snapCollection){
var rootModel;
var metaCollection;
var snapView = 0;
if(snapCollection){
rootModel = snapCollection.findWhere({cur_id: id});
metaCollection = snapCollection
snapView = 1;
}
else{
rootModel = nodesCollection.findWhere({_id: id});
metaCollection = nodesCollection;
error: function(data){
console.log("ERROR- AjaxLoginDATA");
}
});//ajax
},
var rootView = new listView({
viewWindow: ".main1",
model: rootModel,
metaCollection: metaCollection,
snapView: snapView
})
this.changeView(rootView);
},
// index: function(otherID){
// var that = this;
// otherID = otherID ||
changeView: function(view) {
if ( null != this.currentView ) {
this.currentView.undelegateEvents();
}
this.currentView = view;
$("textarea").textareaAutoExpand();
// },
},
viewRoot: function(id, snapCollection){
var rootModel;
var metaCollection;
var snapView = 0;
if(snapCollection){
rootModel = snapCollection.findWhere({cur_id: id});
metaCollection = snapCollection
snapView = 1;
}
else{
rootModel = nodesCollection.findWhere({_id: id});
metaCollection = nodesCollection;
}
var rootView = new listView({
viewWindow: ".main1",
model: rootModel,
metaCollection: metaCollection,
snapView: snapView
})
this.changeView(rootView);
},
changeView: function(view) {
if ( null != this.currentView ) {
this.currentView.undelegateEvents();
}
this.currentView = view;
$("textarea").textareaAutoExpand();
},
setUpSocket: function(){
var that = this;
socket.emitWrapper = function(eventName, data){
console.log(this);
if(this.socket.connected){ this.emit(eventName, data); }
else{ //(alert + lock)
alert("Internet connection down. Edits not synced. Refresh when back online.");
}
}
socket.on('nodeData', function(data){
//alert("data");
console.log(data);
nodesCollection = new NodesCollection(data);
var id = nodesCollection.findWhere({text: "0root"}).get("_id");
// if(otherID){
// id = otherID
// }
that.viewRoot(id);
//alert("data");
console.log(data);
nodesCollection = new NodesCollection(data);
var id = nodesCollection.findWhere({text: "0root"}).get("_id");
// if(otherID){
// id = otherID
// }
that.viewRoot(id);
});
+3 -3
View File
@@ -16,7 +16,7 @@ addNode = function(botStr, topStr){
_.each(vo.thisModel.get("views"), function(view){
view.updateText(topStr);
});
socket.emit("edit", [vo.thisId, topStr]);
socket.emitWrapper("edit", [vo.thisId, topStr]);
}
@@ -27,7 +27,7 @@ addNode = function(botStr, topStr){
var data = [ [vo.parentId, vo.thisIndex+1] , modelJSON ];
console.log("AddNode DATA"); console.log(data);
socket.emit("newNode", data);
socket.emitWrapper("newNode", data);
var parentViews = vo.parentModel.get("views");
@@ -73,7 +73,7 @@ transclude = function(){
, parents: vo.thisModel.get("parents")
, children: vo.thisModel.get("children")
}
socket.emit("transclude" , [vo.parentId, vo.thisIndex+1, vo.thisId]);
socket.emitWrapper("transclude" , [vo.parentId, vo.thisIndex+1, vo.thisId]);
var parentViews = vo.parentModel.get("views");
var tempIndex = vo.thisIndex+1; //adding nodes alters the index.
_.each(parentViews, function(parentView){
+1 -1
View File
@@ -29,7 +29,7 @@ var moveNode = function(thisModel, dragIndex, oldParModel, newParModel, dropInde
var data = [ids, arrays, indices, CurrentUser];
if(chr){
socket.emit("movedNode", data);
socket.emitWrapper("movedNode", data);
}
INPUT_PROCESSED=true;
+1 -1
View File
@@ -10,7 +10,7 @@
});
vo.thisModel.set("parents", newParents);
if(!broadcast){ //broadCast=true means we received this update from somebody else.
socket.emit("removeNode", [vo.thisId, vo.thisIndex, vo.parentId, CurrentUser]);
socket.emitWrapper("removeNode", [vo.thisId, vo.thisIndex, vo.parentId, CurrentUser]);
}
}
+2 -2
View File
@@ -45,7 +45,7 @@ $(function(){
var that = this;
// alert("editing"); console.log("EDITING");
var id = $(event.target).closest("li").attr("data-id");
socket.emit("editing", [id, CurrentUser.google.name]);
socket.emitWrapper("editing", [id, CurrentUser.google.name]);
voInitializer(that, event);
keydownHandler(event);
//(This event is not firing for some reason..(I wonder if I put it at the top)).
@@ -55,7 +55,7 @@ $(function(){
var id = thisLI.attr("data-id");
var text = thisLI.children().children("textarea").val();
$("textarea").textareaAutoExpand();
socket.emit("blurred", [id, text, CurrentUser]);
socket.emitWrapper("blurred", [id, text, CurrentUser]);
// alert("blur!!");
// editing=false;
});
+2 -2
View File
@@ -1,11 +1,11 @@
$(function(){
$("#COMMIT").click(function(){
socket.emit("COMMIT");
socket.emitWrapper("COMMIT");
});
$(".getRevHistory").click(function(e){
var rootId = $(".root").attr("data-id")
socket.emit("revHistoryRequest", rootId);
socket.emitWrapper("revHistoryRequest", rootId);
$(e.target).attr("data-id", rootId);
});