From 52688859f55cc3ee271f8e10583f354e1f6eabd8 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 4 Mar 2022 20:29:12 +0000 Subject: [PATCH] start implementing list editing --- public/css/style.css | 35 +++++++++++++++ public/javascripts/lsl.js | 91 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 122 insertions(+), 4 deletions(-) diff --git a/public/css/style.css b/public/css/style.css index 7cf3d46..3d6d771 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -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%); +} diff --git a/public/javascripts/lsl.js b/public/javascripts/lsl.js index fa6b412..de4104e 100644 --- a/public/javascripts/lsl.js +++ b/public/javascripts/lsl.js @@ -80,6 +80,77 @@ function select_list(new_selected_list) { selected_list = new_selected_list; } +function edit_list(li) { + li.addClass('editing'); + + var d = $('
') + .append( + $('
') + .append( + $('').text('List name'), + $('').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( + $('') + .text(list.name) + ) + .append( + $('') + .append('') + ); 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) { -- 2.39.5