From 57ca70e27c537763551d0940dd8aebcee5bd9b47 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 31 Jul 2011 20:47:53 -0400 Subject: [PATCH] Add support for assigning permissions in share dialog and switch to post --- apps/files_sharing/ajax/share.php | 6 +-- apps/files_sharing/js/share.js | 86 +++++++++++++++++-------------- 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/apps/files_sharing/ajax/share.php b/apps/files_sharing/ajax/share.php index 6e860d584e..0de899a0e1 100644 --- a/apps/files_sharing/ajax/share.php +++ b/apps/files_sharing/ajax/share.php @@ -4,9 +4,9 @@ $RUNTIME_NOAPPS = true; require_once('../../../lib/base.php'); require_once('../lib_share.php'); -$sources = $_GET['sources']; -$uid_shared_with = $_GET['uid_shared_with']; -$permissions = $_GET['permissions']; +$sources = explode(";", $_POST['sources']); +$uid_shared_with = $_POST['uid_shared_with']; +$permissions = $_POST['permissions']; foreach ($sources as $source) { foreach ($uid_shared_with as $uid) { new OC_Share($source, $uid, $permissions); diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index c688007ddb..6ca018fca0 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -1,10 +1,22 @@ $(document).ready(function() { FileActions.register('all', 'Share', OC.imagePath('core', 'actions/share'), function(filename) { - createShareDialog(filename); + createShareDialog(filename, $('#dir').val()+'/'+filename); }); $('.share').click(function(event) { event.preventDefault(); - createShareDialog(getSelectedFiles('name')); + 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); }); $("input[name=share_type]").live('change', function() { $('#private').toggle(); @@ -12,7 +24,7 @@ $(document).ready(function() { }); $('.uid_shared_with').live('keyup', function() { $(this).autocomplete({ - source: "../apps/files_sharing/ajax/userautocomplete.php", + source: '../apps/files_sharing/ajax/userautocomplete.php', minLength: 1 }); }); @@ -23,9 +35,9 @@ $(document).ready(function() { html += ""; html += ""; $(html).insertAfter('.add-uid_shared_with'); - $(this).html(" -  "); - $(this).removeClass("add-uid_shared_with fancybutton"); - $(this).addClass("remove-uid_shared_with fancybutton"); + $(this).html(' -  '); + $(this).removeClass('add-uid_shared_with fancybutton'); + $(this).addClass('remove-uid_shared_with fancybutton'); }); $('button.remove-uid_shared_with').live('click', function(event) { event.preventDefault(); @@ -34,38 +46,12 @@ $(document).ready(function() { }); $('#expire').datepicker({ dateFormat:'MM d, yy', - altField: "#expire_time", - altFormat: "yy-mm-dd" - }); - $('button.submit').live('click', function(event) { - event.preventDefault(); - if ($("input[name=share_type]:checked").val() == 'public') { - // TODO Construct public link - } else { - // TODO Check all inputs are valid - var sources = ""; - var files = getSelectedFiles('name'); - var length = files.length; - for (var i = 0; i < length; i++) { - sources += "&sources[]=" + $('#dir').val() + "/" + files[i]; - } - var uid_shared_with = $('.uid_shared_with').val(); - var permissions = 0; - var data = sources+'&uid_shared_with[]='+uid_shared_with+'&permissions='+permissions; - $.ajax({ - type: 'GET', - url: '../apps/files_sharing/ajax/share.php', - cache: false, - data: data, - success: function() { - $('#dialog').dialog('close'); - } - }); - } + altField: '#expire_time', + altFormat: 'yy-mm-dd' }); }); -function createShareDialog(fileNames) { +function createShareDialog(filenames, files) { var html = "
"; html += ""; html += ""; @@ -77,8 +63,7 @@ function createShareDialog(fileNames) { html += "
"; html += "Permissions" html += "
"; - html += "
"; - html += "
"; + html += "
"; html += "
"; html += "
"; html += "
"; @@ -86,14 +71,35 @@ function createShareDialog(fileNames) { html += "TODO: Construct a public link"; html += ""; html += ""; - html += "
"; - html += ""; html += "
"; $(html).dialog({ - title: "Share " + fileNames, + title: 'Share ' + filenames, modal: true, close: function(event, ui) { $(this).remove(); + }, + buttons: { + 'Share': function() { + if ($('input[name=share_type]:checked').val() == 'public') { + // TODO Construct public link + } else { + // TODO Check all inputs are valid + var uid_shared_with = $('.uid_shared_with').val(); + var permissions = 0; + $(this).find('input:checkbox:checked').each(function() { + permissions += parseInt($(this).val()); + }); + $.ajax({ + type: 'POST', + url: '../apps/files_sharing/ajax/share.php', + cache: false, + data: '&sources='+encodeURIComponent(files)+'&uid_shared_with[]='+uid_shared_with+'&permissions='+permissions, + success: function() { + $('#dialog').dialog('close'); + } + }); + } + } } }); } \ No newline at end of file