]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fixed sharing status update for new/uploaded files
authorVincent Petry <pvince81@owncloud.com>
Thu, 17 Oct 2013 09:59:13 +0000 (11:59 +0200)
committerVincent Petry <pvince81@owncloud.com>
Thu, 17 Oct 2013 12:56:38 +0000 (14:56 +0200)
Creating new files, folders or uploading files now have their sharing
icon updated accordingly.

For this, the global share status list that is cached in
OC.Share.statuses is reused for new files.

In OC.Share, split loadIcons into loadIcons + updateIcons.

Fixes #4977

Backport of 70c9652cdf6e00f1c62fb9a61d9dd4fb3e2c93c3

apps/files/js/file-upload.js
apps/files/js/fileactions.js
apps/files/js/filelist.js
apps/files_sharing/js/share.js
core/js/share.js

index 0877c6417e69a934ccb46a530626c3e8c5173c14..42f081126191f17f8199cd9730131160f47b07f9 100644 (file)
@@ -260,7 +260,7 @@ $(document).ready(function() {
                          getMimeIcon(result.data.mime,function(path){
                        tr.find('td.filename').attr('style','background-image:url('+path+')');
                          });
-                       FileActions.display(tr.find('td.filename'));
+                       FileActions.display(tr.find('td.filename'), true);
                        } else {
                          OC.dialogs.alert(result.data.message, t('core', 'Error'));
                        }
@@ -325,7 +325,7 @@ $(document).ready(function() {
                  getMimeIcon(mime,function(path){
                        tr.find('td.filename').attr('style','background-image:url('+path+')');
                  });
-                 FileActions.display(tr.find('td.filename'));
+                 FileActions.display(tr.find('td.filename'), true);
                });
                eventSource.listen('error',function(error){
                  $('#uploadprogressbar').fadeOut();
index 5976bb49912f9cf24c0bf6322771cc09017cc38b..dbbc57c3b6abc45e1752d69c10895e80021a1f6d 100644 (file)
@@ -61,7 +61,13 @@ var FileActions = {
                var actions = this.get(mime, type, permissions);
                return actions[name];
        },
-       display: function (parent) {
+       /**
+        * Display file actions for the given element
+        * @param parent "td" element of the file for which to display actions
+        * @param triggerEvent if true, triggers the fileActionsReady on the file
+        * list afterwards (false by default)
+        */
+       display: function (parent, triggerEvent) {
                FileActions.currentFile = parent;
                var actions = FileActions.get(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions());
                var file = FileActions.getCurrentFile();
@@ -140,6 +146,10 @@ var FileActions = {
                        element.on('click', {a: null, elem: parent, actionFunc: actions['Delete']}, actionHandler);
                        parent.parent().children().last().append(element);
                }
+
+               if (triggerEvent){
+                       $('#fileList').trigger(jQuery.Event("fileActionsReady"));
+               }
        },
        getCurrentFile: function () {
                return FileActions.currentFile.parent().attr('data-file');
index 40a4ae95c98ecc8b898e0a1a3d6b57cc9742ad3a..5dd9d45005afbfa05ef9d03abfff2a1b228508bd 100644 (file)
@@ -130,7 +130,7 @@ var FileList={
                if (hidden) {
                        tr.hide();
                }
-               FileActions.display(tr.find('td.filename'));
+               FileActions.display(tr.find('td.filename'), true);
                return tr;
        },
        refresh:function(data) {
@@ -473,7 +473,7 @@ $(document).ready(function(){
                                                data.context.attr('data-permissions', file.permissions);
                                                data.context.data('permissions', file.permissions);
                                        }
-                                       FileActions.display(data.context.find('td.filename'));
+                                       FileActions.display(data.context.find('td.filename'), true);
                                        if (FileList.loadingDone) {
                                                FileList.loadingDone(file.name, file.id);
                                        }
index b2efafde4e78868fcd062582bdad7e6c2c15d685..68f6f3ba76f6e9d1eba761b534ea9d91be85227d 100644 (file)
@@ -1,11 +1,19 @@
 $(document).ready(function() {
 
-       var disableSharing = $('#disableSharing').data('status');
+       var disableSharing = $('#disableSharing').data('status'),
+               sharesLoaded = false;
 
        if (typeof OC.Share !== 'undefined' && typeof FileActions !== 'undefined'  && !disableSharing) {
-
-               $('#fileList').one('fileActionsReady',function(){
-                       OC.Share.loadIcons('file');
+               $('#fileList').on('fileActionsReady',function(){
+                       if (!sharesLoaded){
+                               OC.Share.loadIcons('file');
+                               // assume that we got all shares, so switching directories
+                               // will not invalidate that list
+                               sharesLoaded = true;
+                       }
+                       else{
+                               OC.Share.updateIcons('file');
+                       }
                });
 
                FileActions.register('all', 'Share', OC.PERMISSION_READ, OC.imagePath('core', 'actions/share'), function(filename) {
@@ -38,4 +46,4 @@ $(document).ready(function() {
                        }
                });
        }
-});
\ No newline at end of file
+});
index 4fe510bb23d311cd83af3c5adaed8f73bf4a51ff..7ed91ee785a121755ec1e64eee4f8503d098b805 100644 (file)
@@ -4,57 +4,76 @@ OC.Share={
        SHARE_TYPE_LINK:3,
        SHARE_TYPE_EMAIL:4,
        itemShares:[],
-       statuses:[],
+       statuses:{},
        droppedDown:false,
+       /**
+        * Loads ALL share statuses from server, stores them in OC.Share.statuses then
+        * calls OC.Share.updateIcons() to update the files "Share" icon to "Shared"
+        * according to their share status and share type.
+        */
        loadIcons:function(itemType) {
                // Load all share icons
                $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getItemsSharedStatuses', itemType: itemType }, function(result) {
                        if (result && result.status === 'success') {
+                               OC.Share.statuses = {};
                                $.each(result.data, function(item, data) {
                                        OC.Share.statuses[item] = data;
-                                       var hasLink = data['link'];
-                                       // Links override shared in terms of icon display
-                                       if (hasLink) {
-                                               var image = OC.imagePath('core', 'actions/public');
-                                       } else {
-                                               var image = OC.imagePath('core', 'actions/shared');
-                                       }
-                                       if (itemType != 'file' && itemType != 'folder') {
-                                               $('a.share[data-item="'+item+'"]').css('background', 'url('+image+') no-repeat center');
-                                       } else {
-                                               var file = $('tr[data-id="'+item+'"]');
-                                               if (file.length > 0) {
-                                                       var action = $(file).find('.fileactions .action[data-action="Share"]');
-                                                       var img = action.find('img').attr('src', image);
-                                                       action.addClass('permanent');
-                                                       action.html(' '+t('core', 'Shared')).prepend(img);
-                                               } else {
-                                                       var dir = $('#dir').val();
-                                                       if (dir.length > 1) {
-                                                               var last = '';
-                                                               var path = dir;
-                                                               // Search for possible parent folders that are shared
-                                                               while (path != last) {
-                                                                       if (path == data['path']) {
-                                                                               var actions = $('.fileactions .action[data-action="Share"]');
-                                                                               $.each(actions, function(index, action) {
-                                                                                       var img = $(action).find('img');
-                                                                                       if (img.attr('src') != OC.imagePath('core', 'actions/public')) {
-                                                                                               img.attr('src', image);
-                                                                                               $(action).addClass('permanent');
-                                                                                               $(action).html(' '+t('core', 'Shared')).prepend(img);
-                                                                                       }
-                                                                               });
+                               });
+                               OC.Share.updateIcons(itemType);
+                       }
+               });
+       },
+       /**
+        * Updates the files' "Share" icons according to the known
+        * sharing states stored in OC.Share.statuses.
+        * (not reloaded from server)
+        */
+       updateIcons:function(itemType){
+               var item;
+               for (item in OC.Share.statuses){
+                       var data = OC.Share.statuses[item];
+
+                       var hasLink = data['link'];
+                       // Links override shared in terms of icon display
+                       if (hasLink) {
+                               var image = OC.imagePath('core', 'actions/public');
+                       } else {
+                               var image = OC.imagePath('core', 'actions/shared');
+                       }
+                       if (itemType != 'file' && itemType != 'folder') {
+                               $('a.share[data-item="'+item+'"]').css('background', 'url('+image+') no-repeat center');
+                       } else {
+                               var file = $('tr[data-id="'+item+'"]');
+                               if (file.length > 0) {
+                                       var action = $(file).find('.fileactions .action[data-action="Share"]');
+                                       var img = action.find('img').attr('src', image);
+                                       action.addClass('permanent');
+                                       action.html(' '+t('core', 'Shared')).prepend(img);
+                               } else {
+                                       var dir = $('#dir').val();
+                                       if (dir.length > 1) {
+                                               var last = '';
+                                               var path = dir;
+                                               // Search for possible parent folders that are shared
+                                               while (path != last) {
+                                                       if (path == data['path']) {
+                                                               var actions = $('.fileactions .action[data-action="Share"]');
+                                                               $.each(actions, function(index, action) {
+                                                                       var img = $(action).find('img');
+                                                                       if (img.attr('src') != OC.imagePath('core', 'actions/public')) {
+                                                                               img.attr('src', image);
+                                                                               $(action).addClass('permanent');
+                                                                               $(action).html(' '+t('core', 'Shared')).prepend(img);
                                                                        }
-                                                                       last = path;
-                                                                       path = OC.Share.dirname(path);
-                                                               }
+                                                               });
                                                        }
+                                                       last = path;
+                                                       path = OC.Share.dirname(path);
                                                }
                                        }
-                               });
+                               }
                        }
-               });
+               }
        },
        updateIcon:function(itemType, itemSource) {
                var shares = false;