Task edit: Using actually saved data to update the form.

Instead of just copying the form data, we now use the data returned from
the server.

Also, don't use $(task + ' span.name'), just use $(task).find('span.name').
This is faster, and allows us to save $(task) in a variable to make it
even faster still.
This commit is contained in:
2016-09-22 11:06:00 +02:00
parent 62b72bfbb1
commit c4c6f6ccad
2 changed files with 12 additions and 10 deletions

View File

@@ -59,27 +59,28 @@ function task_save(task_id, task_url) {
var $button = $form.find("button[type='submit']");
var payload = $form.serialize();
var task = '#task-' + task_id;
var $task = $(task);
$button.attr('disabled', true);
$(task).addClass('processing');
$task.addClass('processing');
$('#status-bar').text('Saving task...');
if (console) console.log('Sending:', payload);
$.post(task_url, payload)
.done(function(data) {
if (console) console.log('Done saving', data);
.done(function(saved_task) {
if (console) console.log('Done saving', saved_task);
// Update the task list.
// NOTE: this is tightly linked to the HTML of the task list in for_project.jade.
$(task + ' span.name').text($form.find("input[name='name']").val());
$(task + ' span.type').text($form.find("select[name='task_type']").val());
$(task + ' span.status').text($form.find("select[name='status']").val().replace('_', ' '));
$(task)
$task.find('span.name').text(saved_task.name);
$task.find('span.type').text(saved_task.task_type);
$task.find('span.status').text(saved_task.properties.status.replace('_', ' '));
$task
.removeClass('col-list-item task-list-item')
.addClass('col-list-item task-list-item status-' + $form.find("select[name='status']").val());
.addClass('col-list-item task-list-item status-' + saved_task.properties.status);
$('#status-bar').text('Saved task. ' + data.time);
$('#status-bar').text('Saved task. ' + saved_task._updated);
})
.fail(function(xhr_or_response_data) {
// jQuery sends the response data (if JSON), or an XHR object (if not JSON).