Skip to content

Commit

Permalink
Merge pull request #3139 from Uninett/uncrispyfy/navbar-link-formset
Browse files Browse the repository at this point in the history
Uncrispyfy NavbarlinkForm and NavbarLinkFormSet
  • Loading branch information
lunkwill42 authored Oct 16, 2024
2 parents d619998 + 81d632a commit 4a25978
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
12 changes: 10 additions & 2 deletions python/nav/web/sass/nav/my_account.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
@import "../navsettings";

#navigation-preferences {
#navigation-preferences {
.asteriskField {
display:none;
}

.link-delete label{
color:$alert-color;
}
}

.row {
display: flex;
}

.row .link-delete {
align-self: center;
}
}
16 changes: 16 additions & 0 deletions python/nav/web/templates/webfront/_navbar_link_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% load forms %}
<div class="row">
{% for field in form %}
{% if field in form.attrs.form_fields %}
<div class="columns medium-5">
{% show_field field %}
</div>
{% elif field.name == 'DELETE' and navbar_formset.can_delete %}
<div class="columns link-delete medium-2">
{% include 'custom_crispy_templates/horizontal_checkbox.html' %}
</div>
{% elif form.render_unmentioned_fields %}
{{ field }}
{% endif %}
{% endfor %}
</div>
11 changes: 8 additions & 3 deletions python/nav/web/templates/webfront/preferences.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% extends "base.html" %}

{% load crispy_forms_tags %}

{% block base_header_additional_head %}
<link rel="stylesheet" href="{{ STATIC_URL }}css/nav/my_account.css" />
<script>require(['src/navigation_preferences']);</script>
Expand Down Expand Up @@ -95,7 +93,14 @@
<fieldset>
<legend>'My stuff' quick links</legend>
<p>A quick link requires both link text and URL.</p>
{% crispy navbar_formset navbar_formset.form.helper %}
{% csrf_token %}
<div>{{ navbar_formset.management_form }}</div>
{% include 'foundation-5/errors_formset.html' %}
{% for form in navbar_formset %}
{% include 'webfront/_navbar_link_form.html' %}
{% empty %}
{{ navbar_formset }}
{% endfor %}
<input type="submit" class="button primary small" name="submit" value="Save changes" />
</fieldset>

Expand Down
21 changes: 5 additions & 16 deletions python/nav/web/webfront/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@

from django import forms
from django.forms.models import modelformset_factory
from crispy_forms.helper import FormHelper
from crispy_forms_foundation.layout import Layout, Row, Column, HTML
from nav.models.profiles import NavbarLink, Account
from nav.web.crispyforms import (
CheckBox,
SubmitField,
set_flat_form_attributes,
FlatFieldset,
Expand All @@ -48,20 +45,12 @@ class NavbarlinkForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(NavbarlinkForm, self).__init__(*args, **kwargs)
self.empty_permitted = True
self.helper = FormHelper()
self.helper.form_tag = False
self.render_unmentioned_fields = True

self.helper.layout = Layout(
Row(
Column('name', css_class='medium-5'),
Column('uri', css_class='medium-5'),
Column(
HTML('<label>&nbsp;</label>'),
CheckBox('DELETE'),
css_class='link-delete medium-2',
),
),
self.attrs = set_flat_form_attributes(
form_fields=[
self['name'],
self['uri'],
]
)


Expand Down

0 comments on commit 4a25978

Please sign in to comment.