]> git.agnieray.net Git - galette.git/blob - galette/templates/default/elements/list.html.twig
Fix batch actions JS for group managers; fixes #1702 (#306)
[galette.git] / galette / templates / default / elements / list.html.twig
1 {% set mode = mode|default('') %}
2 {% set is_paginated = is_paginated ?? (nb > 0) %}
3 {% set is_public = is_public ?? false %}
4
5 {% extends (mode == 'ajax') ? "ajax.html.twig" : is_public ? "public_page.html.twig" : "page.html.twig" %}
6 {% import "macros.twig" as macros %}
7
8 {% block content %}
9 {% if mode == 'ajax' %}
10 <div id="main-container">
11 {% endif %}
12 {% block search %}{% endblock %}
13 {% block infoline %}
14 <form action="{% if infoline.route is defined %}{{ url_for(infoline.route.name, infoline.route.args|default([])) }}{% endif %}" method="post" class="ui form">
15 <div class="infoline">
16 <div class="ui basic horizontal segments">
17 <div class="ui basic fitted segment">
18 <div class="ui label">{{ infoline.label }}</div>
19 {% block infoline_actions %}{% endblock %}
20 </div>
21 {% if infoline.route is defined %}
22 <div class="ui basic right aligned fitted segment">
23 <div class="inline field">
24 <label for="nbshow">{{ _T('Records per page:') }}</label>
25 <select name="nbshow" id="nbshow" class="ui dropdown nochosen">
26 {% for key, value in nbshow_options %}
27 <option value="{{ key }}"{% if key == numrows %} selected="selected"{% endif %}>{{ value }}</option>
28 {% endfor %}
29 </select>
30 <noscript><span><input type="submit" value="{{ _T('Change') }}" class="ui button" /></span></noscript>
31 </div>
32 </div>
33 {% endif %}
34 </div>
35 </div>
36 {% if mode != 'ajax' %}
37 {% include "components/forms/csrf.html.twig" %}
38 {% endif %}
39 </form>
40 {% endblock %}
41 {% if form is defined %}
42 <form action="{% if form.route is defined %}{{ url_for(form.route.name, form.route.args|default([])) }}{% endif %}" method="post" id="listform" class="ui form">
43 <div class="ui basic fitted segment">
44
45 {% if mode != 'ajax' and batch_actions is defined and batch_actions|length > 0 %}
46 {{ macros.drawBatchActionsList(batch_actions) }}
47 {% endif %}
48 {% endif %}
49
50 {% if list_type is defined and list_type == 'cards' %}
51 <div class="{% if nb %}ui doubling {% if cards_columns is defined %}{{ cards_columns }}{% else %}six{% endif %} column cards loader_selector{% endif %}">
52 {% else %}
53 <div class="ui basic fitted segment loader_selector">
54 <table class="listing ui celled{% if basic_table is not defined %} striped{% endif %} table">
55 <thead>
56 <tr>
57 {% block header %}
58 {% for column in columns %}
59 <th class="left">
60 {% if form is defined and column.order is defined %}
61 <a href="{{ url_for(form.order.name, form.order.args|default([])|merge({"option": "order", "value": column.order})) }}">
62 {{ column.label }}
63 {% if filters.orderby == column.order %}
64 {% if filters.ordered == constant('Galette\\Core\\Pagination::ORDER_ASC') %}
65 <i class="ui angle down icon tooltip"></i>
66 {% else %}
67 <i class="ui angle up icon tooltip"></i>
68 {% endif %}
69 {% endif %}
70 </a>
71 {% else %}
72 {{ column.label }}
73 {% endif %}
74 </th>
75 {% endfor %}
76 {% if mode != 'ajax' and no_action is not defined or no_action == false %}
77 <th class="actions_row">{{ _T('Actions') }}</th>
78 {% endif %}
79 {% endblock %}
80 </tr>
81 </thead>
82 <tbody>
83 {% endif %}
84 {% block body %}{% endblock %}
85 {% if list_type is not defined %}
86 </tbody>
87 <tfoot>
88 {% block footer %}{% endblock %}
89 </tfoot>
90 </table>
91 {% endif %}
92
93 {% if form is defined and mode != 'ajax' and batch_actions is defined and batch_actions|length > 0 %}
94 {{ macros.drawBatchActionsList(batch_actions) }}
95 {% endif %}
96
97 </div>
98
99 {% if is_paginated %}
100 <div class="ui basic center aligned fitted segment">
101 <div class="ui inverted pagination menu">
102 <div class="header item">
103 {{ _T('Pages:') }}
104 </div>
105 {{ pagination|raw }}
106 </div>
107 </div>
108 {% endif %}
109
110 {% if form is defined %}
111 {% block extra_form %}{% endblock %}
112 {% include "components/forms/csrf.html.twig" %}
113 </form>
114 {% endif %}
115 {% block legend %}{% endblock %}
116 {% if mode == 'ajax' %}
117 </div>
118 {% endif %}
119 {% endblock %}
120
121 {% set _legend_block = block('legend') %}
122
123 {% block javascripts %}
124 <script type="text/javascript">
125 {% if batch is defined and batch_actions is defined and batch_actions|length > 0 %}
126 var _checkselection = function() {
127 var _checked = $('#listform').find('input[type=checkbox]:checked').length;
128 if ( _checked == 0 ) {
129 {% include "elements/js/modal.js.twig" with {
130 modal_title_twig: batch.modal.title|e("js"),
131 modal_content_twig: batch.modal.content|e("js"),
132 modal_class: "tiny",
133 modal_deny_only: true,
134 modal_cancel_text: _T("Close")|e("js"),
135 modal_classname: "redalert",
136 } %}
137 return false;
138 } else {
139 return true;
140 }
141 }
142 {% endif %}
143 $(function(){
144 {% if batch is defined and batch_actions is defined and batch_actions|length > 0 %}
145 var _init_page = function(res){
146 {% if login.isAdmin() or login.isStaff() or login.isGroupManager() %}
147 {# Use of Javascript to draw specific elements that are not relevant if JS is inactive #}
148 var _checklinks = '<a href="#" class="checkall ui blue tertiary button">{{ _T("(Un)Check all")|e('js') }}</a>' +
149 ' | <a href="#" class="checkinvert ui blue tertiary button">{{ _T("Invert selection")|e('js') }}</a> | ';
150 {% if _legend_block is not empty %}
151 var _legendlink = '<div class="ui basic right aligned fitted segment"><a href="#" class="show_legend ui blue tertiary button">{{ _T("Show legend")|e('js') }}</a></div></div>';
152 {% endif %}
153 $('.batch-select-action').before(_checklinks);
154 $('.batch-select-action').dropdown({
155 onChange: function(value, text, $selectedItem) {
156 if (!_checkselection()) {
157 return false;
158 }
159 // Handle direct download actions.
160 if (value.endsWith('__directdownload')) {
161 const _value = value.split('__');
162 var value = _value[0];
163 var _form = $('#listform');
164 _form.append($('<input id="directdownload" type="hidden" name="' + value + '" value="true"/>'));
165 _form.submit();
166 $('#directdownload').remove();
167 {% if login.isAdmin() or login.isStaff() %}
168 // Handle delete.
169 } else if (value == 'delete') {
170 {% include "elements/js/removal.js.twig" with {
171 selector: ".batch-delete",
172 deleteurl: url_for(batch.route.name, batch.route.args|default([])),
173 extra_data: "delete: true, entries_sel: $('#listform input[type=\"checkbox\"]:checked').map(function(){ return $(this).val(); }).get()",
174 method: "POST",
175 loader: "button",
176 loader_parent: ".batch-select-action"
177 } %}
178 {% endif %}
179 }
180 // Handle other custom list actions.
181 {% if batch_selection is defined %}
182 {% block batch_selection %}{% endblock %}
183 {% endif %}
184 }
185 });
186 $('.batch-selection').after({% if _legend_block is not empty %}_legendlink{% else %}_checklinks{% endif %});
187 _bind_check('entries_sel');
188 {% endif %}
189 }
190 _init_page();
191 {% endif %}
192 {% if _legend_block is not empty %}
193 _bind_legend();
194 {% endif %}
195 {% include "elements/js/removal.js.twig" with {
196 single_action: "true"
197 } %}
198 });
199 </script>
200 {% endblock %}