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