Prepare drop down UI for share API
This commit is contained in:
parent
8198114615
commit
bc68f14c4b
|
@ -17,7 +17,7 @@ OCP\Util::connectHook('OC_User', 'post_removeFromGroup', 'OC_Share', 'removeFrom
|
||||||
|
|
||||||
$dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
|
$dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
|
||||||
if ($dir != '/Shared' || OCP\Config::getAppValue('files_sharing', 'resharing', 'yes') == 'yes') {
|
if ($dir != '/Shared' || OCP\Config::getAppValue('files_sharing', 'resharing', 'yes') == 'yes') {
|
||||||
OCP\Util::addscript("files_sharing", "share");
|
OCP\Util::addScript('core', 'share');
|
||||||
}
|
}
|
||||||
OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min");
|
OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min");
|
||||||
OCP\Util::addStyle( 'files_sharing', 'sharing' );
|
OCP\Util::addStyle( 'files_sharing', 'sharing' );
|
||||||
|
|
|
@ -20,9 +20,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
|
if (isset($_POST['action'])) {
|
||||||
switch ($_POST['action']) {
|
switch ($_POST['action']) {
|
||||||
case 'share':
|
case 'share':
|
||||||
$return = OCP\Share::share($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith'], $_POST['permissions']);
|
$return = OCP\Share::share($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith'], $_POST['permissions']);
|
||||||
|
// TODO May need to return private link
|
||||||
($return) ? OCP\JSON::success() : OCP\JSON::error();
|
($return) ? OCP\JSON::success() : OCP\JSON::error();
|
||||||
break;
|
break;
|
||||||
case 'unshare':
|
case 'unshare':
|
||||||
|
@ -38,5 +40,20 @@ switch ($_POST['action']) {
|
||||||
($return) ? OCP\JSON::success() : OCP\JSON::error();
|
($return) ? OCP\JSON::success() : OCP\JSON::error();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (isset($_GET['fetch'])) {
|
||||||
|
switch ($_GET['fetch']) {
|
||||||
|
case 'getItemsSharedStatuses':
|
||||||
|
$return = OCP\Share::getItemsSharedStatuses($_POST['itemType']);
|
||||||
|
($return) ? OCP\JSON::success(array('data' => $return)) : OCP\JSON::error();
|
||||||
|
break;
|
||||||
|
case 'getItemShared':
|
||||||
|
$return = OCP\Share::getItemShared($_POST['itemType'], $_POST['item']);
|
||||||
|
($return) ? OCP\JSON::success(array('data' => $return)) : OCP\JSON::error();
|
||||||
|
break;
|
||||||
|
case 'getShareWith':
|
||||||
|
// TODO Autocomplete for all users, groups, etc.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
119
core/js/share.js
119
core/js/share.js
|
@ -1,35 +1,34 @@
|
||||||
OC.Share={
|
OC.Share={
|
||||||
icons:[],
|
item:[],
|
||||||
itemUsers:[],
|
statuses:[],
|
||||||
itemGroups:[],
|
loadIcons:function(itemType) {
|
||||||
itemPrivateLink:false,
|
// Load all share icons
|
||||||
usersAndGroups:[],
|
$.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getItemsSharedStatuses', itemType: itemType }, function(result) {
|
||||||
loadIcons:function() {
|
|
||||||
// Cache all icons for shared files
|
|
||||||
$.getJSON(OC.filePath('core', 'ajax', 'share.php'), function(result) {
|
|
||||||
if (result && result.status === 'success') {
|
if (result && result.status === 'success') {
|
||||||
$.each(result.data, function(item, hasPrivateLink) {
|
$.each(result.data, function(item, hasPrivateLink) {
|
||||||
if (hasPrivateLink) {
|
// Private links override shared in terms of icon display
|
||||||
OC.Share.icons[item] = OC.imagePath('core', 'actions/public');
|
if (itemType == 'file') {
|
||||||
|
OC.Share.statuses[item] = hasPrivateLink;
|
||||||
} else {
|
} else {
|
||||||
OC.Share.icons[item] = OC.imagePath('core', 'actions/shared');
|
if (hasPrivateLink) {
|
||||||
|
$('.share').find('[data-item="'+item+'"]').attr('src', OC.imagePath('core', 'actions/public'));
|
||||||
|
} else {
|
||||||
|
$('.share').find('[data-item="'+item+'"]').attr('src', OC.imagePath('core', 'actions/shared'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
loadItem:function(item) {
|
loadItem:function(itemType, item) {
|
||||||
$.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { item: item }, async: false, success: function(result) {
|
$.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getItemShared', itemType: itemType, item: item }, async: false, function(result) {
|
||||||
if (result && result.status === 'success') {
|
if (result && result.status === 'success') {
|
||||||
var item = result.data;
|
OC.Share.item = result.data;
|
||||||
OC.Share.itemUsers = item.users;
|
|
||||||
OC.Share.itemGroups = item.groups;
|
|
||||||
OC.Share.itemPrivateLink = item.privateLink;
|
|
||||||
}
|
}
|
||||||
}});
|
}});
|
||||||
},
|
},
|
||||||
share:function(source, uid_shared_with, permissions, callback) {
|
share:function(itemType, shareType, shareWith, permissions, callback) {
|
||||||
$.post(OC.filePath('core', 'ajax', 'share.php'), { sources: source, uid_shared_with: uid_shared_with, permissions: permissions }, function(result) {
|
$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'share', itemType: itemType, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
|
||||||
if (result && result.status === 'success') {
|
if (result && result.status === 'success') {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(result.data);
|
callback(result.data);
|
||||||
|
@ -39,8 +38,8 @@ OC.Share={
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
unshare:function(source, uid_shared_with, callback) {
|
unshare:function(itemType, shareType, shareWith, callback) {
|
||||||
$.post(OC.filePath('core', 'ajax', 'share.php'), { source: source, uid_shared_with: uid_shared_with }, function(result) {
|
$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'unshare', itemType: itemType, shareType: shareType, shareWith: shareWith }, function(result) {
|
||||||
if (result && result.status === 'success') {
|
if (result && result.status === 'success') {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
|
@ -50,16 +49,17 @@ OC.Share={
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setPermissions:function(source, uid_shared_with, permissions) {
|
setPermissions:function(itemType, item, shareType, shareWith, permissions) {
|
||||||
$.post(OC.filePath('core', 'ajax', 'share.php'), { source: source, uid_shared_with: uid_shared_with, permissions: permissions }, function(result) {
|
$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setPermissions', itemType: itemType, item: item, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) {
|
||||||
if (!result || result.status !== 'success') {
|
if (!result || result.status !== 'success') {
|
||||||
OC.dialogs.alert('Error', 'Error while changing permissions');
|
OC.dialogs.alert('Error', 'Error while changing permissions');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
showDropDown:function(item, appendTo) {
|
showDropDown:function(itemType, item, appendTo) {
|
||||||
OC.Share.loadItem(item);
|
OC.Share.loadItem(item);
|
||||||
var html = '<div id="dropdown" class="drop" data-item="'+item+'">';
|
var html = '<div id="dropdown" class="drop" data-item="'+item+'">';
|
||||||
|
// TODO replace with autocomplete textbox
|
||||||
html += '<select data-placeholder="User or Group" id="share_with" class="chzen-select">';
|
html += '<select data-placeholder="User or Group" id="share_with" class="chzen-select">';
|
||||||
html += '<option value="" selected="selected" disabled="disabled">Your groups & members</option>';
|
html += '<option value="" selected="selected" disabled="disabled">Your groups & members</option>';
|
||||||
html += '</select>';
|
html += '</select>';
|
||||||
|
@ -81,43 +81,6 @@ OC.Share={
|
||||||
html += '</form>';
|
html += '</form>';
|
||||||
html += '</div>';
|
html += '</div>';
|
||||||
$(html).appendTo(appendTo);
|
$(html).appendTo(appendTo);
|
||||||
if (OC.Share.usersAndGroups.length < 1) {
|
|
||||||
$.ajax({type: 'GET', url: OC.filePath('files_sharing', 'ajax', 'userautocomplete.php'), async: false, success: function(users) {
|
|
||||||
if (users) {
|
|
||||||
OC.Share.usersAndGroups = users;
|
|
||||||
$.each(users, function(index, user) {
|
|
||||||
$(user).appendTo('#share_with');
|
|
||||||
});
|
|
||||||
$('#share_with').trigger('liszt:updated');
|
|
||||||
}
|
|
||||||
}});
|
|
||||||
} else {
|
|
||||||
$.each(OC.Share.usersAndGroups, function(index, user) {
|
|
||||||
$(user).appendTo('#share_with');
|
|
||||||
});
|
|
||||||
$('#share_with').trigger('liszt:updated');
|
|
||||||
}
|
|
||||||
if (OC.Share.itemUsers) {
|
|
||||||
$.each(OC.Share.itemUsers, function(index, user) {
|
|
||||||
if (user.parentFolder) {
|
|
||||||
OC.Share.addSharedWith(user.uid, user.permissions, false, user.parentFolder);
|
|
||||||
} else {
|
|
||||||
OC.Share.addSharedWith(user.uid, user.permissions, false, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (OC.Share.itemGroups) {
|
|
||||||
$.each(OC.Share.itemGroups, function(index, group) {
|
|
||||||
if (group.parentFolder) {
|
|
||||||
OC.Share.addSharedWith(group.gid, group.permissions, group.users, group.parentFolder);
|
|
||||||
} else {
|
|
||||||
OC.Share.addSharedWith(group.gid, group.permissions, group.users, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (OC.Share.itemPrivateLink) {
|
|
||||||
OC.Share.showPrivateLink(item, OC.Share.itemPrivateLink);
|
|
||||||
}
|
|
||||||
$('#dropdown').show('blind');
|
$('#dropdown').show('blind');
|
||||||
$('#share_with').chosen();
|
$('#share_with').chosen();
|
||||||
},
|
},
|
||||||
|
@ -215,45 +178,53 @@ OC.Share={
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
$('.share').live('click', function() {
|
||||||
|
if ($(this).data('itemType') !== undefined && $(this).data('item') !== undefined) {
|
||||||
|
OC.Share.showDropDown($(this).data('itemType'), $(this).data('item'), $(this));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (typeof FileActions !== 'undefined') {
|
if (typeof FileActions !== 'undefined') {
|
||||||
OC.Share.loadIcons();
|
OC.Share.loadIcons('file');
|
||||||
FileActions.register('all', 'Share', function(filename) {
|
FileActions.register('all', 'Share', function(filename) {
|
||||||
// Return the correct sharing icon
|
// Return the correct sharing icon
|
||||||
if (scanFiles.scanning) { return; } // workaround to prevent additional http request block scanning feedback
|
if (scanFiles.scanning) { return; } // workaround to prevent additional http request block scanning feedback
|
||||||
var item = $('#dir').val() + '/' + filename;
|
var item = $('#dir').val() + '/' + filename;
|
||||||
// Check if icon is in cache
|
// Check if status is in cache
|
||||||
if (OC.Share.icons[item]) {
|
if (OC.Share.statuses[item] === true) {
|
||||||
return OC.Share.icons[item];
|
return OC.imagePath('core', 'actions/public');
|
||||||
|
} else if (OC.Share.statuses[item] === false) {
|
||||||
|
return OC.imagePath('core', 'actions/shared');
|
||||||
} else {
|
} else {
|
||||||
var last = '';
|
var last = '';
|
||||||
var path = OC.Share.dirname(item);
|
var path = OC.Share.dirname(item);
|
||||||
// Search for possible parent folders that are shared
|
// Search for possible parent folders that are shared
|
||||||
while (path != last) {
|
while (path != last) {
|
||||||
if (OC.Share.icons[path]) {
|
if (OC.Share.statuses[path] === true) {
|
||||||
OC.Share.icons[item] = OC.Share.icons[path];
|
return OC.imagePath('core', 'actions/public');
|
||||||
return OC.Share.icons[item];
|
} else if (OC.Share.statuses[path] === false) {
|
||||||
|
return OC.imagePath('core', 'actions/shared');
|
||||||
}
|
}
|
||||||
last = path;
|
last = path;
|
||||||
path = OC.Share.dirname(path);
|
path = OC.Share.dirname(path);
|
||||||
}
|
}
|
||||||
OC.Share.icons[item] = OC.imagePath('core', 'actions/share');
|
return OC.imagePath('core', 'actions/share');
|
||||||
return OC.Share.icons[item];
|
|
||||||
}
|
}
|
||||||
}, function(filename) {
|
}, function(filename) {
|
||||||
var file = $('#dir').val() + '/' + filename;
|
var item = $('#dir').val() + '/' + filename;
|
||||||
var appendTo = $('tr').filterAttr('data-file',filename).find('td.filename');
|
var appendTo = $('tr').filterAttr('data-file',filename).find('td.filename');
|
||||||
// Check if drop down is already visible for a different file
|
// Check if drop down is already visible for a different file
|
||||||
if (($('#dropdown').length > 0)) {
|
if (($('#dropdown').length > 0)) {
|
||||||
if (file != $('#dropdown').data('item')) {
|
if (item != $('#dropdown').data('item')) {
|
||||||
OC.Share.hideDropDown(function () {
|
OC.Share.hideDropDown(function () {
|
||||||
$('tr').removeClass('mouseOver');
|
$('tr').removeClass('mouseOver');
|
||||||
$('tr').filterAttr('data-file', filename).addClass('mouseOver');
|
$('tr').filterAttr('data-file', filename).addClass('mouseOver');
|
||||||
OC.Share.showDropDown(file, appendTo);
|
OC.Share.showDropDown('file', item, appendTo);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$('tr').filterAttr('data-file',filename).addClass('mouseOver');
|
$('tr').filterAttr('data-file',filename).addClass('mouseOver');
|
||||||
OC.Share.showDropDown(file, appendTo);
|
OC.Share.showDropDown('file', item, appendTo);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,8 +30,7 @@ class Share {
|
||||||
|
|
||||||
const SHARE_TYPE_USER = 0;
|
const SHARE_TYPE_USER = 0;
|
||||||
const SHARE_TYPE_GROUP = 1;
|
const SHARE_TYPE_GROUP = 1;
|
||||||
const SHARETYPE_CONTACT = 2;
|
const SHARE_TYPE_PRIVATE_LINK = 3;
|
||||||
const SHARETYPE_PRIVATE_LINK = 4;
|
|
||||||
|
|
||||||
const PERMISSION_READ = 0;
|
const PERMISSION_READ = 0;
|
||||||
const PERMISSION_UPDATE = 1;
|
const PERMISSION_UPDATE = 1;
|
||||||
|
@ -39,9 +38,10 @@ class Share {
|
||||||
const PERMISSION_SHARE = 3;
|
const PERMISSION_SHARE = 3;
|
||||||
|
|
||||||
const FORMAT_NONE = -1;
|
const FORMAT_NONE = -1;
|
||||||
|
const FORMAT_STATUSES = -2;
|
||||||
|
|
||||||
private static $shareTypeUserAndGroups = -1;
|
private static $shareTypeUserAndGroups = -1;
|
||||||
private static $shareTypeGroupUserUnique = 3;
|
private static $shareTypeGroupUserUnique = 2;
|
||||||
private static $backends = array();
|
private static $backends = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,7 +95,7 @@ class Share {
|
||||||
* @param int Number of items to return (optional) Returns all by default
|
* @param int Number of items to return (optional) Returns all by default
|
||||||
* @return Return depends on format
|
* @return Return depends on format
|
||||||
*/
|
*/
|
||||||
public static function getItemsOwned($itemType, $format = self::FORMAT_NONE, $limit = -1) {
|
public static function getItemsShared($itemType, $format = self::FORMAT_NONE, $limit = -1) {
|
||||||
return self::getItems($itemType, null, null, null, \OC_User::getUser(), $format, $limit);
|
return self::getItems($itemType, null, null, null, \OC_User::getUser(), $format, $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,10 +106,20 @@ class Share {
|
||||||
* @param int Format (optional) Format type must be defined by the backend
|
* @param int Format (optional) Format type must be defined by the backend
|
||||||
* @return Return depends on format
|
* @return Return depends on format
|
||||||
*/
|
*/
|
||||||
public static function getItemOwned($itemType, $item, $format = self::FORMAT_NONE) {
|
public static function getItemShared($itemType, $item, $format = self::FORMAT_NONE) {
|
||||||
return self::getItems($itemType, $item, null, null, \OC_User::getUser(), $format, 1);
|
return self::getItems($itemType, $item, null, null, \OC_User::getUser(), $format, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the status of each shared item of item type owned by the current user
|
||||||
|
* @param string Item type
|
||||||
|
* @param int Number of items to return (optional) Returns all by default
|
||||||
|
* @return array, item as key with a value of true if item has a private link or false
|
||||||
|
*/
|
||||||
|
public static function getItemsSharedStatuses($itemType, $limit = -1) {
|
||||||
|
return self::getItems($itemType, null, null, null, \OC_User::getUser(), self::FORMAT_STATUSES, $limit);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Share an item with a user, group, or via private link
|
* @brief Share an item with a user, group, or via private link
|
||||||
* @param string Item type
|
* @param string Item type
|
||||||
|
@ -455,6 +465,16 @@ class Share {
|
||||||
return $items[key($items)];
|
return $items[key($items)];
|
||||||
}
|
}
|
||||||
return $items;
|
return $items;
|
||||||
|
} else if ($format == self::FORMAT_STATUSES) {
|
||||||
|
$statuses = array();
|
||||||
|
foreach ($items as $item) {
|
||||||
|
if ($item['shareType'] == self::SHARE_TYPE_PRIVATE_LINK) {
|
||||||
|
$statuses[$item['item']] = true;
|
||||||
|
} else if (!isset($statuses[$item['item']])) {
|
||||||
|
$statuses[$items['item']] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $statuses;
|
||||||
} else {
|
} else {
|
||||||
return $backend->formatItems($items, $format);
|
return $backend->formatItems($items, $format);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue