]> git.agnieray.net Git - galette.git/blob - galette/templates/default/pages/mailing_form.html.twig
Fix pagination in members select modals
[galette.git] / galette / templates / default / pages / mailing_form.html.twig
1 {% extends 'page.html.twig' %}
2
3 {% block content %}
4 {% if preferences.pref_mail_method == constant('Galette\\Core\\Mailing::METHOD_DISABLED') and constant('GALETTE_MODE') != 'DEMO' %}
5 <div id="errorbox" class="ui red message">
6 <h1>{{ _T("- ERROR -") }}</h1>
7 <p>{{ _T("Email sent is disabled in the preferences. Ask galette admin") }}</p>
8 </div>
9 {% elseif mailing_saved is not defined %}
10 <form action="{{ path_for('doMailing') }}" id="listform" method="post" enctype="multipart/form-data" class="ui form">
11 <div class="ui basic fitted segment">
12 <div class="ui styled fluid accordion row">
13 <div class="active title">
14 <i class="jsonly hidden icon dropdown"></i>
15 {{ _T("Mailing information") }}
16 </div>
17 <div class="active content field">
18 {% include "elements/mailing_recipients.html.twig" %}
19 {% if mailing.current_step == constant('Galette\\Core\\Mailing::STEP_SENT') %}
20 {% set path = path_for('members') %}
21 {% set text = _T("Go back to members list") %}
22 {% else %}
23 {% set path = '#' %}
24 {% set text = _T("Manage selected members") %}
25 {% endif %}
26 <a
27 id="btnusers"
28 href="{{ path }}"
29 class="jsonly disabled ui labeled icon button"
30 >
31 <i class="users icon"></i>
32 {{ text }}
33 </a>
34 <noscript>
35 <div class="ui message">{{ _T("This feature requires javascript.") }}</div>
36 </noscript>
37 </div>
38 </div>
39 </div>
40 {% if mailing.current_step == constant('Galette\\Core\\Mailing::STEP_START') %}
41 <div class="ui basic fitted segment">
42 <div class="ui styled fluid accordion row">
43 <div class="active title">
44 <i class="jsonly hidden icon dropdown"></i>
45 {{ _T("Attachments") }}
46 </div>
47 <div class="active content field">
48 {% if attachments|length > 0 %}
49 <label>
50 {{ _T("Existing attachments:") }}
51 </label>
52 <ul id="existing_attachments">
53 {% for attachment in attachments %}
54 <li>
55 <a
56 href="?remove_attachment={{ attachment.getFileName() }}"
57 class="rm_attachement tooltip delete"
58 >
59 <i class="ui trash alt red icon"></i>
60 <span class="sr-only">{{ _T("Remove attachment") }}</span>
61 </a>
62 {{ attachment.getFileName() }}
63 </li>
64 {% endfor %}
65 </ul>
66 {% endif %}
67 <label for="attachment" title="{{ _T("Select attachments") }}">{{ _T("Add attachment") }}</label>
68 <div class="ui right corner labeled input">
69 <div class="ui corner label">
70 <i class="circular inverted primary link icon info tooltip" title="{{ _T("Select files to add as attachments.<br/>Multiple file selection using 'ctrl' or 'shift' keys are only available on compatible browsers.") }}"></i>
71 </div>
72 <input type="file" name="attachment[]" id="attachment" multiple="multiple">
73 </div>
74 </div>
75 </div>
76 </div>
77
78 <div class="ui basic fitted segment">
79 <div class="ui styled fluid accordion row">
80 <div class="active title">
81 <i class="jsonly hidden icon dropdown"></i>
82 {{ _T("Write your mailing") }}
83 </div>
84 <div class="active content field">
85 <div class="inline field">
86 <label for="sender">{{ _T("Sender") }}</label>
87 <select name="sender" id="sender" class="ui dropdown nochosen">
88 <option value="{{ constant('Galette\\Core\\GaletteMail::SENDER_PREFS') }}">{{ _T("from preferences") }}</option>
89 {% if not login.isSuperAdmin() %}
90 <option value="{{ constant('Galette\\Core\\GaletteMail::SENDER_CURRENT') }}">{{ _T("current logged in user") }}</option>
91 {% endif %}
92 <option value="{{ constant('Galette\\Core\\GaletteMail::SENDER_OTHER') }}">{{ _T("other") }}</option>
93 </select>
94 </div>
95 <div class="field required">
96 <label for="sender_name">{{ _T("Name") }}</label>
97 <input type="text" name="sender_name" id="sender_name" value="{{ preferences.pref_email_nom }}" disabled="disabled"/>
98 </div>
99 <div class="field required">
100 <label for="sender_address">{{ _T("Address") }}</label>
101 <input type="text" name="sender_address" id="sender_address" value="{{ preferences.pref_email }}" disabled="disabled"/>
102 </div>
103 <div class="field required">
104 <label for="mailing_objet">{{ _T("Object:") }}</label>
105 <input type="text" name="mailing_objet" id="mailing_objet" value="{{ mailing.subject }}" size="80" required/>
106 </div>
107 <div class="field required">
108 <label for="mailing_corps">{{ _T("Message:") }}</label>
109 <textarea name="mailing_corps" id="mailing_corps" cols="80" rows="15" required>{% if mailing.message %}{{ mailing.message|escape }}{% endif %}</textarea>
110 <input type="hidden" name="html_editor_active" id="html_editor_active" value="{% if html_editor_active %}1{% else %}0{% endif %}"/>
111 </div>
112 <div id="summernote_toggler" class="jsonly hidden ui basic right aligned fitted segment">
113 <a class="ui blue tertiary button" href="javascript:activateMailingEditor('mailing_corps');" id="activate_editor">{{ _T("Activate HTML editor") }}</a>
114 </div>
115 <div class="inline field">
116 <input type="checkbox" name="mailing_html" id="mailing_html" value="1" {% if mailing.html == 1 or preferences.pref_editor_enabled == 1 %}checked="checked"{% endif %}/><label for="mailing_html">{{ _T("Interpret HTML") }}</label>
117 </div>
118 </div>
119 </div>
120 </div>
121
122 <div class="ui basic center aligned segment">
123 <button type="submit" name="mailing_go" id="btnpreview" class="ui labeled icon button">
124 <i class="eye icon" aria-hidden="true"></i>
125 {{ _T("Preview") }}
126 </button>
127 <button type="submit" name="mailing_save" class="ui labeled icon button action">
128 <i class="save icon" aria-hidden="true"></i>
129 {{ _T("Save") }}
130 </button>
131 <button type="submit" name="mailing_confirm" class="ui labeled icon button {% if constant('GALETTE_MODE') == 'DEMO' %} disabled" disabled="disabled{% endif %}">
132 <i class="rocket icon" aria-hidden="true"></i>
133 {{ _T("Send") }}
134 </button>
135 <button type="submit" name="mailing_cancel" formnovalidate class="ui labeled icon button">
136 <i class="trash icon" aria-hidden="true"></i>
137 {{ _T("Cancel mailing") }}
138 </button>
139 </div>
140 {% endif %}
141 {% if mailing.current_step == constant('Galette\\Core\\Mailing::STEP_PREVIEW') %}
142 <section class="mailing_write" id="mail_preview">
143 <header class="ui-state-default ui-state-active">{{ _T("Preview your mailing") }}</header>
144 <div>
145 <p><span class="bline">{{ _T("Object:") }}</span>{{ mailing.subject }}</p>
146 <p>
147 <span class="bline">{{ _T("Message:") }}</span><br/>
148 {% if mailing.html %}
149 {{ mailing.message }}
150 {% else %}
151 <pre>{{ mailing.wrapped_message }}</pre>
152 {% endif %}
153 </p>
154 </div>
155 <div>
156 <p>
157 <button type="submit" name="mailing_reset" class="ui labeled icon button">
158 <i class="backward icon"></i>
159 {{ _T("Modifiy mailing") }}
160 </button>
161 <button type="submit" name="mailing_confirm"{% if constant('GALETTE_MODE') == 'DEMO' %} class="ui labeled icon button disabled" disabled="disabled"{% else %} class="ui labeled icon button"{% endif %}>
162 <i class="rocket icon" aria-hidden="true"></i>
163 {{ _T("Send") }}
164 </button>
165 <button type="submit" name="mailing_cancel" formnovalidate class="ui labeled icon button">
166 <i class="trash red icon" aria-hidden="true"></i>
167 {{ _T("Cancel mailing") }}
168 </button>
169
170 <input type="hidden" name="mailing_objet" value="{{ mailing.subject }}"/>
171 <input type="hidden" name="mailing_corps" value="{% if mailing.message %}{{ mailing.message|escape }}{% endif %}"/>
172 </p>
173 </div>
174 </section>
175 {% endif %}
176 {% include "components/forms/csrf.html.twig" %}
177 </form>
178 {% endif %}
179 {% endblock %}
180
181 {% block javascripts %}
182 {% if (preferences.pref_mail_method != constant('Galette\\Core\\Mailing::METHOD_DISABLED') or constant('GALETTE_MODE') != 'DEMO') and mailing_saved is not defined %}
183 {% if mailing.current_step != constant('Galette\\Core\\Mailing::STEP_SENT') %}
184 <script type="text/javascript">
185 $(function() {
186 {# Preview popup #}
187 $('#btnpreview').click(function(){
188 var _sender = $('#sender').val();
189 var _sender_name = $('#sender_name').val();
190 var _sender_address = $('#sender_address').val();
191 var _subject = $('#mailing_objet').val();
192 var _body = $('#mailing_corps').val();
193 var _html = $('#mailing_html').is(':checked');
194 var _attachments = [];
195 $('#existing_attachments li').each(function(){
196 _attachments[_attachments.length] = $(this).text();
197 });
198 $.ajax({
199 url: '{{ path_for('mailingPreview') }}',
200 type: "POST",
201 data: {
202 sender: _sender,
203 sender_name: _sender_name,
204 sender_address: _sender_address,
205 subject: _subject,
206 body: _body,
207 html: _html,
208 attachments: _attachments
209 },
210 {% include "elements/js/loader.js.twig" %},
211 success: function(res){
212 _preview_dialog(res);
213 },
214 error: function() {
215 alert("{{ _T("An error occurred displaying preview :(")|e("js") }}");
216 }
217 });
218 return false;
219 });
220
221 var _preview_dialog = function(res){
222 $('body').modal({
223 title: '{{ _T("Mailing preview")|e("js") }}',
224 class: 'scrolling',
225 content: res,
226 actions: [{
227 text : '{{ _T("Close")|e('js') }}',
228 class : 'cancel'
229 }]
230 }).modal('show');
231 }
232
233 {# Members popup #}
234 $('#btnusers').click(function(){
235 $.ajax({
236 url: '{{ path_for('ajaxMembers') }}',
237 type: "POST",
238 data: {
239 multiple: true
240 },
241 {% include "elements/js/loader.js.twig" with {
242 selector: '#btnusers',
243 loader: 'button'
244 } %},
245 success: function(res){
246 _members_dialog(res);
247 },
248 error: function() {
249 alert("{{ _T("An error occurred displaying members interface :(")|e("js") }}");
250 }
251 });
252 return false;
253 });
254
255 var _members_dialog = function(res){
256 $('body').modal({
257 title: '{{ _T("Members selection")|e("js") }}',
258 class: 'members-selection fullscreen scrolling',
259 content: res,
260 actions: [{
261 text : '{{ _T("Close")|e('js') }}',
262 class : 'cancel'
263 }]
264 }).modal('show');
265 _members_ajax_mapper(res);
266 }
267
268 var _members_ajax_mapper = function(res){
269 $('#btnvalid').click(function(){
270 //first, let's store new recipients in mailing object
271 var _recipients = new Array();
272 $('li[id^="member_"]').each(function(){
273 _recipients[_recipients.length] = this.id.substring(7, this.id.length);
274 });
275 $.ajax({
276 url: '{{ path_for('mailingRecipients') }}',
277 type: "POST",
278 data: {
279 recipients: _recipients
280 },
281 {% include "elements/js/loader.js.twig" with {
282 selector: '#btnvalid',
283 loader: 'button'
284 } %},
285 success: function(res){
286 $('#unreachables_count').remove();
287 $('#recipients_count').replaceWith(res);
288 $('.members-selection').modal('hide');
289 },
290 error: function() {
291 alert("{{ _T("An error occurred displaying members interface :(")|e("js") }}");
292 }
293 });
294 });
295 //Remap links
296 var _none = $('#none_selected').clone();
297 $('li[id^="member_"]').click(function(){
298 $(this).remove();
299 if ( $('#selected_members ul li').length == 0 ) {
300 $('#selected_members ul').append(_none);
301 }
302 });
303 $('.members-selection a.choice').click(function(e){
304 e.preventDefault();
305 var _mid = this.href.match(/.*\/(\d+)$/)[1];
306 var _mname = $(this).text();
307 $('#none_selected').remove()
308 if ( $('#member_' + _mid).length == 0 ) {
309 var _li = '<li id="member_' + _mid + '" class="item"><i class="user minus icon"></i><span class="ui content">' + _mname + '</span></li>';
310 $('#selected_members ul').append(_li);
311 $('#member_' + _mid).click(function(){
312 $(this).remove();
313 if ( $('#selected_members ul li').length == 0 ) {
314 $('#selected_members ul').append(_none);
315 }
316 });
317 }
318 return false;
319 });
320
321 $('.members-selection .pagination a').click(function(){
322 var _members = new Array();
323 var _unreach = new Array();
324 $('li[id^="member_"]').each(function(){
325 var _mid = this.id.substring(7, this.id.length);
326 if ($(this).hasClass('unreachables')) {
327 _unreach[_unreach.length] = _mid;
328 } else {
329 _members[_members.length] = _mid;
330 }
331 });
332
333 $.ajax({
334 url: this.href,
335 type: "POST",
336 data: {
337 multiple: true,
338 members: _members,
339 unreachables: _unreach
340 },
341 {% include "elements/js/loader.js.twig" with {
342 loader: '#listing'
343 } %},
344 success: function(res){
345 $('#listing').remove();
346 var _listing = $($.parseHTML(res)).find('#listing');
347 $('.members-selection .eleven.wide.column').append(_listing);
348 _members_ajax_mapper(res);
349 },
350 error: function() {
351 alert("{{ _T("An error occurred displaying members interface :(")|e("js") }}");
352 }
353 });
354 return false;
355 });
356 }
357
358 $('.rm_attachement').click(function(){
359 var _link = $(this);
360 $('body').modal({
361 title: '{{ _T("Remove attachment") }}',
362 class: 'fullscreen scrolling',
363 content: '{{ _T("Are you sure you want to remove this attachment?") }}<br/>{{ _T("This will immediately remove attachment from disk and cannot be undo.") }}',
364 actions: [{
365 text : '{{ _T("Remove")|e('js') }}',
366 class : 'red approve',
367 click : function() {
368 window.location.href = '{{ path_for('mailing') }}' + _link.attr('href');
369 }
370 }, {
371 text : '{{ _T("Cancel")|e('js') }}',
372 class : 'cancel'
373 }]
374 }).modal('show');
375 return false;
376 });
377
378 $('#sender').on('change', function() {
379 var _this = $(this);
380 var _sender_name = $('#sender_name');
381 var _sender_address = $('#sender_address');
382 var _editable = false;
383 var _val = _this.val();
384 switch (_val) {
385 case '{{ constant('Galette\\Core\\GaletteMail::SENDER_PREFS') }}':
386 _sender_name.val('{{ preferences.pref_email_nom|e('js') }}');
387 _sender_address.val('{{ preferences.pref_email|e('js') }}');
388 break;
389
390 {% if not login.isSuperAdmin() %}
391 case '{{ constant('Galette\\Core\\GaletteMail::SENDER_CURRENT') }}':
392 _sender_name.val('{{ sender_current['name']|e('js') }}');
393 _sender_address.val('{{ sender_current['email']|e('js') }}');
394 break;
395 {% endif %}
396 case '{{ constant('Galette\\Core\\GaletteMail::SENDER_OTHER') }}':
397 _sender_name.val('');
398 _sender_address.val('');
399 _editable = true;
400 break;
401 }
402
403 if (_editable) {
404 _sender_name.removeAttr('disabled');
405 _sender_address.removeAttr('disabled');
406 $('#sender + span').removeClass('disabled');
407 } else {
408 _sender_name.attr('disabled', 'disabled');
409 _sender_address.attr('disabled', 'disabled');
410 $('#sender + span').addClass('disabled');
411 }
412 });
413 });
414 </script>
415 {% endif %}
416 {% endif %}
417 {% endblock %}