mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
If items are dropped on the home directory of another user, try to share the items rather than copy/move
This commit is contained in:
parent
6f0706ffc5
commit
1c2ba76db2
@ -1387,6 +1387,40 @@ async function UIWindow(options) {
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
// if this is the home directory of another user, show the sharing dialog
|
||||
// --------------------------------------------------------
|
||||
let cur_path = $(el_window).attr('data-path');
|
||||
if(countSubstr(cur_path, '/') === 1 && cur_path !== '/'+window.user.username){
|
||||
let username = cur_path.split('/')[1];
|
||||
|
||||
const items_to_share = []
|
||||
|
||||
// first item
|
||||
items_to_share.push({
|
||||
uid: $(ui.draggable).attr('data-uid'),
|
||||
path: $(ui.draggable).attr('data-path'),
|
||||
icon: $(ui.draggable).find('.item-icon img').attr('src'),
|
||||
name: $(ui.draggable).find('.item-name').text(),
|
||||
});
|
||||
|
||||
// all subsequent items
|
||||
const cloned_items = document.getElementsByClassName('item-selected-clone');
|
||||
for(let i =0; i<cloned_items.length; i++){
|
||||
const source_item = document.getElementById('item-' + $(cloned_items[i]).attr('data-id'));
|
||||
if(!source_item) continue;
|
||||
items_to_share.push({
|
||||
uid: $(source_item).attr('data-uid'),
|
||||
path: $(source_item).attr('data-path'),
|
||||
icon: $(source_item).find('.item-icon img').attr('src'),
|
||||
name: $(source_item).find('.item-name').text(),
|
||||
})
|
||||
}
|
||||
|
||||
UIWindowShare(items_to_share, username);
|
||||
return;
|
||||
}
|
||||
|
||||
// If ctrl key is down, copy items. Except if target is Trash
|
||||
if(e.ctrlKey && $(window.mouseover_window).attr('data-path') !== window.trash_path){
|
||||
// Copy items
|
||||
|
@ -238,6 +238,13 @@ async function UIWindowShare(items, recipient){
|
||||
perm_list += `<div style="float:right;"><span class="remove-permission-link remove-permission-icon" data-recipient-username="${recipient_username}" data-permission="${perm_id}">✕</span></div>`;
|
||||
perm_list += `</div>`;
|
||||
|
||||
// reset input
|
||||
$(el_window).find('.error').hide();
|
||||
$(el_window).find('.access-recipient').val('');
|
||||
|
||||
// disable 'Give Access' button
|
||||
$(el_window).find('.give-access-btn').prop('disabled', true);
|
||||
|
||||
// append recipient to list
|
||||
$(el_window).find('.share-recipients').append(`${perm_list}`);
|
||||
|
||||
@ -246,6 +253,7 @@ async function UIWindowShare(items, recipient){
|
||||
contacts.push(recipient_username);
|
||||
puter.kv.set('contacts', JSON.stringify(contacts));
|
||||
}
|
||||
|
||||
},
|
||||
error: function(err) {
|
||||
// at this point 'username_not_found' and 'shared_with_self' are the only
|
||||
|
@ -2380,4 +2380,20 @@ window.set_menu_item_prop = (items, item_id, prop, val) => {
|
||||
set_menu_item_prop(item.items, item_id, prop, val);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
window.countSubstr = (str, substring)=>{
|
||||
if (substring.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let count = 0;
|
||||
let pos = str.indexOf(substring);
|
||||
|
||||
while (pos !== -1) {
|
||||
count++;
|
||||
pos = str.indexOf(substring, pos + 1);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user