Skip to content

Commit

Permalink
Undo is done. closes #47
Browse files Browse the repository at this point in the history
kdkavanagh committed Apr 16, 2014
1 parent 49fe26c commit 8382303
Showing 4 changed files with 25 additions and 29 deletions.
6 changes: 5 additions & 1 deletion handoff-tool/src/main/webapp/js/MHandoff/UndoStack.js
Original file line number Diff line number Diff line change
@@ -24,7 +24,11 @@ define([], function(){

UndoStack.prototype.empty = function() {
this.stack = new Array();
}
};

UndoStack.prototype.isEmpty = function() {
return this.stack.length == 0;
};

return UndoStack;
});
34 changes: 12 additions & 22 deletions handoff-tool/src/main/webapp/js/MHandoff/Views/NoteGridView.js
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ define([
var noteView = new NoteTileView({parent : self, noteModel:note,templates:this.templates});
self.noteViews.push(noteView);
self.activeNoteViews.push(noteView);

self.listenTo(noteView, 'remove', self.noteRemoved);
return noteView;
},

@@ -142,28 +142,17 @@ define([


undoRemove:function() {
this.undoStack.undo('save');
// if(this.mostRecentlyDeletedView != null) {
// $('#undoAlert').alert('close');
// this.noteViews.push(this.mostRecentlyDeletedView);
// this.mostRecentlyDeletedView.render();
// this.mostRecentlyDeletedView = null;
// this.trigger('gridchange');
// var undoButton = document.getElementById("undoButton");
// undoButton.style.display = 'none';
// }
var theModel = this.undoStack.undo('save');
var newView = this.createView(theModel, this).render( this.isotopeObj);
if(this.undoStack.isEmpty()) {
this.$el.find('#undoButton').prop('disabled', true);
}
},


noteRemove:function(event) {
noteRemoved:function(event) {
//remove the view from our list of views to render
var undoButton = document.getElementById("undoButton");
undoButton.style.display = '';
this.mostRecentlyDeletedView = event;
var index = this.activeNoteViews.indexOf(event);
if (index > -1) {
this.activeNoteViews.splice(index, 1);
}
this.$el.find('#undoButton').prop('disabled', false);
var index = this.noteViews.indexOf(event);
if (index > -1) {
this.noteViews.splice(index, 1);
@@ -184,12 +173,13 @@ define([
}
}
}).data('isotope');
for (var i = 0; i < this.activeNoteViews.length; i++) {
this.activeNoteViews[i].render(this.isotopeObj);
for (var i = 0; i < this.noteViews.length; i++) {
this.noteViews[i].render(this.isotopeObj);
}
this.resetFilters();
this.isotopeObj.layout();
$(window).resize();
this.$el.find('#undoButton').prop('disabled', true);
//$(window).resize();

return this;
},
10 changes: 6 additions & 4 deletions handoff-tool/src/main/webapp/js/MHandoff/Views/NoteTileView.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,8 @@ define([

initialize : function (options) {
this.options = options || {};

this.parent = this.options.parent;
_.bindAll(this, 'removeClickHandler');
this.noteModel = this.options.noteModel;
this.templates = this.options.templates;
this.template = this.templates.tile;
@@ -72,10 +73,11 @@ define([
},

removeClickHandler : function(event){
console.log("Removing...");
this.$closeIcon.tooltip('hide');
this.parent.undoStack.push(this.noteModel, 'destroy');
this.$closeIcon.tooltip('hide');
this.remove();
this.parent.undoStack.push(this.noteModel, 'destroy');
//Unset the id because if we redo this, we need to recreate it on the server
this.noteModel.unset('noteId', {silent:true});
this.trigger('remove', this);
return false;
},
Original file line number Diff line number Diff line change
@@ -57,8 +57,8 @@
<span class="glyphicon glyphicon-plus"></span> Add Note
</button>
<button type="button" id="undoButton"
class="btn btn-primary newButton" style="display: none">
<span class="glyphicon"></span> Undo Last Action
class="btn btn-primary newButton">
<span class="glyphicon"></span>Undo Remove
</button>

<div id="noteGrid"></div>

0 comments on commit 8382303

Please sign in to comment.