summaryrefslogtreecommitdiff
path: root/src/application/templates/old/view_topic.twig
blob: 70d0d67987a4f6d43373588bce080ce10066104d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
{% set canReply =
    not ctx.topic.isLocked
    and currentUser is not null
    and currentUser.hasPermission(permission("CREATE_OWN_POST")) %}

{% set canEdit =
    currentUser is not null and (
        (
            ctx.topicAuthor is not null
            and currentUser.id == ctx.topicAuthor.id
            and ctx.topicAuthor.hasPermission(permission("EDIT_OWN_TOPIC"))
        )
        or currentUser.hasPermission(permission("EDIT_OTHER_TOPIC"))
    ) %}

{% set couldEditPost =
    currentUser is not null
    and (
        currentUser.hasPermission(permission("EDIT_OWN_POST"))
        or currentUser.hasPermission(permission("EDIT_OTHER_POST"))
    ) %}

{% set canDelete =
    currentUser is not null and (
        (
            ctx.topicAuthor is not null
            and currentUser.id == ctx.topicAuthor.id
            and ctx.topicAuthor.hasPermission(permission("DELETE_OWN_TOPIC"))
        )
        or currentUser.hasPermission(permission("DELETE_OTHER_TOPIC"))
    ) %}

{% set canSubscribe = currentUser is not null %}

{% set isSubscribed =
    currentUser is not null
    and ctx.subscription is not null %}

{% set title = ctx.topic.title %}
{% extends "base.twig" %}

{% block content %}

{% set formError = getAndClearFormError("updateTopic") %}
{% if formError %}
    {% include "components/alert_error.twig" with { message: formError } %}
{% endif %}
{% set formError = getAndClearFormError("lockTopic") %}
{% if formError %}
    {% include "components/alert_error.twig" with { message: formError } %}
{% endif %}
{% set formError = null %}

<hr color="silver" noshade>

<div class="page-header margin-top-0 clearfix">
    <div id="displayHeading">
        <h1>
            {% if ctx.topic.isLocked %}
                <span class="fa fa-lock text-muted" aria-hidden="true"></span>
            {% endif %}
            {{ ctx.topic.title }}
            <div class="pull-right text-normal">
                {%- if canEdit and not ctx.topic.isLocked -%}
                    <button id="btn-edit-title" class="seamless js-only m-r"><img src="/ui/theme-files/old/pencil.gif" width="16" height="16" draggable="false" alt="{{ __("Edit title") }}"></button>
                {%- endif -%}
                {%- if canReply -%}
                    <button id="btn-reply" class="seamless js-only m-r"><img src="/ui/theme-files/old/undo.gif" width="16" height="16" draggable="false" alt="{{ __("Reply") }}"></button>
                {%- endif -%}
                {%- if canEdit -%}
                    {%- if ctx.topic.isLocked -%}
                        <form action="?_action=locktopic" method="post" class="inline">{#
                            #}<input type="hidden" name="topic" value="{{ ctx.topic.id }}">{#
                            #}<input type="hidden" name="locked" value="false">{#
                            #}<button type="submit" class="seamless m-r"><img src="/ui/theme-files/old/lock_open.gif" width="16" height="16" draggable="false" alt="{{ __("Unlock topic") }}"></button>{#
                        #}</form>
                    {%- else -%}
                        <form action="?_action=locktopic" method="post" class="inline">{#
                            #}<input type="hidden" name="topic" value="{{ ctx.topic.id }}">{#
                            #}<input type="hidden" name="locked" value="true">{#
                            #}<button type="submit" class="seamless m-r"><img src="/ui/theme-files/old/lock.gif" width="16" height="16" draggable="false" alt="{{ __("Lock topic") }}"></button>{#
                        #}</form>
                    {%- endif -%}
                {%- endif -%}
                {%- if canSubscribe -%}
                    <form action="?_action=subscribetopic" method="post" class="inline">{#
                        #}<input type="hidden" name="topic" value="{{ ctx.topic.id }}">
                        {%- if isSubscribed -%}
                            <button type="submit" class="seamless m-r"><img src="/ui/theme-files/old/unsubscribe.gif" width="16" height="16" draggable="false" alt="{{ __("Unsubscribe from topic") }}"></button>
                        {%- else -%}
                            <button type="submit" class="seamless m-r"><img src="/ui/theme-files/old/subscribe.gif" width="16" height="16" draggable="false" alt="{{ __("Subscribe to topic") }}"></button>
                        {%- endif -%}
                    </form>
                {%- endif -%}
                {%- if canDelete -%}
                    <form action="?_action=deletetopic" method="post" class="inline">{#
                        #}<input type="hidden" name="topic" value="{{ ctx.topic.id }}">{#
                        #}<button type="submit" class="seamless m-r"><img src="/ui/theme-files/old/garbage.gif" width="16" height="16" draggable="false" alt="{{ __("Delete topic") }}"></button>{#
                    #}</form>
                {%- endif -%}
            </div>
        </h1>
        {{ __("Started by %user% on %date%", {
            "user": (ctx.topicAuthor is not null) ? ('<a href="?_action=viewuser&amp;user=' ~ ctx.topicAuthor.id|url_encode|e("html") ~ '">' ~ ctx.topicAuthor.displayName|e("html") ~ '</a>') : __("(deleted)"),
            "date": '<span class="_time">' ~ ctx.topic.creationDate.format("c")|e("html") ~ '</span>',
        }) }} &bull; {{ ___(
            "%n% person is watching this topic",
            "%n% people are watching this topic",
            ctx.subscription_count,
            {
                n: ctx.subscription_count,
            },
        ) }}
    </div>
    {% if canEdit %}
        <form action="?_action=updatetopic" method="post" id="editHeading" style="display: none;" class="inline">
            <input type="hidden" name="topic" value="{{ ctx.topic.id }}">
            <table width="100%" cellspacing="0">
            <tr>
                <td width="100%">
                    <input type="text" class="fw h1" name="title" id="i_edit_title" data-original-value="{{ ctx.topic.title }}" value="{{ ctx.topic.title }}">
                </td>
                <td align="right">
                    <nobr>
                        <button type="submit" class="btn btn-success">{{ __("Save changes") }}</button>
                        <button type="button" id="topicTitleEditCancel">{{ __("Cancel") }}</button>
                    </nobr>
                </td>
            </tr>
            </table>
        </form>
    {% endif %}
</div>
<script>
{% if canEdit %}
$(function() {
    $("#btn-edit-title").click(function() {
        $("#displayHeading").hide();
        $("#editHeading").show();
        $("#i_edit_title").val($("#i_edit_title").attr("data-original-value")).focus();
    });
    $("#topicTitleEditCancel").click(function() {
        $("#displayHeading").show();
        $("#editHeading").hide();
    });
});
{% endif %}
</script>
{% if couldEditPost %}
<script>
$(function() {
    $("._edit-post").click(function() {
        var $post = $("#post-" + $(this).attr("data-post-id"));
        var $postContent = $post.find(".post-content");
        $("#i_edit_message").css("height", "").val($post.attr("data-text"));
        $("#i_edit_post").val($(this).attr("data-post-id"));
        $("#diag-edit-post").modal();
    });
    $("#diag-edit-post").on("shown.bs.modal", function() {
        $("#i_edit_message").focus();
    });
});
{% endif %}
{% if canReply %}
$(function() {
    function focusReplyBox() {
        var msgInput = $("#i_message");
        msgInput[0].scrollIntoView();
        msgInput.focus();
    }
    $("#btn-reply").click(function() {
        focusReplyBox();
    });
    $("._reply-post").click(function() {
        var text = $("#post-" + $(this).attr("data-post-id")).attr("data-text");
        var val = $("#i_message").val();
        var lines = text.split("\n");
        for (var i = 0; i < lines.length; ++i)
            val += "\n> " + lines[i];
        val += "\n\n";
        $("#i_message").val(val.replace(/^\n+/, ""));
        focusReplyBox();
    });
});
{% endif %}
</script>

<table border="1" cellspacing="0" cellpadding="4" bordercolor="silver" width="100%" bgcolor="white">
{% for item in ctx.allItems %}
    {% if item.type == "post" %}
        {% include "components/post.twig" with {
            post: item.post,
            postAuthor: item.postAuthor,
            topicAuthor: item.topicAuthor,
            topic: item.topic,
            attachments: item.attachments,
            hide_actions: false,
            hide_pfp: false,
        } %}
    {% elseif item.type == "logMessage" %}
        {% include "components/topic_log.twig" with {
            type: item.type,
            logMessage: item.logMessage,
            postAuthor: item.postAuthor,
            topicAuthor: item.topicAuthor,
            topic: item.topic,
            hide_actions: false,
            hide_pfp: false,
        } %}
    {% endif %}
{% endfor %}
</table>

{% if ctx.topic.isLocked %}
    <br>
    <table cellspacing="0" cellpadding="8" bgcolor="#FFCC99" border="1" bordercolor="#996633" width="100%">
    <tr><td align="center">
        <img src="/ui/theme-files/old/lock_large.gif" border="0" alt="" width="32" height="32" draggable="false"><br>
        <i>{{ __("This topic has been locked") }}</i>
    </td></tr>
    </table>
    <br>
{% elseif currentUser is not null %}
    {% set formId = "addpost" %}
    <h3 id="form">{{ __("Reply to this topic") }}</h3>
    {% set formError = getAndClearFormError(formId) %}
    {% if formError %}
        {% include "components/alert_error.twig" with { message: formError } %}
    {% endif %}
    <form action="{{ g.server.REQUEST_URI }}#form" method="post" enctype="multipart/form-data">
        <input type="hidden" name="form_id" value="{{ formId }}">
        
        <label for="i_message">{{ __("Message:") }}</label><br>
        {% include "components/post_editor.twig" with { value: "", name: "message", id: "i_message" } %}
        <br>
        <label for="i_files">{{ __("Attachments: <small>(max. %max_attachment_count% files, max. %max_attachment_size% MiB each)</small>", {
            "max_attachment_count": constant("MAX_ATTACHMENT_COUNT"),
            "max_attachment_size": constant("MAX_ATTACHMENT_SIZE") // (2**20),
        }) }}</label><br>
        <input type="file" name="files[]" id="i_files" multiple accept="*/*"><br>
        <br>
        {% if not isSubscribed %}
            <label><input type="checkbox" name="subscribe" value="on" checked> {{ __("Subscribe to topic") }}</label><br>
            <br>
        {% endif %}
        <button type="submit">{{ __("Post reply") }}</button>
    </form>
{% else %}
    <br>
    <table cellspacing="0" cellpadding="8" bgcolor="lightskyblue" border="1" bordercolor="skyblue" width="100%">
    <tr><td align="center">
        <h3>{{ __("Log in to reply to this topic") }}</h3>
        <form action="." method="get" class="inline">
            <input type="hidden" name="_action" value="auth">
            <input type="hidden" name="next" value="{{ g.server.REQUEST_URI }}">
            <button type="submit">{{ __("Log in") }}</button>
        </form>
    </td></tr>
    </table>
    <br>
{% endif %}


{% endblock %}