Skip to content

Commit 1decff1

Browse files
committed
[UPD] Nuevo campo accordion
1 parent c896873 commit 1decff1

File tree

6 files changed

+311
-238
lines changed

6 files changed

+311
-238
lines changed

src/genweb6/core/content/accordion_tabs/accordion_tabs.pt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929

3030
<tal:accordion tal:condition="python:tipus == 'accordion'"
3131
tal:define="accordion_open_multiple python:bool(getattr(context, 'accordion_open_multiple', False));
32+
accordion_open_first python:bool(getattr(context, 'accordion_open_first', False));
3233
accordion_items_expanded python:bool(getattr(context, 'accordion_items_expanded', False))">
3334

3435
<div class="accordion" tal:attributes="id string:uid-${token}">
3536
<tal:item tal:repeat="content context/contents">
3637
<div class="accordion-item"
37-
tal:define="is_expanded python:accordion_items_expanded;">
38+
tal:define="is_expanded python:accordion_open_first and content['first'] or accordion_items_expanded;">
3839
<h2 class="accordion-header" tal:attributes="id string:heading-${content/id};">
3940
<button type="button" data-bs-toggle="collapse"
4041
tal:content="content/title"

src/genweb6/core/content/accordion_tabs/accordion_tabs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ class IAccordionTabs(model.Schema, IDexteritySchema):
9696
default=False,
9797
)
9898

99+
accordion_open_first = schema.Bool(
100+
title=_(u'Obrir el primer panell de l’acordió per defecte'),
101+
description=_(u"Si està activat, el primer panell de l'acordió s'obrirà per defecte."),
102+
required=False,
103+
default=False,
104+
)
105+
99106
accordion_items_expanded = schema.Bool(
100107
title=_(u"Desplegar tots els items de l'acordió per defecte"),
101108
description=_(u"Si està activat, tots els items de l'acordió sortiran desplegats per defecte."),
Lines changed: 71 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,85 @@
11
function showElementsType() {
2-
var value = $('select#form-widgets-type_template').val();
3-
4-
switch(value) {
5-
case '--NOVALUE--':
6-
$('#formfield-form-widgets-accordion_open_multiple').hide();
7-
$('#formfield-form-widgets-accordion_items_expanded').hide();
8-
break;
9-
case 'accordion':
10-
$('#formfield-form-widgets-accordion_open_multiple').show();
11-
$('#formfield-form-widgets-accordion_items_expanded').show();
12-
break;
13-
case 'nav':
14-
$('#formfield-form-widgets-accordion_open_multiple').hide();
15-
$('#formfield-form-widgets-accordion_items_expanded').hide();
16-
break;
17-
}
2+
var value = $('select#form-widgets-type_template').val();
3+
4+
switch(value) {
5+
case '--NOVALUE--':
6+
$('#formfield-form-widgets-accordion_open_multiple').hide();
7+
$('#formfield-form-widgets-accordion_open_first').hide();
8+
$('#formfield-form-widgets-accordion_items_expanded').hide();
9+
break;
10+
case 'accordion':
11+
$('#formfield-form-widgets-accordion_open_multiple').show();
12+
$('#formfield-form-widgets-accordion_open_first').show();
13+
$('#formfield-form-widgets-accordion_items_expanded').show();
14+
break;
15+
case 'nav':
16+
$('#formfield-form-widgets-accordion_open_multiple').hide();
17+
$('#formfield-form-widgets-accordion_open_first').hide();
18+
$('#formfield-form-widgets-accordion_items_expanded').hide();
19+
break;
20+
}
1821
}
1922

2023
function showCollectionSelector() {
21-
var value = $('select#form-widgets-content').val();
22-
23-
switch(value) {
24-
case 'inside':
25-
if ($('body.template-edit').length > 0) {
26-
$('#formfield-form-widgets-content .form-text').show();
27-
} else {
28-
$('#formfield-form-widgets-content .form-text').hide();
29-
}
30-
$('#formfield-form-widgets-collection').hide();
31-
break;
32-
default:
33-
$('#formfield-form-widgets-content .form-text').hide();
34-
$('#formfield-form-widgets-collection').show();
35-
break;
24+
var value = $('select#form-widgets-content').val();
25+
26+
switch(value) {
27+
case 'inside':
28+
if ($('body.template-edit').length > 0) {
29+
$('#formfield-form-widgets-content .form-text').show();
30+
} else {
31+
$('#formfield-form-widgets-content .form-text').hide();
32+
}
33+
$('#formfield-form-widgets-collection').hide();
34+
break;
35+
default:
36+
$('#formfield-form-widgets-content .form-text').hide();
37+
$('#formfield-form-widgets-collection').show();
38+
break;
39+
}
40+
}
41+
42+
function disableSecondaryCheckboxIfPrincipalIsChecked(principal_checkbox, secondary_checkbox, enable_secondary_checkbox = false) {
43+
if (principal_checkbox.length === 0 || secondary_checkbox.length === 0) {
44+
return;
45+
}
46+
47+
var isOpenFirstChecked = principal_checkbox.is(':checked');
48+
if (isOpenFirstChecked) {
49+
secondary_checkbox.prop('disabled', true);
50+
if (enable_secondary_checkbox) {
51+
secondary_checkbox.prop('checked', true);
52+
} else {
53+
secondary_checkbox.prop('checked', false);
3654
}
55+
} else {
56+
secondary_checkbox.prop('disabled', false);
57+
}
3758
}
3859

3960
$(document).ready(function(){
4061

62+
showElementsType();
63+
showCollectionSelector();
64+
disableSecondaryCheckboxIfPrincipalIsChecked($('#form-widgets-accordion_open_first input[type="checkbox"]'), $('#form-widgets-accordion_items_expanded input[type="checkbox"]'));
65+
disableSecondaryCheckboxIfPrincipalIsChecked($('#form-widgets-accordion_items_expanded input[type="checkbox"]'), $('#form-widgets-accordion_open_first input[type="checkbox"]'));
66+
disableSecondaryCheckboxIfPrincipalIsChecked($('#form-widgets-accordion_items_expanded input[type="checkbox"]'), $('#form-widgets-accordion_open_multiple input[type="checkbox"]'), true);
67+
68+
$('select#form-widgets-type_template').on('change', function(){
4169
showElementsType();
70+
});
71+
72+
$('select#form-widgets-content').on('change', function(){
4273
showCollectionSelector();
74+
});
4375

44-
$('select#form-widgets-type_template').on('change', function(){
45-
showElementsType();
46-
});
76+
$('#form-widgets-accordion_open_first input[type="checkbox"]').on('change', function(){
77+
disableSecondaryCheckboxIfPrincipalIsChecked($('#form-widgets-accordion_open_first input[type="checkbox"]'), $('#form-widgets-accordion_items_expanded input[type="checkbox"]'));
78+
});
4779

48-
$('select#form-widgets-content').on('change', function(){
49-
showCollectionSelector();
50-
});
80+
$('#form-widgets-accordion_items_expanded input[type="checkbox"]').on('change', function(){
81+
disableSecondaryCheckboxIfPrincipalIsChecked($('#form-widgets-accordion_items_expanded input[type="checkbox"]'), $('#form-widgets-accordion_open_first input[type="checkbox"]'));
82+
disableSecondaryCheckboxIfPrincipalIsChecked($('#form-widgets-accordion_items_expanded input[type="checkbox"]'), $('#form-widgets-accordion_open_multiple input[type="checkbox"]'), true);
83+
});
84+
5185
});

0 commit comments

Comments
 (0)