Make hooks/callbacks inherit type
This commit is contained in:
parent
3af63c5ef6
commit
97d12b0fab
14
app/urls.py
14
app/urls.py
|
@ -47,13 +47,19 @@ urlpatterns = [
|
||||||
path("accounts/", include("django.contrib.auth.urls")),
|
path("accounts/", include("django.contrib.auth.urls")),
|
||||||
path("accounts/signup/", base.Signup.as_view(), name="signup"),
|
path("accounts/signup/", base.Signup.as_view(), name="signup"),
|
||||||
path("hooks/<str:type>/", hooks.Hooks.as_view(), name="hooks"),
|
path("hooks/<str:type>/", hooks.Hooks.as_view(), name="hooks"),
|
||||||
path("hooks/modal/add/", hooks.HookAction.as_view(), name="hook_action"),
|
path("hooks/<str:type>/add/", hooks.HookAction.as_view(), name="hook_action"),
|
||||||
path("hooks/modal/add/<str:name>/", hooks.HookAction.as_view(), name="hook_action"),
|
|
||||||
path(
|
path(
|
||||||
"hooks/page/del/<str:hook_id>/", hooks.HookAction.as_view(), name="hook_action"
|
"hooks/<str:type>/add/<str:name>/",
|
||||||
|
hooks.HookAction.as_view(),
|
||||||
|
name="hook_action",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"hooks/modal/edit/<str:hook_id>/",
|
"hooks/<str:type>/del/<str:hook_id>/",
|
||||||
|
hooks.HookAction.as_view(),
|
||||||
|
name="hook_action",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"hooks/<str:type>/edit/<str:hook_id>/",
|
||||||
hooks.HookAction.as_view(),
|
hooks.HookAction.as_view(),
|
||||||
name="hook_action",
|
name="hook_action",
|
||||||
),
|
),
|
||||||
|
|
|
@ -297,7 +297,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<div id="modals-here">
|
<div id="modals-here">
|
||||||
</div>
|
</div>
|
||||||
<div id="items-here">
|
<div id="windows-here">
|
||||||
</div>
|
</div>
|
||||||
<div id="widgets-here" style="display: none;">
|
<div id="widgets-here" style="display: none;">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
{% extends 'wm/modal.html' %}
|
|
||||||
{% load crispy_forms_tags %}
|
|
||||||
|
|
||||||
{% load crispy_forms_bulma_field %}
|
|
||||||
{% block modal_content %}
|
|
||||||
<form
|
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
|
||||||
{% if hook_id is not None %}
|
|
||||||
hx-put="{% url 'hook_action' hook_id %}"
|
|
||||||
{% else %}
|
|
||||||
hx-put="{% url 'hook_action' %}"
|
|
||||||
{% endif %}
|
|
||||||
hx-target="#hooks-table"
|
|
||||||
hx-swap="outerHTML">
|
|
||||||
{% csrf_token %}
|
|
||||||
{{ form|crispy }}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="button is-light modal-close-button">
|
|
||||||
Cancel
|
|
||||||
</button>
|
|
||||||
<button type="submit" class="button is-info modal-close-button">Submit</button>
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
<button class="modal-close is-large" aria-label="close"></button>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<i
|
||||||
|
class="fa-solid fa-xmark has-text-grey-light float-right"
|
||||||
|
onclick='grid.removeWidget("widget-{{ unique }}");'></i>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<i
|
||||||
|
class="fa-solid fa-xmark has-text-grey-light float-right"
|
||||||
|
data-script="on click remove the closest <nav/>"></i>
|
|
@ -20,9 +20,9 @@
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button
|
<button
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-get="{% url 'hook_action' hook_id=item.id %}"
|
hx-get="{% url 'hook_action' type=type hook_id=item.id %}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
hx-target="#modals-here"
|
hx-target="#{{ type }}s-here"
|
||||||
class="button is-info">
|
class="button is-info">
|
||||||
<span class="icon-text">
|
<span class="icon-text">
|
||||||
<span class="icon">
|
<span class="icon">
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-delete="{% url 'hook_action' hook_id=item.id %}"
|
hx-delete="{% url 'hook_action' type=type hook_id=item.id %}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
hx-target="#hooks-table"
|
hx-target="#hooks-table"
|
||||||
class="button is-danger">
|
class="button is-danger">
|
||||||
|
@ -42,7 +42,8 @@
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
<a href="{% url 'callbacks' type='{{ type }}' hook_id=item.id %}"><button
|
{% if type == 'page' %}
|
||||||
|
<a href="{% url 'callbacks' type=type hook_id=item.id %}"><button
|
||||||
class="button is-success">
|
class="button is-success">
|
||||||
<span class="icon-text">
|
<span class="icon-text">
|
||||||
<span class="icon">
|
<span class="icon">
|
||||||
|
@ -51,6 +52,20 @@
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</a>
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<button
|
||||||
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
|
hx-get="{% url 'callbacks' type=type hook_id=item.id %}"
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#{{ type }}s-here"
|
||||||
|
class="button is-success">
|
||||||
|
<span class="icon-text">
|
||||||
|
<span class="icon">
|
||||||
|
<i class="fa-solid fa-eye"></i>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
{% include 'partials/notify.html' %}
|
||||||
|
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
|
||||||
|
{% load crispy_forms_bulma_field %}
|
||||||
|
<form
|
||||||
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
|
{% if hook_id is not None %}
|
||||||
|
hx-put="{% url 'hook_action' hook_id %}"
|
||||||
|
{% else %}
|
||||||
|
hx-put="{% url 'hook_action' %}"
|
||||||
|
{% endif %}
|
||||||
|
hx-target="#hooks-table"
|
||||||
|
hx-swap="outerHTML">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form|crispy }}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="button is-light modal-close-button">
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button type="submit" class="button is-info modal-close-button">Submit</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button
|
<button
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-get="{% url 'hook_action' %}"
|
hx-get="{% url 'hook_action' type=type %}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
hx-target="#modals-here"
|
hx-target="#modals-here"
|
||||||
class="button is-info">
|
class="button is-info">
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-get="{% url 'hooks' type='window' %}"
|
hx-get="{% url 'hooks' type='window' %}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
hx-target="#items-here"
|
hx-target="#windows-here"
|
||||||
hx-swap="afterend"
|
hx-swap="afterend"
|
||||||
class="button is-info">
|
class="button is-info">
|
||||||
<span class="icon-text">
|
<span class="icon-text">
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
{% block modal_content %}
|
{% block modal_content %}
|
||||||
{% include window_content %}
|
{% include window_content %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<button class="modal-close is-large" aria-label="close"></button>
|
{% include 'partials/close-modal.html' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -3,9 +3,7 @@
|
||||||
<p class="panel-heading" style="padding: .2em; line-height: .5em;">
|
<p class="panel-heading" style="padding: .2em; line-height: .5em;">
|
||||||
<i class="fa-solid fa-arrows-up-down-left-right has-text-grey-light"></i>
|
<i class="fa-solid fa-arrows-up-down-left-right has-text-grey-light"></i>
|
||||||
{% block close_button %}
|
{% block close_button %}
|
||||||
<i
|
{% include 'partials/close-window.html' %}
|
||||||
class="fa-solid fa-xmark has-text-grey-light float-right"
|
|
||||||
data-script="on click remove the closest <nav/>"></i>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block heading %}
|
{% block heading %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
<p class="panel-heading" style="padding: .2em; line-height: .5em;">
|
<p class="panel-heading" style="padding: .2em; line-height: .5em;">
|
||||||
<i class="fa-solid fa-arrows-up-down-left-right has-text-grey-light"></i>
|
<i class="fa-solid fa-arrows-up-down-left-right has-text-grey-light"></i>
|
||||||
{% block close_button %}
|
{% block close_button %}
|
||||||
<i
|
{% include 'partials/close-widget.html' %}
|
||||||
class="fa-solid fa-xmark has-text-grey-light float-right"
|
|
||||||
onclick='grid.removeWidget("widget-{{ unique }}");'></i>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<i
|
<i
|
||||||
class="fa-solid fa-arrows-minimize has-text-grey-light float-right"
|
class="fa-solid fa-arrows-minimize has-text-grey-light float-right"
|
||||||
|
|
|
@ -92,19 +92,25 @@ class Hooks(LoginRequiredMixin, View):
|
||||||
"unique": unique,
|
"unique": unique,
|
||||||
"window_content": self.window_content,
|
"window_content": self.window_content,
|
||||||
"items": hooks,
|
"items": hooks,
|
||||||
|
"type": type,
|
||||||
}
|
}
|
||||||
return render(request, template_name, context)
|
return render(request, template_name, context)
|
||||||
|
|
||||||
|
|
||||||
class HookAction(LoginRequiredMixin, APIView):
|
class HookAction(LoginRequiredMixin, APIView):
|
||||||
template_name = "modals/add-hook.html"
|
allowed_types = ["modal", "widget", "window", "page"]
|
||||||
|
window_content = "window-content/add-hook.html"
|
||||||
parser_classes = [FormParser]
|
parser_classes = [FormParser]
|
||||||
|
|
||||||
def get(self, request, hook_id=None):
|
def get(self, request, type, hook_id=None):
|
||||||
"""
|
"""
|
||||||
Get the form for adding or editing a hook.
|
Get the form for adding or editing a hook.
|
||||||
:param hook_id: The id of the hook to edit. Optional.
|
:param hook_id: The id of the hook to edit. Optional.
|
||||||
"""
|
"""
|
||||||
|
if type not in self.allowed_types:
|
||||||
|
return HttpResponseBadRequest
|
||||||
|
template_name = f"wm/{type}.html"
|
||||||
|
unique = str(uuid.uuid4())[:8]
|
||||||
if hook_id:
|
if hook_id:
|
||||||
try:
|
try:
|
||||||
hook = Hook.objects.get(id=hook_id, user=request.user)
|
hook = Hook.objects.get(id=hook_id, user=request.user)
|
||||||
|
@ -115,15 +121,22 @@ class HookAction(LoginRequiredMixin, APIView):
|
||||||
context = {
|
context = {
|
||||||
"message": message,
|
"message": message,
|
||||||
"message_class": message_class,
|
"message_class": message_class,
|
||||||
|
"window_content": self.window_content,
|
||||||
}
|
}
|
||||||
return render(request, self.template_name, context)
|
return render(request, template_name, context)
|
||||||
else:
|
else:
|
||||||
form = HookForm()
|
form = HookForm()
|
||||||
context = {"form": form, "hook_id": hook_id}
|
context = {
|
||||||
|
"form": form,
|
||||||
|
"hook_id": hook_id,
|
||||||
|
"type": type,
|
||||||
|
"unique": unique,
|
||||||
|
"window_content": self.window_content,
|
||||||
|
}
|
||||||
|
|
||||||
return render(request, self.template_name, context)
|
return render(request, template_name, context)
|
||||||
|
|
||||||
def put(self, request, hook_id=None):
|
def put(self, request, type, hook_id=None):
|
||||||
"""
|
"""
|
||||||
Add or edit a hook.
|
Add or edit a hook.
|
||||||
:param hook_id: The id of the hook to edit. Optional.
|
:param hook_id: The id of the hook to edit. Optional.
|
||||||
|
@ -160,6 +173,7 @@ class HookAction(LoginRequiredMixin, APIView):
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"items": hooks,
|
"items": hooks,
|
||||||
|
"type": type,
|
||||||
}
|
}
|
||||||
if message:
|
if message:
|
||||||
context["message"] = message
|
context["message"] = message
|
||||||
|
@ -167,7 +181,7 @@ class HookAction(LoginRequiredMixin, APIView):
|
||||||
template_name = "partials/hook-list.html"
|
template_name = "partials/hook-list.html"
|
||||||
return render(request, template_name, context)
|
return render(request, template_name, context)
|
||||||
|
|
||||||
def delete(self, request, hook_id):
|
def delete(self, request, type, hook_id):
|
||||||
"""
|
"""
|
||||||
Delete a hook.
|
Delete a hook.
|
||||||
:param hook_id: The id of the hook to delete.
|
:param hook_id: The id of the hook to delete.
|
||||||
|
@ -186,6 +200,7 @@ class HookAction(LoginRequiredMixin, APIView):
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"items": hooks,
|
"items": hooks,
|
||||||
|
"type": type,
|
||||||
}
|
}
|
||||||
if message:
|
if message:
|
||||||
context["message"] = message
|
context["message"] = message
|
||||||
|
|
Loading…
Reference in New Issue