2011-07-27 01:27:40 +00:00
|
|
|
$(document).ready(function() {
|
2011-08-07 19:20:57 +00:00
|
|
|
$(this).click(function(event) {
|
|
|
|
if ($(event.target).parents().index($('#dropdown')) == -1) {
|
|
|
|
if ($('#dropdown').is(':visible')) {
|
|
|
|
$('#dropdown').hide('blind', function() {
|
|
|
|
$('#dropdown').remove();
|
|
|
|
$('tr').removeClass('mouseOver');
|
|
|
|
});
|
|
|
|
}
|
2011-08-02 19:23:17 +00:00
|
|
|
}
|
|
|
|
});
|
2011-07-29 16:11:53 +00:00
|
|
|
FileActions.register('all', 'Share', OC.imagePath('core', 'actions/share'), function(filename) {
|
2011-08-03 19:21:53 +00:00
|
|
|
createShareDropdown(filename, $('#dir').val()+'/'+filename);
|
2011-07-29 19:43:29 +00:00
|
|
|
});
|
|
|
|
$('.share').click(function(event) {
|
|
|
|
event.preventDefault();
|
2011-08-01 00:47:53 +00:00
|
|
|
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;
|
|
|
|
}
|
2011-08-03 19:21:53 +00:00
|
|
|
createShareDropdown(filenames, files);
|
2011-07-27 01:27:40 +00:00
|
|
|
});
|
2011-08-09 14:34:00 +00:00
|
|
|
$('#uid_shared_with').live('change', function() {
|
|
|
|
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-09 21:55:51 +00:00
|
|
|
data: data,
|
|
|
|
success: function() {
|
|
|
|
$('#uid_shared_with option[value="'+uid_shared_with+'"]').remove();
|
|
|
|
$('#uid_shared_with').trigger('liszt:updated');
|
|
|
|
var list = "<li data-uid_shared_with='"+uid_shared_with+"'>";
|
|
|
|
list += uid_shared_with;
|
|
|
|
list += "<input type='checkbox' name='permissions' class='permissions' style='display:none;' /><label>can edit</label>";
|
|
|
|
list += "<a href='' title='Unshare' class='unshare' data-uid_shared_with='"+uid_shared_with+"' style='display:none;'><img class='svg' src='"+OC.imagePath('core','actions/delete')+"'/></a>";
|
|
|
|
list += "</li>";
|
|
|
|
$(list).prependTo('#shared_list');
|
|
|
|
}
|
2011-07-27 01:27:40 +00:00
|
|
|
});
|
|
|
|
});
|
2011-08-09 21:55:51 +00:00
|
|
|
$('#shared_list > li').live('mouseenter', function(event) {
|
|
|
|
$(':hidden', this).show();
|
|
|
|
});
|
|
|
|
$('#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-03 19:21:53 +00:00
|
|
|
$('.permissions').live('change', function() {
|
2011-08-07 19:20:57 +00:00
|
|
|
var permissions;
|
2011-08-09 21:55:51 +00:00
|
|
|
if (this.checked) {
|
2011-08-07 19:20:57 +00:00
|
|
|
permissions = 1;
|
|
|
|
} else {
|
|
|
|
permissions = 0;
|
|
|
|
}
|
|
|
|
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 19:21:53 +00:00
|
|
|
});
|
2011-08-05 15:18:35 +00:00
|
|
|
$('.unshare').live('click', function(event) {
|
2011-08-07 19:20:57 +00:00
|
|
|
// TODO Fix unshare
|
2011-08-05 15:18:35 +00:00
|
|
|
event.preventDefault();
|
2011-08-07 19:20:57 +00:00
|
|
|
event.stopPropagation();
|
2011-08-03 19:21:53 +00:00
|
|
|
var source = $('#dropdown').data('file');
|
2011-08-07 19:20:57 +00:00
|
|
|
var uid_shared_with = $(this).parent().data('uid_shared_with');
|
|
|
|
var data = 'source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with);
|
2011-08-03 19:21:53 +00:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: OC.linkTo('files_sharing','ajax/unshare.php'),
|
|
|
|
cache: false,
|
|
|
|
data: data,
|
|
|
|
success: function() {
|
|
|
|
$(this).parent().remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$('#makelink').live('change', function() {
|
|
|
|
if (this.checked) {
|
|
|
|
var path = $('#dropdown').data('file');
|
|
|
|
var expire = 0;
|
|
|
|
var data = 'path='+path+'&expire='+expire;
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: OC.linkTo('files_publiclink','ajax/makelink.php'),
|
|
|
|
cache: false,
|
|
|
|
data: data,
|
|
|
|
success: function(token) {
|
|
|
|
if (token) {
|
2011-08-05 15:18:35 +00:00
|
|
|
$('#link').data('token', token);
|
|
|
|
$('#link').val('http://'+location.host+OC.linkTo('files_publiclink','get.php')+'?token='+token);
|
2011-08-03 19:21:53 +00:00
|
|
|
$('#link').show('blind');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2011-08-05 15:18:35 +00:00
|
|
|
var token = $('#link').data('token');
|
|
|
|
var data = 'token='+token;
|
2011-08-03 19:21:53 +00:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: OC.linkTo('files_publiclink','ajax/deletelink.php'),
|
|
|
|
cache: false,
|
|
|
|
data: data,
|
|
|
|
success: function(){
|
2011-08-05 15:18:35 +00:00
|
|
|
$('#link').hide('blind');
|
2011-08-03 19:21:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-07-27 01:27:40 +00:00
|
|
|
});
|
2011-08-07 19:20:57 +00:00
|
|
|
$('#link').live('click', function() {
|
|
|
|
$(this).focus();
|
|
|
|
$(this).select();
|
|
|
|
});
|
2011-07-29 19:43:29 +00:00
|
|
|
});
|
|
|
|
|
2011-08-03 19:21:53 +00:00
|
|
|
function createShareDropdown(filenames, files) {
|
|
|
|
var html = "<div id='dropdown' data-file='"+files+"'>";
|
2011-07-29 19:43:29 +00:00
|
|
|
html += "<div id='private'>";
|
2011-08-09 14:34:00 +00:00
|
|
|
html += "<select data-placeholder='User or Group' style='width:220px;' id='uid_shared_with' class='chzen-select'>";
|
|
|
|
html += "<option value=''></option>";
|
|
|
|
html += "</select>";
|
2011-08-09 21:55:51 +00:00
|
|
|
html += "<ul id='shared_list'></ul>";
|
2011-07-29 19:43:29 +00:00
|
|
|
html += "</div>";
|
2011-08-02 16:19:49 +00:00
|
|
|
html += "<div id='public'>";
|
2011-08-03 19:21:53 +00:00
|
|
|
html += "<input type='checkbox' name='makelink' id='makelink' value='1' /><label for='makelink'>make public</label>";
|
2011-08-02 16:58:33 +00:00
|
|
|
html += "<input type='checkbox' name='public_link_write' id='public_link_write' value='1' /><label for='public_link_write'>allow upload</label>";
|
2011-08-03 19:21:53 +00:00
|
|
|
html += "<br />";
|
2011-08-09 21:55:51 +00:00
|
|
|
html += "<input id='link' style='display:none; width:90%;' />";
|
2011-07-29 19:43:29 +00:00
|
|
|
html += "</div>";
|
2011-08-02 19:23:17 +00:00
|
|
|
$('tr[data-file="'+filenames+'"]').addClass('mouseOver');
|
2011-08-02 16:58:33 +00:00
|
|
|
$(html).appendTo($('tr[data-file="'+filenames+'"] td.filename'));
|
2011-08-09 14:34:00 +00:00
|
|
|
$.getJSON(OC.linkTo('files_sharing', 'ajax/userautocomplete.php'), function(users) {
|
|
|
|
if (users) {
|
|
|
|
$.each(users, function(index, row) {
|
|
|
|
$(row).appendTo('#uid_shared_with');
|
|
|
|
});
|
|
|
|
$('#uid_shared_with').trigger('liszt:updated');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$.getJSON(OC.linkTo('files_sharing', 'ajax/getitem.php'), { source: files }, function(users) {
|
2011-08-03 19:21:53 +00:00
|
|
|
if (users) {
|
2011-08-09 21:55:51 +00:00
|
|
|
var list;
|
2011-08-03 19:21:53 +00:00
|
|
|
$.each(users, function(index, row) {
|
2011-08-09 15:00:14 +00:00
|
|
|
$('#uid_shared_with option[value="'+row.uid_shared_with+'"]').remove();
|
2011-08-10 17:38:58 +00:00
|
|
|
if (isNaN(index)) {
|
2011-08-08 19:49:16 +00:00
|
|
|
list += "<li>Parent folder "+index.substr(0, index.lastIndexOf('-'))+" shared with "+row.uid_shared_with+"</li>";
|
2011-08-07 19:20:57 +00:00
|
|
|
} else {
|
|
|
|
list += "<li data-uid_shared_with='"+row.uid_shared_with+"'>";
|
|
|
|
list += row.uid_shared_with;
|
|
|
|
var checked;
|
2011-08-09 21:55:51 +00:00
|
|
|
var style;
|
2011-08-07 19:20:57 +00:00
|
|
|
if (row.permissions > 0) {
|
|
|
|
checked = "checked='checked'";
|
2011-08-09 21:55:51 +00:00
|
|
|
} else {
|
|
|
|
style = "style='display:none;'";
|
2011-08-07 19:20:57 +00:00
|
|
|
}
|
2011-08-09 21:55:51 +00:00
|
|
|
list += "<input type='checkbox' name='permissions' id='"+index+"' class='permissions' "+checked+" "+style+" /><label for='"+index+"' "+style+">can edit</label>";
|
|
|
|
list += "<a href='' title='Unshare' class='unshare' data-uid_shared_with='"+row.uid_shared_with+"' style='display:none;'><img class='svg' src='"+OC.imagePath('core','actions/delete')+"'/></a>";
|
2011-08-07 19:20:57 +00:00
|
|
|
list += "</li>";
|
|
|
|
|
2011-08-03 19:21:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$(list).appendTo('#shared_list');
|
2011-08-09 15:00:14 +00:00
|
|
|
$('#uid_shared_with').trigger('liszt:updated');
|
2011-08-03 19:21:53 +00:00
|
|
|
}
|
|
|
|
});
|
2011-08-09 14:34:00 +00:00
|
|
|
$.getJSON(OC.linkTo('files_publiclink', 'ajax/getlink.php'), { path: files }, function(token) {
|
2011-08-03 19:21:53 +00:00
|
|
|
if (token) {
|
|
|
|
$('#makelink').attr('checked', true);
|
2011-08-05 15:18:35 +00:00
|
|
|
$('#link').data('token', token);
|
|
|
|
$('#link').val('http://'+location.host+OC.linkTo('files_publiclink','get.php')+'?token='+token);
|
2011-08-03 19:21:53 +00:00
|
|
|
$('#link').show('blind');
|
|
|
|
}
|
2011-08-05 15:18:35 +00:00
|
|
|
});
|
2011-08-03 19:21:53 +00:00
|
|
|
$('#dropdown').show('blind');
|
2011-08-09 14:34:00 +00:00
|
|
|
$('#uid_shared_with').chosen();
|
2011-08-02 16:58:33 +00:00
|
|
|
}
|