mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-11-18 21:09:42 -05:00
feat: RBAC + SAML support
This commit is contained in:
469
templates/admin/base.html
Normal file
469
templates/admin/base.html
Normal file
@@ -0,0 +1,469 @@
|
||||
{% load i18n static jazzmin admin_urls %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
{% get_current_language_bidi as LANGUAGE_BIDI %}
|
||||
{% get_jazzmin_settings request as jazzmin_settings %}
|
||||
{% get_jazzmin_ui_tweaks as jazzmin_ui %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
<!-- Prevent admin panel being crawled by search engines -->
|
||||
<meta name="robots" content="none, noarchive">
|
||||
|
||||
<title>{% block title %}{{ title }} | {{ jazzmin_settings.site_title }}{% endblock %}</title>
|
||||
|
||||
<!-- Font Awesome Icons -->
|
||||
<link rel="stylesheet" href="{% static "vendor/fontawesome-free/css/all.min.css" %}">
|
||||
|
||||
<!-- Bootstrap and adminLTE -->
|
||||
<link rel="stylesheet" href="{% static "vendor/adminlte/css/adminlte.min.css" %}" id="adminlte-css">
|
||||
|
||||
<!-- Bootswatch theme -->
|
||||
{% if jazzmin_ui.theme.name != 'default' %}
|
||||
<link rel="stylesheet" href="{{ jazzmin_ui.theme.src }}" id="jazzmin-theme" />
|
||||
{% endif %}
|
||||
|
||||
{% if jazzmin_ui.dark_mode_theme %}
|
||||
<link rel="stylesheet" href="{{ jazzmin_ui.dark_mode_theme.src }}" id="jazzmin-dark-mode-theme" media="(prefers-color-scheme: dark)"/>
|
||||
{% endif %}
|
||||
|
||||
<!-- Custom fixes for django -->
|
||||
<link rel="stylesheet" href="{% static "jazzmin/css/main.css" %}">
|
||||
|
||||
{% if jazzmin_settings.custom_css %}
|
||||
<!-- Custom CSS -->
|
||||
<link rel="stylesheet" href="{% static jazzmin_settings.custom_css %}">
|
||||
{% endif %}
|
||||
|
||||
<!-- favicons -->
|
||||
<link rel="shortcut icon" href="{% static jazzmin_settings.site_icon %}" type="image/png">
|
||||
<link rel="icon" href="{% static jazzmin_settings.site_icon %}" sizes="32x32" type="image/png">
|
||||
|
||||
{% if jazzmin_settings.use_google_fonts_cdn %}
|
||||
<!-- Google Font: Source Sans Pro -->
|
||||
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
|
||||
{% endif %}
|
||||
|
||||
{% block extrastyle %} {% endblock %}
|
||||
{% block extrahead %} {% endblock %}
|
||||
</head>
|
||||
<body class="hold-transition{% if not jazzmin_settings.show_sidebar %} no-sidebar{% else %} sidebar-mini{% endif %} {% sidebar_status request %} {% if is_popup %}popup {% endif %}{% block bodyclass %}{% endblock %} {{ jazzmin_ui.body_classes }} {% if jazzmin_ui.dark_mode_theme %}theme-dark{% endif %}" data-admin-utc-offset="{% now "Z" %}">
|
||||
|
||||
<div class="wrapper">
|
||||
|
||||
{% if not is_popup %}
|
||||
<nav class="main-header navbar navbar-expand {{ jazzmin_ui.navbar_classes }}" id="jazzy-navbar">
|
||||
<ul class="navbar-nav">
|
||||
|
||||
{% if jazzmin_settings.show_sidebar %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item">
|
||||
<a href="{% url 'admin:index' %}" class="brand-link">
|
||||
<img src="{% static jazzmin_settings.site_logo %}" alt="{{ jazzmin_settings.site_header }} Logo" class="{{ jazzmin_settings.site_logo_classes }} brand-image" style="opacity: .8; margin: 0 0 0 5px;">
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% get_top_menu user request.current_app|default:"admin" as top_menu %}
|
||||
{% for link in top_menu %}
|
||||
<li class="nav-item d-none d-sm-inline-block{% if link.children %} dropdown{% endif %}">
|
||||
{% if link.children %}
|
||||
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
{{ link.name }}
|
||||
</a>
|
||||
<div class="dropdown-menu">
|
||||
{% for child in link.children %}
|
||||
<a class="dropdown-item" href="{{ child.url }}" {% if link.new_window %}target="_blank"{% endif %}>{{ child.name }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<a href="{{ link.url }}" class="nav-link" {% if link.new_window %}target="_blank"{% endif %}>{{ link.name }}</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% if jazzmin_settings.search_model %}
|
||||
{% for search_model in jazzmin_settings.search_models_parsed %}
|
||||
<form action="{{ search_model.search_url }}" method="GET" class="form-inline ml-3">
|
||||
<div class="input-group input-group-sm">
|
||||
<input class="form-control form-control-navbar" name="q" type="search" placeholder="{% trans 'Search' %} {{ search_model.search_name }}..." aria-label="{% trans 'Search' %} {{ search_model.search_name }}...">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-navbar" type="submit">
|
||||
<i class="fas fa-search"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<ul class="navbar-nav ml-auto">
|
||||
|
||||
{% if jazzmin_settings.show_ui_builder %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-widget="control-sidebar" data-slide="true" href="#" role="button">
|
||||
<i class="fas fa-th-large"></i>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if 'django.contrib.admindocs'|app_is_installed %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'django-admindocs-docroot' %}" role="button">
|
||||
<i class="fas fa-book"></i>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if jazzmin_settings.language_chooser %}
|
||||
{% get_available_languages as LANGUAGES %}
|
||||
{% get_language_info_list for LANGUAGES as languages %}
|
||||
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link btn" data-toggle="dropdown" href="#" title="Choose language">
|
||||
<i class="fas fa-globe" aria-hidden="true"></i>
|
||||
</a>
|
||||
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-left" id="jazzy-languagemenu">
|
||||
<form action="{% url 'set_language' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<input name="next" type="hidden" value="{{ request.get_full_path|remove_lang:LANGUAGE_CODE }}" />
|
||||
{% for language in languages %}
|
||||
<button
|
||||
type="submit"
|
||||
name="language"
|
||||
value="{{ language.code }}"
|
||||
class="dropdown-item {% if language.code == LANGUAGE_CODE %}active{% endif %}"
|
||||
lang="{{ language.code }}"
|
||||
>
|
||||
{{ language.name_local|title }}
|
||||
</button>
|
||||
{% endfor %}
|
||||
</form>
|
||||
</div>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link btn" data-toggle="dropdown" href="#" title="{{ request.user }}">
|
||||
<i class="far fa-user" aria-hidden="true"></i>
|
||||
</a>
|
||||
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-left" id="jazzy-usermenu">
|
||||
<span class="dropdown-header">{% trans 'Account' %}</span>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a href="{% url 'admin:password_change' %}" class="dropdown-item">
|
||||
<i class="fas fa-key mr-2"></i> {% trans 'Change password' %}
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<form id="logout-form" method="post" action="{% url 'admin:logout' %}">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="dropdown-item"><i class="fas fa-users mr-2"></i> {% translate 'Log out' %}</button>
|
||||
</form>
|
||||
{% get_user_menu user request.current_app|default:"admin" as user_menu %}
|
||||
{% for link in user_menu %}
|
||||
<div class="dropdown-divider"></div>
|
||||
<a href="{{ link.url }}" class="dropdown-item" {% if link.new_window %}target="_blank"{% endif %}>
|
||||
<i class="{{ link.icon }} mr-2"></i> {% trans link.name %}
|
||||
</a>
|
||||
{% endfor %}
|
||||
<div class="dropdown-divider"></div>
|
||||
{% if perms|can_view_self %}
|
||||
<a href="{% jazzy_admin_url request.user request.current_app|default:"admin" %}" class="dropdown-item dropdown-footer">{% trans 'See Profile' %}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
{% block sidebar %}
|
||||
{% if jazzmin_settings.show_sidebar %}
|
||||
{% get_side_menu as side_menu_list %}
|
||||
|
||||
<aside class="main-sidebar elevation-4 {{ jazzmin_ui.sidebar_classes }}" id="jazzy-sidebar">
|
||||
<a href="{% url 'admin:index' %}" class="brand-link {{ jazzmin_ui.brand_classes }}" id="jazzy-logo">
|
||||
<img src="{% static jazzmin_settings.site_logo %}" alt="{{ jazzmin_settings.site_header }} Logo" class="{{ jazzmin_settings.site_logo_classes }} brand-image elevation-3" style="opacity: .8">
|
||||
<span class="brand-text font-weight-light">{{ jazzmin_settings.site_brand }}</span>
|
||||
</a>
|
||||
|
||||
<div class="sidebar">
|
||||
{% comment %}
|
||||
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
|
||||
<div class="image">
|
||||
{% if jazzmin_settings|has_jazzmin_setting:"user_avatar" %}
|
||||
<img src="{% get_user_avatar request.user %}" width="160px" class="img-circle elevation-2" alt="User Image">
|
||||
{% else %}
|
||||
<i class="fas fa-inverse user-profile fa-user-circle"></i>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% comment %}
|
||||
<div class="info">
|
||||
{% if perms|can_view_self %}
|
||||
<a href="{% jazzy_admin_url request.user request.current_app|default:"admin" %}" class="d-block">{{ request.user }}</a>
|
||||
{% else %}
|
||||
<span class="d-block" style="color: white;">{{ request.user }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endcomment %}
|
||||
|
||||
<nav class="mt-2">
|
||||
<ul class="nav nav-pills nav-sidebar flex-column {{ jazzmin_ui.sidebar_list_classes }}" data-widget="treeview" role="menu" data-collapsible="false">
|
||||
|
||||
<li class="nav-item">
|
||||
<a href="/" class="nav-link">
|
||||
<i class="nav-icon fas fa-th-large"></i>
|
||||
<p>View Site</p>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
{% if jazzmin_settings.navigation_expanded %}
|
||||
{% for app in side_menu_list %}
|
||||
<li class="nav-header">{{ app.name }}</li>
|
||||
{% for model in app.models %}
|
||||
<li class="nav-item">
|
||||
{% if model.url %}
|
||||
<a href="{{ model.url }}" class="nav-link">
|
||||
<i class="nav-icon {{ model.icon }}"></i> <p>{{ model.name }}</p>
|
||||
</a>
|
||||
{% else %}
|
||||
<span class="nav-link disabled">
|
||||
<i class="nav-icon {{ model.icon }}"></i> <p>{{ model.name }}</p>
|
||||
</span>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% for app in side_menu_list %}
|
||||
<li class="nav-item has-treeview">
|
||||
<a href="#" class="nav-link">
|
||||
<i class="nav-icon {{ app.icon }}"></i>
|
||||
<p>{{ app.name|truncatechars:21 }} <i class="fas fa-angle-left right"></i></p>
|
||||
</a>
|
||||
<ul class="nav nav-treeview" style="display: none;">
|
||||
{% for model in app.models %}
|
||||
<li class="nav-item">
|
||||
<a href="{% if model.url %}{{ model.url }}{% else %}javascript:void(0){% endif %}" class="nav-link">
|
||||
<i class="nav-icon {{ model.icon }}"></i>
|
||||
<p>{{ model.name }}</p>
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</aside>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
|
||||
<div class="content-wrapper" {% if is_popup %}style="margin-left:0px; padding-top: 20px;"{% endif %}>
|
||||
{% block page_content %}
|
||||
{% if not is_popup %}
|
||||
<div class="content border-bottom mb-2">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-auto d-flex flex-grow-1 align-items-center">
|
||||
<h1 class="h4 m-0 pr-3 mr-3 border-right">{% block content_title %}{% endblock %}</h1>
|
||||
{% block breadcrumbs %}{% endblock %}
|
||||
</div>
|
||||
{% block page_actions %}{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="content">
|
||||
<div class="container-fluid">
|
||||
<section id="content" class="content">
|
||||
{% block messages %}
|
||||
{% for message in messages %}
|
||||
{% if message.tags == 'success' %}
|
||||
<div class="alert alert-success alert-dismissible">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×
|
||||
</button>
|
||||
<i class="icon fa fa-check"></i>{{ message|capfirst }}
|
||||
</div>
|
||||
{% elif message.tags == 'error' %}
|
||||
<div class="alert alert-danger alert-dismissible">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×
|
||||
</button>
|
||||
<i class="icon fa fa-ban"></i>{{ message|capfirst }}
|
||||
</div>
|
||||
{% elif message.tags == 'warning' %}
|
||||
<div class="alert alert-warning alert-dismissible">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×
|
||||
</button>
|
||||
<i class="icon fa fa-exclamation-triangle"></i>{{ message|capfirst }}
|
||||
</div>
|
||||
{% elif message.tags == 'info' %}
|
||||
<div class="alert alert-info alert-dismissible">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×
|
||||
</button>
|
||||
<i class="icon fa fa-info"></i>{{ message|capfirst }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endblock messages %}
|
||||
<div class="row">
|
||||
{% block content %} {% endblock %}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
{% block footer %}
|
||||
{% if not is_popup %}
|
||||
<footer class="main-footer {{ jazzmin_ui.footer_classes }}">
|
||||
<div class="float-right d-none d-sm-inline">
|
||||
<b>{% trans 'Jazzmin version' %}</b> {% get_jazzmin_version %}
|
||||
</div>
|
||||
{% autoescape off %}
|
||||
<strong>{% trans 'Copyright' %} © {% now 'Y' %} {{ jazzmin_settings.copyright }}.</strong> {% trans 'All rights reserved.' %}
|
||||
{% endautoescape %}
|
||||
</footer>
|
||||
{% if jazzmin_settings.show_ui_builder %}
|
||||
{% include 'jazzmin/includes/ui_builder_panel.html' %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
</div>
|
||||
|
||||
{% if jazzmin_settings.show_ui_builder %}
|
||||
<div id="codeBox" class="modal fade" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">{% trans 'UI Configuration' %}</h4>
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>{% trans 'Copy this info your settings file to persist these UI changes' %}</p>
|
||||
<pre><code></code></pre>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn {{ jazzmin_ui.button_classes.danger }}" data-dismiss="modal">{% trans 'Close' %}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="{% static "admin/js/vendor/jquery/jquery.js" %}"></script>
|
||||
<!-- Bootstrap 5 -->
|
||||
<script src="{% static "vendor/bootstrap/js/bootstrap.min.js" %}"></script>
|
||||
<!-- AdminLTE App -->
|
||||
<script src="{% static "vendor/adminlte/js/adminlte.min.js" %}"></script>
|
||||
<!-- Django customisations -->
|
||||
<script src="{% static "jazzmin/js/main.js" %}"></script>
|
||||
|
||||
{% if jazzmin_settings.custom_js %}
|
||||
<script src="{% static jazzmin_settings.custom_js %}"></script>
|
||||
{% endif %}
|
||||
|
||||
{% if jazzmin_settings.show_ui_builder %}
|
||||
<script>
|
||||
window.ui_changes = {{ jazzmin_ui.raw|as_json|safe }};
|
||||
</script>
|
||||
<script src="{% static "jazzmin/js/ui-builder.js" %}"></script>
|
||||
{% endif %}
|
||||
|
||||
{% block extrajs %}{% endblock %}
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const breadcrumbItems = document.querySelectorAll('.breadcrumb-item a');
|
||||
|
||||
breadcrumbItems.forEach(function(link) {
|
||||
if (link.getAttribute('href') === '/admin/account/') {
|
||||
link.setAttribute('href', '/admin/users/');
|
||||
link.textContent = 'Users';
|
||||
}
|
||||
|
||||
if (link.getAttribute('href') === '/admin/rbac/') {
|
||||
link.setAttribute('href', '/admin/users/');
|
||||
link.textContent = 'Users';
|
||||
}
|
||||
});
|
||||
|
||||
const identityProvidersHeader = Array.from(document.querySelectorAll('.nav-header')).find(
|
||||
header => header.textContent.trim() === 'Identity_Providers'
|
||||
);
|
||||
|
||||
if (identityProvidersHeader) {
|
||||
identityProvidersHeader.style.display = 'none';
|
||||
|
||||
const loginOptionsItem = document.querySelector('.nav-item a[href="/admin/identity_providers/loginoption/"]');
|
||||
if (loginOptionsItem) {
|
||||
loginOptionsItem.closest('.nav-item').style.display = 'none';
|
||||
}
|
||||
|
||||
const userLogsItem = document.querySelector('.nav-item a[href="/admin/identity_providers/identityprovideruserlog/"]');
|
||||
if (userLogsItem) {
|
||||
userLogsItem.closest('.nav-item').style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
const tables = document.querySelectorAll('table.table-sm');
|
||||
|
||||
for (const table of tables) {
|
||||
const userLink = table.querySelector('a[href="/admin/users/user/"]');
|
||||
if (userLink) {
|
||||
const tbody = table.querySelector('tbody');
|
||||
if (tbody) {
|
||||
const emailAddressesRow = document.createElement('tr');
|
||||
emailAddressesRow.innerHTML = `
|
||||
<td>
|
||||
<a href="/admin/account/emailaddress/">Email Addresses</a>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group float-right">
|
||||
<a href="/admin/account/emailaddress/add/" class="btn btn-xs btn-success addlink">Add</a>
|
||||
<a href="/admin/account/emailaddress/" class="btn btn-xs btn-info changelink">Change</a>
|
||||
</div>
|
||||
</td>
|
||||
`;
|
||||
|
||||
const groupsRow = document.createElement('tr');
|
||||
groupsRow.innerHTML = `
|
||||
<td>
|
||||
<a href="/admin/rbac/rbacgroup/">Groups</a>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group float-right">
|
||||
<a href="/admin/rbac/rbacgroup/add/" class="btn btn-xs btn-success addlink">Add</a>
|
||||
<a href="/admin/rbac/rbacgroup/" class="btn btn-xs btn-info changelink">Change</a>
|
||||
</div>
|
||||
</td>
|
||||
`;
|
||||
|
||||
tbody.appendChild(emailAddressesRow);
|
||||
tbody.appendChild(groupsRow);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
38
templates/admin/files/category/change_form.html
Normal file
38
templates/admin/files/category/change_form.html
Normal file
@@ -0,0 +1,38 @@
|
||||
{% extends 'admin/change_form.html' %}
|
||||
|
||||
{% block extrahead %}
|
||||
{{ block.super }}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Array of fields to modify
|
||||
const fieldNames = [
|
||||
'rbac_groups',
|
||||
];
|
||||
|
||||
// Process each field
|
||||
fieldNames.forEach(fieldName => {
|
||||
const fieldElement = document.querySelector(`.field-${fieldName}`);
|
||||
if (fieldElement) {
|
||||
const row = fieldElement.closest('.row');
|
||||
if (row) {
|
||||
const label = row.querySelector(`label[for="id_${fieldName}"]`);
|
||||
if (label) {
|
||||
label.remove();
|
||||
}
|
||||
|
||||
fieldElement.classList.remove('col-sm-7');
|
||||
fieldElement.classList.add('col-sm-12');
|
||||
|
||||
const otherColElements = row.querySelectorAll('.col-sm-7');
|
||||
otherColElements.forEach(colElement => {
|
||||
colElement.classList.remove('col-sm-7');
|
||||
colElement.classList.add('col-sm-12');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
30
templates/admin/identity_providers/change_form.html
Normal file
30
templates/admin/identity_providers/change_form.html
Normal file
@@ -0,0 +1,30 @@
|
||||
{% extends "admin/change_form.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block extrahead %}
|
||||
{{ block.super }}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const importCsvField = document.querySelector('.field-import_csv');
|
||||
let targetFieldset = null;
|
||||
|
||||
if (importCsvField) {
|
||||
targetFieldset = importCsvField.closest('fieldset.module.aligned');
|
||||
|
||||
const inlineFormsets = document.querySelectorAll('.js-inline-admin-formset');
|
||||
const lastInlineFormset = inlineFormsets[inlineFormsets.length - 1];
|
||||
|
||||
if (false && targetFieldset && lastInlineFormset) {
|
||||
lastInlineFormset.after(targetFieldset);
|
||||
}
|
||||
}
|
||||
|
||||
const providerLabel = document.querySelector('label[for="id_provider"]');
|
||||
if (providerLabel && providerLabel.textContent.includes('Provider:')) {
|
||||
providerLabel.textContent = providerLabel.textContent.replace('Provider:', 'Protocol:');
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
41
templates/admin/rbac/rbacgroup/change_form.html
Normal file
41
templates/admin/rbac/rbacgroup/change_form.html
Normal file
@@ -0,0 +1,41 @@
|
||||
{% extends 'admin/change_form.html' %}
|
||||
|
||||
{% block extrahead %}
|
||||
{{ block.super }}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Array of fields to modify
|
||||
const fieldNames = [
|
||||
'contributors_field',
|
||||
'managers_field',
|
||||
'members_field',
|
||||
'categories'
|
||||
];
|
||||
|
||||
// Process each field
|
||||
fieldNames.forEach(fieldName => {
|
||||
const fieldElement = document.querySelector(`.field-${fieldName}`);
|
||||
if (fieldElement) {
|
||||
const row = fieldElement.closest('.row');
|
||||
if (row) {
|
||||
const label = row.querySelector(`label[for="id_${fieldName}"]`);
|
||||
if (label) {
|
||||
label.remove();
|
||||
}
|
||||
|
||||
fieldElement.classList.remove('col-sm-7');
|
||||
fieldElement.classList.add('col-sm-12');
|
||||
|
||||
const otherColElements = row.querySelectorAll('.col-sm-7');
|
||||
otherColElements.forEach(colElement => {
|
||||
colElement.classList.remove('col-sm-7');
|
||||
colElement.classList.add('col-sm-12');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
153
templates/admin/socialaccount/socialapp/change_form.html
Normal file
153
templates/admin/socialaccount/socialapp/change_form.html
Normal file
@@ -0,0 +1,153 @@
|
||||
{% extends "admin/change_form.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block extrahead %}
|
||||
{{ block.super }}
|
||||
<script>
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
const continueButton = document.querySelector('input[name="_continue"]');
|
||||
const continueDiv = continueButton ? continueButton.closest('.form-group') : null;
|
||||
const saveButton = document.querySelector('input[name="_save"]');
|
||||
const saveDiv = saveButton ? saveButton.closest('.form-group') : null;
|
||||
|
||||
if (continueDiv && saveDiv) {
|
||||
saveDiv.parentNode.insertBefore(continueDiv, saveDiv);
|
||||
}
|
||||
|
||||
const addAnotherButton = document.querySelector('input[name="_addanother"]');
|
||||
const addAnotherDiv = addAnotherButton ? addAnotherButton.closest('.form-group') : null;
|
||||
|
||||
if (addAnotherDiv) {
|
||||
addAnotherDiv.parentNode.removeChild(addAnotherDiv);
|
||||
}
|
||||
|
||||
const styleEl = document.createElement('style');
|
||||
styleEl.textContent = `
|
||||
.csv-import-section label {
|
||||
font-weight: 600;
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.csv-import-section .help {
|
||||
color: #666;
|
||||
font-style: italic;
|
||||
margin-top: 5px;
|
||||
}
|
||||
.csv-import-section input[type="file"] {
|
||||
padding: 8px;
|
||||
border: 1px solid #ced4da;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
}
|
||||
.csv-import-section input[type="file"]:focus {
|
||||
border-color: #80bdff;
|
||||
outline: 0;
|
||||
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(styleEl);
|
||||
setTimeout(function() {
|
||||
moveFieldsToTabs();
|
||||
handleErrorsAndActivateTabs();
|
||||
performRestStuff();
|
||||
}, 500);
|
||||
|
||||
function moveFieldsToTabs() {
|
||||
const groupsImportCsvField = document.querySelector('.field-groups_csv');
|
||||
const categoriesImportCsvField = document.querySelector('.field-categories_csv');
|
||||
|
||||
const categoryMappingsTab = document.querySelector('#category-mapping-tab');
|
||||
const groupMappingsTab = document.querySelector('#group-mapping-tab');
|
||||
|
||||
if (groupsImportCsvField && groupMappingsTab) {
|
||||
groupsImportCsvField.classList.add('csv-import-section');
|
||||
|
||||
groupsImportCsvField.style.padding = '15px';
|
||||
groupsImportCsvField.style.margin = '0 0 20px 0';
|
||||
groupsImportCsvField.style.borderRadius = '5px';
|
||||
groupsImportCsvField.style.border = '1px solid #dee2e6';
|
||||
|
||||
const groupFieldTitle = document.createElement('h3');
|
||||
groupFieldTitle.style.marginTop = '0';
|
||||
groupFieldTitle.style.fontSize = '16px';
|
||||
groupsImportCsvField.insertBefore(groupFieldTitle, groupsImportCsvField.firstChild);
|
||||
|
||||
const groupCardHeader = groupMappingsTab.querySelector('.card-header');
|
||||
if (groupCardHeader) {
|
||||
groupCardHeader.parentNode.insertBefore(groupsImportCsvField, groupCardHeader);
|
||||
} else {
|
||||
groupMappingsTab.insertBefore(groupsImportCsvField, groupMappingsTab.firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
if (categoriesImportCsvField && categoryMappingsTab) {
|
||||
categoriesImportCsvField.classList.add('csv-import-section');
|
||||
|
||||
categoriesImportCsvField.style.padding = '15px';
|
||||
categoriesImportCsvField.style.margin = '0 0 20px 0';
|
||||
categoriesImportCsvField.style.borderRadius = '5px';
|
||||
categoriesImportCsvField.style.border = '1px solid #dee2e6';
|
||||
|
||||
const categoryFieldTitle = document.createElement('h3');
|
||||
categoryFieldTitle.style.marginTop = '0';
|
||||
categoryFieldTitle.style.fontSize = '16px';
|
||||
categoriesImportCsvField.insertBefore(categoryFieldTitle, categoriesImportCsvField.firstChild);
|
||||
|
||||
const categoryCardHeader = categoryMappingsTab.querySelector('.card-header');
|
||||
if (categoryCardHeader) {
|
||||
categoryCardHeader.parentNode.insertBefore(categoriesImportCsvField, categoryCardHeader);
|
||||
} else {
|
||||
categoryMappingsTab.insertBefore(categoriesImportCsvField, categoryMappingsTab.firstChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleErrorsAndActivateTabs() {
|
||||
// Check for errors in the moved fields
|
||||
const hasGroupsFieldError = document.querySelector('.field-groups_csv .errorlist');
|
||||
const hasCategoriesFieldError = document.querySelector('.field-categories_csv .errorlist');
|
||||
|
||||
const groupTab = document.querySelector('a[href="#group-mapping-tab"]');
|
||||
const categoryTab = document.querySelector('a[href="#category-mapping-tab"]');
|
||||
|
||||
if (hasGroupsFieldError && groupTab) {
|
||||
document.querySelectorAll('.nav-link').forEach(tab => tab.classList.remove('active'));
|
||||
document.querySelectorAll('.tab-pane').forEach(pane => pane.classList.remove('active', 'show'));
|
||||
|
||||
groupTab.classList.add('active');
|
||||
document.querySelector('#group-mapping-tab').classList.add('active', 'show');
|
||||
|
||||
hasGroupsFieldError.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
}
|
||||
else if (hasCategoriesFieldError && categoryTab) {
|
||||
document.querySelectorAll('.nav-link').forEach(tab => tab.classList.remove('active'));
|
||||
document.querySelectorAll('.tab-pane').forEach(pane => pane.classList.remove('active', 'show'));
|
||||
|
||||
categoryTab.classList.add('active');
|
||||
document.querySelector('#category-mapping-tab').classList.add('active', 'show');
|
||||
|
||||
hasCategoriesFieldError.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
}
|
||||
}
|
||||
|
||||
function performRestStuff() {
|
||||
const addLinks = document.querySelectorAll('.add-row a');
|
||||
addLinks.forEach(function(link) {
|
||||
link.textContent = 'Add';
|
||||
});
|
||||
|
||||
const plusIcons = document.querySelectorAll('td.original i.fas.fa-plus');
|
||||
plusIcons.forEach(function(icon) {
|
||||
icon.remove();
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
{% load i18n admin_urls static admin_modify %}
|
||||
|
||||
<style type="text/css">
|
||||
.help-text-inline {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
padding: 2px 0 0 0;
|
||||
}
|
||||
|
||||
.inline-group .tabular td {
|
||||
vertical-align: top;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<div class="js-inline-admin-formset inline-group" id="{{ inline_admin_formset.formset.prefix }}-group"
|
||||
data-inline-type="tabular"
|
||||
data-inline-formset="{{ inline_admin_formset.inline_formset_data }}">
|
||||
<div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
|
||||
{{ inline_admin_formset.formset.management_form }}
|
||||
<fieldset class="module {{ inline_admin_formset.classes }}">
|
||||
{{ inline_admin_formset.formset.non_form_errors }}
|
||||
<table class="table table-hover text-nowrap">
|
||||
<thead><tr>
|
||||
<th class="original"></th>
|
||||
{% for field in inline_admin_formset.fields %}
|
||||
{% if not field.widget.is_hidden %}
|
||||
<th class="column-{{ field.name }}{% if field.required %} required{% endif %}">{{ field.label|capfirst }}
|
||||
{% if field.help_text %}<img src="{% static "admin/img/icon-unknown.svg" %}" class="help help-tooltip" width="10" height="10" alt="({{ field.help_text|striptags }})" title="{{ field.help_text|striptags }}">{% endif %}
|
||||
</th>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %}<th>Actions</th>{% endif %}
|
||||
</tr></thead>
|
||||
|
||||
<tbody>
|
||||
{% for inline_admin_form in inline_admin_formset %}
|
||||
{% if inline_admin_form.form.non_field_errors %}
|
||||
<tr class="row-form-errors"><td colspan="{{ inline_admin_form|cell_count }}">{{ inline_admin_form.form.non_field_errors }}</td></tr>
|
||||
{% endif %}
|
||||
<tr class="form-row{% if inline_admin_form.original or inline_admin_form.show_url %} has_original{% endif %}{% if forloop.last and inline_admin_formset.has_add_permission %} empty-form{% endif %}"
|
||||
id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
|
||||
<td class="original">
|
||||
{% if inline_admin_form.original or inline_admin_form.show_url %}
|
||||
<p>
|
||||
{% if inline_admin_form.original %}
|
||||
{% if inline_admin_form.model_admin.show_change_link and inline_admin_form.model_admin.has_registered_model %}
|
||||
<a
|
||||
href="{% url inline_admin_form.model_admin.opts|admin_urlname:'change' inline_admin_form.original.pk|admin_urlquote %}"
|
||||
class="{% if inline_admin_formset.has_change_permission %}inlinechangelink{% else %}inlineviewlink{% endif %}">
|
||||
{% if inline_admin_formset.has_change_permission %}
|
||||
<i class="fas fa-pencil-alt fa-sm"> </i>
|
||||
{% else %}
|
||||
<i class="fas fa-eye fa-sm"> </i>
|
||||
{% endif %}
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% if inline_admin_form.show_url %}
|
||||
<a href="{{ inline_admin_form.absolute_url }}" title="{% trans "View on site" %}">
|
||||
<i class="fas fa-eye fa-sm"> </i>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</p>
|
||||
{% else %}
|
||||
<i class="fas fa-plus fa-sm text-success"> </i>
|
||||
{% endif %}
|
||||
{% if inline_admin_form.needs_explicit_pk_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
|
||||
{% if inline_admin_form.fk_field %}{{ inline_admin_form.fk_field.field }}{% endif %}
|
||||
{% spaceless %}
|
||||
{% for fieldset in inline_admin_form %}
|
||||
{% for line in fieldset %}
|
||||
{% for field in line %}
|
||||
{% if not field.is_readonly and field.field.is_hidden %}{{ field.field }}{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endspaceless %}
|
||||
</td>
|
||||
{% for fieldset in inline_admin_form %}
|
||||
{% for line in fieldset %}
|
||||
{% for field in line %}
|
||||
{% if field.is_readonly or not field.field.is_hidden %}
|
||||
<td {% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
|
||||
{% if field.is_readonly %}
|
||||
<p>{{ field.contents }}</p>
|
||||
{% else %}
|
||||
{{ field.field }}
|
||||
<div class="help-block text-red">
|
||||
{{ field.field.errors.as_ul }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %}
|
||||
<td class="delete">
|
||||
{{ inline_admin_form.deletion_field.field.as_hidden }}
|
||||
{% if inline_admin_form.original %}
|
||||
<div>
|
||||
<a href="#" class="inline-deletelink remove-row">{% trans "Remove" %}</a>
|
||||
{{ inline_admin_form.field_should_delete }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
|
||||
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
function initRemoveButtons() {
|
||||
const removeButtons = document.querySelectorAll('.inline-deletelink.remove-row');
|
||||
|
||||
removeButtons.forEach(function(button) {
|
||||
button.removeEventListener('click', handleRemoveClick);
|
||||
button.addEventListener('click', handleRemoveClick);
|
||||
});
|
||||
}
|
||||
|
||||
function handleRemoveClick(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const row = this.closest('tr');
|
||||
|
||||
fadeOut(row, 300);
|
||||
console.log(1)
|
||||
const formPrefix = row.id.split('-')[0];
|
||||
const rowNum = row.id.split('-')[1];
|
||||
const deleteField = document.getElementById('id_' + formPrefix + '-' + rowNum + '-should_delete');
|
||||
console.log(2)
|
||||
if (deleteField) {
|
||||
console.log(deleteField)
|
||||
deleteField.value = '1';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function fadeOut(element, duration) {
|
||||
let opacity = 1;
|
||||
const interval = 50;
|
||||
const delta = interval / duration;
|
||||
|
||||
function decreaseOpacity() {
|
||||
opacity -= delta;
|
||||
element.style.opacity = opacity;
|
||||
|
||||
if (opacity <= 0) {
|
||||
element.style.display = 'none';
|
||||
clearInterval(timer);
|
||||
}
|
||||
}
|
||||
|
||||
const timer = setInterval(decreaseOpacity, interval);
|
||||
}
|
||||
|
||||
initRemoveButtons();
|
||||
|
||||
const addRowButtons = document.querySelectorAll('.add-row a');
|
||||
addRowButtons.forEach(function(button) {
|
||||
button.addEventListener('click', function() {
|
||||
setTimeout(initRemoveButtons, 100);
|
||||
});
|
||||
});
|
||||
|
||||
function addHelpText() {
|
||||
var fields = document.querySelectorAll('.with-help-text');
|
||||
fields.forEach(function(field) {
|
||||
var helpText = field.getAttribute('data-help-text');
|
||||
if (helpText && !field.nextElementSibling?.classList.contains('help-text-inline')) {
|
||||
var helpElement = document.createElement('p');
|
||||
helpElement.className = 'help-text-inline';
|
||||
helpElement.textContent = helpText;
|
||||
field.parentNode.insertBefore(helpElement, field.nextSibling);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addHelpText();
|
||||
|
||||
document.addEventListener('formset:added', function(event) {
|
||||
setTimeout(addHelpText, 10);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,203 @@
|
||||
{% load i18n admin_urls static admin_modify %}
|
||||
|
||||
<style type="text/css">
|
||||
.help-text-inline {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
padding: 2px 0 0 0;
|
||||
}
|
||||
|
||||
.inline-group .tabular td {
|
||||
vertical-align: top;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<div class="js-inline-admin-formset inline-group" id="{{ inline_admin_formset.formset.prefix }}-group"
|
||||
data-inline-type="tabular"
|
||||
data-inline-formset="{{ inline_admin_formset.inline_formset_data }}">
|
||||
<div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
|
||||
<div id="group-mapping-warning-container" style="display: block; text-align: right; margin-bottom: 8px;">
|
||||
<div id="group-mapping-warning">
|
||||
<strong>Attention: Removing group mapping will also delete the named Group.</strong>
|
||||
<img src="{% static 'admin/img/icon-unknown.svg' %}" class="help help-tooltip" width="13" height="13" style="margin-left: 4px; vertical-align: middle;" alt="Help" title="Avoid deleting the group by unlinking the group from IDP under Users > Groups > IDP Config Name">
|
||||
</div>
|
||||
</div>
|
||||
{{ inline_admin_formset.formset.management_form }}
|
||||
<fieldset class="module {{ inline_admin_formset.classes }}">
|
||||
{{ inline_admin_formset.formset.non_form_errors }}
|
||||
<table class="table table-hover text-nowrap">
|
||||
<thead><tr>
|
||||
<th class="original"></th>
|
||||
{% for field in inline_admin_formset.fields %}
|
||||
{% if not field.widget.is_hidden %}
|
||||
<th class="column-{{ field.name }}{% if field.required %} required{% endif %}">{{ field.label|capfirst }}
|
||||
{% if field.help_text %}<img src="{% static "admin/img/icon-unknown.svg" %}" class="help help-tooltip" width="10" height="10" alt="({{ field.help_text|striptags }})" title="{{ field.help_text|striptags }}">{% endif %}
|
||||
</th>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %}<th>Actions</th>{% endif %}
|
||||
</tr></thead>
|
||||
|
||||
<tbody>
|
||||
{% for inline_admin_form in inline_admin_formset %}
|
||||
{% if inline_admin_form.form.non_field_errors %}
|
||||
<tr class="row-form-errors"><td colspan="{{ inline_admin_form|cell_count }}">{{ inline_admin_form.form.non_field_errors }}</td></tr>
|
||||
{% endif %}
|
||||
<tr class="form-row{% if inline_admin_form.original or inline_admin_form.show_url %} has_original{% endif %}{% if forloop.last and inline_admin_formset.has_add_permission %} empty-form{% endif %}"
|
||||
id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
|
||||
<td class="original">
|
||||
{% if inline_admin_form.original or inline_admin_form.show_url %}
|
||||
<p>
|
||||
{% if inline_admin_form.original %}
|
||||
{% if inline_admin_form.model_admin.show_change_link and inline_admin_form.model_admin.has_registered_model %}
|
||||
<a
|
||||
href="{% url inline_admin_form.model_admin.opts|admin_urlname:'change' inline_admin_form.original.pk|admin_urlquote %}"
|
||||
class="{% if inline_admin_formset.has_change_permission %}inlinechangelink{% else %}inlineviewlink{% endif %}">
|
||||
{% if inline_admin_formset.has_change_permission %}
|
||||
<i class="fas fa-pencil-alt fa-sm"> </i>
|
||||
{% else %}
|
||||
<i class="fas fa-eye fa-sm"> </i>
|
||||
{% endif %}
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% if inline_admin_form.show_url %}
|
||||
<a href="{{ inline_admin_form.absolute_url }}" title="{% trans "View on site" %}">
|
||||
<i class="fas fa-eye fa-sm"> </i>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</p>
|
||||
{% else %}
|
||||
<i class="fas fa-plus fa-sm text-success"> </i>
|
||||
{% endif %}
|
||||
{% if inline_admin_form.needs_explicit_pk_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
|
||||
{% if inline_admin_form.fk_field %}{{ inline_admin_form.fk_field.field }}{% endif %}
|
||||
{% spaceless %}
|
||||
{% for fieldset in inline_admin_form %}
|
||||
{% for line in fieldset %}
|
||||
{% for field in line %}
|
||||
{% if not field.is_readonly and field.field.is_hidden %}{{ field.field }}{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endspaceless %}
|
||||
</td>
|
||||
{% for fieldset in inline_admin_form %}
|
||||
{% for line in fieldset %}
|
||||
{% for field in line %}
|
||||
{% if field.is_readonly or not field.field.is_hidden %}
|
||||
<td {% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
|
||||
{% if field.is_readonly %}
|
||||
<p>{{ field.contents }}</p>
|
||||
{% else %}
|
||||
{{ field.field }}
|
||||
<div class="help-block text-red">
|
||||
{{ field.field.errors.as_ul }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
{% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %}
|
||||
<td class="delete">
|
||||
{{ inline_admin_form.deletion_field.field.as_hidden }}
|
||||
{% if inline_admin_form.original %}
|
||||
<div>
|
||||
<a href="#" class="inline-deletelink remove-row">{% trans "Remove" %}</a>
|
||||
{{ inline_admin_form.field_should_delete }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
function initRemoveButtons() {
|
||||
const removeButtons = document.querySelectorAll('.inline-deletelink.remove-row');
|
||||
|
||||
removeButtons.forEach(function(button) {
|
||||
button.removeEventListener('click', handleRemoveClick);
|
||||
button.addEventListener('click', handleRemoveClick);
|
||||
});
|
||||
}
|
||||
|
||||
function handleRemoveClick(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const row = this.closest('tr');
|
||||
|
||||
fadeOut(row, 300);
|
||||
console.log(1)
|
||||
const formPrefix = row.id.split('-')[0];
|
||||
const rowNum = row.id.split('-')[1];
|
||||
const deleteField = document.getElementById('id_' + formPrefix + '-' + rowNum + '-should_delete');
|
||||
console.log(2)
|
||||
if (deleteField) {
|
||||
console.log(deleteField)
|
||||
deleteField.value = '1';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function fadeOut(element, duration) {
|
||||
let opacity = 1;
|
||||
const interval = 50;
|
||||
const delta = interval / duration;
|
||||
|
||||
function decreaseOpacity() {
|
||||
opacity -= delta;
|
||||
element.style.opacity = opacity;
|
||||
|
||||
if (opacity <= 0) {
|
||||
element.style.display = 'none';
|
||||
clearInterval(timer);
|
||||
}
|
||||
}
|
||||
|
||||
const timer = setInterval(decreaseOpacity, interval);
|
||||
}
|
||||
|
||||
initRemoveButtons();
|
||||
|
||||
const addRowButtons = document.querySelectorAll('.add-row a');
|
||||
addRowButtons.forEach(function(button) {
|
||||
button.addEventListener('click', function() {
|
||||
setTimeout(initRemoveButtons, 100);
|
||||
});
|
||||
});
|
||||
|
||||
function addHelpText() {
|
||||
var fields = document.querySelectorAll('.with-help-text');
|
||||
fields.forEach(function(field) {
|
||||
var helpText = field.getAttribute('data-help-text');
|
||||
if (helpText && !field.nextElementSibling?.classList.contains('help-text-inline')) {
|
||||
var helpElement = document.createElement('p');
|
||||
helpElement.className = 'help-text-inline';
|
||||
helpElement.textContent = helpText;
|
||||
field.parentNode.insertBefore(helpElement, field.nextSibling);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addHelpText();
|
||||
|
||||
document.addEventListener('formset:added', function(event) {
|
||||
setTimeout(addHelpText, 10);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user