Use chosen select form for selecting users in sharing drop down

This commit is contained in:
Michael Gapczynski 2011-08-09 10:34:00 -04:00
parent 23c8d7b3fb
commit cdf2dbcd52
4 changed files with 35 additions and 21 deletions

View file

@ -8,9 +8,7 @@ $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);
}
new OC_Share($source, $uid_shared_with, $permissions);
}
?>

View file

@ -7,23 +7,22 @@ if (!OC_User::isLoggedIn()) {
echo json_encode(array("status" => "error", "data" => array("message" => "Authentication error")));
exit();
}
$query = $_GET['term'];
$length = strlen($query);
$query = strtolower($query);
$users = array();
$ocusers = OC_User::getUsers();
$self = OC_User::getUser();
$groups = OC_GROUP::getUserGroups($self);
$users[] = "<optgroup label='Users'>";
foreach ($ocusers as $user) {
if ($user != $self && substr(strtolower($user), 0, $length) == $query) {
$users[] = (object)array('id' => $user, 'label' => $user, 'name' => $user);
if ($user != $self) {
$users[] = "<option value='".$user."'>".$user."</option>";
}
}
$users[] = "</optgroup>";
$users[] = "<optgroup label='Groups'>";
foreach ($groups as $group) {
if (substr(strtolower($group), 0, $length) == $query) {
$users[] = (object)array('id' => $group, 'label' => $group, 'name' => $group);
}
$users[] = "<option value='".$group."'>".$group."</option>";
}
$users[] = "</optgroup>";
echo json_encode($users);
?>

View file

@ -5,7 +5,9 @@ require_once('apps/files_sharing/sharedstorage.php');
OC_Filesystem::registerStorageType("shared", "OC_Filestorage_Shared", array("datadir"=>"string"));
OC_Util::addScript("files_sharing", "share");
OC_Util::addScript("3rdparty", "chosen/chosen.jquery.min");
OC_Util::addStyle( 'files_sharing', 'sharing' );
OC_Util::addStyle("3rdparty", "chosen/chosen");
OC_App::addNavigationSubEntry("files_index", array(
"id" => "files_sharing_list",
"order" => 10,

View file

@ -28,17 +28,21 @@ $(document).ready(function() {
}
createShareDropdown(filenames, files);
});
$('#uid_shared_with').live('keyup', function() {
$(this).autocomplete({
source: OC.linkTo('files_sharing','ajax/userautocomplete.php')
});
$('.ui-autocomplete').click(function(event) {
event.stopPropagation();
$('#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,
data: data
});
});
$('.permissions').live('change', function() {
var permissions;
if (this.checked) {
if ($(this).checked) {
permissions = 1;
} else {
permissions = 0;
@ -111,7 +115,9 @@ $(document).ready(function() {
function createShareDropdown(filenames, files) {
var html = "<div id='dropdown' data-file='"+files+"'>";
html += "<div id='private'>";
html += "<input placeholder='User or Group' id='uid_shared_with' />";
html += "<select data-placeholder='User or Group' style='width:220px;' id='uid_shared_with' class='chzen-select'>";
html += "<option value=''></option>";
html += "</select>";
html += "<div id='shared_list'></div>";
html += "</div>";
html += "<div id='public'>";
@ -122,7 +128,15 @@ function createShareDropdown(filenames, files) {
html += "</div>";
$('tr[data-file="'+filenames+'"]').addClass('mouseOver');
$(html).appendTo($('tr[data-file="'+filenames+'"] td.filename'));
$.getJSON(OC.linkTo('files_sharing','ajax/getitem.php'), { source: files }, function(users) {
$.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) {
if (users) {
var list = "<ul>";
$.each(users, function(index, row) {
@ -146,7 +160,7 @@ function createShareDropdown(filenames, files) {
$(list).appendTo('#shared_list');
}
});
$.getJSON(OC.linkTo('files_publiclink','ajax/getlink.php'), { path: files }, function(token) {
$.getJSON(OC.linkTo('files_publiclink', 'ajax/getlink.php'), { path: files }, function(token) {
if (token) {
$('#makelink').attr('checked', true);
$('#link').data('token', token);
@ -155,4 +169,5 @@ function createShareDropdown(filenames, files) {
}
});
$('#dropdown').show('blind');
$('#uid_shared_with').chosen();
}