From cb21406e18cf492b5e0356ba04d341acb20cafd6 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 26 Jul 2012 21:56:22 -0400 Subject: [PATCH] Implement CRUDS in share dropdown, and some clean-up --- apps/files_sharing/css/sharing.css | 10 +-- core/js/share.js | 103 ++++++++++++++++++++++------- 2 files changed, 85 insertions(+), 28 deletions(-) diff --git a/apps/files_sharing/css/sharing.css b/apps/files_sharing/css/sharing.css index a2fa870c43..f1d6faa6b0 100644 --- a/apps/files_sharing/css/sharing.css +++ b/apps/files_sharing/css/sharing.css @@ -7,9 +7,11 @@ -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; } #shareWithList { padding:0.5em; list-style-type: none; } -#privateLink { border-top:1px solid #ddd; padding-top:0.5em; } +#shareWithList li { padding-top:0.1em; } +#dropdown label { font-weight:normal; } +#dropdown input[type="checkbox"] { margin:0 0.2em 0 0.5em; } +a.showCruds { display:inline; opacity:.5; } +a.showCruds:hover { opacity:1; } 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; } -#share_with_chzn { display: block; } +#privateLink { border-top:1px solid #ddd; padding-top:0.5em; } \ No newline at end of file diff --git a/core/js/share.js b/core/js/share.js index 4cff9ec1a6..18e68ce78d 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -2,6 +2,11 @@ OC.Share={ SHARE_TYPE_USER:0, SHARE_TYPE_GROUP:1, SHARE_TYPE_PRIVATE_LINK:3, + PERMISSION_CREATE:4, + PERMISSION_READ:1, + PERMISSION_UPDATE:2, + PERMISSION_DELETE:8, + PERMISSION_SHARE:16, item:[], statuses:[], loadIcons:function(itemType) { @@ -66,18 +71,14 @@ OC.Share={ showDropDown:function(itemType, item, appendTo, privateLink) { var html = ''; @@ -88,12 +89,11 @@ OC.Share={ if (share.share_type == OC.Share.SHARE_TYPE_PRIVATE_LINK) { OC.Share.showPrivateLink(item, share.share_with); } else { - OC.Share.addShareWith(share.share_with, share.permissions); + OC.Share.addShareWith(share.share_type, share.share_with, share.permissions); } }); } $('#dropdown').show('blind'); - $('#share_with').chosen(); }, hideDropDown:function(callback) { $('#dropdown').hide('blind', function() { @@ -103,12 +103,34 @@ OC.Share={ } }); }, - addShareWith:function(shareWith, permissions) { - var checked = ((permissions > 0) ? 'checked="checked"' : 'style="display:none;"'); - var style = ((permissions == 0) ? 'style="display:none;"' : ''); - var html = '
  • '; + addShareWith:function(shareType, shareWith, permissions) { + var editChecked = createChecked = updateChecked = deleteChecked = shareChecked = ''; + if (permissions & OC.Share.PERMISSION_CREATE) { + createChecked = 'checked="checked"'; + editChecked = 'checked="checked"'; + } + if (permissions & OC.Share.PERMISSION_UPDATE) { + updateChecked = 'checked="checked"'; + editChecked = 'checked="checked"'; + } + if (permissions & OC.Share.PERMISSION_DELETE) { + deleteChecked = 'checked="checked"'; + editChecked = 'checked="checked"'; + } + if (permissions & OC.Share.PERMISSION_SHARE) { + shareChecked = 'checked="checked"'; + } + var html = '
  • '; html += shareWith; - html += ''; + html += ''; + html += ''; + html += ''; + html += ''; html += '
  • '; $(html).appendTo('#shareWithList'); @@ -224,36 +246,69 @@ $(document).ready(function() { $('#shareWithList li').live('mouseenter', function(event) { // Show permissions and unshare button - $(':hidden', this).show(); + $(':hidden', this).filter(':not(.cruds)').show(); }); $('#shareWithList li').live('mouseleave', function(event) { // Hide permissions and unshare button - $('a', this).hide(); - if (!$('input:[type=checkbox]', this).is(':checked')) { - $('input:[type=checkbox]', this).hide(); - $('label', this).hide(); + if (!$('.cruds', this).is(':visible')) { + $('a', this).hide(); + if (!$('input[name="edit"]', this).is(':checked')) { + $('input:[type=checkbox]', this).hide(); + $('label', this).hide(); + } + } else { + $('a.unshare', this).hide(); } }); $('#shareWith').live('change', function() { + var shareType = $(li).data('share-type'); var shareWith = $(this).val(); - OC.Share.share($('#dropdown').data('item-type'), $('#dropdown').data('item'), 0, shareWith, 0, function() { - OC.Share.addShareWith(shareWith, 0); + // Default permissions are Read and Share + var permissions = OC.Share.PERMISSION_READ | OC.Share.PERMISSION_SHARE; + OC.Share.share($('#dropdown').data('item-type'), $('#dropdown').data('item'), shareType, shareWith, permissions, function() { + OC.Share.addShareWith(shareType, shareWith, permissions); $('#shareWith').val(''); }); }); - + + $('.showCruds').live('click', function() { + $(this).parent().find('.cruds').toggle(); + }); + $('.unshare').live('click', function() { var li = $(this).parent(); - OC.Share.unshare($('#dropdown').data('item-type'), $('#dropdown').data('item'), 0, $(this).data('share-with'), function() { + OC.Share.unshare($('#dropdown').data('item-type'), $('#dropdown').data('item'), $(li).data('share-type'), $(li).data('share-with'), function() { $(li).remove(); }); }); $('.permissions').live('change', function() { - var permissions = (this.checked) ? 1 : 0; - OC.Share.changePermissions($('#dropdown').data('item'), $(this).parent().data('uid_shared_with'), permissions); + if ($(this).attr('name') == 'edit') { + var li = $(this).parent().parent() + var checkboxes = $('.permissions', li); + var checked = $(this).is(':checked'); + // Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck + $(checkboxes).filter('input[name="create"]').attr('checked', checked); + $(checkboxes).filter('input[name="update"]').attr('checked', checked); + $(checkboxes).filter('input[name="delete"]').attr('checked', checked); + } else { + var li = $(this).parent().parent().parent(); + var checkboxes = $('.permissions', li); + // Uncheck Edit if Create, Update, and Delete are not checked + if (!$(this).is(':checked') && !$(checkboxes).filter('input[name="create"]').is(':checked') && !$(checkboxes).filter('input[name="update"]').is(':checked') && !$(checkboxes).filter('input[name="delete"]').is(':checked')) { + $(checkboxes).filter('input[name="edit"]').attr('checked', false); + // Check Edit if Create, Update, or Delete is checked + } else if (($(this).attr('name') == 'create' || $(this).attr('name') == 'update' || $(this).attr('name') == 'delete')) { + $(checkboxes).filter('input[name="edit"]').attr('checked', true); + } + } + var permissions = OC.Share.PERMISSION_READ; + $(checkboxes).filter(':not(input[name="edit"])').filter(':checked').each(function(index, checkbox) { + permissions |= $(checkbox).data('permissions'); + }); + OC.Share.setPermissions($('#dropdown').data('item-type'), $('#dropdown').data('item'), $(li).data('share-type'), $(li).data('share-with'), permissions); }); $('#privateLinkCheckbox').live('change', function() {