Fix pagination controls, move mixin to common app, fix pagination invocation on all views, and other random bug fixes
This commit is contained in:
parent
7edefe23c3
commit
6a61b79bbe
425 changed files with 51656 additions and 243 deletions
150
staticfiles/admin/fields/ckeditor_init.js
Normal file
150
staticfiles/admin/fields/ckeditor_init.js
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
$(document).ready(function () {
|
||||
|
||||
|
||||
// This sample still does not showcase all CKEditor 5 features (!)
|
||||
// Visit https://ckeditor.com/docs/ckeditor5/latest/features/index.html to browse all the features.
|
||||
CKEDITOR.ClassicEditor.create(document.querySelector(".ckeditor-field"), {
|
||||
// https://ckeditor.com/docs/ckeditor5/latest/features/toolbar/toolbar.html#extended-toolbar-configuration-format
|
||||
height: '350px',
|
||||
toolbar: {
|
||||
items: [
|
||||
'exportPDF', 'exportWord', '|',
|
||||
'findAndReplace', 'selectAll', '|',
|
||||
'heading', '|',
|
||||
'bold', 'italic', 'strikethrough', 'underline', 'code', 'subscript', 'superscript', 'removeFormat', '|',
|
||||
'bulletedList', 'numberedList', 'todoList', '|',
|
||||
'outdent', 'indent', '|',
|
||||
'undo', 'redo',
|
||||
'-',
|
||||
'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', 'highlight', '|',
|
||||
'alignment', '|',
|
||||
'link', 'insertImage', 'blockQuote', 'insertTable', 'mediaEmbed', 'codeBlock', 'htmlEmbed', '|',
|
||||
'specialCharacters', 'horizontalLine', 'pageBreak', '|',
|
||||
'textPartLanguage', '|',
|
||||
'sourceEditing'
|
||||
],
|
||||
shouldNotGroupWhenFull: true
|
||||
},
|
||||
// Changing the language of the interface requires loading the language file using the <script> tag.
|
||||
// language: 'es',
|
||||
list: {
|
||||
properties: {
|
||||
styles: true,
|
||||
startIndex: true,
|
||||
reversed: true
|
||||
}
|
||||
},
|
||||
// https://ckeditor.com/docs/ckeditor5/latest/features/headings.html#configuration
|
||||
heading: {
|
||||
options: [
|
||||
{model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph'},
|
||||
{model: 'heading1', view: 'h1', title: 'Heading 1', class: 'ck-heading_heading1'},
|
||||
{model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2'},
|
||||
{model: 'heading3', view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3'},
|
||||
{model: 'heading4', view: 'h4', title: 'Heading 4', class: 'ck-heading_heading4'},
|
||||
{model: 'heading5', view: 'h5', title: 'Heading 5', class: 'ck-heading_heading5'},
|
||||
{model: 'heading6', view: 'h6', title: 'Heading 6', class: 'ck-heading_heading6'}
|
||||
]
|
||||
},
|
||||
// https://ckeditor.com/docs/ckeditor5/latest/features/editor-placeholder.html#using-the-editor-configuration
|
||||
placeholder: 'Welcome to CKEditor 5!',
|
||||
// https://ckeditor.com/docs/ckeditor5/latest/features/font.html#configuring-the-font-family-feature
|
||||
fontFamily: {
|
||||
options: [
|
||||
'default',
|
||||
'Arial, Helvetica, sans-serif',
|
||||
'Courier New, Courier, monospace',
|
||||
'Georgia, serif',
|
||||
'Lucida Sans Unicode, Lucida Grande, sans-serif',
|
||||
'Tahoma, Geneva, sans-serif',
|
||||
'Times New Roman, Times, serif',
|
||||
'Trebuchet MS, Helvetica, sans-serif',
|
||||
'Verdana, Geneva, sans-serif'
|
||||
],
|
||||
supportAllValues: true
|
||||
},
|
||||
// https://ckeditor.com/docs/ckeditor5/latest/features/font.html#configuring-the-font-size-feature
|
||||
fontSize: {
|
||||
options: [10, 12, 14, 'default', 18, 20, 22],
|
||||
supportAllValues: true
|
||||
},
|
||||
// Be careful with the setting below. It instructs CKEditor to accept ALL HTML markup.
|
||||
// https://ckeditor.com/docs/ckeditor5/latest/features/general-html-support.html#enabling-all-html-features
|
||||
htmlSupport: {
|
||||
allow: [
|
||||
{
|
||||
name: /.*/,
|
||||
attributes: true,
|
||||
classes: true,
|
||||
styles: true
|
||||
}
|
||||
]
|
||||
},
|
||||
// Be careful with enabling previews
|
||||
// https://ckeditor.com/docs/ckeditor5/latest/features/html-embed.html#content-previews
|
||||
// htmlEmbed: {
|
||||
// showPreviews: true
|
||||
// },
|
||||
// https://ckeditor.com/docs/ckeditor5/latest/features/link.html#custom-link-attributes-decorators
|
||||
link: {
|
||||
decorators: {
|
||||
addTargetToExternalLinks: true,
|
||||
defaultProtocol: 'https://',
|
||||
toggleDownloadable: {
|
||||
mode: 'manual',
|
||||
label: 'Downloadable',
|
||||
attributes: {
|
||||
download: 'file'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
// https://ckeditor.com/docs/ckeditor5/latest/features/mentions.html#configuration
|
||||
// mention: {
|
||||
// feeds: [
|
||||
// {
|
||||
// marker: '@',
|
||||
// feed: [
|
||||
// '@apple', '@bears', '@brownie', '@cake', '@cake', '@candy', '@canes', '@chocolate', '@cookie', '@cotton', '@cream',
|
||||
// '@cupcake', '@danish', '@donut', '@dragée', '@fruitcake', '@gingerbread', '@gummi', '@ice', '@jelly-o',
|
||||
// '@liquorice', '@macaroon', '@marzipan', '@oat', '@pie', '@plum', '@pudding', '@sesame', '@snaps', '@soufflé',
|
||||
// '@sugar', '@sweet', '@topping', '@wafer'
|
||||
// ],
|
||||
// minimumCharacters: 1
|
||||
// }
|
||||
// ]
|
||||
// },
|
||||
// The "super-build" contains more premium features that require additional configuration, disable them below.
|
||||
// Do not turn them on unless you read the documentation and know how to configure them and setup the editor.
|
||||
removePlugins: [
|
||||
// These two are commercial, but you can try them out without registering to a trial.
|
||||
// 'ExportPdf',
|
||||
// 'ExportWord',
|
||||
'CKBox',
|
||||
'FontFamily',
|
||||
'CKFinder',
|
||||
'EasyImage',
|
||||
// This sample uses the Base64UploadAdapter to handle image uploads as it requires no configuration.
|
||||
// https://ckeditor.com/docs/ckeditor5/latest/features/images/image-upload/base64-upload-adapter.html
|
||||
// Storing images as Base64 is usually a very bad idea.
|
||||
// Replace it on production website with other solutions:
|
||||
// https://ckeditor.com/docs/ckeditor5/latest/features/images/image-upload/image-upload.html
|
||||
// 'Base64UploadAdapter',
|
||||
'RealTimeCollaborativeComments',
|
||||
'RealTimeCollaborativeTrackChanges',
|
||||
'RealTimeCollaborativeRevisionHistory',
|
||||
'PresenceList',
|
||||
'Comments',
|
||||
'TrackChanges',
|
||||
'TrackChangesData',
|
||||
'RevisionHistory',
|
||||
'Pagination',
|
||||
'WProofreader',
|
||||
// Careful, with the Mathtype plugin CKEditor will not load when loading this sample
|
||||
// from a local file system (file://) - load this site via HTTP server if you enable MathType
|
||||
'MathType'
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
BIN
staticfiles/admin/fields/ckeditor_init.js.gz
Normal file
BIN
staticfiles/admin/fields/ckeditor_init.js.gz
Normal file
Binary file not shown.
106
staticfiles/admin/fields/json-editor/json_editor_init.js
Normal file
106
staticfiles/admin/fields/json-editor/json_editor_init.js
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
function getCookie(name) {
|
||||
// Split document.cookie into individual cookie strings
|
||||
const cookies = document.cookie.split(';');
|
||||
|
||||
// Iterate through each cookie
|
||||
for (let cookie of cookies) {
|
||||
// Trim whitespace and split into name-value pair
|
||||
const [cookieName, cookieValue] = cookie.trim().split('=');
|
||||
|
||||
// Check if this is the cookie we're looking for
|
||||
if (cookieName === name) {
|
||||
// Return the decoded value
|
||||
return decodeURIComponent(cookieValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Return null if cookie not found
|
||||
return null;
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
JSONEditor.defaults.callbacks.upload = {
|
||||
"defaultUploadHandler": function (jseditor, type, file, cbs) {
|
||||
// Create a new XMLHttpRequest object
|
||||
var xhr = new XMLHttpRequest();
|
||||
const htmlElement = document.documentElement;
|
||||
let url = '/admin/json-editor-upload-handler/'
|
||||
if (htmlElement.hasAttribute('data-use-i18n') && htmlElement.getAttribute('data-use-i18n') === "1") {
|
||||
const djangoLang = htmlElement.getAttribute('lang');
|
||||
if (djangoLang) {
|
||||
url = `/${djangoLang}${url}`;
|
||||
}
|
||||
}
|
||||
|
||||
// Configure it to send a POST request to the server endpoint
|
||||
xhr.open('POST', url, true);
|
||||
|
||||
// Handle upload progress
|
||||
xhr.upload.addEventListener('progress', function (event) {
|
||||
if (event.lengthComputable) {
|
||||
var percent = Math.round((event.loaded / event.total) * 100);
|
||||
cbs.updateProgress(percent); // Update progress bar with percentage
|
||||
}
|
||||
});
|
||||
|
||||
// Handle successful upload
|
||||
xhr.addEventListener('load', function () {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
var response = xhr.responseText; // Server returns the URL as plain text
|
||||
cbs.success(response); // Call success callback with the URL
|
||||
} else {
|
||||
cbs.failure('Upload failed: ' + xhr.statusText); // Call failure callback with error
|
||||
}
|
||||
});
|
||||
|
||||
// Handle upload errors
|
||||
xhr.addEventListener('error', function () {
|
||||
cbs.failure('Upload failed'); // Call failure callback on network error
|
||||
});
|
||||
|
||||
// Prepare the file for upload
|
||||
var formData = new FormData();
|
||||
formData.append('file', file); // Append the file to FormData
|
||||
|
||||
// Send the request to the server
|
||||
xhr.send(formData);
|
||||
}
|
||||
};
|
||||
|
||||
function init_editor_json_editor(
|
||||
editor,
|
||||
schema,
|
||||
json_viewer_div,
|
||||
) {
|
||||
let schema_str = JSON.parse(editor.value)
|
||||
|
||||
let jsoneditor__ = new JSONEditor(
|
||||
json_viewer_div, {
|
||||
theme: 'tailwind',
|
||||
schema: JSON.parse(schema),
|
||||
disable_edit_json: true,
|
||||
disable_properties: true,
|
||||
disable_array_delete_all_rows: true,
|
||||
disable_array_delete_last_row: true,
|
||||
disable_array_reorder: true,
|
||||
grid_columns: 3,
|
||||
prompt_before_delete: false,
|
||||
disable_collapse: true,
|
||||
startval: schema_str || []
|
||||
})
|
||||
|
||||
jsoneditor__.on('change', () => {
|
||||
$(editor).val(JSON.stringify(jsoneditor__.getValue()))
|
||||
})
|
||||
}
|
||||
|
||||
$('.django-json-editor-field').each(function (i, editor) {
|
||||
let editor_id = $(editor).attr('id')
|
||||
init_editor_json_editor(
|
||||
editor,
|
||||
$(`#${editor_id}-schema-template`).html(),
|
||||
$(`#${editor_id}-viewer`)[0]
|
||||
)
|
||||
})
|
||||
})
|
||||
BIN
staticfiles/admin/fields/json-editor/json_editor_init.js.gz
Normal file
BIN
staticfiles/admin/fields/json-editor/json_editor_init.js.gz
Normal file
Binary file not shown.
8
staticfiles/admin/fields/json-editor/jsoneditor.min.js
vendored
Normal file
8
staticfiles/admin/fields/json-editor/jsoneditor.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
staticfiles/admin/fields/json-editor/jsoneditor.min.js.gz
Normal file
BIN
staticfiles/admin/fields/json-editor/jsoneditor.min.js.gz
Normal file
Binary file not shown.
47
staticfiles/admin/fields/keyvalue_field/script.js
Normal file
47
staticfiles/admin/fields/keyvalue_field/script.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
$(document).ready(function () {
|
||||
let editors = document.getElementsByClassName('keyvalue-json-editor-field')
|
||||
$(editors).each((index, editor) => {
|
||||
let schema_str = JSON.parse(editor.value)
|
||||
$(editor).addClass("hidden")
|
||||
let json_viewer_div = $(`<div class="json-view-editor"></div>`)
|
||||
$(editor).parent().append(json_viewer_div)
|
||||
|
||||
let properties = {
|
||||
key: {type: 'string'},
|
||||
value: {type: 'string'},
|
||||
}
|
||||
|
||||
init(editor, json_viewer_div, properties, schema_str || [])
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
function init(editor, json_viewer_div, properties, start_value = []) {
|
||||
let jsoneditor = new JSONEditor(
|
||||
json_viewer_div[0], {
|
||||
theme: 'bootstrap4',
|
||||
schema: {
|
||||
type: "array",
|
||||
format: 'table',
|
||||
title: ' ',
|
||||
items: {
|
||||
type: 'object',
|
||||
title: 'item',
|
||||
properties: properties
|
||||
},
|
||||
},
|
||||
disable_edit_json: true,
|
||||
disable_properties: false,
|
||||
disable_array_delete_all_rows: true,
|
||||
disable_array_delete_last_row: true,
|
||||
disable_array_reorder: true,
|
||||
grid_columns: 3,
|
||||
prompt_before_delete: false,
|
||||
disable_collapse: true,
|
||||
startval: start_value
|
||||
})
|
||||
jsoneditor.on('change', () => {
|
||||
$(editor).val(JSON.stringify(jsoneditor.getValue()))
|
||||
})
|
||||
}
|
||||
BIN
staticfiles/admin/fields/keyvalue_field/script.js.gz
Normal file
BIN
staticfiles/admin/fields/keyvalue_field/script.js.gz
Normal file
Binary file not shown.
9
staticfiles/admin/fields/keyvalue_field/style.css
Normal file
9
staticfiles/admin/fields/keyvalue_field/style.css
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
.json-view-editor .row .form-group {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.json-view-editor .row .form-group label {
|
||||
margin-bottom: 0;
|
||||
margin-right: 10px;
|
||||
}
|
||||
BIN
staticfiles/admin/fields/keyvalue_field/style.css.gz
Normal file
BIN
staticfiles/admin/fields/keyvalue_field/style.css.gz
Normal file
Binary file not shown.
22
staticfiles/admin/fields/thousand_sep_field.js
Normal file
22
staticfiles/admin/fields/thousand_sep_field.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
function convertPersianToEnglish(value) {
|
||||
const persianNumbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
|
||||
const englishNumbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||
|
||||
for (let i = 0; i < persianNumbers.length; i++) {
|
||||
value = value.replace(new RegExp(persianNumbers[i], 'g'), englishNumbers[i]);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function formatNumber(input) {
|
||||
let value = convertPersianToEnglish(input.value);
|
||||
// Remove any existing thousand separators and non-digit characters
|
||||
value = value.replace(/,/g, '').replace(/\D/g, '');
|
||||
|
||||
// Add thousand separators
|
||||
value = value.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
|
||||
// Update the input value
|
||||
input.value = value;
|
||||
}
|
||||
BIN
staticfiles/admin/fields/thousand_sep_field.js.gz
Normal file
BIN
staticfiles/admin/fields/thousand_sep_field.js.gz
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue