UIWindowConfirmDownload.js 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Copyright (C) 2024 Puter Technologies Inc.
  3. *
  4. * This file is part of Puter.
  5. *
  6. * Puter is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import UIWindow from './UIWindow.js'
  20. // todo do this using uid rather than item_path, since item_path is way mroe expensive on the DB
  21. async function UIWindowConfirmDownload(options){
  22. return new Promise(async (resolve) => {
  23. let h = '';
  24. h += `<div>`;
  25. // Confirm download
  26. h +=`<div style="margin-bottom:20px; float:left; padding-top:3px; font-size:15px; overflow: hidden; width: calc(100% - 40px); text-overflow: ellipsis; white-space: nowrap;">`;
  27. // Message
  28. h += `<p style="font-weight:bold;">Do you want to download this file?</p>`;
  29. h += `<div style="overflow:hidden; float:left; width: 100px; height: 100px; display:flex; display: flex; justify-content: center; align-items: center;">`;
  30. h += `<img style="float:left; margin-right: 7px; width: 60px; height: 60px; filter: drop-shadow(0px 0px 1px rgba(102, 102, 102, 1));" src="${html_encode((await item_icon({is_dir: options.is_dir === '1' || options.is_dir === 'true', type: options.type, name: options.name})).image)}" />`;
  31. h += `</div>`;
  32. // Item information
  33. h += `<div style="overflow:hidden;">`;
  34. // Name
  35. h += `<p style="text-overflow: ellipsis; overflow: hidden;"><span class="dl-conf-item-attr">${i18n('name')}:</span> ${options.name ?? options.url}</p>`;
  36. // Type
  37. h += `<p style="text-overflow: ellipsis; overflow: hidden;"><span class="dl-conf-item-attr">${i18n('type')}:</span> ${options.is_dir === '1' || options.is_dir === 'true' ? 'Folder' : options.type ?? 'Unknown File Type'}</p>`;
  38. // Source
  39. h += `<p style="text-overflow: ellipsis; overflow: hidden;"><span class="dl-conf-item-attr">${i18n('from')}:</span> ${options.source}</p>`;
  40. h += `</div>`;
  41. h += `</div>`;
  42. // Download
  43. h += `<button style="float:right; margin-top: 15px; margin-right: -2px; margin-left:10px;" class="button button-small button-primary btn-download-confirm">${i18n('download')}</button>`;
  44. // Cancel
  45. h += `<button style="float:right; margin-top: 15px;" class="button button-small btn-download-cancel">${i18n('cancel')}</button>`;
  46. h +=`</div>`;
  47. const el_window = await UIWindow({
  48. title: `Upload`,
  49. icon: window.icons[`app-icon-uploader.svg`],
  50. uid: null,
  51. is_dir: false,
  52. body_content: h,
  53. has_head: false,
  54. selectable_body: false,
  55. draggable_body: true,
  56. allow_context_menu: false,
  57. is_resizable: false,
  58. is_droppable: false,
  59. init_center: true,
  60. allow_native_ctxmenu: false,
  61. allow_user_select: false,
  62. window_class: 'window-upload-progress',
  63. width: 450,
  64. dominant: true,
  65. window_css:{
  66. height: 'initial',
  67. },
  68. body_css: {
  69. padding: '22px',
  70. width: 'initial',
  71. 'background-color': 'rgba(231, 238, 245, .95)',
  72. 'backdrop-filter': 'blur(3px)',
  73. }
  74. });
  75. $(el_window).find('.btn-download-confirm').on('click submit', function(e){
  76. $(el_window).close();
  77. resolve(true);
  78. })
  79. $(el_window).find('.btn-download-cancel').on('click submit', function(e){
  80. $(el_window).close();
  81. resolve(false);
  82. })
  83. })
  84. }
  85. export default UIWindowConfirmDownload