8000 fix: Apphook widget detection by fsbraun · Pull Request #8263 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

fix: Apphook widget detection #8263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions cms/static/cms/js/widgets/forms.apphookselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,40 @@ __webpack_public_path__ = require('../modules/get-dist-path')('bundle.forms.apph
// #############################################################################
// APP HOOK SELECT
require.ensure([], function (require) {
var $ = require('jquery');
var apphookData = {
const $ = require('jquery');
let apphookData = {
apphooks_configuration: {},
apphooks_configuration_value: undefined,
apphooks_configuration_url: {}
};
var dataElement = document.querySelector('script[data-cms-widget-applicationconfigselect]');

if (dataElement) {
apphookData = JSON.parse(dataElement.querySelector('script').textContent);
}

var apphooks_configuration = apphookData.apphooks_configuration || {};

// shorthand for jQuery(document).ready();
$(function () {
var appHooks = $('#application_urls, #id_application_urls');
var selected = appHooks.find('option:selected');
var appNsRow = $('.form-row.application_namespace, .form-row.field-application_namespace');
var appNs = appNsRow.find('#application_namespace, #id_application_namespace');
var appCfgsRow = $('.form-row.application_configs, .form-row.field-application_configs');
var appCfgs = appCfgsRow.find('#application_configs, #id_application_configs');
var appCfgsAdd = appCfgsRow.find('#add_application_configs');
var original_ns = appNs.val();
const dataElement = document.querySelector('div[data-cms-widget-applicationconfigselect]');

if (dataElement) {
apphookData = JSON.parse(dataElement.querySelector('script').textContent);
}

const apphooks_configuration = apphookData.apphooks_configuration || {};

const appHooks = $('#application_urls, #id_application_urls');
const selected = appHooks.find('option:selected');
const appNsRow = $('.form-row.application_namespace, .form-row.field-application_namespace');
const appNs = appNsRow.find('#application_namespace, #id_application_namespace');
const appCfgsRow = $('.form-row.application_configs, .form-row.field-application_configs');
const appCfgs = appCfgsRow.find('#application_configs, #id_application_configs');
const appCfgsAdd = appCfgsRow.find('#add_application_configs');
const original_ns = appNs.val();

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

if ($(appCfgs).length > 0 && apphooks_configuration[opt.val()]) {
appCfgs.html('');
for (var i = 0; i < apphooks_configuration[opt.val()].length; i++) {
var selectedCfgs = '';
for (let i = 0; i < apphooks_configuration[opt.val()].length; i++) {
let selectedCfgs = '';

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