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