diff --git a/core/js/share.js b/core/js/share.js index 0157bcdba7..85b920a691 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -885,40 +885,6 @@ $(document).ready(function() { return false; }); - $(document).on('click', '#dropdown .unshare', function() { - var $li = $(this).closest('li'); - var itemType = $('#dropdown').data('item-type'); - var itemSource = $('#dropdown').data('item-source'); - var shareType = $li.data('share-type'); - var shareWith = $li.attr('data-share-with'); - var $button = $(this); - - if (!$button.is('a')) { - $button = $button.closest('a'); - } - - if ($button.hasClass('icon-loading-small')) { - // deletion in progress - return false; - } - $button.empty().addClass('icon-loading-small'); - - OC.Share.unshare(itemType, itemSource, shareType, shareWith, function() { - $li.remove(); - var index = OC.Share.itemShares[shareType].indexOf(shareWith); - OC.Share.itemShares[shareType].splice(index, 1); - // updated list of shares - OC.Share.currentShares[shareType].splice(index, 1); - $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares})); - OC.Share.updateIcon(itemType, itemSource); - if (typeof OC.Share.statuses[itemSource] === 'undefined') { - $('#expiration').slideUp(OC.menuSpeed); - } - }); - - return false; - }); - $(document).on('change', '#dropdown .permissions', function() { var li = $(this).closest('li'); if ($(this).attr('name') == 'edit') { diff --git a/core/js/sharedialogshareelistview.js b/core/js/sharedialogshareelistview.js index 895f14508d..dda2fe949a 100644 --- a/core/js/sharedialogshareelistview.js +++ b/core/js/sharedialogshareelistview.js @@ -212,6 +212,9 @@ }); } + var view = this; + this.$el.find('.unshare').click(function() { view.onUnshare(this, view); }); + return this; }, @@ -224,6 +227,24 @@ this._template = Handlebars.compile(TEMPLATE); } return this._template; + }, + + onUnshare: function(element, view) { + var $element = $(element); + + if($element.hasClass('icon-loading-small')) { + // in process + return; + } + $element.empty().addClass('icon-loading-small'); + + var $li = $element.closest('li'); + var shareType = $li.data('share-type'); + var shareWith = $li.attr('data-share-with'); + + view.model.removeShare(shareType, shareWith); + + return false; } }); diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index 3569c6ffd1..dabcc65c0a 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -121,15 +121,7 @@ }, removeLinkShare: function() { - var model = this; - var itemType = this.get('itemType'); - var itemSource = this.get('itemSource'); - - OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() { - model.fetch(); - //FIXME: updateIcon belongs to view - OC.Share.updateIcon(itemType, itemSource); - }); + this.removeShare(OC.Share.SHARE_TYPE_LINK, ''); }, setPublicUpload: function(allow) { @@ -179,6 +171,18 @@ }); }, + removeShare: function(shareType, shareWith) { + var model = this; + var itemType = this.get('itemType'); + var itemSource = this.get('itemSource'); + + OC.Share.unshare(itemType, itemSource, shareType, shareWith, function() { + model.fetch(); + //FIXME: updateIcon belongs to view + OC.Share.updateIcon(itemType, itemSource); + }); + }, + /** * @returns {boolean} */