Skip to content

Commit

Permalink
Merge pull request #1031 from plone/fredvd-unreregister-eventhandlers
Browse files Browse the repository at this point in the history
prevent double xhr requests with folder navigation in structure pattern
  • Loading branch information
jensens authored Nov 9, 2020
2 parents 98675cb + 620a873 commit bef28e9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mockup/patterns/structure/js/views/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ define([
},
setCurrentPath: function(path) {
this.collection.setCurrentPath(path);
this.textfilter.clearTerm();
this.textfilter.clearTerm(false);
this.clearStatus();
},
getAjaxUrl: function(url) {
Expand Down
3 changes: 2 additions & 1 deletion mockup/patterns/structure/js/views/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ define([
self.subsetIds = [];
self.contextInfo = null;

$('body').on('context-info-loaded', function(event, data) {
$('body').off('context-info-loaded').on('context-info-loaded', function(event, data) {

self.contextInfo = data;
/* set default page info */
self.setContextInfo();
Expand Down
15 changes: 8 additions & 7 deletions mockup/patterns/structure/js/views/textfilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ define([
setFilterStatusMessage: function() {
var clear_btn = $('<button type="button" class="btn btn-primary btn-xs"></button>')
.text(_t('Clear'))
.on('click', function() {
.off('click.textfilter').on('click.textfilter', function() {
this.clearFilter();
}.bind(this));

Expand All @@ -66,15 +66,16 @@ define([
}
},

setTerm: function(term, set_input) {
setTerm: function(term, set_input, refresh) {
var term_el = this.$el[0].querySelector('.search-query');
this.term = encodeURIComponent(term);
if (set_input) {
term_el.value = term;
}
this.app.collection.currentPage = 1;
this.app.collection.pager();

if (refresh === undefined || refresh == true) {
this.app.collection.currentPage = 1;
this.app.collection.pager();
}
if (term) {
term_el.classList.add('has-filter');
this.setFilterStatusMessage();
Expand Down Expand Up @@ -127,8 +128,8 @@ define([
}
},

clearTerm: function() {
this.setTerm('', true);
clearTerm: function(refresh) {
this.setTerm('', true, refresh);
},

clearFilter: function() {
Expand Down
3 changes: 2 additions & 1 deletion mockup/patterns/structure/pattern-structureupdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ define([

init: function() {

$('body').on('context-info-loaded', function (e, data) {
$('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;');
}
Expand Down
1 change: 1 addition & 0 deletions news/3203.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent a folder_contents navigation from triggering the double amount of XHR requests through the text filter. Also correctly unregister/register events with a namespace in the structure pattern.[fredvd]

0 comments on commit bef28e9

Please sign in to comment.