$(document).ready(function() { var shared_status = {}; if (typeof FileActions !== 'undefined') { FileActions.register('all', 'Share', function(filename) { if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback var icon; if (typeof filename == 'undefined') { return false; } var file = $('#dir').val()+'/'+filename; if(shared_status[file]) return shared_status[file].icon; $.ajax({ type: 'GET', url: OC.linkTo('files_sharing', 'ajax/getitem.php'), dataType: 'json', data: {source: file}, async: false, success: function(users) { if (users) { icon = OC.imagePath('core', 'actions/shared'); $.each(users, function(index, row) { if (row.uid_shared_with == 'public') { icon = OC.imagePath('core', 'actions/public'); } }); } else { icon = OC.imagePath('core', 'actions/share'); } shared_status[file]= { timestamp: new Date().getTime(), icon: icon }; } }); return icon; }, function(filename) { if (($('#dropdown').length > 0)) { $('#dropdown').hide('blind', function() { var dropdownFile = $('#dropdown').data('file') var file = $('#dir').val()+'/'+filename; $('#dropdown').remove(); $('tr').removeClass('mouseOver'); if (dropdownFile != file) { createDropdown(filename, file); } }); } else { createDropdown(filename, $('#dir').val()+'/'+filename); } }); }; $('.share').click(function(event) { event.preventDefault(); event.stopPropagation(); var filenames = getSelectedFiles('name'); var length = filenames.length; var files = ''; for (var i = 0; i < length; i++) { files += $('#dir').val()+'/'+filenames[i]+';'; } createDropdown(false, files); }); $(this).click(function(event) { if (!($(event.target).hasClass('drop')) && $(event.target).parents().index($('#dropdown')) == -1) { if ($('#dropdown').is(':visible')) { delete shared_status[$('#dropdown').data('file')]; //Remove File from icon cache $('#dropdown').hide('blind', function() { $('#dropdown').remove(); $('tr').removeClass('mouseOver'); }); } } }); $('#share_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, data: data, success: function(result) { if (result !== 'false') { addUser(uid_shared_with, permissions, false); } } }); }); $('#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(); } }); $('.permissions').live('change', function() { var permissions = (this.checked) ? 1 : 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 }); }); $('.unshare').live('click', function(event) { event.preventDefault(); var user = $(this).parent(); var source = $('#dropdown').data('file'); var uid_shared_with = user.data('uid_shared_with'); var data = 'source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with); $.ajax({ type: 'GET', url: OC.linkTo('files_sharing','ajax/unshare.php'), cache: false, data: data, success: function() { var option = ''; $(user).remove(); $(option).appendTo('#share_with'); $('#share_with').trigger('liszt:updated'); } }); }); $('#makelink').live('change', function() { if (this.checked) { var source = $('#dropdown').data('file'); var uid_shared_with = 'public'; 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, data: data, success: function(token) { if (token) { showPublicLink(token, source.substr(source.lastIndexOf('/'))); } } }); } else { var source = $('#dropdown').data('file'); var uid_shared_with = 'public'; var data = 'source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with); $.ajax({ type: 'GET', url: OC.linkTo('files_sharing','ajax/unshare.php'), cache: false, data: data, success: function(){ $('#link').hide('blind'); $('#emailBreak').remove(); $('#email').hide('blind'); $('#emailButton').hide('blind'); } }); } }); $('#link').live('click', function() { $(this).focus(); $(this).select(); }); $('#emailButton').live('click', function() { $('#email').css('font-weight', 'bold'); $('#email').animate({ fontWeight: 'normal' }, 2000, function() { $(this).val(''); }).val('Email sent'); $.post(OC.filePath('files_sharing','ajax','email.php'), 'toaddress='+$('#email').val()+'&link='+$('#link').val()); }); }); function createDropdown(filename, files) { var html = '