From cc69ca476b865b886e0a4c07bf7cede279d30588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=27rysiek=27=20Wo=C5=BAniak?= Date: Fri, 24 Jan 2014 19:24:35 +0100 Subject: [PATCH] implementing HTML+CSS sharing interface: time for JS; done: 1. adding and removing share-withs; 2. reacting to permission updates (for the time being without POSTing them) --- css/linkshare.css | 4 + js/calendar.js | 143 ++++++++++++++++++++----------- templates/part.internalshare.php | 32 +++++-- 3 files changed, 125 insertions(+), 54 deletions(-) diff --git a/css/linkshare.css b/css/linkshare.css index fd227f8b..d4aefd93 100644 --- a/css/linkshare.css +++ b/css/linkshare.css @@ -89,6 +89,10 @@ .shared-with-list > li { text-align:right; } +/* that's just a stub to be used by JS later, hid it! */ +.shared-with-list > li.stub { + display:none; +} .shared-with-list > li img { vertical-align:-20%; opacity:0.5; diff --git a/js/calendar.js b/js/calendar.js index b984acf0..a11324d1 100644 --- a/js/calendar.js +++ b/js/calendar.js @@ -591,68 +591,113 @@ Calendar={ event.preventDefault(); }, select: function(event, selected) { - var itemType = 'event'; - var itemSource = $('#sharewith').data('item-source'); + var itemType = $(this).data('item-type'); + var itemSource = $(this).data('item-source'); var shareType = selected.item.value.shareType; var shareWith = selected.item.value.shareWith; $(this).val(shareWith); + var shareWithInput = $(this) // Default permissions are Read and Share var permissions = OC.PERMISSION_READ | OC.PERMISSION_SHARE; OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, function(data) { - var newitem = '
  • ' - + shareWith - + (shareType === OC.Share.SHARE_TYPE_GROUP ? ' ('+t('core', 'group')+')' : '') - + '' - + '' - + '' - + '
  • '; - $('.sharedby.eventlist').append(newitem); - $('#sharedWithNobody').remove(); - $('#sharewith').val(''); + // we need to "fix" the share-can-edit-ITEMPTYPE-ITEMSOURCE-0 checkbox and label + var editCheckboxIdStub = 'share-can-edit-' + itemType + '-' + itemSource + '-' + var curEditCheckboxId = $(shareWithInput).parents('.share-interface-container.internal-share').find('.shared-with-entry-container').length + // find the stub + var newitem = $(shareWithInput) + .parents('.share-interface-container.internal-share') + .find('.shared-with-entry-container.stub') + // clone it + .clone() + // populate the stub with data + .attr('data-item-type', itemType) + .attr('data-share-with', shareWith) + .attr('data-permissions', permissions) + .attr('data-share-type', shareType) + .attr('data-item-soutce', itemSource) + .attr('title', shareWith) + // populate stub's elements + .find('.username') + .html(shareWith + (shareType === OC.Share.SHARE_TYPE_GROUP ? ' ('+t('core', 'group')+')' : '')) + .end() + .find('.share-options input[name="create"]') + .prop('checked', true) // TODO base that on what we get in response? + .end() + .find('.share-options input[name="update"]') + .prop('checked', true) // TODO base that on what we get in response? + .end() + .find('.share-options input[name="delete"]') + .prop('checked', true) // TODO base that on what we get in response? + .end() + .find('.share-options input[name="share"]') + .prop('checked', true) // TODO base that on what we get in response? + .end() + // handle the share-can-edit-ITEMPTYPE-ITEMSOURCE-0 checkbox and label + .find('#' + editCheckboxIdStub + '0') + .prop('id', editCheckboxIdStub + curEditCheckboxId) + .end() + .find('label[for=' + editCheckboxIdStub + '0]') + .prop('for', editCheckboxIdStub + curEditCheckboxId) + .end() + // remove the "stub" class + .removeClass('stub') + // append it where it's needed most + $(shareWithInput) + .parents('.share-interface-container.internal-share') + .children('.shared-with-list') + .append(newitem) + // clear + $(shareWithInput).val(''); }); return false; } });}); - $('.shareactions > input:checkbox').change(function() { - var container = $(this).parents('li').first(); - var permissions = parseInt(container.data('permissions')); - var itemType = container.data('item-type'); - var shareType = container.data('share-type'); - var itemSource = container.data('item'); - var shareWith = container.data('share-with'); - var permission = null; - if($(this).hasClass('update')) { - permission = OC.PERMISSION_UPDATE; - permission = OC.PERMISSION_DELETE; - } else if($(this).hasClass('share')) { - permission = OC.PERMISSION_SHARE; - } - // This is probably not the right way, but it works :-P - if($(this).is(':checked')) { - permissions += permission; - } else { - permissions -= permission; - } + // using .off() to make sure the event is only attached once + $(document) + .off('change', '.shared-with-entry-container input:checkbox[data-permissions]') + .on('change', '.shared-with-entry-container input:checkbox[data-permissions]', function(){ - container.data('permissions',permissions); - - OC.Share.setPermissions(itemType, itemSource, shareType, shareWith, permissions); - }); + console.log('PERMISSIONS!') + var container = $(this).parents('li').first(); + var permissions = parseInt(container.data('permissions')); + var itemType = container.data('item-type'); + var shareType = container.data('share-type'); + var itemSource = container.data('item'); + var shareWith = container.data('share-with'); + var permission = null; + if($(this).hasClass('update')) { + permission = OC.PERMISSION_UPDATE; + permission = OC.PERMISSION_DELETE; + } else if($(this).hasClass('share')) { + permission = OC.PERMISSION_SHARE; + } + // This is probably not the right way, but it works :-P + if($(this).is(':checked')) { + permissions += permission; + } else { + permissions -= permission; + } + + container.data('permissions',permissions); + console.log('setting permissions to: ' + permissions) + + //OC.Share.setPermissions(itemType, itemSource, shareType, shareWith, permissions); + }); - $('.shareactions > .delete').click(function() { - var container = $(this).parents('li').first(); - var itemType = container.data('item-type'); - var shareType = container.data('share-type'); - var itemSource = container.data('item'); - var shareWith = container.data('share-with'); - OC.Share.unshare(itemType, itemSource, shareType, shareWith, function() { - container.remove(); - }); - }); + // using .off() to make sure the event is only attached once + $(document) + .off('click', '.shared-with-entry-container .unshare') + .on('click', '.shared-with-entry-container .unshare', function(e) { + var container = $(this).parents('li').first(); + var itemType = container.data('item-type'); + var shareType = container.data('share-type'); + var itemSource = container.data('item'); + var shareWith = container.data('share-with'); + OC.Share.unshare(itemType, itemSource, shareType, shareWith, function() { + container.remove(); + }); + }); } } }, diff --git a/templates/part.internalshare.php b/templates/part.internalshare.php index 40ae3c3f..7c49ff79 100644 --- a/templates/part.internalshare.php +++ b/templates/part.internalshare.php @@ -1,19 +1,41 @@
    + data-item-source="" + data-item-type="" + data-permissions="" + autocomplete="off" />