Skip to content

Commit

Permalink
[fix] Fixed multiple requests made for fetching default template values
Browse files Browse the repository at this point in the history
openwisp#423 (openwisp#424)

The JS code made multiple HTTP request for fetching default template
values when any of organization or backend field were updated.

Fixed it by not triggering "click" event of sortedm2m-items and manaully
updating primary keys of templates using JS.

Closes openwisp#423
  • Loading branch information
pandafy committed Apr 8, 2021
1 parent 3d82c1e commit 3b955a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ django.jQuery(function ($) {
$.get(url).done(function (data) {
unCheckInputs();
$.each(data.default_templates, function (i, uuid) {
$('input.sortedm2m[value=' + uuid + ']').trigger('click');
$('input.sortedm2m[value=' + uuid + ']').prop('checked', true);
});
$('input[name="config-0-templates"]').attr('value', data.default_templates.join(','));
$('.sortedm2m-items:first').trigger('change');

});
},
bindDefaultTemplateLoading = function (urlSchema) {
Expand Down
11 changes: 5 additions & 6 deletions openwisp_controller/config/static/config/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,6 @@
}
});

// fill device context field with default values of selected templates.
getDefaultValues(true);

$('.sortedm2m-items').on('change', function() {
getDefaultValues();
});
// so that other files can use updateContext
window.updateContext = updateContext;
};
Expand Down Expand Up @@ -378,6 +372,11 @@
addConfig.click(bindLoadUi);
// otherwise load immediately
bindLoadUi();
// fill device context field with default values of selected templates.
getDefaultValues(true);
$('.sortedm2m-items').on('change', function() {
getDefaultValues();
});
});
}(django.jQuery));

Expand Down

0 comments on commit 3b955a2

Please sign in to comment.