]> git.ktnx.net Git - lsl.git/commitdiff
working list item updates, enter submits
authorDamyan Ivanov <dmn@debian.org>
Sun, 6 Mar 2022 11:33:29 +0000 (11:33 +0000)
committerDamyan Ivanov <dmn@debian.org>
Sun, 6 Mar 2022 11:33:29 +0000 (11:33 +0000)
public/javascripts/lsl.js

index 09f71449b383e5b97b684771c3a6d240ab255032..3e66db6ede1441b20f9e361e286b30d5a8659af9 100644 (file)
@@ -281,6 +281,28 @@ function delete_list_item(dlg, li) {
         got_lists_version(resp.lists_version);
     });
 }
+function save_list_item(dlg,li) {
+    var new_description = dlg.find('input[type="text"]').val();
+
+    $.ajax( li.data('lsl-uri'),
+        {   type: 'PUT',
+            data: JSON.stringify({
+                description: new_description,
+                version: li.data('lsl-version')})
+        }
+    )
+    .done((d)=>{
+        selected_list.data('lsl-version', selected_list.data('lsl-version') + 1);
+
+        li.data('lsl-description', new_description);
+        li.data('lsl-version', d.version);
+        li.find('.description').text(new_description);
+
+        dlg.dialog('destroy');
+        got_list_version(d.list_version);
+        got_lists_version(d.lists_version);
+    });
+}
 function edit_list_item(li) {
     var d = $('<div>')
         .append(
@@ -288,6 +310,14 @@ function edit_list_item(li) {
                 .append(
                     $('<legend>').text('Item name'),
                     $('<input type="text" size="10">')
+                    .on('keypress', (ev) => {
+                        if (13 == ev.keyCode) {
+                            save_list_item(d, li);
+                            return false;
+                        }
+
+                        return true;
+                    })
                     .val(li.data('lsl-description'))
                 )
         );