Fix toggle element being removed when MainFileInfoView is rendered again

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>
This commit is contained in:
Daniel Calviño Sánchez 2017-06-09 08:57:34 +02:00
parent 2384703cf6
commit 365d7918b2
2 changed files with 26 additions and 10 deletions

View File

@ -31,7 +31,16 @@
return; 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;
}
});
} }
}; };

View File

@ -63,6 +63,13 @@
this._toggleHandle = $('<span>').addClass('tag-label').text(t('systemtags', 'Tags')); this._toggleHandle = $('<span>').addClass('tag-label').text(t('systemtags', 'Tags'));
this._toggleHandle.prepend($('<span>').addClass('icon icon-tag')); 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');
}
});
}, },
/** /**
@ -112,6 +119,15 @@
this.selectedTagsCollection.remove(tagId); 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) { setFileInfo: function(fileInfo) {
var self = this; var self = this;
if (!this._rendered) { if (!this._rendered) {
@ -147,15 +163,6 @@
this.$el.append(this._inputView.$el); this.$el.append(this._inputView.$el);
this._inputView.render(); 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() { remove: function() {