]> source.dussan.org Git - nextcloud-server.git/commitdiff
Dynamically update shared status icon
authorMichael Gapczynski <mtgap@owncloud.com>
Fri, 24 Aug 2012 19:32:06 +0000 (15:32 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Fri, 24 Aug 2012 19:32:06 +0000 (15:32 -0400)
core/js/share.js

index bd1fa14d3f573b7ace03394e4366d2d268997a62..3db69dc69010287b2d13e45dd20fd4e823fc1557 100644 (file)
@@ -30,6 +30,34 @@ OC.Share={
                        }
                });
        },
+       updateIcon:function(itemType, itemSource) {
+               if (itemType == 'file' || itemType == 'folder') {
+                       var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file');
+                       if ($('#dir').val() == '/') {
+                               itemSource = $('#dir').val() + filename;
+                       } else {
+                               itemSource = $('#dir').val() + '/' + filename;
+                       }
+               }
+               var shares = false;
+               $.each(OC.Share.itemShares, function(index) {
+                       if (OC.Share.itemShares[index].length > 0) {
+                               shares = true;
+                               return;
+                       }
+               });
+               if (shares) {
+                       $('a.share[data-item="'+itemSource+'"]').css('background', 'url('+OC.imagePath('core', 'actions/shared')+') no-repeat center');
+                       if (typeof OC.Share.statuses[itemSource] === 'undefined') {
+                               OC.Share.statuses[itemSource] = false;
+                       }
+               } else {
+                       if (itemType != 'file' && itemType != 'folder') {
+                               $('a.share[data-item="'+itemSource+'"]').css('background', 'url('+OC.imagePath('core', 'actions/share')+') no-repeat center');
+                       }
+                       delete OC.Share.statuses[itemSource];
+               }
+       },
        loadItem:function(itemType, itemSource) {
                var data = '';
                var checkReshare = true;
@@ -122,7 +150,6 @@ OC.Share={
                                                OC.Share.showPrivateLink(item, share.share_with);
                                        } else {
                                                OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions);
-                                               
                                        }
                                });
                        }
@@ -149,14 +176,17 @@ OC.Share={
                                event.preventDefault();
                        },
                        select: function(event, selected) {
+                               var itemType = $('#dropdown').data('item-type');
+                               var itemSource = $('#dropdown').data('item-source');
                                var shareType = selected.item.value.shareType;
                                var shareWith = selected.item.value.shareWith;
                                $(this).val(shareWith);
                                // 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-source'), shareType, shareWith, permissions, function() {
+                               OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, function() {
                                        OC.Share.addShareWith(shareType, shareWith, permissions, possiblePermissions);
                                        $('#shareWith').val('');
+                                       OC.Share.updateIcon(itemType, itemSource);
                                });
                                return false;
                        }
@@ -327,12 +357,15 @@ $(document).ready(function() {
 
        $('.unshare').live('click', function() {
                var li = $(this).parent();
+               var itemType = $('#dropdown').data('item-type');
+               var itemSource = $('#dropdown').data('item-source');
                var shareType = $(li).data('share-type');
                var shareWith = $(li).data('share-with');
-               OC.Share.unshare($('#dropdown').data('item-type'), $('#dropdown').data('item-source'), shareType, shareWith, function() {
+               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);
+                       OC.Share.updateIcon(itemType, itemSource);
                });
        });