return m ? m[1] : null;
}
function add_list_item(data) {
- var item = $('<li>').addClass('list-item-row').data('item', data);
+ var item = $('<li>').addClass('list-item-row').data({
+ 'lsl-uri': data.uri,
+ 'lsl-version': data.version,
+ 'lsl-done': data.done});
var cb = $('<input type="checkbox">');
if (data.done) cb.prop('checked', true);
item.append(cb);
}
function new_list_item_submission_done(data) {
got_lists_version(data.lists_version);
+ selected_list.data('lsl-version', selected_list.data('lsl-version') + 1 );
got_list_version(data.list_version);
- var item_data = selected_list.data('items');
-
var new_item = {
description: $('#new-list-item input[type="text"]').val().trim(),
done: $('#new-list-item input[type="checkbox"]').prop('checked'),
version: 1,
+ uri: data.uri,
};
- item_data.items.push(new_item);
- item_data.version = data.version;
+ selected_list.data('lsl-items').push(new_item);
add_list_item(new_item);
$('#new-list-item input').val('');
function handle_list_item_state_changed(ev) {
var item = $(ev.target).closest('li');
var cb = item.find('input[type="checkbox"]');
- var item_data = item.data('item');
- $.ajax(item_data.uri,
+ $.ajax(item.data('lsl-uri'),
{ type: 'PUT',
data: JSON.stringify({
- version: item_data.version,
+ version: item.data('lsl-version'),
done: cb.prop('checked')})
}
)
.done(function(resp){
- item_data.version = resp.version;
+ item.data('lsl-version', resp.version);
got_lists_version(resp.lists_version);
+ selected_list.data('lsl-version', selected_list.data('lsl-version')+1);
got_list_version(resp.list_version);
});
}