From d118ab71e6aa4f300ba6e42663d13a63a2323122 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 21 Dec 2020 21:37:10 +0000 Subject: files_ng: implement directory and bulk file download --- view/js/mod_cloud.js | 43 ++++++++++++++++++++++++++++++++++++++++++- view/tpl/cloud_directory.tpl | 11 ++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) (limited to 'view') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index cbd9c2a08..736dec471 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -56,6 +56,24 @@ $(document).ready(function () { close_and_deactivate_all_panels(); }); + $('.cloud-tool-dir-download-btn').on('click', function (e) { + e.preventDefault(); + close_and_deactivate_all_panels() + + let id = $(this).data('id'); + if(! id) { + return false; + } + + close_and_deactivate_all_panels(); + + // some trickery to trigger download action via ajax + let form = $('
').attr('action', 'attach').attr('method', 'post'); + form.append($("").attr('type', 'hidden').attr('name', 'channel_id').attr('value', channelId)); + form.append($("").attr('type', 'hidden').attr('name', 'attach_ids[]').attr('value', id)); + form.appendTo('body').submit().remove(); + }); + $('.cloud-tool-delete-btn').on('click', function (e) { e.preventDefault(); let id = $(this).data('id'); @@ -255,14 +273,37 @@ $(document).ready(function () { $('#cloud-multi-tool-submit, #cloud-multi-tool-categories').show(); }); + $('#cloud-multi-tool-download-btn').on('click', function (e) { + e.preventDefault(); + + let post_data = $('.cloud-multi-tool-checkbox:checked'); + + if(! post_data.length) { + return false; + } + + close_and_deactivate_all_panels(); + + // some trickery to trigger download action via ajax + var form = $('
').attr('action', 'attach').attr('method', 'post'); + form.append($("").attr('type', 'hidden').attr('name', 'channel_id').attr('value', channelId)); + post_data.each(function () { + form.append($("").attr('type', 'hidden').attr('name', 'attach_ids[]').attr('value', this.value)); + }); + form.appendTo('body').submit().remove(); + }); + $('#cloud-multi-tool-delete-btn').on('click', function (e) { e.preventDefault(); - let post_data = $('.cloud-multi-tool-checkbox').serializeArray(); + close_and_deactivate_all_panels(); + + let post_data = $('.cloud-multi-tool-checkbox:checked').serializeArray(); if(! post_data.length) { return false; } + let confirm = confirmDelete(); if (confirm) { $('body').css('cursor', 'wait'); diff --git a/view/tpl/cloud_directory.tpl b/view/tpl/cloud_directory.tpl index a6993fe97..5886391bb 100644 --- a/view/tpl/cloud_directory.tpl +++ b/view/tpl/cloud_directory.tpl @@ -87,6 +87,7 @@ {{/if}} Move or copy Categories + Download {{$delete}} @@ -172,23 +173,27 @@ Rename Move or copy Categories - {{if !$item.collection}} {{if $item.is_owner}} Post {{/if}} + {{if $item.collection}} + Download + {{else}} Download {{/if}} {{$delete}} {{else}} - {{if ($is_admin || !$item.collection) && $item.attach_id}} + {{if $is_admin || $item.attach_id}}