SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit d7ef0855 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

attempt to beautify and simplify forum posts

parent d5962cf2
No related branches found
No related tags found
1 merge request!62[Forums] Simplify Forum posts UI and code
{% load crispy_forms_tags %}
<div id="{{ origin }}" class="text-body bg-white m-2 p-2">
<div id="post-form-container" class="text-body bg-white m-2 p-2">
<h3 class="highlight">
{{ text }}
<a class="ms-4 px-1 py-0 btn btn-sm btn-warning text-white"
hx-get="{% url 'forums:_hx_post_form_button' slug=slug parent_model=parent_model parent_id=parent_id origin=origin target=target text=text %}"
hx-target="#{{ origin }}"
hx-get="{% url 'forums:_hx_post_form_button' slug=slug parent_model=parent_model parent_id=parent_id text=text %}"
hx-target="#post-form-container"
hx-swap="outerHTML"
hx-trigger="click, newPost-{{ target }} from:body"
>
Cancel
</a>
hx-trigger="click, newPost-{{ target }} from:body">Cancel</a>
</h3>
<form hx-post="{% url 'forums:_hx_post_form' slug=slug parent_model=parent_model parent_id=parent_id origin=origin target=target text=text %}"
hx-confirm="Create this Post?"
hx-target="#{{ target }}"
hx-swap="beforebegin"
>
<form hx-post="{% url 'forums:_hx_post_form' slug=slug parent_model=parent_model parent_id=parent_id text=text %}"
hx-confirm="Create this Post?"
{% if parent_model == "forum" %}
hx-target="#thread-posts"
hx-swap="beforestart"
{% elif parent_model == "post" %}
hx-target="#post-{{ parent_id }}-replies"
hx-swap="beforeend"
{% endif %}>
{% crispy form %}
</form>
</div>
<div id="{{ origin }}">
<button class="btn btn-sm btn-primary ms-2 mt-1 px-1 py-0"
hx-get="{% url 'forums:_hx_post_form' slug=slug parent_model=parent_model parent_id=parent_id origin=origin target=target text=text %}"
hx-target="#{{ origin }}"
hx-swap="outerHTML"
>
{% include "bi/arrow-return-right.html" %} <small>{{ text }}</small>
</button>
</div>
<button class="btn btn-sm btn-primary ms-2 mt-1 px-1 py-0"
hx-get="{% url 'forums:_hx_post_form' slug=slug parent_model=parent_model parent_id=parent_id text=text %}"
hx-swap="innerHTML"
{% if parent_model == 'forum' %}
hx-target="#new-post-form"
{% elif parent_model == 'post' %}
hx-target="#post-{{ parent_id }}-reply"
{% endif %}
>
{% include "bi/arrow-return-right.html" %}
<small>{{ text }}</small>
</button>
......@@ -7,10 +7,30 @@
{% block breadcrumb_items %}
{{ block.super }}
<span class="breadcrumb-item">{% if forum.meeting %}Meeting{% else %}Forum{% endif %} Details</span>
<span class="breadcrumb-item">
{% if forum.meeting %}
Meeting
{% else %}
Forum
{% endif %}
Details</span>
{% endblock %}
{% block pagetitle %}: {% if forum.meeting %}Meeting{% else %}Forum{% endif %} details{% endblock pagetitle %}
{% block pagetitle %}
:
{% if forum.meeting %}
Meeting
{% else %}
Forum
{% endif %}
details
{% endblock pagetitle %}
{% block content %}
......@@ -19,78 +39,126 @@
<div class="row">
<div class="col-12">
<h2 class="highlight">
{% if forum.meeting %}
{% with context_colors=forum.meeting.context_colors %}
<span class="badge bg-{{ context_colors.bg }} mx-0 mb-2 p-2 text-{{ context_colors.text }}">
{{ context_colors.message }}&emsp;
<span class="small"> [{{ forum.meeting.date_from|date:"Y-m-d" }} to {{ forum.meeting.date_until|date:"Y-m-d" }}]</span>
</span>
{% endwith %}
<br/>
{% endif %}
<span class="d-flex flex-wrap justify-content-between">
<a href="{{ forum.get_absolute_url }}">{{ forum }}</a>
<span class="badge bg-primary rounded-pill">{{ forum.cf_nr_posts }} post{{ forum.cf_nr_posts|pluralize }}</span>
</span>
{% if forum.meeting %}
{% with context_colors=forum.meeting.context_colors %}
<span class="badge bg-{{ context_colors.bg }} mx-0 mb-2 p-2 text-{{ context_colors.text }}">
{{ context_colors.message }}&emsp;
<span class="small">[{{ forum.meeting.date_from|date:"Y-m-d" }} to {{ forum.meeting.date_until|date:"Y-m-d" }}]</span>
</span>
{% endwith %}
<br />
{% endif %}
<span class="d-flex flex-wrap justify-content-between">
<a href="{{ forum.get_absolute_url }}">{{ forum }}</a>
<span class="badge bg-primary rounded-pill">{{ forum.cf_nr_posts }} post{{ forum.cf_nr_posts|pluralize }}</span>
</span>
</h2>
{% if forum.parent %}
<p>Parent: <a href="{{ forum.parent.get_absolute_url }}">{{ forum.parent }}</a></p>
<p>
Parent: <a href="{{ forum.parent.get_absolute_url }}">{{ forum.parent }}</a>
</p>
{% endif %}
{% if forum.child_forums.all|length > 0 %}
<p>Descendants: {% for child in forum.child_forums.all %}<a href="{{ child.get_absolute_url }}">{{ child }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</p>
<p>
Descendants:
{% for child in forum.child_forums.all %}
<a href="{{ child.get_absolute_url }}">{{ child }}</a>
{% if not forloop.last %},{% endif %}
{% endfor %}
</p>
{% endif %}
{% if "can_administer_forum" in forum_user_perms %}
<div class="container border border-danger m-2 p-2">
<h4>Admin actions:</h4>
<ul>
<li>
{% if forum.meeting %}
<a href="{% url 'forums:meeting_update' slug=forum.meeting.slug %}" class="text-warning">Update this Meeting</a>
{% else %}
<a href="{% url 'forums:forum_update' slug=forum.slug %}" class="text-warning">Update this Forum</a>
{% endif %}
</li>
<li>
{% if not forum.child_forums.all|length > 0 %}
<a href="{% url 'forums:forum_delete' slug=forum.slug %}" class="text-danger">Delete this {% if forum.meeting %}Meeting{% else %}Forum{% endif %} (and all Posts {% if forum.meeting %}and Motions {% endif %}it contains)</a>
{% else %}
<span class="text-danger" style="text-decoration: line-through;">Delete this Forum</span> Please delete descendant Forums first.
{% endif %}
</li>
{% if not forum.meeting %}
<li><a href="{% url 'forums:forum_create' parent_model='forum' parent_id=forum.id %}">Create a (sub)Forum within this one</a></li>
<li><a href="{% url 'forums:meeting_create' parent_model='forum' parent_id=forum.id %}">Create a Meeting within this Forum</a></li>
{% endif %}
</ul>
{% if "can_administer_forum" in forum_user_perms %}
<details id="forum-permissions-details"
class="border border-danger bg-danger bg-opacity-10 m-2">
<summary class="bg-danger bg-opacity-10 p-2">
Permissions on this {% if forum.meeting %}Meeting{% else %}Forum{% endif %} instance (view/manage)
<span id="forum-permissions-details-contents-indicator" class="htmx-indicator p-2">
<button class="btn btn-warning" type="button" disabled>
<strong>Loading...</strong>
<div class="spinner-grow spinner-grow-sm ms-2" role="status" aria-hidden="true"></div>
</button>
</span>
</summary>
<div id="forum-permissions-details-contents"
class="p-2"
hx-get="{% url 'forums:_hx_forum_permissions' slug=forum.slug %}"
hx-trigger="toggle once from:#forum-permissions-details"
hx-target="#forum-permissions-details-contents"
hx-indicator="#forum-permissions-details-contents-indicator"
>
</div>
</details>
{% endif %}
</div>
<div class="container border border-danger m-2 p-2">
<h4>Admin actions:</h4>
<ul>
<li>
{% if forum.meeting %}
<a href="{% url 'forums:meeting_update' slug=forum.meeting.slug %}"
class="text-warning">Update this Meeting</a>
{% else %}
<a href="{% url 'forums:forum_update' slug=forum.slug %}"
class="text-warning">Update this Forum</a>
{% endif %}
</li>
<li>
{% if not forum.child_forums.all|length > 0 %}
<a href="{% url 'forums:forum_delete' slug=forum.slug %}"
class="text-danger">Delete this
{% if forum.meeting %}
Meeting
{% else %}
Forum
{% endif %}
(and all Posts
{% if forum.meeting %}and Motions{% endif %}
it contains)</a>
{% else %}
<span class="text-danger" style="text-decoration: line-through;">Delete this Forum</span> Please delete descendant Forums first.
{% endif %}
</li>
{% if not forum.meeting %}
<li>
<a href="{% url 'forums:forum_create' parent_model='forum' parent_id=forum.id %}">Create a (sub)Forum within this one</a>
</li>
<li>
<a href="{% url 'forums:meeting_create' parent_model='forum' parent_id=forum.id %}">Create a Meeting within this Forum</a>
</li>
{% endif %}
</ul>
{% if "can_administer_forum" in forum_user_perms %}
<details id="forum-permissions-details"
class="border border-danger bg-danger bg-opacity-10 m-2">
<summary class="bg-danger bg-opacity-10 p-2">
Permissions on this
{% if forum.meeting %}
Meeting
{% else %}
Forum
{% endif %}
instance (view/manage)
<span id="forum-permissions-details-contents-indicator"
class="htmx-indicator p-2">
<button class="btn btn-warning" type="button" disabled>
<strong>Loading...</strong>
<div class="spinner-grow spinner-grow-sm ms-2"
role="status"
aria-hidden="true"></div>
</button>
</span>
</summary>
<div id="forum-permissions-details-contents"
class="p-2"
hx-get="{% url 'forums:_hx_forum_permissions' slug=forum.slug %}"
hx-trigger="toggle once from:#forum-permissions-details"
hx-target="#forum-permissions-details-contents"
hx-indicator="#forum-permissions-details-contents-indicator"></div>
</details>
{% endif %}
</div>
{% endif %}
</div>
</div>
......@@ -98,121 +166,130 @@
<div class="col">
<h2>Table of Contents</h2>
<div class="m-2">
<ul>
<li><a href="#Description">Description</a></li>
{% if forum.meeting %}
<li><a href="#Preamble">Preamble</a></li>
<li><a href="#Motions">Motions</a></li>
{% endif %}
<li><a href="#Posts">Posts</a>
</li>
{% if forum.meeting %}
<li><a href="#Minutes">Minutes</a></li>
{% endif %}
</ul>
<ul>
<li>
<a href="#Description">Description</a>
</li>
{% if forum.meeting %}
<li>
<a href="#Preamble">Preamble</a>
</li>
<li>
<a href="#Motions">Motions</a>
</li>
{% endif %}
<li>
<a href="#Posts">Posts</a>
</li>
{% if forum.meeting %}
<li>
<a href="#Minutes">Minutes</a>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
<details id="forum-quick-links-all-details"
class="border border-dark m-1 mb-2">
class="border border-dark m-1 mb-2">
<summary class="bg-dark text-white my-0 ps-4 py-1">
<strong>
Quick links: all posts and motions&emsp;(click to toggle)
</strong>
<span id="forum-quick-links-all-details-contents-indicator" class="htmx-indicator p-2">
<button class="btn btn-warning" type="button" disabled>
<strong>Loading...</strong>
<div class="spinner-grow spinner-grow-sm ms-2" role="status" aria-hidden="true"></div>
</button>
<strong>Quick links: all posts and motions&emsp;(click to toggle)</strong>
<span id="forum-quick-links-all-details-contents-indicator"
class="htmx-indicator p-2">
<button class="btn btn-warning" type="button" disabled>
<strong>Loading...</strong>
<div class="spinner-grow spinner-grow-sm ms-2"
role="status"
aria-hidden="true"></div>
</button>
</span>
</summary>
<div id="forum-quick-links-all-details-contents"
class="mx-2 mt-0"
hx-get="{% url 'forums:_hx_forum_quick_links_all' slug=forum.slug %}"
hx-trigger="toggle once from:#forum-quick-links-all-details"
hx-target="#forum-quick-links-all-details-contents"
hx-indicator="#forum-quick-links-all-details-contents-indicator"
>
</div>
class="mx-2 mt-0"
hx-get="{% url 'forums:_hx_forum_quick_links_all' slug=forum.slug %}"
hx-trigger="toggle once from:#forum-quick-links-all-details"
hx-target="#forum-quick-links-all-details-contents"
hx-indicator="#forum-quick-links-all-details-contents-indicator"></div>
</details>
<details id="forum-quick-links-followups-details"
class="border border-dark m-1 mb-4">
class="border border-dark m-1 mb-4">
<summary class="bg-dark text-white my-0 ps-4 py-1">
<strong>
Quick links: anchor posts, latest followup&emsp;(click to toggle)
</strong>
<span id="forum-quick-links-followups-details-contents-indicator" class="htmx-indicator p-2">
<button class="btn btn-warning" type="button" disabled>
<strong>Loading...</strong>
<div class="spinner-grow spinner-grow-sm ms-2" role="status" aria-hidden="true"></div>
</button>
<strong>Quick links: anchor posts, latest followup&emsp;(click to toggle)</strong>
<span id="forum-quick-links-followups-details-contents-indicator"
class="htmx-indicator p-2">
<button class="btn btn-warning" type="button" disabled>
<strong>Loading...</strong>
<div class="spinner-grow spinner-grow-sm ms-2"
role="status"
aria-hidden="true"></div>
</button>
</span>
</summary>
<div id="forum-quick-links-followups-details-contents"
class="mx-2 mt-0"
hx-get="{% url 'forums:_hx_forum_quick_links_followups' slug=forum.slug %}"
hx-trigger="toggle once from:#forum-quick-links-followups-details"
hx-target="#forum-quick-links-followups-details-contents"
hx-indicator="#forum-quick-links-followups-details-contents-indicator"
>
</div>
class="mx-2 mt-0"
hx-get="{% url 'forums:_hx_forum_quick_links_followups' slug=forum.slug %}"
hx-trigger="toggle once from:#forum-quick-links-followups-details"
hx-target="#forum-quick-links-followups-details-contents"
hx-indicator="#forum-quick-links-followups-details-contents-indicator"></div>
</details>
<div class="row">
<div class="col-12">
<h2 class="highlight" id="Description">Description</h2>
<div class="m-2">
{% automarkup forum.description %}
</div>
<div class="m-2">{% automarkup forum.description %}</div>
</div>
</div>
{% if forum.meeting %}
<div class="row">
<div class="col-12">
<h2 class="highlight" id="Preamble">Preamble</h2>
<div class="m-2">
{% automarkup forum.meeting.preamble %}
</div>
<h2 class="highlight" id="Preamble">Preamble</h2>
<div class="m-2">{% automarkup forum.meeting.preamble %}</div>
</div>
</div>
<div class="row">
<div class="col-12">
<h2 class="highlight" id="Motions">Motions</h2>
<ul>
{% if forum.meeting.future %}
<li>Adding Motions will be activated once the meeting starts</li>
{% elif forum.meeting.past %}
<li><span class="text-danger">Adding Motions is deactivated</span> (Meeting is over)</li>
{% else %}
<li>
<div id="new-motion-form">
{% include "forums/_hx_motion_form_button.html" with slug=forum.slug %}
</div>
</li>
{% endif %}
</ul>
{% for motion in forum.motions.all %}
<div id="thread-{{ motion.post.id }}"
hx-get="{% url 'forums:_hx_thread_from_post' slug=forum.slug post_id=motion.post.id %}"
hx-target="#thread-{{ motion.post.id }}"
hx-trigger="load"
>
<div id="thread-{{ motion.post.id }}-indicator"
class="htmx-indicator p-2"
>
</div>
<button class="btn btn-warning" type="button" disabled>
<strong>Loading thread {{ motion.post.id }}</strong>
<div class="spinner-grow spinner-grow-sm ms-2" role="status" aria-hidden="true"></div>
</button>
</div>
{% endfor %}
<div id="thread-motions"></div>
<h2 class="highlight" id="Motions">Motions</h2>
<ul>
{% if forum.meeting.future %}
<li>Adding Motions will be activated once the meeting starts</li>
{% elif forum.meeting.past %}
<li>
<span class="text-danger">Adding Motions is deactivated</span> (Meeting is over)
</li>
{% else %}
<li>
<div id="new-motion-form">{% include "forums/_hx_motion_form_button.html" with slug=forum.slug %}</div>
</li>
{% endif %}
</ul>
{% for motion in forum.motions.all %}
<div id="thread-{{ motion.post.id }}"
hx-get="{% url 'forums:_hx_thread_from_post' slug=forum.slug post_id=motion.post.id %}"
hx-target="#thread-{{ motion.post.id }}"
hx-trigger="load">
<div id="thread-{{ motion.post.id }}-indicator" class="htmx-indicator p-2"></div>
<button class="btn btn-warning" type="button" disabled>
<strong>Loading thread {{ motion.post.id }}</strong>
<div class="spinner-grow spinner-grow-sm ms-2"
role="status"
aria-hidden="true"></div>
</button>
</div>
{% endfor %}
<div id="thread-motions"></div>
</div>
</div>
......@@ -222,35 +299,35 @@
<div class="row">
<div class="col-12">
<h2 class="highlight" id="Posts">Posts</h2>
{% if not forum.meeting or forum.meeting.ongoing %}
<ul>
<li>
<div id="new-post-form">
{% include "forums/_hx_post_form_button.html" with slug=forum.slug parent_model='forum' parent_id=forum.id origin="new-post-form" target="thread-posts" text="Add a new Post" %}
</div>
</li>
</ul>
<ul>
<li>
<div id="new-post-form">
{% include "forums/_hx_post_form_button.html" with slug=forum.slug parent_model='forum' parent_id=forum.id text="Add a new Post" %}
</div>
</li>
</ul>
{% endif %}
{% for post in forum.posts.motions_excluded %}
<div id="thread-{{ post.id }}"
hx-get="{% url 'forums:_hx_thread_from_post' slug=forum.slug post_id=post.id %}"
hx-target="#thread-{{ post.id }}"
hx-swap="outerHTML"
hx-trigger="load"
hx-indicator="#thread-{{ post.id }}-indicator"
>
<div id="thread-{{ post.id }}-indicator"
class="htmx-indicator p-2"
>
</div>
<button class="btn btn-warning" type="button" disabled>
<strong>Loading thread {{ post.id }}</strong>
<div class="spinner-grow spinner-grow-sm ms-2" role="status" aria-hidden="true"></div>
</button>
</div>
<div id="thread-{{ post.id }}"
hx-get="{% url 'forums:_hx_thread_from_post' slug=forum.slug post_id=post.id %}"
hx-target="#thread-{{ post.id }}"
hx-swap="outerHTML"
hx-trigger="load"
hx-indicator="#thread-{{ post.id }}-indicator">
<div id="thread-{{ post.id }}-indicator" class="htmx-indicator p-2"></div>
<button class="btn btn-warning" type="button" disabled>
<strong>Loading thread {{ post.id }}</strong>
<div class="spinner-grow spinner-grow-sm ms-2"
role="status"
aria-hidden="true"></div>
</button>
</div>
{% endfor %}
<div id="thread-posts"></div>
</div>
......@@ -259,16 +336,15 @@
{% if forum.meeting %}
<div class="row">
<div class="col-12">
<h2 class="highlight" id="Minutes">Minutes</h2>
<div class="m-2">
{% automarkup forum.meeting.minutes %}
</div>
<h2 class="highlight" id="Minutes">Minutes</h2>
<div class="m-2">{% automarkup forum.meeting.minutes %}</div>
</div>
</div>
{% endif %}
{% endblock content %}
{% block footer_script %}
<script nonce="{{ request.csp_nonce }}">
document.body.addEventListener("newPost", function(evt) {
......
{% load automarkup %}
{% load guardian_tags %}
{% get_obj_perms request.user for forum as "forum_user_perms" %}
<div id="thread-{{ post.id }}">
<div class="card m-2 {% if post.motion %}text-white bg-dark{% else %}text-body{% endif %}" id="post{{ post.id }}">
<div class="card-header">
{{ post.subject }}
<div class="postInfo">
{{ post.posted_by.first_name }} {{ post.posted_by.last_name }} on {{ post.posted_on|date:"Y-m-d" }}
- {% include 'permalink.html' with object=post %}
{% if post.parent and not post.motion %}
- regarding <a href="{{ post.parent.get_absolute_url }}">{{ post.parent }}</a>
{% endif %}
{% get_obj_perms request.user for forum as "forum_user_perms" %}
{% with post.get_followups|length as nr_followup_threads %}
<div id="post{{ post.id }}"
class="mt-3 border border-secondary rounded rounded-sm">
<div id="post-{{ post.id }}-header" class="p-2
{% if post.motion %}bg-warning{% else %}bg-primary{% endif %}
bg-opacity-25 d-flex align-content-center justify-content-between">
<div>
<span class="me-1">{{ post.posted_by.first_name }} {{ post.posted_by.last_name }}</span>
<span class="text-muted me-1">on {{ post.posted_on|date:"Y-m-d" }}</span>
{% include 'permalink.html' with object=post %}
</div>
<div class="fs-5 me-1">
{% if "Re:" not in post.subject %}{{ post.subject }}{% endif %}
</div>
</div>
<div class="card-body">
<div id="post-{{ post.id }}-body" class="p-3">
{% automarkup post.text %}
</div>
<div class="card-footer">
<div class="d-flex flex-wrap justify-content-end align-items-center">
<div class="flex-grow-1">
{% with post.get_followups|length as nr_followup_threads %}
{% if nr_followup_threads > 0 %}
<span class="badge bg-info rounded-pill text-dark me-2 px-2">{{ nr_followup_threads }} followup thread{{ nr_followup_threads|pluralize }}, {% with nr_followups=post.cf_nr_followups %}{{ nr_followups }} post{{ nr_followups|pluralize }}{% endwith %} in total</span>
{% endif %}
{% endwith %}
</div>
{% if post.motion %}
<div id="motion-{{ post.motion.id }}-voting-indicator"
class="htmx-indicator p-2"
>
<button class="btn btn-warning" type="button" disabled>
<strong>Loading voting data...</strong>
<div class="spinner-grow spinner-grow-sm ms-2" role="status" aria-hidden="true"></div>
</button>
</div>
<div id="motion-{{ post.motion.id }}-voting"
class="align-self-center px-2"
hx-get="{% url 'forums:_hx_motion_voting' slug=forum.slug motion_id=post.motion.id %}"
hx-trigger="load"
hx-target="#motion-{{ post.motion.id }}-voting"
hx-swap="innerHTML"
hx-indicator="#motion-{{ post.motion.id }}-voting-indicator"
>
</div>
{% endif %}
{% if post.motion %}
<hr class="bg-primary" />
<div id="post-{{ post.id }}-motion-voting"
class="d-flex justify-content-start">
<div id="motion-{{ post.motion.id }}-voting"
class="align-self-center px-2"
hx-get="{% url 'forums:_hx_motion_voting' slug=forum.slug motion_id=post.motion.id %}"
hx-trigger="load"
hx-target="#motion-{{ post.motion.id }}-voting"
hx-swap="innerHTML"
hx-indicator="#motion-{{ post.motion.id }}-voting-indicator"></div>
<div id="motion-{{ post.motion.id }}-voting-indicator"
class="htmx-indicator p-2">
<button class="btn btn-warning" type="button" disabled>
<strong>Loading voting data...</strong>
<div class="spinner-grow spinner-grow-sm ms-2"
role="status"
aria-hidden="true"></div>
</button>
</div>
</div>
{% endif %}
<div id="post-{{ post.id }}-reply"
class="mt-2 d-flex justify-content-start">
{% if posting_open %}
{% if post.motion %}
{% include "forums/_hx_post_form_button.html" with slug=forum.slug parent_model='motion' parent_id=post.id text="Comment on this Motion" %}
{% else %}
{% include "forums/_hx_post_form_button.html" with slug=forum.slug parent_model='post' parent_id=post.id text="Reply" %}
{% endif %}
{% endif %}
</div>
</div>
</div>
<details open id="post-{{ post.id }}-replies-details" class="mt-1">
{% if posting_open %}
{% with id_str=post.id|stringformat:"s" %}
{% with thread_str="thread-"|add:id_str %}
<div id="{{ thread_str|add:'-origin' }}">
{% if post.motion %}
{% include "forums/_hx_post_form_button.html" with slug=forum.slug parent_model='motion' parent_id=post.id origin=thread_str|add:"-origin" target=thread_str|add:"-new" text="Comment on this Motion" %}
{% else %}
{% include "forums/_hx_post_form_button.html" with slug=forum.slug parent_model='post' parent_id=post.id origin=thread_str|add:"-origin" target=thread_str|add:"-new" text="Reply" %}
{% endif %}
</div>
{% endwith %}
{% endwith %}
{% if nr_followup_threads > 0 %}
<summary class="ms-1 text-info list-triangle d-none-empty">
<span class="badge bg-info bg-opacity-50 rounded-pill text-dark me-2 px-2">Show/Collapse {{ nr_followup_threads }} followup thread{{ nr_followup_threads|pluralize }}</span>
</summary>
{% else %}
<summary class="d-none-empty"></summary>
{% endif %}
<div class="followupPosts{% if post.motion %}AfterMotion{% endif %}"
>
<div id="post-{{ post.id }}-replies"
class="ms-3 ps-4 border-start border-secondary">
{% for followup in post.get_followups %}
<div id="thread-{{ followup.id }}"
hx-get="{% url 'forums:_hx_thread_from_post' slug=forum.slug post_id=followup.id %}"
hx-target="#thread-{{ followup.id }}"
hx-swap="outerHTML"
hx-trigger="load delay:1s"
hx-indicator="#thread-{{ followup.id }}-indicator"
>
<div id="thread-{{ followup.id }}-indicator"
class="htmx-indicator p-2"
>
<button class="btn btn-warning" type="button" disabled>
<strong>Loading thread {{ followup.id }}</strong>
<div class="spinner-grow spinner-grow-sm ms-2" role="status" aria-hidden="true"></div>
</button>
</div>
</div>
<div id="thread-{{ followup.id }}"
hx-get="{% url 'forums:_hx_thread_from_post' slug=forum.slug post_id=followup.id %}"
hx-target="#thread-{{ followup.id }}"
hx-swap="outerHTML"
hx-trigger="load delay:1s"
hx-indicator="#thread-{{ followup.id }}-indicator">
<div id="thread-{{ followup.id }}-indicator" class="htmx-indicator p-2">
<button class="btn btn-warning" type="button" disabled>
<strong>Loading thread {{ followup.id }}</strong>
<div class="spinner-grow spinner-grow-sm ms-2"
role="status"
aria-hidden="true"></div>
</button>
</div>
</div>
{% endfor %}
<div id="thread-{{ post.id }}-new" style="height: 0px;"></div>
</div>
</details>
{% endwith %}
</div>
<div id="post-{{ post.parent_object_id }}-reply" hx-swap-oob="innerHTML">
{% if posting_open %}
{% if post.motion %}
{% include "forums/_hx_post_form_button.html" with slug=forum.slug parent_model='motion' parent_id=post.parent_object_id text="Comment on this Motion" %}
{% else %}
{% include "forums/_hx_post_form_button.html" with slug=forum.slug parent_model='post' parent_id=post.parent_object_id text="Reply" %}
{% endif %}
{% endif %}
</div>
<div id="new-post-form" hx-swap-oob="innerHTML">
{% include "forums/_hx_post_form_button.html" with slug=forum.slug parent_model='forum' parent_id=forum.id text="Add a new Post" %}
</div>
......@@ -150,10 +150,7 @@ urlpatterns = [
),
),
path(
(
"_hx_post_form/<str:parent_model>/<int:parent_id>/"
"<str:origin>/<str:target>/<str:text>/"
),
("_hx_post_form/<str:parent_model>/<int:parent_id>/<str:text>/"),
include(
[
path(
......
......@@ -245,62 +245,41 @@ class ForumListView(LoginRequiredMixin, ListView):
@permission_required_or_403("forums.can_post_to_forum", (Forum, "slug", "slug"))
def _hx_post_form_button(request, slug, parent_model, parent_id, origin, target, text):
def _hx_post_form_button(request, slug, parent_model, parent_id, text):
context = {
"slug": slug,
"parent_model": parent_model,
"parent_id": parent_id,
"origin": origin,
"target": target,
"text": text,
}
return render(request, "forums/_hx_post_form_button.html", context)
@permission_required_or_403("forums.can_post_to_forum", (Forum, "slug", "slug"))
def _hx_post_form(request, slug, parent_model, parent_id, origin, target, text):
def _hx_post_form(request, slug, parent_model, parent_id, text):
forum = get_object_or_404(Forum, slug=slug)
context = {
"slug": slug,
"parent_model": parent_model,
"parent_id": parent_id,
"origin": origin,
"target": target,
"text": text,
}
if request.method == "POST":
form = PostForm(request.POST, forum=forum)
if form.is_valid():
post = form.save()
thread_initiator = post.get_thread_initiator()
response = render(
request,
"forums/post_card.html",
context={"forum": forum, "post": thread_initiator},
context={
"forum": forum,
"post": post,
"posting_open": True, # If a post has just been made, posting is open
},
)
response["HX-Trigger-After-Settle"] = json.dumps(
{"newPost": f"post{post.id}"}
)
# if the parent is a forum, then this is a new Motion or Post,
# and we keep the requested target and swap (== beforebegin).
# Otherwise, we retarget to the initiator post, and swap outerHTML.
# In both cases we refocus the browser after settle.
if parent_model in ["forum", "meeting"]:
# trigger new post form closure
response["HX-Trigger"] = f"newPost-{target}"
# refocus browser on new post
response["HX-Trigger-After-Settle"] = json.dumps(
{
"newPost": f"{target}",
}
)
else:
# force rerendering of whole thread from initiator down
response["HX-Retarget"] = f"#thread-{thread_initiator.id}"
response["HX-Reswap"] = "outerHTML"
# refocus browser on initiator
response["HX-Trigger-After-Settle"] = json.dumps(
{
"newPost": f"thread-{thread_initiator.id}",
}
)
return response
else:
subject = ""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment