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:
@@ -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).
|
||||
|
@@ -5,6 +5,7 @@ import flask
|
||||
|
||||
import pillarsdk
|
||||
from pillar.web.system_util import pillar_api
|
||||
import pillar.api.utils
|
||||
|
||||
from .modules import attract_project_view
|
||||
from .node_types.task import node_type_task
|
||||
@@ -67,7 +68,7 @@ def save(project, task_id):
|
||||
|
||||
task = current_attract.task_manager.edit_task(task_id, **task_dict)
|
||||
|
||||
return flask.jsonify({'task_id': task_id, 'etag': task._etag, 'time': task._updated })
|
||||
return pillar.api.utils.jsonify(task.to_dict())
|
||||
|
||||
|
||||
@perproject_blueprint.route('/create', methods=['POST'])
|
||||
|
Reference in New Issue
Block a user