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 $button = $form.find("button[type='submit']");
|
||||||
var payload = $form.serialize();
|
var payload = $form.serialize();
|
||||||
var task = '#task-' + task_id;
|
var task = '#task-' + task_id;
|
||||||
|
var $task = $(task);
|
||||||
|
|
||||||
$button.attr('disabled', true);
|
$button.attr('disabled', true);
|
||||||
$(task).addClass('processing');
|
$task.addClass('processing');
|
||||||
$('#status-bar').text('Saving task...');
|
$('#status-bar').text('Saving task...');
|
||||||
|
|
||||||
if (console) console.log('Sending:', payload);
|
if (console) console.log('Sending:', payload);
|
||||||
|
|
||||||
$.post(task_url, payload)
|
$.post(task_url, payload)
|
||||||
.done(function(data) {
|
.done(function(saved_task) {
|
||||||
if (console) console.log('Done saving', data);
|
if (console) console.log('Done saving', saved_task);
|
||||||
|
|
||||||
// Update the task list.
|
// Update the task list.
|
||||||
// NOTE: this is tightly linked to the HTML of the task list in for_project.jade.
|
// 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.find('span.name').text(saved_task.name);
|
||||||
$(task + ' span.type').text($form.find("select[name='task_type']").val());
|
$task.find('span.type').text(saved_task.task_type);
|
||||||
$(task + ' span.status').text($form.find("select[name='status']").val().replace('_', ' '));
|
$task.find('span.status').text(saved_task.properties.status.replace('_', ' '));
|
||||||
$(task)
|
$task
|
||||||
.removeClass('col-list-item task-list-item')
|
.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) {
|
.fail(function(xhr_or_response_data) {
|
||||||
// jQuery sends the response data (if JSON), or an XHR object (if not JSON).
|
// jQuery sends the response data (if JSON), or an XHR object (if not JSON).
|
||||||
|
@@ -5,6 +5,7 @@ import flask
|
|||||||
|
|
||||||
import pillarsdk
|
import pillarsdk
|
||||||
from pillar.web.system_util import pillar_api
|
from pillar.web.system_util import pillar_api
|
||||||
|
import pillar.api.utils
|
||||||
|
|
||||||
from .modules import attract_project_view
|
from .modules import attract_project_view
|
||||||
from .node_types.task import node_type_task
|
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)
|
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'])
|
@perproject_blueprint.route('/create', methods=['POST'])
|
||||||
|
Reference in New Issue
Block a user