831f53a469491814457ee508e64fc56f7d9b365e
[moodle.git] / mod / forum / templates / discussion_list.mustache
1 {{!
2     This file is part of Moodle - http://moodle.org/
4     Moodle is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
9     Moodle is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
14     You should have received a copy of the GNU General Public License
15     along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16 }}
17 {{!
18     @template mod_forum/discussion_list
20     Template to display the list of forum discussions.
22     Classes required for JS:
23     * none
25     Data attributes required for JS:
26     * none
28     Context variables required for this template:
29     * TODO
31     Example context (json):
32     {
33     }
34 }}
35 <div id="discussion-list-{{uniqid}}">
36     {{{groupchangemenu}}}
38     {{#notifications}}
39         {{> core/notification}}
40     {{/notifications}}
42     {{#forum.capabilities.create}}
43         <div class="p-t-1 p-b-1">
44             <a class="btn btn-primary" data-toggle="collapse" href="#collapseAddForm">
45                 {{$discussion_create_text}}
46                     {{#str}}addanewdiscussion, forum{{/str}}
47                 {{/discussion_create_text}}
48             </a>
49             <div class="collapse m-t-1" id="collapseAddForm">
50                 {{{newdiscussionhtml}}}
51             </div>
52         </div>
53     {{/forum.capabilities.create}}
54     {{^forum.capabilities.create}}
55         {{#forum.capabilities.selfenrol}}
56             <div class="p-t-1 p-b-1">
57                 <a class="btn btn-primary" href="{{forum.urls.create}}">
58                     {{$discussion_create_text}}
59                         {{#str}}addanewdiscussion, forum{{/str}}
60                     {{/discussion_create_text}}
61                 </a>
62             </div>
63         {{/forum.capabilities.selfenrol}}
64     {{/forum.capabilities.create}}
67     {{#state.hasdiscussions}}
68         {{$discussion_top_pagination}}
69             {{{ pagination }}}
70         {{/discussion_top_pagination}}
71         {{$discussion_list_output}}
72             <span id="discussion-table-description-{{uniqid}}" class="sr-only">
73                 {{#str}} showingcountoftotaldiscussions, mod_forum, {"count": "{{visiblediscussioncount}}", "total":"{{totaldiscussioncount}}"} {{/str}}
74             </span>
75             <table
76                 class="table table-hover discussion-list"
77                 aria-label='{{#str}} showingcountoftotaldiscussions, mod_forum, {"count": "{{visiblediscussioncount}}", "total":"{{totaldiscussioncount}}"} {{/str}}'
78                 aria-describedby="discussion-table-description-{{uniqid}}"
79             >
80                 {{$discussion_list_header}}
81                 <thead>
82                     <tr>
83                         <th scope="col">
84                             <span class="accesshide">{{#str}}status{{/str}}</span>
85                         </th>
86                         <th scope="col" class="p-l-0">{{#str}}discussion, mod_forum{{/str}}</th>
87                         {{#forum.state.groupmode}}
88                             <th scope="col" class="group">{{#str}}group{{/str}}</th>
89                         {{/forum.state.groupmode}}
90                         <th scope="col" class="author">
91                             {{#str}}startedby, mod_forum{{/str}}
92                         </th>
93                         <th scope="col" class="lastpost">
94                             {{#state.sortorder.islastpostdesc}}
95                                 <a href="{{{forum.urls.sortlastpostasc}}}" aria-label="{{#str}}discussionlistsortbylastpostasc, mod_forum{{/str}}">{{#str}}lastpost, mod_forum{{/str}}</a> <span class="text-primary">{{#pix}}t/downlong, core, {{#str}}desc, core{{/str}}{{/pix}}</span>
96                             {{/state.sortorder.islastpostdesc}}
97                             {{#state.sortorder.islastpostasc}}
98                                 <a href="{{{forum.urls.sortlastpostdesc}}}" aria-label="{{#str}}discussionlistsortbylastpostdesc, mod_forum{{/str}}">{{#str}}lastpost, mod_forum{{/str}}</a> <span class="text-primary">{{#pix}}t/uplong, core, {{#str}}asc, core{{/str}}{{/pix}}</span>
99                             {{/state.sortorder.islastpostasc}}
100                             {{^state.sortorder.islastpostdesc}}
101                                 {{^state.sortorder.islastpostasc}}
102                                     <a href="{{{forum.urls.sortlastpostdesc}}}" aria-label="{{#str}}discussionlistsortbylastpostdesc, mod_forum{{/str}}">{{#str}}lastpost, mod_forum{{/str}}</a>
103                                 {{/state.sortorder.islastpostasc}}
104                             {{/state.sortorder.islastpostdesc}}
105                         </th>
106                         {{#forum.capabilities.viewdiscussions}}
107                             <th scope="col" class="text-center">
108                                 {{#state.sortorder.isrepliesdesc}}
109                                     <a href="{{{forum.urls.sortrepliesasc}}}" aria-label="{{#str}}discussionlistsortbyrepliesasc, mod_forum{{/str}}">{{#str}}replies, mod_forum{{/str}}</a> <span class="text-primary">{{#pix}}t/downlong, core, {{#str}}desc, core{{/str}}{{/pix}}</span>
110                                 {{/state.sortorder.isrepliesdesc}}
111                                 {{#state.sortorder.isrepliesasc}}
112                                     <a href="{{{forum.urls.sortrepliesdesc}}}" aria-label="{{#str}}discussionlistsortbyrepliesdesc, mod_forum{{/str}}">{{#str}}replies, mod_forum{{/str}}</a> <span class="text-primary">{{#pix}}t/uplong, core, {{#str}}asc, core{{/str}}{{/pix}}</span>
113                                 {{/state.sortorder.isrepliesasc}}
114                                 {{^state.sortorder.isrepliesdesc}}
115                                     {{^state.sortorder.isrepliesasc}}
116                                         <a href="{{{forum.urls.sortrepliesdesc}}}" aria-label="{{#str}}discussionlistsortbyrepliesdesc, mod_forum{{/str}}">{{#str}}replies, mod_forum{{/str}}</a>
117                                     {{/state.sortorder.isrepliesasc}}
118                                 {{/state.sortorder.isrepliesdesc}}
119                                 {{#forum.userstate.tracked}}
120                                     <a href="{{{forum.urls.markasread}}}">{{#pix}}t/markasread, core, {{#str}}markallread, mod_forum{{/str}}{{/pix}}</a>
121                                 {{/forum.userstate.tracked}}
122                             </th>
123                         {{/forum.capabilities.viewdiscussions}}
124                         <th scope="col" class="discussionsubscription">
125                             <span class="accesshide">{{#str}}actions{{/str}}</span>
126                         </th>
127                     </tr>
128                 </thead>
129                 {{/discussion_list_header}}
130                 {{$discussion_list_body}}
131                 <tbody>
132                     {{#summaries}}
133                         <!-- The discussion class is only required for behat tests to identify the row -->
134                         <tr class="discussion {{#discussion.timed}}{{#istimed}}{{^visible}}dimmed_text{{/visible}}{{/istimed}}{{/discussion.timed}}"
135                             data-region="discussion-list-item"
136                             data-discussionid="{{id}}"
137                             data-forumid="{{forumid}}">
138                             <td class="pinned p-0 text-center align-middle">
139                                 {{#discussion.pinned}}
140                                     {{#pix}}i/pinned, mod_forum, {{#str}}discussionpinned, mod_forum{{/str}}{{/pix}}
141                                 {{/discussion.pinned}}
142                                 {{^discussion.pinned}}
143                                     {{#discussion}}
144                                         {{> mod_forum/forum_discussion_favourite_toggle}}
145                                     {{/discussion}}
146                                 {{/discussion.pinned}}
147                             </td>
148                             <th scope="row" class="topic p-0 align-middle">
149                                 <div class="p-3 p-l-0">
150                                     <a class="w-100 h-100 d-block" href="{{discussion.urls.view}}" title="{{discussion.name}}" aria-label="{{discussion.name}}">
151                                         {{#shortentext}}72, {{{discussion.name}}}{{/shortentext}}
152                                     </a>
153                                     <div>
154                                         <span class="badge badge-danger rounded" data-region="locked-label" {{^discussion.locked}}hidden{{/discussion.locked}}>
155                                             {{#str}}locked, forum{{/str}}
156                                         </span>
157                                         <span class="badge badge-light rounded" data-region="subscribed-label" {{^discussion.userstate.subscribed}}hidden{{/discussion.userstate.subscribed}}>
158                                             {{#str}}subscribed, forum{{/str}}
159                                         </span>
160                                         {{#discussion.timed.istimed}}
161                                         <a href="#" role="button" class="badge badge-primary rounded" data-region="timed-label"
162                                             data-toggle="popover" data-container="body" data-placement="right" data-html="true"
163                                             data-content='{{#discussion.timed}}{{#discussion.times}}{{> mod_forum/discussion_times}}{{/discussion.times}}{{/discussion.timed}}'
164                                             data-trigger="click" aria-label="{{#str}}timeddiscussion, forum{{/str}}" title="{{#str}}timeddiscussion, forum{{/str}}">
165                                             {{#str}}timed, forum{{/str}}
166                                         </a>
167                                         {{/discussion.timed.istimed}}
168                                     </div>
169                                 </div>
170                             </th>
171                             {{#forum.state.groupmode}}
172                                 <td class="group align-middle">
173                                     {{#discussion.group}}
174                                         <img alt="{{#str}} pictureof, core, {{name}} {{/str}}"
175                                              class="border rounded h-auto rounded-circle grouppicture"
176                                              src="{{{urls.picture}}}"
177                                              title="{{#str}} pictureof, core, {{name}} {{/str}}">
178                                         {{#urls.userlist}}
179                                             <a href="{{{urls.userlist}}}" role="button" aria-label='{{#str}} memberofgroup, group, {{name}}{{/str}}'>
180                                                 {{#shortentext}}15, {{name}}{{/shortentext}}
181                                             </a>
182                                         {{/urls.userlist}}
183                                         {{^urls.userlist}}
184                                             <span>{{name}}</span>
185                                         {{/urls.userlist}}
186                                     {{/discussion.group}}
187                                 </td>
188                             {{/forum.state.groupmode}}
189                             <td class="author align-middle">
190                                 {{#firstpostauthor}}
191                                     <div class="d-flex flex-row">
192                                         <div class="align-middle p-0">
193                                             <img class="rounded-circle userpicture" src="{{urls.profileimage}}"
194                                                  alt="{{#str}}pictureof, moodle, {{fullname}}{{/str}}"
195                                                  title="{{#str}}pictureof, moodle, {{fullname}}{{/str}}" >
196                                         </div>
197                                         <div class="align-middle">
198                                             <div>{{fullname}}</div>
199                                             <div>
200                                                 <small>{{#userdate}}{{discussion.times.created}}, {{#str}}strftimedatemonthabbr, langconfig{{/str}}{{/userdate}}</small>
201                                             </div>
202                                         </div>
203                                     </div>
204                                 {{/firstpostauthor}}
205                             </td>
206                             <td class="text-left align-middle">
207                                 {{! TODO Check q&a, eachuser }}
208                                 {{#latestpostid}}
209                                     <a href="{{{discussion.urls.viewlatest}}}" title="{{#userdate}}{{discussion.times.modified}},{{#str}}strftimerecentfull{{/str}}{{/userdate}}">
210                                         {{#userdate}}
211                                             {{discussion.times.modified}}, {{#str}}strftimedateshortmonthabbr, langconfig{{/str}}
212                                         {{/userdate}}
213                                     </a>
214                                 {{/latestpostid}}
215                             </td>
216                             {{#forum.capabilities.viewdiscussions}}
217                                 <td class="p-0 text-center align-middle">
218                                     <span class="p-1">{{replies}}</span>
219                                     {{#forum.userstate.tracked}}
220                                         {{#unread}}
221                                         {{! TODO Rewrite as AJAX}}
222                                             <span class="p-1">
223                                                 <a href="{{{discussion.urls.viewfirstunread}}}" class="badge badge-primary rounded-circle" aria-label="{{#str}}unreadpostsnumber, mod_forum, {{unread}}{{/str}}">{{unread}}</a>
224                                             </span>
225                                             <span class="p-1">
226                                                 <a href="{{{discussion.urls.markasread}}}">{{#pix}}t/markasread, core, {{#str}}markalldread, mod_forum{{/str}}{{/pix}}</a>
227                                             </span>
228                                         {{/unread}}
229                                     {{/forum.userstate.tracked}}
230                                 </td>
231                             {{/forum.capabilities.viewdiscussions}}
232                             <td class="p-0 align-middle" data-container="discussion-summary-actions">
233                                 {{#discussion}}
234                                     <div class="d-flex flex-wrap justify-content-end pr-4">
235                                         {{#hasanyactions}}
236                                             <div data-container='discussion-tools'>
237                                                 {{> mod_forum/forum_action_menu}}
238                                             </div>
239                                         {{/hasanyactions}}
240                                     </div>
241                                 {{/discussion}}
242                             </td>
243                         </tr>
244                     {{/summaries}}
245                 </tbody>
246                 {{/discussion_list_body}}
247             </table>
248         {{/discussion_list_output}}
249         {{$discussion_bottom_pagination}}
250             {{{ pagination }}}
251         {{/discussion_bottom_pagination}}
252         {{#can_create_discussion}}
253             <div class="forumaddnew">
254                 <a href="{{create_discussion_link}}" class="btn btn-primary">{{create_discussion_link_text}}</a>
255             </div>
256         {{/can_create_discussion}}
257     {{/state.hasdiscussions}}
258     {{^state.hasdiscussions}}
259         <div class="forumnodiscuss">
260             {{$no_discussions_text}}
261                 ({{#str}}nodiscussions, forum{{/str}})
262             {{/no_discussions_text}}
263         </div>
264     {{/state.hasdiscussions}}
266 </div>
267 {{#js}}
268     require(['jquery', 'mod_forum/discussion_list'], function($, View) {
269         var root = $('#discussion-list-{{uniqid}}');
270         View.init(root);
271     });
272 {{/js}}