/** * Copyright (C) 2024 Puter Technologies Inc. * * This file is part of Puter. * * Puter is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ import UIWindow from './UIWindow.js' import UIContextMenu from './UIContextMenu.js' import UIAlert from './UIAlert.js' async function UIWindowMyWebsites(options){ let h = ''; h += `
`; h += `
`; const el_window = await UIWindow({ title: `My Websites`, app: 'my-websites', single_instance: true, icon: null, uid: null, is_dir: false, body_content: h, has_head: true, selectable_body: false, draggable_body: false, allow_context_menu: false, is_resizable: false, is_droppable: false, init_center: true, allow_native_ctxmenu: true, allow_user_select: true, width: 400, dominant: true, onAppend: function(el_window){ }, window_css:{ }, body_css: { padding: '10px', width: 'initial', 'background-color': 'rgba(231, 238, 245)', 'backdrop-filter': 'blur(3px)', 'padding-bottom': 0, 'height': '351px', 'box-sizing': 'border-box', } }); // /sites let init_ts = Date.now(); let loading = setTimeout(function(){ $(el_window).find('.window-body').html(`

Loading...

`); }, 1000); puter.hosting.list().then(function (sites){ setTimeout(function(){ // clear loading clearTimeout(loading); // user has sites if(sites.length > 0){ let h =''; for(let i=0; i< sites.length; i++){ h += `
`; h += `${sites[i].subdomain}.puter.site`; h += ``; // there is a directory associated with this site if(sites[i].root_dir){ h += `

`; h+= ``; h+= `${sites[i].root_dir.path}`; h += `

`; h += `

`; h += ``; h += `Disassociate Folder`; h += `

`; } h += `

No directory associated with this address.

`; h += `
`; } $(el_window).find('.window-body').html(h); } // has no sites else{ $(el_window).find('.window-body').html(`

You haven't published any websites!

`); } }, Date.now() - init_ts < 1000 ? 0 : 2000); }) } $(document).on('click', '.mywebsites-dir-path', function(e){ e = e.target; UIWindow({ path: $(e).attr('data-path'), title: $(e).attr('data-name'), icon: window.icons['folder.svg'], uid: $(e).attr('data-uuid'), is_dir: true, app: 'explorer', }); }) $(document).on('click', '.mywebsites-site-setting', function(e){ const pos = e.target.getBoundingClientRect(); UIContextMenu({ parent_element: e.target, position: {top: pos.top+25, left: pos.left-193}, items: [ //-------------------------------------------------- // Release Address //-------------------------------------------------- { html: `Release Address`, onClick: async function(){ const alert_resp = await UIAlert({ message: `Are you sure you want to release this address?`, buttons:[ { label: 'Yes, Release It', type: 'primary', }, { label: 'Cancel' }, ] }) if(alert_resp !== 'Yes, Release It'){ return; } $.ajax({ url: api_origin + "/delete-site", type: 'POST', data: JSON.stringify({ site_uuid: $(e.target).attr('data-site-uuid'), }), async: false, contentType: "application/json", headers: { "Authorization": "Bearer "+auth_token }, statusCode: { 401: function () { logout(); }, }, success: function (){ $(`.mywebsites-card[data-uuid="${$(e.target).attr('data-site-uuid')}"]`).fadeOut(); } }) } } ] }); }) $(document).on('click', '.mywebsites-dis-dir', function(e){ puter.hosting.delete( // dir $(e.target).attr('data-dir-uuid'), // hostname $(e.target).attr('data-site-uuid'), // success function (){ $(`.mywebsites-no-dir-notice[data-site-uuid="${$(e.target).attr('data-site-uuid')}"]`).show(); $(`.mywebsites-dir-path[data-uuid="${$(e.target).attr('data-dir-uuid')}"]`).remove(); // remove the website badge from all instances of the dir $(`.item[data-uid="${$(e.target).attr('data-dir-uuid')}"]`).find('.item-has-website-badge').fadeOut(300); $(e.target).hide(); } ) }) export default UIWindowMyWebsites