Add support for assigning permissions in share dialog and switch to post

This commit is contained in:
Michael Gapczynski 2011-07-31 20:47:53 -04:00
parent a14a83b9c6
commit 57ca70e27c
2 changed files with 49 additions and 43 deletions

View File

@ -4,9 +4,9 @@ $RUNTIME_NOAPPS = true;
require_once('../../../lib/base.php'); require_once('../../../lib/base.php');
require_once('../lib_share.php'); require_once('../lib_share.php');
$sources = $_GET['sources']; $sources = explode(";", $_POST['sources']);
$uid_shared_with = $_GET['uid_shared_with']; $uid_shared_with = $_POST['uid_shared_with'];
$permissions = $_GET['permissions']; $permissions = $_POST['permissions'];
foreach ($sources as $source) { foreach ($sources as $source) {
foreach ($uid_shared_with as $uid) { foreach ($uid_shared_with as $uid) {
new OC_Share($source, $uid, $permissions); new OC_Share($source, $uid, $permissions);

View File

@ -1,10 +1,22 @@
$(document).ready(function() { $(document).ready(function() {
FileActions.register('all', 'Share', OC.imagePath('core', 'actions/share'), function(filename) { FileActions.register('all', 'Share', OC.imagePath('core', 'actions/share'), function(filename) {
createShareDialog(filename); createShareDialog(filename, $('#dir').val()+'/'+filename);
}); });
$('.share').click(function(event) { $('.share').click(function(event) {
event.preventDefault(); 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() { $("input[name=share_type]").live('change', function() {
$('#private').toggle(); $('#private').toggle();
@ -12,7 +24,7 @@ $(document).ready(function() {
}); });
$('.uid_shared_with').live('keyup', function() { $('.uid_shared_with').live('keyup', function() {
$(this).autocomplete({ $(this).autocomplete({
source: "../apps/files_sharing/ajax/userautocomplete.php", source: '../apps/files_sharing/ajax/userautocomplete.php',
minLength: 1 minLength: 1
}); });
}); });
@ -23,9 +35,9 @@ $(document).ready(function() {
html += "<label>Share with <input placeholder='User or Group' class='uid_shared_with' /></label>"; html += "<label>Share with <input placeholder='User or Group' class='uid_shared_with' /></label>";
html += "<button class='add-uid_shared_with fancybutton'>+</button>"; html += "<button class='add-uid_shared_with fancybutton'>+</button>";
$(html).insertAfter('.add-uid_shared_with'); $(html).insertAfter('.add-uid_shared_with');
$(this).html("&nbsp-&nbsp&nbsp"); $(this).html('&nbsp-&nbsp&nbsp');
$(this).removeClass("add-uid_shared_with fancybutton"); $(this).removeClass('add-uid_shared_with fancybutton');
$(this).addClass("remove-uid_shared_with fancybutton"); $(this).addClass('remove-uid_shared_with fancybutton');
}); });
$('button.remove-uid_shared_with').live('click', function(event) { $('button.remove-uid_shared_with').live('click', function(event) {
event.preventDefault(); event.preventDefault();
@ -34,38 +46,12 @@ $(document).ready(function() {
}); });
$('#expire').datepicker({ $('#expire').datepicker({
dateFormat:'MM d, yy', dateFormat:'MM d, yy',
altField: "#expire_time", altField: '#expire_time',
altFormat: "yy-mm-dd" 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');
}
});
}
}); });
}); });
function createShareDialog(fileNames) { function createShareDialog(filenames, files) {
var html = "<div id='dialog' align='center'>"; var html = "<div id='dialog' align='center'>";
html += "<label><input type='radio' name='share_type' value='private' checked='checked' /> Private</label>"; html += "<label><input type='radio' name='share_type' value='private' checked='checked' /> Private</label>";
html += "<label><input type='radio' name='share_type' value='public' /> Public</label>"; html += "<label><input type='radio' name='share_type' value='public' /> Public</label>";
@ -77,8 +63,7 @@ function createShareDialog(fileNames) {
html += "<div id='permissions'style='text-align: left'>"; html += "<div id='permissions'style='text-align: left'>";
html += "Permissions" html += "Permissions"
html += "<br />"; html += "<br />";
html += "<label><input type='checkbox' name='share_permissions' value='0' checked='checked' disabled='disable' /> Read</label><br />"; html += "<label><input type='checkbox' name='share_permissions' value='1' /> Edit</label><br />";
html += "<label><input type='checkbox' name='share_permissions' value='1' /> Write</label><br />";
html += "<label><input type='checkbox' name='share_permissions' value='2' /> Delete</label><br />"; html += "<label><input type='checkbox' name='share_permissions' value='2' /> Delete</label><br />";
html += "</div>"; html += "</div>";
html += "</div>"; html += "</div>";
@ -86,14 +71,35 @@ function createShareDialog(fileNames) {
html += "TODO: Construct a public link"; html += "TODO: Construct a public link";
html += "<input placeholder='Expires' id='expire' />"; html += "<input placeholder='Expires' id='expire' />";
html += "</div>"; html += "</div>";
html += "<br />";
html += "<button class='submit fancybutton'>Share</button>";
html += "<div>"; html += "<div>";
$(html).dialog({ $(html).dialog({
title: "Share " + fileNames, title: 'Share ' + filenames,
modal: true, modal: true,
close: function(event, ui) { close: function(event, ui) {
$(this).remove(); $(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');
}
});
}
}
} }
}); });
} }