nextcloud/apps/files_sharing/js/share.js

71 lines
2.5 KiB
JavaScript
Raw Normal View History

$(document).ready(function() {
2011-08-02 23:23:17 +04:00
$('#dialog').live('mouseleave', function(event) {
if ($(this).is(':visible')) {
$(this).hide('blind', function() {
$(this).remove();
});
}
});
FileActions.register('all', 'Share', OC.imagePath('core', 'actions/share'), function(filename) {
createShareDialog(filename, $('#dir').val()+'/'+filename);
});
$('.share').click(function(event) {
event.preventDefault();
var filenames = getSelectedFiles('name');
var length = filenames.length;
var files = '';
for (var i = 0; i < length; i++) {
files += $('#dir').val()+'/'+filenames[i]+';';
}
var lastFileName = filenames.pop();
if (filenames.length > 0) {
filenames = filenames.join(', ')+' and '+lastFileName;
} else {
filenames = lastFileName;
}
createShareDialog(filenames, files);
});
2011-08-02 20:19:49 +04:00
$('#uid_shared_with').live('keyup', function() {
$(this).autocomplete({
2011-08-02 20:19:49 +04:00
source: '../apps/files_sharing/ajax/userautocomplete.php'
});
});
$('button.remove-uid_shared_with').live('click', function(event) {
event.preventDefault();
alert("remove");
// TODO Remove corresponding row
});
});
function createShareDialog(filenames, files) {
2011-08-02 23:23:17 +04:00
var html = "<div id='dialog' style='display: none'>";
html += "<div id='private'>";
html += "<label for='uid_shared_with'><strong>Share with</strong></label><input placeholder='User or Group' id='uid_shared_with' />";
html += "<input type='checkbox' name='permissions' id='permissions' value='1' /><label for='permissions'>allow editing</label><br />";
html += "<br />";
2011-08-02 20:19:49 +04:00
html += "<div id='shared_list'></div>";
$.getJSON(OC.linkTo('files_sharing','ajax/getitem.php'), { source: files }, function(users) {
var list = "";
$.each(users, function(index, row) {
list += row.uid_shared_with;
list += "<input type='checkbox' name='share_private_permissions' value='1' /><label>allow editing</label><br />";
2011-08-02 20:19:49 +04:00
if (row.permissions > 0) {
$('share_private_permissions').prop('checked', true);
}
});
$(list).appendTo('#shared_list');
});
html += "</div>";
2011-08-02 23:23:17 +04:00
html += "<hr />";
2011-08-02 20:19:49 +04:00
html += "<div id='public'>";
html += "<input type='checkbox' name='public_link' id='public_link' value='1' /><label for='public_link'>make public</label>";
html += "<input type='checkbox' name='public_link_write' id='public_link_write' value='1' /><label for='public_link_write'>allow upload</label>";
2011-08-02 20:19:49 +04:00
html += "<div id='link'>";
html += "</div>";
html += "</div>";
2011-08-02 23:23:17 +04:00
$('tr[data-file="'+filenames+'"]').addClass('mouseOver');
$(html).appendTo($('tr[data-file="'+filenames+'"] td.filename'));
2011-08-02 23:23:17 +04:00
$('#dialog').show('blind');
}