Editing tasks works, still needs refactoring & unittests

This commit is contained in:
2016-09-08 11:24:58 +02:00
parent dc43b7686a
commit 5543d75101
5 changed files with 71 additions and 9 deletions

View File

@@ -0,0 +1,29 @@
function save_task(task_id, task_url) {
console.log('Saving task to', task_url);
var $form = $('.task form');
var $button = $form.find("button[type='submit']");
var payload = $form.serialize();
$button.attr('disabled', true);
if (console) console.log('Sending:', payload);
$.post(task_url, payload)
.done(function(data) {
if (console) console.log('Done saving', data);
// Update the task list.
// NOTE: this is tightly linked to the HTML of the task list in for_project.jade.
$('#task-' + task_id).text($form.find("input[name='name']").val());
})
.fail(function(xhr_or_response_data) {
// jQuery sends the response data (if JSON), or an XHR object (if not JSON).
if (console) console.log('Failed saving', xhr_or_response_data);
})
.always(function() {
$button.attr('disabled', false);
})
;
return false; // prevent synchronous POST to current page.
}