]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix toggle element being removed when MainFileInfoView is rendered again
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Fri, 9 Jun 2017 06:57:34 +0000 (08:57 +0200)
committerDaniel Calviño Sánchez <danxuliu@gmail.com>
Tue, 13 Jun 2017 14:41:21 +0000 (16:41 +0200)
The toggle element was added to the MainFileInfoView element when
SystemTagsInfoView was rendered. However, if the MainFileInfoView was
rendered again after that the toggle element was removed. Therefore,
instead of adding it when SystemTagsInfoView is rendered, the toggle
element has to be added when MainFileInfoView triggers its "post-render"
event.

Note, however, that when MainFileInfoView is rendered all the events are
removed from its child elements. As the toggle uses a "click" event
either the event has to be added back or the element has to be detached
before the MainFileInfoView is rendered.

Fixes #4944

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
apps/systemtags/js/filesplugin.js
apps/systemtags/js/systemtagsinfoview.js

index db97b91a0726e350afc95b535a4539ed167fa5c5..229d64da9d516cf15ddbb8a45f846364716692ba 100644 (file)
                                return;
                        }
 
-                       fileList.registerDetailView(new OCA.SystemTags.SystemTagsInfoView());
+                       var systemTagsInfoView = new OCA.SystemTags.SystemTagsInfoView();
+                       fileList.registerDetailView(systemTagsInfoView);
+
+                       _.each(fileList.getRegisteredDetailViews(), function(detailView) {
+                               if (detailView instanceof OCA.Files.MainFileInfoDetailView) {
+                                       systemTagsInfoView.setMainFileInfoView(detailView);
+
+                                       return;
+                               }
+                       });
                }
        };
 
index f98c4b046e4cf0b30766a2c659a05660cb2d9423..ce5de2048ab5ce797696c86592059ab933f5ba38 100644 (file)
 
                        this._toggleHandle = $('<span>').addClass('tag-label').text(t('systemtags', 'Tags'));
                        this._toggleHandle.prepend($('<span>').addClass('icon icon-tag'));
+
+                       this._toggleHandle.on('click', function () {
+                               self.$el.toggleClass('hidden');
+                               if (!self.$el.hasClass('hidden')) {
+                                       self.$el.find('.systemTagsInputField').select2('open');
+                               }
+                       });
                },
 
                /**
                        this.selectedTagsCollection.remove(tagId);
                },
 
+               setMainFileInfoView: function(mainFileInfoView) {
+                       this.listenTo(mainFileInfoView, 'pre-render', function() {
+                               this._toggleHandle.detach();
+                       });
+                       this.listenTo(mainFileInfoView, 'post-render', function() {
+                               mainFileInfoView.$el.find('.file-details').append(this._toggleHandle);
+                       });
+               },
+
                setFileInfo: function(fileInfo) {
                        var self = this;
                        if (!this._rendered) {
 
                        this.$el.append(this._inputView.$el);
                        this._inputView.render();
-
-                       $('#app-sidebar').find('.mainFileInfoView .file-details').append(this._toggleHandle);
-                       this._toggleHandle.off('click');
-                       this._toggleHandle.on('click', function () {
-                               self.$el.toggleClass('hidden');
-                               if (!self.$el.hasClass('hidden')) {
-                                       self.$el.find('.systemTagsInputField').select2('open');
-                               }
-                       });
                },
 
                remove: function() {