mirror of https://gitlab.com/tildes/tildes.git
Browse Source
Refactor bookmark toggle button some more
Refactor bookmark toggle button some more
This should (mostly) work for also applying this to some of the other toggle buttons, but will probably still need a bit of work.merge-requests/69/head
Deimos
6 years ago
6 changed files with 49 additions and 105 deletions
-
10tildes/tildes/templates/intercooler/post_action_toggle_button.jinja2
-
55tildes/tildes/templates/macros/buttons.jinja2
-
10tildes/tildes/templates/macros/comments.jinja2
-
10tildes/tildes/templates/topic.jinja2
-
26tildes/tildes/views/api/web/comment.py
-
37tildes/tildes/views/api/web/topic.py
@ -1,39 +1,38 @@ |
|||||
{# Copyright (c) 2019 Tildes contributors <code@tildes.net> #} |
{# Copyright (c) 2019 Tildes contributors <code@tildes.net> #} |
||||
{# SPDX-License-Identifier: AGPL-3.0-or-later #} |
{# SPDX-License-Identifier: AGPL-3.0-or-later #} |
||||
|
|
||||
{% macro post_action_toggle_button(subject, is_toggled, normal_name, normal_label, toggled_name, toggled_label, route_name) %} |
|
||||
{% if is_toggled %} |
|
||||
<li><button class="btn-post-action btn-post-action-used" name="{{ toggled_name }}" |
|
||||
|
{% macro post_action_toggle_button(name, subject, is_toggled) %} |
||||
{% if subject is comment %} |
{% if subject is comment %} |
||||
data-ic-delete-from="{{ request.route_url( |
|
||||
route_name, |
|
||||
comment_id36=subject.comment_id36, |
|
||||
) }}" |
|
||||
data-ic-target="#comment-{{ subject.comment_id36 }} .comment-itself:first" |
|
||||
|
{% set type_name = "comment" %} |
||||
{% elif subject is topic %} |
{% elif subject is topic %} |
||||
data-ic-delete-from="{{ request.route_url( |
|
||||
route_name, |
|
||||
topic_id36=subject.topic_id36, |
|
||||
) }}" |
|
||||
|
{% set type_name = "topic" %} |
||||
{% endif %} |
{% endif %} |
||||
|
{% set route_name = "ic_" + type_name + "_" + name %} |
||||
|
|
||||
|
{% if name == "bookmark" %} |
||||
|
{% set normal_label = "Bookmark" %} |
||||
|
{% set toggled_label = "Unbookmark" %} |
||||
|
{% endif %} |
||||
|
|
||||
|
<li> |
||||
|
{% if not is_toggled %} |
||||
|
<button class="btn-post-action" |
||||
|
data-ic-put-to="{{ _post_action_toggle_button_url(route_name, subject) }}" |
||||
data-ic-replace-target="true" |
data-ic-replace-target="true" |
||||
>{{ toggled_label }} |
|
||||
|
>{{ normal_label }}</button> |
||||
{% else %} |
{% else %} |
||||
<li><button class="btn-post-action" name="{{ normal_name }}" |
|
||||
{% if subject is comment %} |
|
||||
data-ic-put-to="{{ request.route_url( |
|
||||
route_name, |
|
||||
comment_id36=subject.comment_id36, |
|
||||
) }}" |
|
||||
data-ic-target="#comment-{{ subject.comment_id36 }} .comment-itself:first" |
|
||||
{% elif subject is topic %} |
|
||||
data-ic-put-to="{{ request.route_url( |
|
||||
route_name, |
|
||||
topic_id36=subject.topic_id36, |
|
||||
) }}" |
|
||||
{% endif %} |
|
||||
|
<button class="btn-post-action btn-post-action-used" |
||||
|
data-ic-delete-from="{{ _post_action_toggle_button_url(route_name, subject) }}" |
||||
data-ic-replace-target="true" |
data-ic-replace-target="true" |
||||
>{{ normal_label }} |
|
||||
|
>{{ toggled_label }}</button> |
||||
{% endif %} |
{% endif %} |
||||
</button></li> |
|
||||
|
</li> |
||||
|
{% endmacro %} |
||||
|
|
||||
|
{% macro _post_action_toggle_button_url(route_name, subject) %} |
||||
|
{% if subject is comment -%} |
||||
|
{{ request.route_url(route_name, comment_id36=subject.comment_id36) }} |
||||
|
{% elif subject is topic -%} |
||||
|
{{ request.route_url(route_name, topic_id36=subject.topic_id36) }} |
||||
|
{%- endif %} |
||||
{% endmacro %} |
{% endmacro %} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue