Skip to content

Commit

Permalink
Delete a story from a sprint.
Browse files Browse the repository at this point in the history
  • Loading branch information
pneff committed Dec 12, 2008
1 parent a931c48 commit 58b0bf8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
1 change: 1 addition & 0 deletions scrumboard/config/routing.py
Expand Up @@ -26,6 +26,7 @@ def make_map():
map.connect('/stories/{id}/delete.json', controller='stories', action='delete_json')
map.connect('/sprints/{id}/stories.json', controller='sprints', action='stories_json')
map.connect('/sprints/{id}/add_story.json', controller='sprints', action='add_story_json')
map.connect('/sprints/{id}/{story_id}/delete.json', controller='sprints', action='delete_story_json')

# Default routes
map.connect('/{controller}/{action}')
Expand Down
9 changes: 9 additions & 0 deletions scrumboard/controllers/sprints.py
Expand Up @@ -42,3 +42,12 @@ def add_story_json(self, id):
model.meta.Session.add(sprint)
model.meta.Session.commit()
return {'story': story.get_as_dict()}

@jsonify
def delete_story_json(self, id, story_id):
story = model.meta.Session.query(model.Story).get(story_id)
sprint = model.meta.Session.query(model.Sprint).get(id)
sprint.stories.remove(story)
model.meta.Session.add(sprint)
model.meta.Session.commit()
return {'status': 'ok'}
17 changes: 12 additions & 5 deletions scrumboard/public/static/sprints/stories.js
@@ -1,6 +1,8 @@
(function() {
YAHOO.namespace('scrumboard.sprint');
YAHOO.scrumboard.sprint.id = null;
var sprintId = location.href.substr(location.href.lastIndexOf('/')+1);
sprintId = parseInt(sprintId, 10);
YAHOO.scrumboard.sprint.id = sprintId;
YAHOO.scrumboard.sprint.stories = null;

// Table object using the YUI scrolling data table.
Expand All @@ -9,10 +11,15 @@
};
YAHOO.lang.extend(YAHOO.scrumboard.stories.sprintStoryTable, YAHOO.scrumboard.stories.table);
YAHOO.scrumboard.stories.sprintStoryTable.prototype.getListUrl = function() {
var id = location.href.substr(location.href.lastIndexOf('/')+1);
id = parseInt(id, 10);
YAHOO.scrumboard.sprint.id = id;
return "/sprints/" + id + "/stories.json";
var sprintId = YAHOO.scrumboard.sprint.id;
return "/sprints/" + sprintId + "/stories.json";
};
YAHOO.scrumboard.stories.sprintStoryTable.prototype.getDeleteUrl = function(id) {
var sprintId = YAHOO.scrumboard.sprint.id;
return '/sprints/' + sprintId + '/' + id + '/delete.json';
};
YAHOO.scrumboard.stories.sprintStoryTable.prototype.onDeleteCellClick = function(target) {
this.removeStory(target);
};

YAHOO.util.Event.onContentReady('sprintstories', function() {
Expand Down
28 changes: 17 additions & 11 deletions scrumboard/public/static/stories/table-common.js
Expand Up @@ -125,13 +125,17 @@
var target = oArgs.target;
var column = this.table.getColumn(target);
if (column.key == 'delete') {
if (confirm('Are you sure you want to delete this story?')) {
this.removeStory(target);
}
this.onDeleteCellClick(target);
} else {
this.table.onEventSelectCell(oArgs);
}
},

onDeleteCellClick: function(target) {
if (confirm('Are you sure you want to delete this story?')) {
this.removeStory(target);
}
},

onKeyEvent: function(oArgs) {
if (oArgs.event.keyCode == YAHOO.util.KeyListener.KEY.ENTER) {
Expand Down Expand Up @@ -180,8 +184,9 @@
Dom.removeClass(prevSelected, 'over');
};
this.ddRow.onDragDrop = function(ev) {
var table = this.table;
Dom.removeClass(prevSelected, 'over');
this.table.unselectAllRows();
table.unselectAllRows();
YAHOO.util.DragDropMgr.stopDrag(ev, true);
Dom.get(this.getDragEl()).style.visibility = 'hidden';
Dom.setStyle(this.getEl(), 'position', 'static');
Expand All @@ -191,16 +196,16 @@
if (drops.length > 0 && this.id != drops[0].id) {
var source = Dom.get(this.id);
var target = Dom.get(drops[0].id);
var sourceRecord = this.table.getRecord(this.id);
var targetRecord = this.table.getRecord(drops[0].id);
var sourceRecord = table.getRecord(this.id);
var targetRecord = table.getRecord(drops[0].id);
YAHOO.util.Connect.asyncRequest('POST',
this.getReorderUrl(),
{
success: function(o) {
var response = YAHOO.lang.JSON.parse(o.responseText);
this.table.deleteRow(sourceRecord);
this.table.addRow(response.record,
this.table.getRecordIndex(targetRecord)+1);
table.deleteRow(sourceRecord);
table.addRow(response.record,
table.getRecordIndex(targetRecord)+1);
},
failure: function() {
alert("Could not move record.");
Expand All @@ -219,12 +224,13 @@
},

removeStory: function(target) {
var record = this.table.getRecord(target);
var table = this.table;
var record = table.getRecord(target);
YAHOO.util.Connect.asyncRequest('DELETE',
this.getDeleteUrl(record.getData('id')),
{
success: function (o) {
this.table.deleteRow(target);
table.deleteRow(target);
},
failure: function (o) {
alert("Could not delete this row.");
Expand Down

0 comments on commit 58b0bf8

Please sign in to comment.