]> git.ktnx.net Git - lsl.git/commitdiff
start implementing list editing
authorDamyan Ivanov <dmn@debian.org>
Fri, 4 Mar 2022 20:29:12 +0000 (20:29 +0000)
committerDamyan Ivanov <dmn@debian.org>
Fri, 4 Mar 2022 20:29:12 +0000 (20:29 +0000)
public/css/style.css
public/javascripts/lsl.js

index 7cf3d465683e0a805b5da75def5617f211601c36..3d6d771444f5915052f1fd02b46a2c269dbe6c6c 100644 (file)
@@ -217,6 +217,9 @@ ul#lists > li {
     cursor: pointer;
     border: 1px solid transparent;
     transition: 0.25s;
+    display: grid;
+    grid-template-columns: auto max-content;
+    column-gap: 1ex;
 }
 ul#lists > li:hover {
     border: 1px solid black;
@@ -227,3 +230,35 @@ ul#lists > li.selected {
 #new-list-item {
     margin-top: 1em;
 }
+span.list-edit-trigger {
+    visibility: hidden;
+    opacity: 0;
+    transition: 0.25s;
+    margin-top: auto;
+    margin-bottom: auto;
+}
+ul#lists > li:hover span.list-edit-trigger {
+    visibility: visible;
+    opacity: 1;
+}
+ul#lists > li span.ui-icon-disk,
+ul#lists > li.editing span.ui-icon-pencil {
+    display: none;
+}
+
+ul#lists > li.editing span.ui-icon-disk { display: inline-block; }
+
+.ui-widget-overlay {
+    opacity: 0.3;
+}
+.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset {
+    float: none;
+    text-align: right;
+}
+.ui-dialog-buttonset > button.btn-delete {
+    float: left;
+}
+
+.ui-button.btn-delete:hover {
+    background: hsl(0, 70%, 92.9%);
+}
index fa6b4127fb6d9758d9523b785e5ab51f449a1924..de4104e5bf8b4e723e31cee1f22d0935eafd2903 100644 (file)
@@ -80,6 +80,77 @@ function select_list(new_selected_list) {
 
     selected_list = new_selected_list;
 }
+function edit_list(li) {
+    li.addClass('editing');
+
+    var d = $('<div>')
+        .append(
+            $('<fieldset>')
+                .append(
+                    $('<legend>').text('List name'),
+                    $('<input type="text" size="40">').val(li.data('lsl-name'))
+                )
+        );
+
+    d.dialog({
+        autoOpen: true,
+        modal: true,
+        title: 'Edit list',
+        close: ()=>{
+            li.removeClass('editing');
+        },
+        width: 'max-content',
+        buttons: [
+            {
+                class: 'btn-delete',
+                icon: 'ui-icon-trash',
+                text: 'Delete',
+                click: () => {
+                    delete_list(li, d);
+                },
+            },
+            {
+                text: 'Cancel',
+                click: ()=>{ d.dialog('destroy'); },
+            },
+            {
+                icon: 'ui-icon-disk',
+                text: 'OK',
+                click: () => {
+                    save_list(li, d);
+                },
+            },
+        ],
+    });
+}
+function delete_list(li, dlg) {
+    var lists_ver = lists_version;
+    $.ajax( li.data('lsl-uri'),
+        { type: 'DELETE' }
+    )
+    .done((d)=>{
+        lists_version = lists_ver + 1;
+        if (li.hasClass('selected')) {
+            var new_selected = li.next();
+            if (new_selected.length) {
+                select_list(new_selected)
+            }
+            else {
+                new_selected = li.prev();
+                if (new_selected.length) {
+                    select_list(new_selected);
+                }
+                else {
+                    $('#page').removeClass('have-lists');
+                }
+            }
+        }
+
+        li.remove();
+        dlg.dialog('destroy');
+        got_lists_version(d.lists_version);
+    });
+}
 function load_lists() {
     $.get(uri_base + '/api/v1/list')
     .always(()=>{
@@ -123,7 +194,14 @@ function load_lists() {
                     .data('lsl-uri', list.uri)
                     .data('lsl-version', list.version)
                     .data('lsl-name', list.name)
-                    .text(list.name);
+                    .append(
+                        $('<span class="list-name">')
+                        .text(list.name)
+                    )
+                    .append(
+                        $('<span class="list-edit-trigger">')
+                        .append('<span class="ui-icon ui-icon-pencil">')
+                    );
                 lists.append(list_item);
             }
         });
@@ -233,9 +311,14 @@ $(function(){
 
         return true;
     });
-    $('ul#lists').on('click', 'li', ev=>{
-        select_list($(ev.target));
-    });
+    $('ul#lists')
+        .on('click', 'li', ev=>{
+            select_list($(ev.target).closest('li'));
+        })
+        .on('click', 'li > span.list-edit-trigger', ev => {
+            edit_list($(ev.target).closest('li'));
+            return false;
+        });
     $('#new-list-item button').on('click', handle_new_list_item_submission);
     $('#new-list-item input').on('keypress', ev => {
         if (13 == ev.keyCode) {