Fix ajax share file and replace 'User or Group' select form with a textbox

This commit is contained in:
Michael Gapczynski 2012-06-25 14:55:49 -04:00 committed by Bart Visscher
parent 9fdfcc29fe
commit b5961635ea
2 changed files with 17 additions and 45 deletions

View File

@ -18,37 +18,38 @@
* You should have received a copy of the GNU Affero General Public * You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
require_once '../../lib/base.php';
OCP\JSON::checkLoggedIn(); OC_JSON::checkLoggedIn();
if (isset($_POST['action'])) { 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 // TODO May need to return private link
($return) ? OCP\JSON::success() : OCP\JSON::error(); ($return) ? OC_JSON::success() : OC_JSON::error();
break; break;
case 'unshare': case 'unshare':
$return = OCP\Share::unshare($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith']); $return = OCP\Share::unshare($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith']);
($return) ? OCP\JSON::success() : OCP\JSON::error(); ($return) ? OC_JSON::success() : OC_JSON::error();
break; break;
case 'setTarget': case 'setTarget':
$return = OCP\Share::setTarget($_POST['itemType'], $_POST['item'], $_POST['newTarget']); $return = OCP\Share::setTarget($_POST['itemType'], $_POST['item'], $_POST['newTarget']);
($return) ? OCP\JSON::success() : OCP\JSON::error(); ($return) ? OC_JSON::success() : OC_JSON::error();
break; break;
case 'setPermissions': case 'setPermissions':
$return = OCP\Share::setPermissions($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith'], $_POST['permissions']); $return = OCP\Share::setPermissions($_POST['itemType'], $_POST['item'], $_POST['shareType'], $_POST['shareWith'], $_POST['permissions']);
($return) ? OCP\JSON::success() : OCP\JSON::error(); ($return) ? OC_JSON::success() : OC_JSON::error();
break; break;
} }
} else if (isset($_GET['fetch'])) { } else if (isset($_GET['fetch'])) {
switch ($_GET['fetch']) { switch ($_GET['fetch']) {
case 'getItemsSharedStatuses': case 'getItemsSharedStatuses':
$return = OCP\Share::getItemsSharedStatuses($_POST['itemType']); $return = OCP\Share::getItemsSharedStatuses($_POST['itemType']);
($return) ? OCP\JSON::success(array('data' => $return)) : OCP\JSON::error(); ($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error();
break; break;
case 'getItemShared': case 'getItemShared':
$return = OCP\Share::getItemShared($_POST['itemType'], $_POST['item']); $return = OCP\Share::getItemShared($_POST['itemType'], $_POST['item']);
($return) ? OCP\JSON::success(array('data' => $return)) : OCP\JSON::error(); ($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error();
break; break;
case 'getShareWith': case 'getShareWith':
// TODO Autocomplete for all users, groups, etc. // TODO Autocomplete for all users, groups, etc.

View File

@ -21,20 +21,20 @@ OC.Share={
}); });
}, },
loadItem:function(itemType, item) { loadItem:function(itemType, item) {
$.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getItemShared', itemType: itemType, item: item }, async: false, function(result) { $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getItemShared', itemType: itemType, item: item }, function(result) {
if (result && result.status === 'success') { if (result && result.status === 'success') {
OC.Share.item = result.data; OC.Share.item = result.data;
} }
}); });
}, },
share:function(itemType, shareType, shareWith, permissions, callback) { share:function(itemType, item, shareType, shareWith, permissions, callback) {
$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'share', itemType: itemType, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) { $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'share', itemType: itemType, item: item, 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);
} }
} else { } else {
OC.dialogs.alert(result.data.message, 'Error while sharing'); OC.dialogs.alert('Error', 'Error while sharing');
} }
}); });
}, },
@ -58,11 +58,9 @@ OC.Share={
}, },
showDropDown:function(itemType, 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-type="'+itemType+'" data-item="'+item+'">';
// TODO replace with autocomplete textbox // TODO replace with autocomplete textbox
html += '<select data-placeholder="User or Group" id="share_with" class="chzen-select">'; html += '<input id="shareWith" type="text" placeholder="Share with" />';
html += '<option value="" selected="selected" disabled="disabled">Your groups & members</option>';
html += '</select>';
html += '<div id="sharedWithList">'; html += '<div id="sharedWithList">';
html += '<ul id="userList"></ul>'; html += '<ul id="userList"></ul>';
html += '<div id="groups" style="display:none;">'; html += '<div id="groups" style="display:none;">';
@ -253,35 +251,8 @@ $(document).ready(function() {
} }
}); });
$('#share_with').live('change', function() { $('#shareWith').live('change', function() {
var item = $('#dropdown').data('item'); OC.Share.share($('#dropdown').data('item-type'), $('#dropdown').data('item'), 0, $(this).val(), 0, false);
var uid_shared_with = $(this).val();
var pos = uid_shared_with.indexOf('(group)');
var isGroup = false;
if (pos != -1) {
// Remove '(group)' from uid_shared_with
uid_shared_with = uid_shared_with.substr(0, pos);
isGroup = true;
}
OC.Share.share(item, uid_shared_with, 0, function() {
if (isGroup) {
// Reload item because we don't know which users are in the group
OC.Share.loadItem(item);
var users;
$.each(OC.Share.itemGroups, function(index, group) {
if (group.gid == uid_shared_with) {
users = group.users;
}
});
OC.Share.addSharedWith(uid_shared_with, 0, users, false);
} else {
OC.Share.addSharedWith(uid_shared_with, 0, false, false);
}
// Change icon
if (!OC.Share.itemPrivateLink) {
OC.Share.icons[item] = OC.imagePath('core', 'actions/shared');
}
});
}); });
$('.unshare').live('click', function() { $('.unshare').live('click', function() {
@ -334,4 +305,4 @@ $(document).ready(function() {
$('#emailPrivateLink').live('submit', function() { $('#emailPrivateLink').live('submit', function() {
OC.Share.emailPrivateLink(); OC.Share.emailPrivateLink();
}); });
}); });