From: Damyan Ivanov Date: Sun, 6 Mar 2022 08:56:05 +0000 (+0000) Subject: fix item/list version/data tracking when adding/modifying list items X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=4af316b9339d4cd09a290549ae223affe61b0d90;p=lsl.git fix item/list version/data tracking when adding/modifying list items avoids some spurious refresh requests --- diff --git a/public/javascripts/lsl.js b/public/javascripts/lsl.js index e57005c..c0125de 100644 --- a/public/javascripts/lsl.js +++ b/public/javascripts/lsl.js @@ -19,7 +19,10 @@ function uri_id(uri) { return m ? m[1] : null; } function add_list_item(data) { - var item = $('
  • ').addClass('list-item-row').data('item', data); + var item = $('
  • ').addClass('list-item-row').data({ + 'lsl-uri': data.uri, + 'lsl-version': data.version, + 'lsl-done': data.done}); var cb = $(''); if (data.done) cb.prop('checked', true); item.append(cb); @@ -234,17 +237,16 @@ function handle_new_list_submission(){ } 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(''); @@ -264,18 +266,18 @@ function handle_new_list_item_submission(){ 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); }); }