Skip to content

Commit

Permalink
Correctly update the context info when changing paths.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thet committed Feb 19, 2021
1 parent 6574033 commit c6cd472
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 43 deletions.
5 changes: 5 additions & 0 deletions 1041.bugfix
Original file line number Diff line number Diff line change
@@ -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]
51 changes: 28 additions & 23 deletions mockup/patterns/structure/js/views/addmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<li/>');
// 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 = $('<li/>');
// 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();
Expand Down
16 changes: 10 additions & 6 deletions mockup/patterns/structure/js/views/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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',
Expand Down
10 changes: 7 additions & 3 deletions mockup/patterns/structure/js/views/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ define([
'<input type="text" name="upload" style="display:none" />' +
'<div class="uploadify-me"></div>'),

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() {
Expand Down
23 changes: 12 additions & 11 deletions mockup/patterns/structure/pattern-structureupdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '&nbsp;');
}
if (this.options.descriptionSelector) {
$(this.options.descriptionSelector, this.$el).html(data.object && data.object.Description || '&nbsp;');
}
}.bind(this));
context_info_loaded_handler: function (e, data) {
if (this.options.titleSelector) {
$(this.options.titleSelector, this.$el).html(data.object && data.object.Title || '&nbsp;');
}
if (this.options.descriptionSelector) {
$(this.options.descriptionSelector, this.$el).html(data.object && data.object.Description || '&nbsp;');
}
},

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));
}

});
Expand Down

0 comments on commit c6cd472

Please sign in to comment.