Update to new Django admin styles for v3.x

This commit is contained in:
Philip Sargent
2022-03-03 14:18:51 +00:00
parent 7f41017ce3
commit dc4374cb9e
151 changed files with 19072 additions and 3638 deletions

View File

@@ -1,39 +1,43 @@
(function($) {
$.fn.prepopulate = function(dependencies, maxLength) {
/*global URLify*/
'use strict';
{
const $ = django.jQuery;
$.fn.prepopulate = function(dependencies, maxLength, allowUnicode) {
/*
Depends on urlify.js
Populates a selected field with the values of the dependent fields,
URLifies and shortens the string.
dependencies - array of dependent fields ids
maxLength - maximum length of the URLify'd string
allowUnicode - Unicode support of the URLify'd string
*/
return this.each(function() {
var prepopulatedField = $(this);
const prepopulatedField = $(this);
var populate = function () {
const populate = function() {
// Bail if the field's value has been changed by the user
if (prepopulatedField.data('_changed')) {
return;
}
var values = [];
const values = [];
$.each(dependencies, function(i, field) {
field = $(field);
if (field.val().length > 0) {
values.push(field.val());
}
});
prepopulatedField.val(URLify(values.join(' '), maxLength));
prepopulatedField.val(URLify(values.join(' '), maxLength, allowUnicode));
};
prepopulatedField.data('_changed', false);
prepopulatedField.change(function() {
prepopulatedField.on('change', function() {
prepopulatedField.data('_changed', true);
});
if (!prepopulatedField.val()) {
$(dependencies.join(',')).keyup(populate).change(populate).focus(populate);
$(dependencies.join(',')).on('keyup change focus', populate);
}
});
};
})(django.jQuery);
}