Added etag checking when saving tasks & shots. Still a bit rough.

Needs nicer user interface stuff for explaining what's going on.
This commit is contained in:
2016-09-22 18:28:11 +02:00
parent d13abb5b34
commit 498e1d5ecc
7 changed files with 47 additions and 7 deletions

View File

@@ -133,13 +133,16 @@ function attract_form_save(form_id, item_id, item_save_url, options={})
if (console) console.log('Done saving', saved_item);
$('#status-bar')
.text('Saved ' + options.type + '. ' + saved_item._updated);
$form.find("input[name='_etag']").val(saved_item._etag);
if (options.done) options.done($item, saved_item);
})
.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);
$('#status-bar').text('Failed saving. ' + xhr_or_response_data.responseText);
$button.removeClass('btn-default').addClass('btn-danger');
$('#status-bar').text('Failed saving. ' + xhr_or_response_data.status);
if (options.fail) options.fail($item, xhr_or_response_data);
})
@@ -171,7 +174,12 @@ function task_save(task_id, task_url) {
;
},
fail: function($item, xhr_or_response_data) {
$('#task-details').html(xhr_or_response_data.responseText);
if (xhr_or_response_data.status == 412) {
// 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.
} else {
$('#task-details').html(xhr_or_response_data.responseText);
}
},
type: 'task'
});
@@ -189,7 +197,12 @@ function shot_save(shot_id, shot_url) {
;
},
fail: function($item, xhr_or_response_data) {
$('#task-details').html(xhr_or_response_data.responseText);
if (xhr_or_response_data.status == 412) {
// 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.
} else {
$('#task-details').html(xhr_or_response_data.responseText);
}
},
type: 'shot'
});