return \%r;
};
+# modify shipping list
+put '/list/:list_id' => sub {
+ my $list_id = route_parameters->get('list_id');
+ length($list_id) and $list_id =~ /^\d{1,18}$/
+ or return invalid_input('bad list ID');
+
+ my $req = request_data;
+
+ my $name = $req->{name} // '';
+ my $version = $req->{version} // -1;
+
+ length($version) and $version =~ /^\d{1,18}$/
+ or return invalid_input('bad version');
+
+ my $dbh = get_database;
+
+ my $list = $dbh->resultset('ShoppingList')->find($list_id);
+ unless ($list) {
+ return exception 404, "No such list";
+ }
+
+ # in case no real changes are needed will return the current state
+ if ( $name ne ( $list->name // '') ) {
+ unless ($version == $list->version) {
+ return exception 409,
+ sprintf( 'Outdated version (current is %d)', $list->version );
+ }
+
+ $list->update({
+ name => $name // '',
+ version => $version + 1,
+ });
+ }
+
+ return {
+ version => $list->version,
+ lists_version => increment_lists_version($dbh),
+ };
+};
+
# delete shopping list
del '/list/:list_id' => sub {
my $list_id = route_parameters->get('list_id');
dlg.dialog('destroy');
got_lists_version(d.lists_version);
});
+}
+function save_list(dlg) {
+ var lists_ver = lists_version;
+ var new_name = dlg.find('input[type="text"]').val();
+
+ $.ajax( selected_list.data('lsl-uri'),
+ { type: 'PUT',
+ data: JSON.stringify({ name: new_name,
+ version: selected_list.data('lsl-version')})
+ }
+ )
+ .done((d)=>{
+ lists_version = lists_ver + 1;
+
+ selected_list.find('.list-name').text(new_name);
+ selected_list.data('lsl-name', new_name);
+ $('#selected-list-name').text(new_name);
+
dlg.dialog('destroy');
got_lists_version(d.lists_version);
});