Added task deletion. GUI still ugly, though.

This commit is contained in:
2016-09-23 13:58:14 +02:00
parent 971b8e6392
commit 3925c044d5
6 changed files with 115 additions and 3 deletions

View File

@@ -20,6 +20,26 @@
return this;
};
/**
* Fades out the element, then erases its contents and shows the now-empty element again.
*/
$.fn.fadeOutAndClear = function(fade_speed) {
var target = this;
this
.fadeOut(fade_speed, function() {
target
.html('')
.show();
});
}
$.fn.hideAndRemove = function(hide_speed, finished) {
this.slideUp(hide_speed, function() {
this.remove();
if (typeof finished !== 'undefined') finished();
});
}
$.fn.removeClassPrefix = function(prefix) {
this.each(function(i, el) {
var classes = el.className.split(" ").filter(function(c) {
@@ -31,6 +51,20 @@
};
}(jQuery));
/**
* Removes the task from the task list and shot list, and show the 'task-add-link'
* when this was the last task in its category.
*/
function _remove_task_from_list(task_id) {
var $task_link = $('#task-' + task_id)
var $task_link_parent = $task_link.parent();
$task_link.hideAndRemove(300, function() {
if ($task_link_parent.children('.task-link').length == 0) {
$task_link_parent.find('.task-add-link').removeClass('hidden');
}
});
}
/**
* Shows a task in the #task-details div.
*/
@@ -220,6 +254,36 @@ function shot_save(shot_id, shot_url) {
});
}
function task_delete(task_id, task_etag, task_delete_url) {
if (task_id === undefined || task_etag === undefined || task_delete_url === undefined) {
throw new ReferenceError("task_delete(" + task_id + ", " + task_etag + ", " + task_delete_url + ") called.");
}
$.ajax({
type: 'DELETE',
url: task_delete_url,
data: {'etag': task_etag}
})
.done(function(e) {
if (console) console.log('Task', task_id, 'was deleted.');
$('#task-details').fadeOutAndClear();
_remove_task_from_list(task_id);
})
.fail(function(xhr) {
$('#status-bar').text('Unable to delete task, code ' + xhr.status);
if (xhr.status == 412) {
alert('Someone else edited this task before you deleted it; refresh to try again.');
// TODO: implement something nice here. Just make sure we don't throw
// away the user's edits. It's up to the user to handle this.
// TODO: refresh activity feed and point user to it.
} else {
// TODO: find a better place to put this error message, without overwriting the
// task the user is looking at in-place.
$('#task-view-feed').html(xhr.responseText);
}
});
}
$(function() {
$("a.shot-link[data-shot-id]").click(function(e) {
e.preventDefault();