File tree Expand file tree Collapse file tree 9 files changed +102
-13
lines changed
Expand file tree Collapse file tree 9 files changed +102
-13
lines changed Original file line number Diff line number Diff line change 1+ Split user preferences into multiple sections
Original file line number Diff line number Diff line change @@ -5196,6 +5196,11 @@ details.collapse summary::-webkit-details-marker {
51965196 margin-bottom : 1rem ;
51975197}
51985198
5199+ .mx-auto {
5200+ margin-left : auto;
5201+ margin-right : auto;
5202+ }
5203+
51995204.-ml-2 {
52005205 margin-left : -0.5rem ;
52015206}
@@ -5406,6 +5411,14 @@ details.collapse summary::-webkit-details-marker {
54065411 max-width : 20rem ;
54075412}
54085413
5414+ .max-w-md {
5415+ max-width : 28rem ;
5416+ }
5417+
5418+ .max-w-screen-md {
5419+ max-width : 768px ;
5420+ }
5421+
54095422.flex-1 {
54105423 flex : 1 1 0% ;
54115424}
@@ -5819,6 +5832,10 @@ details.collapse summary::-webkit-details-marker {
58195832 padding : 1.5rem ;
58205833}
58215834
5835+ .p-0\. 5 {
5836+ padding : 0.125rem ;
5837+ }
5838+
58225839.px-1 {
58235840 padding-left : 0.25rem ;
58245841 padding-right : 0.25rem ;
@@ -6201,6 +6218,10 @@ details.collapse summary::-webkit-details-marker {
62016218 .lg\:grid-cols-4 {
62026219 grid-template-columns : repeat (4 , minmax (0 , 1fr ));
62036220 }
6221+
6222+ .lg\:grid-cols-2 {
6223+ grid-template-columns : repeat (2 , minmax (0 , 1fr ));
6224+ }
62046225}
62056226
62066227@media (min-width : 1280px ) {
Original file line number Diff line number Diff line change 1+ < section id ="{% block section_id %}{% endblock section_id %} "
2+ class ="card card-base border border-base-200 p-4 max-w-screen-md mx-auto space-y-2 ">
3+ < h3 class ="card-title text-xl ">
4+ {% block section_title %}
5+ {% endblock section_title %}
6+ </ h3 >
7+ < form hx-post ="{% url 'htmx:update-preferences' namespace='argus_htmx' %} "
8+ hx-headers ='{"X-CSRFToken": "{{ csrf_token }}"} '
9+ class ="space-y-2 ">
10+ < ul class ="card-body menu ">
11+ {% block section_forms %}
12+ {% endblock section_forms %}
13+ </ ul >
14+ < div class ="preference-form-actions flex justify-end gap-2 px-2 ">
15+ < button class ="btn btn-primary btn-sm "> Save preferences</ button >
16+ < button type ="reset " class ="btn btn-sm "> Reset</ button >
17+ </ div >
18+ </ form >
19+ </ section >
Original file line number Diff line number Diff line change 1+ {% extends "htmx/user/preference_form/_base_form.html" %}
2+ {% block section_id %}
3+ user-settings
4+ {% endblock section_id %}
5+ {% block section_title %}
6+ Incident Table
7+ {% endblock section_title %}
8+ {% block section_forms %}
9+ {% for form in incident_forms %}{{ form }}{% endfor %}
10+ {% endblock section_forms %}
Original file line number Diff line number Diff line change 1+ < script >
2+ const BUTTON_SELECTOR = '.preference-form-actions button' ;
3+ document . querySelectorAll ( 'form' ) . forEach ( form => {
4+ const getFormData = f => JSON . stringify ( Object . fromEntries ( new FormData ( f ) ) ) ;
5+ const initial = getFormData ( form ) ;
6+
7+ // Disable all preference buttons on initialization
8+ form . querySelectorAll ( BUTTON_SELECTOR ) . forEach ( btn => {
9+ btn . disabled = true ;
10+ } ) ;
11+
12+ const updateButtons = ( ) => {
13+ const current = getFormData ( form ) ;
14+ const dirty = current !== initial ;
15+ form . querySelectorAll ( BUTTON_SELECTOR ) . forEach ( btn => {
16+ btn . disabled = ! dirty ;
17+ } ) ;
18+ } ;
19+
20+ form . addEventListener ( 'input' , updateButtons ) ;
21+ form . addEventListener ( 'change' , updateButtons ) ;
22+ form . addEventListener ( 'reset' , ( ) => {
23+ setTimeout ( updateButtons , 0 ) ;
24+ } ) ;
25+ } ) ;
26+ </ script >
Original file line number Diff line number Diff line change 1+ {% extends "htmx/user/preference_form/_base_form.html" %}
2+ {% block section_id %}
3+ theme-settings
4+ {% endblock section_id %}
5+ {% block section_title %}
6+ Theme and Format
7+ {% endblock section_title %}
8+ {% block section_forms %}
9+ {% for form in theme_forms %}{{ form }}{% endfor %}
10+ {% endblock section_forms %}
Original file line number Diff line number Diff line change 22{% extends "htmx/base.html" %}
33{% block main %}
44 < div class ="p-4 space-y-4 ">
5- < h1 class ="text-3xl "> {{ page_title }}</ h1 >
6- < section id ="user-settings " class ="card ">
7- < ul class ="menu card-body ">
8- {% block preferences %}
9- {% for form in forms.values %}{{ form }}{% endfor %}
10- {% endblock preferences %}
11- </ ul >
12- </ section >
5+ {% include "htmx/components/_page_title.html" %}
6+ {% block preferences %}
7+ {% include "htmx/user/preference_form/_theme_and_format_form.html" %}
8+ {% include "htmx/user/preference_form/_incident_table_form.html" %}
9+ {% include "htmx/user/preference_form/_preference_form_script.html" %}
10+ {% endblock preferences %}
1311 </ div >
1412{% endblock main %}
Original file line number Diff line number Diff line change 22< input type ="radio "
33 class ="btn btn-sm btn-block btn-ghost justify-start "
44 {% if widget.value ! = None %}value ="{{ widget.value|stringformat:'s' }} "{% endif %}
5+ {% if widget.attrs.checked %}checked ="checked "{% endif %}
56 aria-label ="{{ widget.label }} "
67 name ="{{ widget.name }} "
7- autocomplete ="off "
8- hx-post ="{% url 'htmx:update-preferences' namespace='argus_htmx' %} "
9- hx-trigger ="change "
10- hx-headers ='{"X-CSRFToken": "{{ widget.attrs.csrf_token }}"} ' />
8+ autocomplete ="off " />
Original file line number Diff line number Diff line change 99from argus .htmx .user .preferences .utils import setup_preference_forms
1010
1111
12+ THEME_PREFERENCES = ["theme" , "datetime_format_name" ]
13+
14+
1215@require_GET
1316def user_preferences (request ) -> HttpResponse :
1417 """Renders the main preferences page for a user"""
1518
1619 forms = setup_preference_forms (request )
20+ theme_forms = [form for name , form in forms .items () if name in THEME_PREFERENCES ]
21+ incident_forms = [form for name , form in forms .items () if name not in THEME_PREFERENCES ]
1722
1823 context = {
1924 "page_title" : "User preferences" ,
20- "forms" : forms ,
25+ "theme_forms" : theme_forms ,
26+ "incident_forms" : incident_forms ,
2127 }
2228
2329 return render (request , "htmx/user/preferences_list.html" , context = context )
You can’t perform that action at this time.
0 commit comments