Clean up in the dropdown for unsharing
This commit is contained in:
parent
1e36e1f2cb
commit
5e8ef33190
4 changed files with 31 additions and 74 deletions
|
@ -6,9 +6,9 @@
|
|||
-moz-box-shadow:0 1px 1px #777; -webkit-box-shadow:0 1px 1px #777; box-shadow:0 1px 1px #777;
|
||||
-moz-border-radius-bottomleft:1em; -webkit-border-bottom-left-radius:1em; border-bottom-left-radius:1em;
|
||||
-moz-border-radius-bottomright:1em; -webkit-border-bottom-right-radius:1em; border-bottom-right-radius:1em; }
|
||||
#sharedWithList { padding:0.5em; list-style-type: none; }
|
||||
#shareWithList { padding:0.5em; list-style-type: none; }
|
||||
#privateLink { border-top:1px solid #ddd; padding-top:0.5em; }
|
||||
a.unshare { float:right; display:inline; margin:0 .5em; padding:.3em .3em 0 .3em !important; opacity:.5; }
|
||||
a.unshare { float:right; display:inline; padding:.3em 0 0 .3em !important; opacity:.5; }
|
||||
a.unshare:hover { opacity:1; }
|
||||
#share_with { width: 16em; }
|
||||
#privateLink label, .edit { font-weight:normal; }
|
||||
|
|
|
@ -47,7 +47,8 @@ if (isset($_POST['action'])) {
|
|||
$return = OCP\Share::getItemsShared($_GET['itemType'], OCP\Share::FORMAT_STATUSES);
|
||||
($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error();
|
||||
break;
|
||||
case 'getItemShared':
|
||||
case 'getItem':
|
||||
// TODO Check if the item was shared to the current user
|
||||
$return = OCP\Share::getItemShared($_GET['itemType'], $_GET['item']);
|
||||
($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error();
|
||||
break;
|
||||
|
|
|
@ -25,7 +25,7 @@ OC.Share={
|
|||
},
|
||||
loadItem:function(itemType, item) {
|
||||
var data = '';
|
||||
$.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { fetch: 'getItemShared', itemType: itemType, item: item }, async: false, success: function(result) {
|
||||
$.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { fetch: 'getItem', itemType: itemType, item: item }, async: false, success: function(result) {
|
||||
if (result && result.status === 'success') {
|
||||
data = result.data;
|
||||
} else {
|
||||
|
@ -45,8 +45,8 @@ OC.Share={
|
|||
}
|
||||
});
|
||||
},
|
||||
unshare:function(itemType, shareType, shareWith, callback) {
|
||||
$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'unshare', itemType: itemType, shareType: shareType, shareWith: shareWith }, function(result) {
|
||||
unshare:function(itemType, item, shareType, shareWith, callback) {
|
||||
$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'unshare', itemType: itemType, item: item, shareType: shareType, shareWith: shareWith }, function(result) {
|
||||
if (result && result.status === 'success') {
|
||||
if (callback) {
|
||||
callback();
|
||||
|
@ -67,15 +67,8 @@ OC.Share={
|
|||
var html = '<div id="dropdown" class="drop" data-item-type="'+itemType+'" data-item="'+item+'">';
|
||||
// TODO replace with autocomplete textbox
|
||||
html += '<input id="shareWith" type="text" placeholder="Share with" />';
|
||||
html += '<div id="sharedWithList">';
|
||||
var sharedWith = OC.Share.loadItem(itemType, item);
|
||||
if (sharedWith) {
|
||||
$.each(sharedWith, function(index, row) {
|
||||
html += row.share_with;
|
||||
html += '<br />';
|
||||
});
|
||||
}
|
||||
html += '</div>';
|
||||
html += '<ul id="shareWithList">';
|
||||
html += '</ul>';
|
||||
html += '<div id="privateLink">';
|
||||
html += '<input type="checkbox" name="privateLinkCheckbox" id="privateLinkCheckbox" value="1" /><label for="privateLinkCheckbox">Share with private link</label>';
|
||||
html += '<br />';
|
||||
|
@ -86,6 +79,14 @@ OC.Share={
|
|||
html += '</form>';
|
||||
html += '</div>';
|
||||
$(html).appendTo(appendTo);
|
||||
var data = OC.Share.loadItem(itemType, item);
|
||||
if (data) {
|
||||
$.each(data, function(index, shares) {
|
||||
$.each(shares, function(id, share) {
|
||||
OC.Share.addShareWith(share.share_with, share.permissions);
|
||||
});
|
||||
});
|
||||
}
|
||||
$('#dropdown').show('blind');
|
||||
$('#share_with').chosen();
|
||||
},
|
||||
|
@ -97,54 +98,16 @@ OC.Share={
|
|||
}
|
||||
});
|
||||
},
|
||||
addSharedWith:function(uid_shared_with, permissions, isGroup, parentFolder) {
|
||||
if (parentFolder) {
|
||||
var sharedWith = '<li>Parent folder '+parentFolder+' shared with '+uid_shared_with+'</li>';
|
||||
} else {
|
||||
var checked = ((permissions > 0) ? 'checked="checked"' : 'style="display:none;"');
|
||||
var style = ((permissions == 0) ? 'style="display:none;"' : '');
|
||||
var sharedWith = '<li data-uid_shared_with="'+uid_shared_with+'">';
|
||||
sharedWith += '<a href="" class="unshare" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core','actions/delete')+'"/></a>';
|
||||
sharedWith += uid_shared_with;
|
||||
sharedWith += '<input type="checkbox" name="permissions" id="'+uid_shared_with+'" class="permissions" '+checked+' />';
|
||||
sharedWith += '<label class="edit" for="'+uid_shared_with+'" '+style+'>can edit</label>';
|
||||
sharedWith += '</li>';
|
||||
}
|
||||
if (isGroup) {
|
||||
// Groups are added to a different list
|
||||
$('#groups').show();
|
||||
$(sharedWith).appendTo('#groupList');
|
||||
// Remove group from select form
|
||||
$('#share_with option[value="'+uid_shared_with+'(group)"]').remove();
|
||||
$('#share_with').trigger('liszt:updated');
|
||||
// Remove users in group from select form
|
||||
$.each(isGroup, function(index, user) {
|
||||
$('#share_with option[value="'+user+'"]').remove();
|
||||
$('#share_with').trigger('liszt:updated');
|
||||
});
|
||||
} else {
|
||||
$(sharedWith).appendTo('#userList');
|
||||
// Remove user from select form
|
||||
$('#share_with option[value="'+uid_shared_with+'"]').remove();
|
||||
$('#share_with').trigger('liszt:updated');
|
||||
}
|
||||
addShareWith:function(shareWith, permissions) {
|
||||
var checked = ((permissions > 0) ? 'checked="checked"' : 'style="display:none;"');
|
||||
var style = ((permissions == 0) ? 'style="display:none;"' : '');
|
||||
var html = '<li >';
|
||||
html += shareWith;
|
||||
html += '<a href="" class="unshare" data-share-with="'+shareWith+'" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core','actions/delete')+'"/></a>';
|
||||
html += '</li>';
|
||||
$(html).appendTo('#shareWithList');
|
||||
|
||||
},
|
||||
removeSharedWith:function(uid_shared_with) {
|
||||
var option;
|
||||
if ($('#userList li[data-uid_shared_with="'+uid_shared_with+'"]').length > 0) {
|
||||
$('#userList li[data-uid_shared_with="'+uid_shared_with+'"]').remove();
|
||||
option = '<option value="'+uid_shared_with+'">'+uid_shared_with+'</option>';
|
||||
} else if ($('#groupList li[data-uid_shared_with="'+uid_shared_with+'"]').length > 0) {
|
||||
$('#groupList li[data-uid_shared_with="'+uid_shared_with+'"]').remove();
|
||||
if ($('#groupList li').length < 1) {
|
||||
$('#groups').hide();
|
||||
}
|
||||
option = '<option value="'+uid_shared_with+'(group)">'+uid_shared_with+' (group)</option>';
|
||||
}
|
||||
$(option).appendTo('#share_with');
|
||||
$('#share_with').trigger('liszt:updated');
|
||||
},
|
||||
showPrivateLink:function(item, token) {
|
||||
$('#privateLinkCheckbox').attr('checked', true);
|
||||
var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&token='+token;
|
||||
|
@ -244,12 +207,12 @@ $(document).ready(function() {
|
|||
// }
|
||||
// });
|
||||
|
||||
$('#sharedWithList li').live('mouseenter', function(event) {
|
||||
$('#shareWithList li').live('mouseenter', function(event) {
|
||||
// Show permissions and unshare button
|
||||
$(':hidden', this).show();
|
||||
});
|
||||
|
||||
$('#sharedWithList li').live('mouseleave', function(event) {
|
||||
$('#shareWithList li').live('mouseleave', function(event) {
|
||||
// Hide permissions and unshare button
|
||||
$('a', this).hide();
|
||||
if (!$('input:[type=checkbox]', this).is(':checked')) {
|
||||
|
@ -263,16 +226,9 @@ $(document).ready(function() {
|
|||
});
|
||||
|
||||
$('.unshare').live('click', function() {
|
||||
var item = $('#dropdown').data('item');
|
||||
var uid_shared_with = $(this).parent().data('uid_shared_with');
|
||||
OC.Share.unshare(item, uid_shared_with, function() {
|
||||
OC.Share.removeSharedWith(uid_shared_with);
|
||||
// Reload item to update cached users and groups for the icon check
|
||||
OC.Share.loadItem(item);
|
||||
// Change icon
|
||||
if (!OC.Share.itemPrivateLink && !OC.Share.itemUsers && !OC.Share.itemGroups) {
|
||||
OC.Share.icons[item] = OC.imagePath('core', 'actions/share');
|
||||
}
|
||||
var li = $(this).parent();
|
||||
OC.Share.unshare($('#dropdown').data('item-type'), $('#dropdown').data('item'), 0, $(this).data('share-with'), function() {
|
||||
$(li).remove();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -479,7 +479,7 @@ class Share {
|
|||
if (isset($uidOwner)) {
|
||||
$select = 'id, item_type, item, item_source, share_type, share_with, permissions, stime, file_source';
|
||||
} else {
|
||||
$select = 'id, item_type, item, item_source, item_target, share_type, share_with, permissions, stime, file_source, file_target';
|
||||
$select = '*';
|
||||
}
|
||||
}
|
||||
$query = \OC_DB::prepare('SELECT '.$select.' FROM *PREFIX*share '.$where);
|
||||
|
|
Loading…
Reference in a new issue