diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index bbb753d5e6..d51a4f5164 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -17,7 +17,7 @@ OCP\Util::connectHook('OC_User', 'post_removeFromGroup', 'OC_Share', 'removeFrom $dir = isset($_GET['dir']) ? $_GET['dir'] : '/'; 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::addStyle( 'files_sharing', 'sharing' ); diff --git a/core/ajax/share.php b/core/ajax/share.php index f87c12dbb5..11fee4a000 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -20,23 +20,40 @@ */ OCP\JSON::checkLoggedIn(); -switch ($_POST['action']) { - case 'share': - $return = OCP\Share::share($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith'], $_POST['permissions']); - ($return) ? OCP\JSON::success() : OCP\JSON::error(); - break; - case 'unshare': - $return = OCP\Share::unshare($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith']); - ($return) ? OCP\JSON::success() : OCP\JSON::error(); - break; - case 'setTarget': - $return = OCP\Share::setTarget($_POST['itemType'], $_POST['item'], $_POST['newTarget']); - ($return) ? OCP\JSON::success() : OCP\JSON::error(); - break; - case 'setPermissions': - $return = OCP\Share::setPermissions($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith'], $_POST['permissions']); - ($return) ? OCP\JSON::success() : OCP\JSON::error(); - break; +if (isset($_POST['action'])) { + switch ($_POST['action']) { + case 'share': + $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(); + break; + case 'unshare': + $return = OCP\Share::unshare($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith']); + ($return) ? OCP\JSON::success() : OCP\JSON::error(); + break; + case 'setTarget': + $return = OCP\Share::setTarget($_POST['itemType'], $_POST['item'], $_POST['newTarget']); + ($return) ? OCP\JSON::success() : OCP\JSON::error(); + break; + case 'setPermissions': + $return = OCP\Share::setPermissions($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith'], $_POST['permissions']); + ($return) ? OCP\JSON::success() : OCP\JSON::error(); + 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; + } } ?> \ No newline at end of file diff --git a/core/js/share.js b/core/js/share.js index 5f695774ce..9ba35616a4 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -1,35 +1,34 @@ OC.Share={ - icons:[], - itemUsers:[], - itemGroups:[], - itemPrivateLink:false, - usersAndGroups:[], - loadIcons:function() { - // Cache all icons for shared files - $.getJSON(OC.filePath('core', 'ajax', 'share.php'), function(result) { + item:[], + statuses:[], + loadIcons:function(itemType) { + // Load all share icons + $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getItemsSharedStatuses', itemType: itemType }, function(result) { if (result && result.status === 'success') { $.each(result.data, function(item, hasPrivateLink) { - if (hasPrivateLink) { - OC.Share.icons[item] = OC.imagePath('core', 'actions/public'); + // Private links override shared in terms of icon display + if (itemType == 'file') { + OC.Share.statuses[item] = hasPrivateLink; } 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) { - $.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { item: item }, async: false, success: function(result) { + loadItem:function(itemType, item) { + $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getItemShared', itemType: itemType, item: item }, async: false, function(result) { if (result && result.status === 'success') { - var item = result.data; - OC.Share.itemUsers = item.users; - OC.Share.itemGroups = item.groups; - OC.Share.itemPrivateLink = item.privateLink; + OC.Share.item = result.data; } }}); }, - share:function(source, uid_shared_with, permissions, callback) { - $.post(OC.filePath('core', 'ajax', 'share.php'), { sources: source, uid_shared_with: uid_shared_with, permissions: permissions }, function(result) { + share:function(itemType, shareType, shareWith, permissions, callback) { + $.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 (callback) { callback(result.data); @@ -39,8 +38,8 @@ OC.Share={ } }); }, - unshare:function(source, uid_shared_with, callback) { - $.post(OC.filePath('core', 'ajax', 'share.php'), { source: source, uid_shared_with: uid_shared_with }, function(result) { + unshare:function(itemType, shareType, shareWith, callback) { + $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'unshare', itemType: itemType, shareType: shareType, shareWith: shareWith }, function(result) { if (result && result.status === 'success') { if (callback) { callback(); @@ -50,16 +49,17 @@ OC.Share={ } }); }, - setPermissions:function(source, uid_shared_with, permissions) { - $.post(OC.filePath('core', 'ajax', 'share.php'), { source: source, uid_shared_with: uid_shared_with, permissions: permissions }, function(result) { + setPermissions:function(itemType, item, shareType, shareWith, permissions) { + $.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') { OC.dialogs.alert('Error', 'Error while changing permissions'); } }); }, - showDropDown:function(item, appendTo) { + showDropDown:function(itemType, item, appendTo) { OC.Share.loadItem(item); var html = '