2011-07-27 05:27:40 +04:00
|
|
|
$(document).ready(function() {
|
2011-10-21 01:02:38 +04:00
|
|
|
var shared_status = {};
|
2011-08-11 19:15:17 +04:00
|
|
|
if (typeof FileActions !== 'undefined') {
|
2011-08-12 19:34:17 +04:00
|
|
|
FileActions.register('all', 'Share', function(filename) {
|
2012-02-01 18:33:12 +04:00
|
|
|
if (scanFiles.scanning){return;}//workaround to prevent aditional http request block scanning feedback
|
2011-08-12 19:34:17 +04:00
|
|
|
var icon;
|
|
|
|
var file = $('#dir').val()+'/'+filename;
|
2011-10-21 01:02:38 +04:00
|
|
|
if(shared_status[file])
|
|
|
|
return shared_status[file].icon;
|
2011-08-12 19:34:17 +04:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: OC.linkTo('files_sharing', 'ajax/getitem.php'),
|
|
|
|
dataType: 'json',
|
2011-11-02 01:35:13 +04:00
|
|
|
data: {source: file},
|
2011-08-12 19:34:17 +04:00
|
|
|
async: false,
|
|
|
|
success: function(users) {
|
2011-08-19 20:47:00 +04:00
|
|
|
if (users) {
|
2011-08-12 19:34:17 +04:00
|
|
|
icon = OC.imagePath('core', 'actions/shared');
|
2011-08-18 21:14:06 +04:00
|
|
|
$.each(users, function(index, row) {
|
|
|
|
if (row.uid_shared_with == 'public') {
|
|
|
|
icon = OC.imagePath('core', 'actions/public');
|
|
|
|
}
|
|
|
|
});
|
2011-08-16 20:18:31 +04:00
|
|
|
} else {
|
|
|
|
icon = OC.imagePath('core', 'actions/share');
|
|
|
|
}
|
2011-10-21 01:02:38 +04:00
|
|
|
shared_status[file]= { timestamp: new Date().getTime(), icon: icon };
|
2011-08-16 20:18:31 +04:00
|
|
|
}
|
|
|
|
});
|
2011-08-12 19:34:17 +04:00
|
|
|
return icon;
|
|
|
|
}, function(filename) {
|
|
|
|
if (($('#dropdown').length > 0)) {
|
2011-08-11 19:52:10 +04:00
|
|
|
$('#dropdown').hide('blind', function() {
|
2011-08-11 20:03:48 +04:00
|
|
|
var dropdownFile = $('#dropdown').data('file')
|
|
|
|
var file = $('#dir').val()+'/'+filename;
|
2011-08-11 19:52:10 +04:00
|
|
|
$('#dropdown').remove();
|
|
|
|
$('tr').removeClass('mouseOver');
|
2011-08-11 20:03:48 +04:00
|
|
|
if (dropdownFile != file) {
|
|
|
|
createDropdown(filename, file);
|
|
|
|
}
|
2011-08-11 19:52:10 +04:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
createDropdown(filename, $('#dir').val()+'/'+filename);
|
|
|
|
}
|
2011-08-11 15:33:43 +04:00
|
|
|
});
|
|
|
|
};
|
2011-08-11 19:15:17 +04:00
|
|
|
|
2011-07-29 23:43:29 +04:00
|
|
|
$('.share').click(function(event) {
|
|
|
|
event.preventDefault();
|
2011-11-06 18:29:51 +04:00
|
|
|
event.stopPropagation();
|
2011-08-01 04:47:53 +04:00
|
|
|
var filenames = getSelectedFiles('name');
|
|
|
|
var length = filenames.length;
|
|
|
|
var files = '';
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
|
|
files += $('#dir').val()+'/'+filenames[i]+';';
|
|
|
|
}
|
2011-08-11 19:09:14 +04:00
|
|
|
createDropdown(false, files);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(this).click(function(event) {
|
2011-08-11 20:50:29 +04:00
|
|
|
if (!($(event.target).hasClass('drop')) && $(event.target).parents().index($('#dropdown')) == -1) {
|
2011-08-11 19:09:14 +04:00
|
|
|
if ($('#dropdown').is(':visible')) {
|
2011-10-21 01:02:38 +04:00
|
|
|
delete shared_status[$('#dropdown').data('file')]; //Remove File from icon cache
|
2011-08-11 19:09:14 +04:00
|
|
|
$('#dropdown').hide('blind', function() {
|
2011-08-12 00:56:09 +04:00
|
|
|
$('#dropdown').remove();
|
2011-08-11 19:09:14 +04:00
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
});
|
|
|
|
}
|
2011-08-01 04:47:53 +04:00
|
|
|
}
|
2011-07-27 05:27:40 +04:00
|
|
|
});
|
2011-08-11 19:09:14 +04:00
|
|
|
|
|
|
|
$('#share_with').live('change', function() {
|
2011-08-09 18:34:00 +04:00
|
|
|
var source = $('#dropdown').data('file');
|
|
|
|
var uid_shared_with = $(this).val();
|
|
|
|
var permissions = 0;
|
|
|
|
var data = 'sources='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with)+'&permissions='+encodeURIComponent(permissions);
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: OC.linkTo('files_sharing','ajax/share.php'),
|
|
|
|
cache: false,
|
2011-08-10 01:55:51 +04:00
|
|
|
data: data,
|
2011-08-13 01:22:32 +04:00
|
|
|
success: function(result) {
|
|
|
|
if (result !== 'false') {
|
|
|
|
addUser(uid_shared_with, permissions, false);
|
|
|
|
}
|
2011-08-10 01:55:51 +04:00
|
|
|
}
|
2011-07-27 05:27:40 +04:00
|
|
|
});
|
|
|
|
});
|
2011-08-11 19:09:14 +04:00
|
|
|
|
2011-08-10 01:55:51 +04:00
|
|
|
$('#shared_list > li').live('mouseenter', function(event) {
|
|
|
|
$(':hidden', this).show();
|
|
|
|
});
|
2011-08-11 19:09:14 +04:00
|
|
|
|
2011-08-10 01:55:51 +04:00
|
|
|
$('#shared_list > li').live('mouseleave', function(event) {
|
|
|
|
$('a', this).hide();
|
|
|
|
if (!$('input:[type=checkbox]', this).is(':checked')) {
|
|
|
|
$('input:[type=checkbox]', this).hide();
|
|
|
|
$('label', this).hide();
|
|
|
|
}
|
|
|
|
});
|
2011-08-11 19:09:14 +04:00
|
|
|
|
2011-08-03 23:21:53 +04:00
|
|
|
$('.permissions').live('change', function() {
|
2011-08-11 19:09:14 +04:00
|
|
|
var permissions = (this.checked) ? 1 : 0;
|
2011-08-07 23:20:57 +04:00
|
|
|
var source = $('#dropdown').data('file');
|
|
|
|
var uid_shared_with = $(this).parent().data('uid_shared_with');
|
|
|
|
var data = 'source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with)+'&permissions='+encodeURIComponent(permissions);
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: OC.linkTo('files_sharing','ajax/setpermissions.php'),
|
|
|
|
cache: false,
|
|
|
|
data: data
|
|
|
|
});
|
2011-08-03 23:21:53 +04:00
|
|
|
});
|
2011-08-11 22:20:50 +04:00
|
|
|
|
2011-08-05 19:18:35 +04:00
|
|
|
$('.unshare').live('click', function(event) {
|
|
|
|
event.preventDefault();
|
2011-08-11 22:20:50 +04:00
|
|
|
var user = $(this).parent();
|
2011-08-03 23:21:53 +04:00
|
|
|
var source = $('#dropdown').data('file');
|
2011-08-11 22:20:50 +04:00
|
|
|
var uid_shared_with = user.data('uid_shared_with');
|
2011-08-07 23:20:57 +04:00
|
|
|
var data = 'source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with);
|
2011-08-03 23:21:53 +04:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: OC.linkTo('files_sharing','ajax/unshare.php'),
|
|
|
|
cache: false,
|
|
|
|
data: data,
|
|
|
|
success: function() {
|
2011-08-20 07:56:04 +04:00
|
|
|
var option = '<option value="'+uid_shared_with+'">'+uid_shared_with+'</option>';
|
2011-08-11 22:20:50 +04:00
|
|
|
$(user).remove();
|
|
|
|
$(option).appendTo('#share_with');
|
|
|
|
$('#share_with').trigger('liszt:updated');
|
2011-08-03 23:21:53 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2011-08-11 19:09:14 +04:00
|
|
|
|
2011-08-03 23:21:53 +04:00
|
|
|
$('#makelink').live('change', function() {
|
|
|
|
if (this.checked) {
|
2011-08-17 04:21:18 +04:00
|
|
|
var source = $('#dropdown').data('file');
|
2011-08-20 07:56:04 +04:00
|
|
|
var uid_shared_with = 'public';
|
2011-08-17 04:21:18 +04:00
|
|
|
var permissions = 0;
|
|
|
|
var data = 'sources='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with)+'&permissions='+encodeURIComponent(permissions);
|
2011-08-03 23:21:53 +04:00
|
|
|
$.ajax({
|
2011-08-17 04:21:18 +04:00
|
|
|
type: 'POST',
|
|
|
|
url: OC.linkTo('files_sharing','ajax/share.php'),
|
2011-08-03 23:21:53 +04:00
|
|
|
cache: false,
|
|
|
|
data: data,
|
2011-08-17 05:32:51 +04:00
|
|
|
success: function(token) {
|
|
|
|
if (token) {
|
2011-08-12 00:56:09 +04:00
|
|
|
showPublicLink(token);
|
2011-08-03 23:21:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2011-08-17 04:21:18 +04:00
|
|
|
var source = $('#dropdown').data('file');
|
2011-08-20 07:56:04 +04:00
|
|
|
var uid_shared_with = 'public';
|
2011-08-17 04:21:18 +04:00
|
|
|
var data = 'source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with);
|
2011-08-03 23:21:53 +04:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
2011-08-17 04:21:18 +04:00
|
|
|
url: OC.linkTo('files_sharing','ajax/unshare.php'),
|
2011-08-03 23:21:53 +04:00
|
|
|
cache: false,
|
|
|
|
data: data,
|
|
|
|
success: function(){
|
2011-08-05 19:18:35 +04:00
|
|
|
$('#link').hide('blind');
|
2011-08-03 23:21:53 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-07-27 05:27:40 +04:00
|
|
|
});
|
2011-08-11 19:09:14 +04:00
|
|
|
|
2011-08-07 23:20:57 +04:00
|
|
|
$('#link').live('click', function() {
|
|
|
|
$(this).focus();
|
|
|
|
$(this).select();
|
|
|
|
});
|
2011-07-29 23:43:29 +04:00
|
|
|
});
|
|
|
|
|
2011-08-11 19:09:14 +04:00
|
|
|
function createDropdown(filename, files) {
|
2011-08-20 07:56:04 +04:00
|
|
|
var html = '<div id="dropdown" class="drop" data-file="'+files+'">';
|
|
|
|
html += '<div id="private">';
|
2012-02-24 01:20:15 +04:00
|
|
|
html += '<select data-placeholder="User or Group" id="share_with" class="chzen-select">';
|
2011-08-20 07:56:04 +04:00
|
|
|
html += '<option value=""></option>';
|
|
|
|
html += '</select>';
|
|
|
|
html += '<ul id="shared_list"></ul>';
|
|
|
|
html += '</div>';
|
|
|
|
html += '<div id="public">';
|
|
|
|
html += '<input type="checkbox" name="makelink" id="makelink" value="1" /><label for="makelink">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>';
|
|
|
|
html += '<br />';
|
|
|
|
html += '<input id="link" style="display:none; width:90%;" />';
|
|
|
|
html += '</div>';
|
2011-08-11 19:09:14 +04:00
|
|
|
if (filename) {
|
2011-11-02 01:35:13 +04:00
|
|
|
$('tr').filterAttr('data-file',filename).addClass('mouseOver');
|
|
|
|
$(html).appendTo($('tr').filterAttr('data-file',filename).find('td.filename'));
|
2011-08-11 19:09:14 +04:00
|
|
|
} else {
|
|
|
|
$(html).appendTo($('thead .share'));
|
|
|
|
}
|
2011-08-09 18:34:00 +04:00
|
|
|
$.getJSON(OC.linkTo('files_sharing', 'ajax/userautocomplete.php'), function(users) {
|
|
|
|
if (users) {
|
|
|
|
$.each(users, function(index, row) {
|
2011-08-11 19:09:14 +04:00
|
|
|
$(row).appendTo('#share_with');
|
2011-08-09 18:34:00 +04:00
|
|
|
});
|
2011-08-11 19:09:14 +04:00
|
|
|
$('#share_with').trigger('liszt:updated');
|
2011-08-09 18:34:00 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$.getJSON(OC.linkTo('files_sharing', 'ajax/getitem.php'), { source: files }, function(users) {
|
2011-08-03 23:21:53 +04:00
|
|
|
if (users) {
|
|
|
|
$.each(users, function(index, row) {
|
2011-08-17 05:32:51 +04:00
|
|
|
if (row.uid_shared_with == 'public') {
|
2011-08-19 20:47:00 +04:00
|
|
|
showPublicLink(row.token);
|
2011-08-17 05:32:51 +04:00
|
|
|
} else if (isNaN(index)) {
|
2011-08-11 19:09:14 +04:00
|
|
|
addUser(row.uid_shared_with, row.permissions, index.substr(0, index.lastIndexOf('-')));
|
2011-08-07 23:20:57 +04:00
|
|
|
} else {
|
2011-08-11 19:09:14 +04:00
|
|
|
addUser(row.uid_shared_with, row.permissions, false);
|
2011-08-03 23:21:53 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('#dropdown').show('blind');
|
2011-08-11 19:09:14 +04:00
|
|
|
$('#share_with').chosen();
|
|
|
|
}
|
|
|
|
|
|
|
|
function addUser(uid_shared_with, permissions, parentFolder) {
|
|
|
|
if (parentFolder) {
|
2011-08-20 07:56:04 +04:00
|
|
|
var user = '<li>Parent folder '+parentFolder+' shared with '+uid_shared_with+'</li>';
|
2011-08-11 19:09:14 +04:00
|
|
|
} else {
|
2011-08-20 07:56:04 +04:00
|
|
|
var checked = ((permissions > 0) ? 'checked="checked"' : 'style="display:none;"');
|
|
|
|
var style = ((permissions == 0) ? 'style="display:none;"' : '');
|
2011-09-26 23:26:49 +04:00
|
|
|
var user = '<li data-uid_shared_with="'+uid_shared_with+'">';
|
|
|
|
user += '<a href="" class="unshare" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core','actions/delete')+'"/></a>';
|
|
|
|
user += uid_shared_with;
|
2011-10-04 18:08:14 +04:00
|
|
|
user += '<input type="checkbox" name="permissions" id="'+uid_shared_with+'" class="permissions" '+checked+' />';
|
2011-09-26 23:26:49 +04:00
|
|
|
user += '<label for="'+uid_shared_with+'" '+style+'>can edit</label>';
|
|
|
|
user += '</li>';
|
2011-08-11 19:09:14 +04:00
|
|
|
}
|
|
|
|
$('#share_with option[value="'+uid_shared_with+'"]').remove();
|
2011-08-11 19:15:17 +04:00
|
|
|
$('#share_with').trigger('liszt:updated');
|
2011-08-11 19:09:14 +04:00
|
|
|
$(user).appendTo('#shared_list');
|
2011-08-02 20:58:33 +04:00
|
|
|
}
|
2011-08-12 00:56:09 +04:00
|
|
|
|
|
|
|
function showPublicLink(token) {
|
|
|
|
$('#makelink').attr('checked', true);
|
|
|
|
$('#link').data('token', token);
|
2011-08-20 07:56:04 +04:00
|
|
|
$('#link').val(parent.location.protocol+'//'+location.host+OC.linkTo('files_sharing','get.php')+'?token='+token);
|
2011-08-12 00:56:09 +04:00
|
|
|
$('#link').show('blind');
|
|
|
|
}
|