From c6cd47201bb1062446ce1d12a1382b33e78f733f Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Fri, 19 Feb 2021 14:37:23 +0100 Subject: [PATCH] Correctly update the context info when changing paths. Do only remove the correct event listener on ``context-info-loaded`` before adding a new one. Fixes a problem where the current path was not updated for the upload popup when changing paths. Fixes: #1016 Refs: #1028, #1030, #1039 --- 1041.bugfix | 5 ++ mockup/patterns/structure/js/views/addmenu.js | 51 ++++++++++--------- mockup/patterns/structure/js/views/table.js | 16 +++--- mockup/patterns/structure/js/views/upload.js | 10 ++-- .../structure/pattern-structureupdater.js | 23 +++++---- 5 files changed, 62 insertions(+), 43 deletions(-) create mode 100644 1041.bugfix diff --git a/1041.bugfix b/1041.bugfix new file mode 100644 index 000000000..a14b2bd4a --- /dev/null +++ b/1041.bugfix @@ -0,0 +1,5 @@ +Do only remove the correct event listener on ``context-info-loaded`` before adding a new one. +Fixes a problem where the current path was not updated for the upload popup when changing paths. +Fixes: #1016 +Refs: #1028, #1030, #1039 +[thet] diff --git a/mockup/patterns/structure/js/views/addmenu.js b/mockup/patterns/structure/js/views/addmenu.js index 60333a37c..d377321b1 100644 --- a/mockup/patterns/structure/js/views/addmenu.js +++ b/mockup/patterns/structure/js/views/addmenu.js @@ -11,34 +11,39 @@ define([ title: 'Add', className: 'btn-group addnew', events: {}, - initialize: function(options) { + + context_info_loaded_handler: function(event, data) { + this.$items.empty(); var self = this; - ButtonGroup.prototype.initialize.apply(self, [options]); - $('body').on('context-info-loaded', function(event, data) { - self.$items.empty(); - _.each(data.addButtons, function(item) { - var view = new ButtonView({ - id: item.id, - title: item.title, - url: item.action - }); - view.render(); - var wrap = $('
  • '); - // As we are reusing the whole ButtonView for render the add content - // list we should remove entirely the "btn btn-default" classes. - // This element in fact, should not have any class at all, so we - // remove the attribute completely - view.$el.removeAttr('class'); + _.each(data.addButtons, function(item) { + var view = new ButtonView({ + id: item.id, + title: item.title, + url: item.action + }); + view.render(); + var wrap = $('
  • '); + // As we are reusing the whole ButtonView for render the add content + // list we should remove entirely the "btn btn-default" classes. + // This element in fact, should not have any class at all, so we + // remove the attribute completely + view.$el.removeAttr('class'); - wrap.append(view.el); - self.$items.append(wrap); - view.$el.click(function(e) { - self.buttonClicked.apply(self, [e, view]); - return false; - }); + wrap.append(view.el); + self.$items.append(wrap); + view.$el.click(function(e) { + self.buttonClicked.apply(self, [e, view]); + return false; }); }); }, + + initialize: function(options) { + ButtonGroup.prototype.initialize.apply(this, [options]); + $('body') + .off('context-info-loaded', this.context_info_loaded_handler.bind(this)) + .on('context-info-loaded', this.context_info_loaded_handler.bind(this)); + }, buttonClicked: function(e, button) { var self = this; e.preventDefault(); diff --git a/mockup/patterns/structure/js/views/table.js b/mockup/patterns/structure/js/views/table.js index 2ef5c297b..b90fb1974 100644 --- a/mockup/patterns/structure/js/views/table.js +++ b/mockup/patterns/structure/js/views/table.js @@ -19,6 +19,13 @@ define([ var TableView = BaseView.extend({ tagName: 'div', template: _.template(TableTemplate), + + context_info_loaded_handler: function(event, data) { + this.contextInfo = data; + /* set default page info */ + this.setContextInfo(); + }, + initialize: function(options) { var self = this; BaseView.prototype.initialize.apply(self, [options]); @@ -31,12 +38,9 @@ define([ self.subsetIds = []; self.contextInfo = null; - $('body').off('context-info-loaded').on('context-info-loaded', function(event, data) { - - self.contextInfo = data; - /* set default page info */ - self.setContextInfo(); - }); + $('body') + .off('context-info-loaded', this.context_info_loaded_handler.bind(this)) + .on('context-info-loaded', this.context_info_loaded_handler.bind(this)); self.dateColumns = [ 'ModificationDate', diff --git a/mockup/patterns/structure/js/views/upload.js b/mockup/patterns/structure/js/views/upload.js index c344d3c21..0317a9864 100644 --- a/mockup/patterns/structure/js/views/upload.js +++ b/mockup/patterns/structure/js/views/upload.js @@ -12,14 +12,18 @@ define([ '' + '
    '), + context_info_loaded_handler: function(event, data) { + this.currentPathData = data; + }, + initialize: function(options) { var self = this; self.app = options.app; PopoverView.prototype.initialize.apply(self, [options]); self.currentPathData = null; - $('body').on('context-info-loaded', function(event, data) { - self.currentPathData = data; - }); + $('body') + .off('context-info-loaded', this.context_info_loaded_handler.bind(this)) + .on('context-info-loaded', this.context_info_loaded_handler.bind(this)); }, render: function() { diff --git a/mockup/patterns/structure/pattern-structureupdater.js b/mockup/patterns/structure/pattern-structureupdater.js index 87556bc25..789b3fdbb 100644 --- a/mockup/patterns/structure/pattern-structureupdater.js +++ b/mockup/patterns/structure/pattern-structureupdater.js @@ -24,18 +24,19 @@ define([ descriptionSelector: '' }, - init: function() { - - $('body').off('context-info-loaded').on('context-info-loaded', function (e, data) { - - if (this.options.titleSelector) { - $(this.options.titleSelector, this.$el).html(data.object && data.object.Title || ' '); - } - if (this.options.descriptionSelector) { - $(this.options.descriptionSelector, this.$el).html(data.object && data.object.Description || ' '); - } - }.bind(this)); + context_info_loaded_handler: function (e, data) { + if (this.options.titleSelector) { + $(this.options.titleSelector, this.$el).html(data.object && data.object.Title || ' '); + } + if (this.options.descriptionSelector) { + $(this.options.descriptionSelector, this.$el).html(data.object && data.object.Description || ' '); + } + }, + init: function() { + $('body') + .off('context-info-loaded', this.context_info_loaded_handler.bind(this)) + .on('context-info-loaded', this.context_info_loaded_handler.bind(this)); } });