From 99fb8e010d982831501bde3f95bb69b400bcc6ba Mon Sep 17 00:00:00 2001 From: jr-k Date: Thu, 11 Jul 2024 20:59:00 +0200 Subject: [PATCH] separate explorer in js file --- data/www/js/explorer.js | 93 +++++++++++++++++++ data/www/js/fleet/node-players-old.js | 110 ----------------------- data/www/js/fleet/node-players.js | 99 +------------------- data/www/js/slideshow/contents.js | 90 +------------------ views/base.jinja.html | 2 +- views/fleet/node-players/list.jinja.html | 5 +- views/slideshow/contents/list.jinja.html | 5 +- 7 files changed, 102 insertions(+), 302 deletions(-) create mode 100644 data/www/js/explorer.js delete mode 100644 data/www/js/fleet/node-players-old.js diff --git a/data/www/js/explorer.js b/data/www/js/explorer.js new file mode 100644 index 0000000..6d246c7 --- /dev/null +++ b/data/www/js/explorer.js @@ -0,0 +1,93 @@ +jQuery(function ($) { + + const initExplr = function () { + $('.explr').each(function () { + $(this).explr({ + classesPlus: 'fa fa-plus', + classesMinus: 'fa fa-minus', + onLoadFinish: function ($tree) { + $tree.removeClass('hidden'); + } + }); + + // Open complete path in explorer sidebar + explrSidebarOpenFromFolder($(this).attr('data-working-folder-id')); + }); + + $('.draggable').each(function () { + $(this).draggable({ + revert: "invalid", + }); + }); + + $('.droppable').each(function () { + $(this).droppable({ + accept: ".draggable", + over: function (event, ui) { + $(this).addClass("highlight-drop"); + }, + out: function (event, ui) { + $(this).removeClass("highlight-drop"); + }, + drop: function (event, ui) { + $(this).removeClass("highlight-drop"); + const $form = $('#folder-move-form'); + const $moved = ui.draggable; + const $target = $(this); + $form.find('[name=is_folder]').val($moved.attr('data-folder')) + $form.find('[name=entity_id]').val($moved.attr('data-id')) + $form.find('[name=new_folder_id]').val($target.attr('data-id')) + ui.draggable.position({ + my: "center", + at: "center", + of: $(this), + using: function (pos) { + $(this).animate(pos, 50); + } + }); + $form.submit(); + } + }); + }); + }; + + const main = function () { + initExplr(); + }; + + $(document).on('click', '.explr-item-edit', function () { + const $item = $('.explr-dirview .highlight-clicked'); + const is_folder = $item.attr('data-folder') === '1'; + + if (is_folder) { + $item.addClass('renaming'); + $item.find('input').focus().select(); + } else { + document.location.href = $(this).attr('data-entity-route').replace('!c!', $item.attr('data-id')); + } + }); + + $(document).on('click', '.explr-item-delete', function () { + const $item = $('.explr-dirview .highlight-clicked'); + const is_folder = $item.attr('data-folder') === '1'; + let route; + + if (is_folder) { + route = $(this).attr('data-folder-route') + '?id=' + $item.attr('data-id'); + } else { + route = $(this).attr('data-entity-route') + '?id=' + $item.attr('data-id'); + } + + if (confirm(l.common_are_you_sure)) { + document.location.href = route; + } + }); + + $(document).keyup(function (e) { + if (e.key === "Escape") { + $('.dirview .new-folder').addClass('hidden'); + } + }); + + main(); +}); \ No newline at end of file diff --git a/data/www/js/fleet/node-players-old.js b/data/www/js/fleet/node-players-old.js deleted file mode 100644 index 36c5884..0000000 --- a/data/www/js/fleet/node-players-old.js +++ /dev/null @@ -1,110 +0,0 @@ -jQuery(document).ready(function ($) { - const $tableActive = $('table.active-node-players'); - const $tableInactive = $('table.inactive-node-players'); - - const getId = function ($el) { - return $el.is('tr') ? $el.attr('data-level') : $el.parents('tr:eq(0)').attr('data-level'); - }; - - const updateTable = function () { - $('table').each(function () { - if ($(this).find('tbody tr.node-player-item:visible').length === 0) { - $(this).find('tr.empty-tr').removeClass('hidden'); - } else { - $(this).find('tr.empty-tr').addClass('hidden'); - } - }).tableDnDUpdate(); - updatePositions(); - }; - - const updatePositions = function (table, row) { - const positions = {}; - $('.node-player-item').each(function (index) { - positions[getId($(this))] = index; - }); - - $.ajax({ - method: 'POST', - url: '/fleet/node-player/position', - headers: {'Content-Type': 'application/json'}, - data: JSON.stringify(positions), - }); - }; - - const main = function () { - $("table").tableDnD({ - dragHandle: 'td a.node-player-sort', - onDrop: updatePositions - }); - }; - - $(document).on('change', 'select.group-picker', function () { - document.location.href = $(this).val(); - }); - - $(document).on('change', 'input[type=checkbox]', function () { - $.ajax({ - url: '/fleet/node-player/toggle', - headers: {'Content-Type': 'application/json'}, - data: JSON.stringify({id: getId($(this)), enabled: $(this).is(':checked')}), - method: 'POST', - }); - - const $tr = $(this).parents('tr:eq(0)').remove().clone(); - - if ($(this).is(':checked')) { - $tableActive.append($tr); - } else { - $tableInactive.append($tr); - } - - updateTable(); - }); - - $(document).on('change', '#node-player-add-type', function () { - const value = $(this).val(); - const inputType = $(this).find('option').filter(function (i, el) { - return $(el).val() === value; - }).data('input'); - - $('.node-player-add-object-input') - .addClass('hidden') - .prop('disabled', true) - .filter('#node-player-add-object-input-' + inputType) - .removeClass('hidden') - .prop('disabled', false) - ; - }); - - - $(document).on('click', '.node-player-add', function () { - showModal('modal-node-player-add'); - $('.modal-node-player-add input:eq(0)').focus().select(); - }); - - $(document).on('click', '.node-player-edit', function () { - const nodePlayer = JSON.parse($(this).parents('tr:eq(0)').attr('data-entity')); - showModal('modal-node-player-edit'); - $('.modal-node-player-edit input:visible:eq(0)').focus().select(); - $('#node-player-edit-name').val(nodePlayer.name); - $('#node-player-edit-group-id').val(nodePlayer.group_id); - $('#node-player-edit-host').val(nodePlayer.host); - $('#node-player-edit-id').val(nodePlayer.id); - }); - - $(document).on('click', '.node-player-delete', function () { - if (confirm(l.js_fleet_node_player_delete_confirmation)) { - const $tr = $(this).parents('tr:eq(0)'); - $tr.remove(); - updateTable(); - $.ajax({ - method: 'DELETE', - url: '/fleet/node-player/delete', - headers: {'Content-Type': 'application/json'}, - data: JSON.stringify({id: getId($(this))}), - }); - } - }); - - main(); -}); \ No newline at end of file diff --git a/data/www/js/fleet/node-players.js b/data/www/js/fleet/node-players.js index 2796d79..c6beed9 100644 --- a/data/www/js/fleet/node-players.js +++ b/data/www/js/fleet/node-players.js @@ -1,60 +1,7 @@ jQuery(document).ready(function ($) { - const initExplr = function () { - $('.explr').each(function() { - $(this).explr({ - classesPlus: 'fa fa-plus', - classesMinus: 'fa fa-minus', - onLoadFinish: function ($tree) { - $tree.removeClass('hidden'); - } - }); - - // Open complete path in explorer sidebar - explrSidebarOpenFromFolder($(this).attr('data-working-folder-id')); - }); - }; - - const initDrags = function () { - $('.draggable').each(function() { - $(this).draggable({ - revert: "invalid", - }); - }); - - $('.droppable').each(function() { - $(this).droppable({ - accept: ".draggable", - over: function (event, ui) { - $(this).addClass("highlight-drop"); - }, - out: function (event, ui) { - $(this).removeClass("highlight-drop"); - }, - drop: function (event, ui) { - $(this).removeClass("highlight-drop"); - const $form = $('#folder-move-form'); - const $moved = ui.draggable; - const $target = $(this); - $form.find('[name=is_folder]').val($moved.attr('data-folder')) - $form.find('[name=entity_id]').val($moved.attr('data-id')) - $form.find('[name=new_folder_id]').val($target.attr('data-id')) - ui.draggable.position({ - my: "center", - at: "center", - of: $(this), - using: function (pos) { - $(this).animate(pos, 50); - } - }); - $form.submit(); - } - }); - }); - }; const main = function () { - initExplr(); - initDrags(); + }; $(document).on('click', '.folder-add', function () { @@ -68,55 +15,11 @@ jQuery(document).ready(function ($) { $('.modal-node-player-add input:eq(0)').focus().select(); }); - $(document).on('click', '.explr-item-edit', function () { - const $item = $('.explr-dirview .highlight-clicked'); - const is_folder = $item.attr('data-folder') === '1'; - - if (is_folder) { - $item.addClass('renaming'); - $item.find('input').focus().select(); - } else { - document.location.href = $(this).attr('data-node-player-route').replace('!c!', $item.attr('data-id')); - } - }); - - $(document).on('click', '.explr-item-delete', function () { - const $item = $('.explr-dirview .highlight-clicked'); - const is_folder = $item.attr('data-folder') === '1'; - let route; - - if (is_folder) { - route = $(this).attr('data-folder-route') + '?id=' + $item.attr('data-id'); - } else { - route = $(this).attr('data-node-player-route') + '?id=' + $item.attr('data-id'); - } - - if (confirm(l.js_fleet_node_player_delete_confirmation)) { - document.location.href = route; - } - }); - - $(document).on('click', '.node-player-edit', function () { - const node_player = JSON.parse($(this).parents('tr:eq(0)').attr('data-entity')); - showModal('modal-node-player-edit'); - - - - $('.modal-node-player-edit input:visible:eq(0)').focus().select(); - $('#node-player-edit-id').val(node_player.id); - }); - $(document).on('submit', '.modal-node-player-add form', function () { const $modal = $(this).parents('.modal:eq(0)'); $modal.find('button[type=submit]').addClass('hidden'); $modal.find('.btn-loading').removeClass('hidden'); }); - $(document).keyup(function (e) { - if (e.key === "Escape") { - $('.dirview .new-folder').addClass('hidden'); - } - }); - main(); }); diff --git a/data/www/js/slideshow/contents.js b/data/www/js/slideshow/contents.js index e7be1ca..42cacc8 100644 --- a/data/www/js/slideshow/contents.js +++ b/data/www/js/slideshow/contents.js @@ -26,62 +26,8 @@ jQuery(document).ready(function ($) { $('.modal:visible button[type=submit]').attr('class', 'btn ' + ('btn-' + color)); }; - const initExplr = function () { - $('.explr').each(function() { - $(this).explr({ - classesPlus: 'fa fa-plus', - classesMinus: 'fa fa-minus', - onLoadFinish: function ($tree) { - $tree.removeClass('hidden'); - } - }); - - // Open complete path in explorer sidebar - explrSidebarOpenFromFolder($(this).attr('data-working-folder-id')); - }); - }; - - const initDrags = function () { - $('.draggable').each(function() { - $(this).draggable({ - revert: "invalid", - }); - }); - - $('.droppable').each(function() { - $(this).droppable({ - accept: ".draggable", - over: function (event, ui) { - $(this).addClass("highlight-drop"); - }, - out: function (event, ui) { - $(this).removeClass("highlight-drop"); - }, - drop: function (event, ui) { - $(this).removeClass("highlight-drop"); - const $form = $('#folder-move-form'); - const $moved = ui.draggable; - const $target = $(this); - $form.find('[name=is_folder]').val($moved.attr('data-folder')) - $form.find('[name=entity_id]').val($moved.attr('data-id')) - $form.find('[name=new_folder_id]').val($target.attr('data-id')) - ui.draggable.position({ - my: "center", - at: "center", - of: $(this), - using: function (pos) { - $(this).animate(pos, 50); - } - }); - $form.submit(); - } - }); - }); - }; - const main = function () { - initExplr(); - initDrags(); + }; $(document).on('change', '.modal input[type=file]', function() { @@ -108,45 +54,11 @@ jQuery(document).ready(function ($) { $('.modal-content-add input:eq(0)').focus().select(); }); - $(document).on('click', '.explr-item-edit', function () { - const $item = $('.explr-dirview .highlight-clicked'); - const is_folder = $item.attr('data-folder') === '1'; - - if (is_folder) { - $item.addClass('renaming'); - $item.find('input').focus().select(); - } else { - document.location.href = $(this).attr('data-content-route').replace('!c!', $item.attr('data-id')); - } - }); - - $(document).on('click', '.explr-item-delete', function () { - const $item = $('.explr-dirview .highlight-clicked'); - const is_folder = $item.attr('data-folder') === '1'; - let route; - - if (is_folder) { - route = $(this).attr('data-folder-route') + '?id=' + $item.attr('data-id'); - } else { - route = $(this).attr('data-content-route') + '?id=' + $item.attr('data-id'); - } - - if (confirm(l.js_slideshow_content_delete_confirmation)) { - document.location.href = route; - } - }); - $(document).on('submit', '.modal-content-add form', function () { const $modal = $(this).parents('.modal:eq(0)'); $modal.find('button[type=submit]').addClass('hidden'); $modal.find('.btn-loading').removeClass('hidden'); }); - $(document).keyup(function (e) { - if (e.key === "Escape") { - $('.dirview .new-folder').addClass('hidden'); - } - }); - main(); }); diff --git a/views/base.jinja.html b/views/base.jinja.html index db8b40f..0760a59 100755 --- a/views/base.jinja.html +++ b/views/base.jinja.html @@ -80,8 +80,8 @@ "icon": "fa-tv", "position": 1, "pills": [ - {"name": l.fleet_node_player_group_page_title, "route": "fleet_node_player_group_list", "icon": "fa-layer-group"}, {"name": l.fleet_node_player_page_title, "route": "fleet_node_player_list", "icon": "fa-tv"}, + {"name": l.fleet_node_player_group_page_title, "route": "fleet_node_player_group_list", "icon": "fa-layer-group"}, ] } }) %} diff --git a/views/fleet/node-players/list.jinja.html b/views/fleet/node-players/list.jinja.html index bf70da0..103f768 100644 --- a/views/fleet/node-players/list.jinja.html +++ b/views/fleet/node-players/list.jinja.html @@ -11,6 +11,7 @@ {% block add_js %} + @@ -29,10 +30,10 @@ {{ HOOK(H_SLIDESHOW_CONTENT_TOOLBAR_ACTIONS_START) }}
- -
diff --git a/views/slideshow/contents/list.jinja.html b/views/slideshow/contents/list.jinja.html index 895bb77..86fb9cb 100644 --- a/views/slideshow/contents/list.jinja.html +++ b/views/slideshow/contents/list.jinja.html @@ -11,6 +11,7 @@ {% block add_js %} + @@ -29,10 +30,10 @@ {{ HOOK(H_SLIDESHOW_CONTENT_TOOLBAR_ACTIONS_START) }}
- -