pricing: add js & css for ordering & formset (#65440)

This commit is contained in:
Lauréline Guérin 2022-05-19 14:53:23 +02:00
parent b443ea9fc1
commit 7d1764c97c
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
5 changed files with 78 additions and 1 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ lingo.egg-info/
junit*xml
pylint.out
*.swp
lingo/manager/static/css/style.css

View File

@ -0,0 +1,35 @@
div.paragraph {
background: white;
box-sizing: border-box;
border: 1px solid #386ede;
border-radius: 3px;
max-width: 100%;
padding: 5px 15px;
margin-bottom: 1rem;
h4 {
margin-top: 5px;
border-bottom: none;
}
}
.sortable {
span.handle {
cursor: move;
display: inline-block;
padding: 0.5ex;
text-align: center;
width: 2em;
height: 100%;
box-sizing: border-box;
font-weight: normal;
}
}
ul.objects-list.sortable {
li {
position: relative;
& > a {
display: inline-block;
}
}
}

View File

@ -0,0 +1,34 @@
$(function() {
$(document).on('click', '#add-pricing-variable-form', function() {
if (typeof property_forms === "undefined") {var property_forms = $('.pricing-variable-form');}
if (typeof total_forms === "undefined") {var total_form = $('#id_form-TOTAL_FORMS');}
if (typeof form_num === "undefined") {var form_num = property_forms.length - 1;}
var new_form = $(property_forms[0]).clone();
var form_regex = RegExp(`form-(\\d){1}-`,'g');
form_num++;
new_form.html(new_form.html().replace(form_regex, `form-${form_num}-`));
new_form.appendTo('#pricing-variable-forms tbody');
$('#id_form-' + form_num + '-key').val('');
$('#id_form-' + form_num + '-value').val('');
total_form.val(form_num + 1);
})
$('.sortable').sortable({
handle: '.handle',
items: '.sortable-item',
update : function(event, ui) {
var new_order = '';
$(this).find('.sortable-item').each(function(i, x) {
var item_id = $(x).data('item-id');
if (new_order) {
new_order += ',';
}
new_order += item_id;
});
$.ajax({
url: $(this).data('order-url'),
data: {'new-order': new_order}
});
}
});
});

View File

@ -1 +1,7 @@
{% extends "lingo/base.html" %}
{% load static %}
{% block extrascripts %}
{{ block.super }}
<script src="{% static 'js/lingo.manager.js' %}"></script>
{% endblock %}

View File

@ -130,7 +130,7 @@ class compile_scss(Command):
class build(_build):
sub_commands = [('compile_translations', None)] + _build.sub_commands
sub_commands = [('compile_translations', None), ('compile_scss', None)] + _build.sub_commands
class install_lib(_install_lib):
@ -169,6 +169,7 @@ setup(
zip_safe=False,
cmdclass={
'build': build,
'compile_scss': compile_scss,
'compile_translations': compile_translations,
'install_lib': install_lib,
'sdist': eo_sdist,