10000 fix: Apphook widget detection (#8263) (#8264) · django-cms/django-cms@9554e87 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9554e87

Browse files
authored
fix: Apphook widget detection (#8263) (#8264)
* fix: Apphook widget detection * Fix: Add related
1 parent 78465d0 commit 9554e87

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

cms/static/cms/js/widgets/forms.apphookselect.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,40 @@ __webpack_public_path__ = require('../modules/get-dist-path')('bundle.forms.apph
1010
// #############################################################################
1111
// APP HOOK SELECT
1212
require.ensure([], function (require) {
13-
var $ = require('jquery');
14-
var apphookData = {
13+
const $ = require('jquery');
14+
let apphookData = {
1515
apphooks_configuration: {},
1616
apphooks_configuration_value: undefined,
1717
apphooks_configuration_url: {}
1818
};
19-
var dataElement = document.querySelector('script[data-cms-widget-applicationconfigselect]');
20-
21-
if (dataElement) {
22-
apphookData = JSON.parse(dataElement.querySelector('script').textContent);
23-
}
24-
25-
var apphooks_configuration = apphookData.apphooks_configuration || {};
2619

2720
// shorthand for jQuery(document).ready();
2821
$(function () {
29-
var appHooks = $('#application_urls, #id_application_urls');
30-
var selected = appHooks.find('option:selected');
31-
var appNsRow = $('.form-row.application_namespace, .form-row.field-application_namespace');
32-
var appNs = appNsRow.find('#application_namespace, #id_application_namespace');
33-
var appCfgsRow = $('.form-row.application_configs, .form-row.field-application_configs');
34-
var appCfgs = appCfgsRow.find('#application_configs, #id_application_configs');
35-
var appCfgsAdd = appCfgsRow.find('#add_application_configs');
36-
var original_ns = appNs.val();
22+
const dataElement = document.querySelector('div[data-cms-widget-applicationconfigselect]');
23+
24+
if (dataElement) {
25+
apphookData = JSON.parse(dataElement.querySelector('script').textContent);
26+
}
27+
28+
const apphooks_configuration = apphookData.apphooks_configuration || {};
29+
30+
const appHooks = $('#application_urls, #id_application_urls');
31+
const selected = appHooks.find('option:selected');
32+
const appNsRow = $('.form-row.application_namespace, .form-row.field-application_namespace');
33+
const appNs = appNsRow.find('#application_namespace, #id_application_namespace');
34+
const appCfgsRow = $('.form-row.application_configs, .form-row.field-application_configs');
35+
const appCfgs = appCfgsRow.find('#application_configs, #id_application_configs');
36+
const appCfgsAdd = appCfgsRow.find('#add_application_configs');
37+
const original_ns = appNs.val();
3738

3839
// Shows / hides namespace / config selection widgets depending on the user input
3940
appHooks.setupNamespaces = function () {
40-
var opt = $(this).find('option:selected');
41+
const opt = $(this).find('option:selected');
4142

4243
if ($(appCfgs).length > 0 && apphooks_configuration[opt.val()]) {
4344
appCfgs.html('');
44-
for (var i = 0; i < apphooks_configuration[opt.val()].length; i++) {
45-
var selectedCfgs = '';
45+
for (let i = 0; i < apphooks_configuration[opt.val()].length; i++) {
46+
let selectedCfgs = '';
4647

4748
if (apphooks_configuration[opt.val()][i][0] === apphookData.apphooks_configuration_value) {
4849
selectedCfgs = 'selected="selected"';
@@ -58,7 +59,8 @@ require.ensure([], function (require) {
5859
// exists, and if it does - we add `_popup` ourselves, because otherwise the popup with
5960
// apphook creation form will not be dismissed correctly
6061
(window.showRelatedObjectPopup ? '?_popup=1' : ''));
61-
appCfgsAdd.on('click', function () {
62+
appCfgsAdd.on('click', function (ev) {
63+
ev.preventDefault();
6264
window.showAddAnotherPopup(this);
6365
});
6466
appCfgsRow.removeClass('hidden');

0 commit comments

Comments
 (0)
0