Update copyright date for 2020
[civicrm-core.git] / templates / CRM / Contact / Form / Task / PDFLetterCommon.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
fee14197 3 | CiviCRM version 5 |
6a488035 4 +--------------------------------------------------------------------+
f299f7db 5 | Copyright CiviCRM LLC (c) 2004-2020 |
6a488035
TO
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25*}
26{*common template for compose PDF letters*}
27{if $form.template.html}
28<table class="form-layout-compressed">
29 <tr>
465c5a7c
CW
30 <td class="label-left">
31 {$form.template.label}
32 {help id="template" title=$form.template.label file="CRM/Contact/Form/Task/PDFLetterCommon.hlp"}
33 </td>
34 <td>
35 {$form.template.html} {ts}OR{/ts} {$form.document_file.html}
36 </td>
8d63890e 37 </tr>
4c71ccb4
RN
38 <tr>
39 <td class="label-left">{$form.subject.label}</td>
40 <td>{$form.subject.html}</td>
41 </tr>
465c5a7c 42 {if $form.campaign_id}
4c71ccb4
RN
43 <tr>
44 <td class="label-left">{$form.campaign_id.label}</td>
45 <td>{$form.campaign_id.html}</td>
46 </tr>
465c5a7c 47 {/if}
6a488035
TO
48</table>
49{/if}
50
4c9dc59f 51<div class="crm-accordion-wrapper collapsed crm-pdf-format-accordion">
6a488035
TO
52 <div class="crm-accordion-header">
53 {$form.pdf_format_header.html}
54 </div>
55 <div class="crm-accordion-body">
4c9dc59f 56 <div class="crm-block crm-form-block">
6a488035
TO
57 <table class="form-layout-compressed">
58 <tr>
a7916823
CW
59 <td class="label-left">{$form.format_id.label} {help id="id-pdf-format" file="CRM/Contact/Form/Task/PDFLetterCommon.hlp"}</td>
60 <td>{$form.format_id.html}</td>
61 </tr>
6a488035
TO
62 <tr>
63 <td class="label-left">{$form.paper_size.label}</td><td>{$form.paper_size.html}</td>
64 <td class="label-left">{$form.orientation.label}</td><td>{$form.orientation.html}</td>
65 </tr>
66 <tr>
67 <td class="label-left">{$form.metric.label}</td><td>{$form.metric.html}</td>
68 <td colspan="2">&nbsp;</td>
69 </tr>
70 <tr>
71 <td>{$form.paper_dimensions.html}</td><td id="paper_dimensions">&nbsp;</td>
72 <td colspan="2">&nbsp;</td>
73 </tr>
74 <tr>
75 <td class="label-left">{$form.margin_top.label}</td><td>{$form.margin_top.html}</td>
76 <td class="label-left">{$form.margin_bottom.label}</td><td>{$form.margin_bottom.html}</td>
77 </tr>
78 <tr>
79 <td class="label-left">{$form.margin_left.label}</td><td>{$form.margin_left.html}</td>
80 <td class="label-left">{$form.margin_right.label}</td><td>{$form.margin_right.html}</td>
81 </tr>
586b8780 82 {* CRM-15883 Suppressing stationery until switch from DOMPDF.
bdfa67c3 83 <tr>
84 <td class="label-left">{$form.stationery.label}</td><td>{$form.stationery.html}</td>
85 <td colspan="2">&nbsp;</td>
86 </tr>
586b8780 87 *}
6a488035
TO
88 </table>
89 <div id="bindFormat">{$form.bind_format.html}&nbsp;{$form.bind_format.label}</div>
90 <div id="updateFormat" style="display: none">{$form.update_format.html}&nbsp;{$form.update_format.label}</div>
91 </div>
92 </div>
93</div>
94
04a76231 95<div class="crm-accordion-wrapper crm-document-accordion ">
96 <div class="crm-accordion-header">
4c9dc59f 97 {ts}Preview Document{/ts}
04a76231 98 </div><!-- /.crm-accordion-header -->
99 <div class="crm-accordion-body">
8d63890e 100 <div id='document-preview'></div>
04a76231 101 </div><!-- /.crm-accordion-body -->
102</div><!-- /.crm-accordion-wrapper -->
103
6a488035
TO
104<div class="crm-accordion-wrapper crm-html_email-accordion ">
105<div class="crm-accordion-header">
106 {$form.html_message.label}
107</div><!-- /.crm-accordion-header -->
108 <div class="crm-accordion-body">
ac0a3db5
CW
109 <div class="helpIcon" id="helphtml">
110 <input class="crm-token-selector big" data-field="html_message" />
13d9bc82 111 {help id="id-token-html" tplFile=$tplFile isAdmin=$isAdmin file="CRM/Contact/Form/Task/Email.hlp"}
ac0a3db5 112 </div>
6a488035
TO
113 <div class="clear"></div>
114 <div class='html'>
6a488035
TO
115 {$form.html_message.html}<br />
116 </div>
117
118<div id="editMessageDetails">
119 <div id="updateDetails" >
120 {$form.updateTemplate.html}&nbsp;{$form.updateTemplate.label}
121 </div>
122 <div>
123 {$form.saveTemplate.html}&nbsp;{$form.saveTemplate.label}
124 </div>
125</div>
126
127<div id="saveDetails" class="section">
128 <div class="label">{$form.saveTemplateName.label}</div>
129 <div class="content">{$form.saveTemplateName.html|crmAddClass:huge}</div>
130</div>
131
132 </div><!-- /.crm-accordion-body -->
133</div><!-- /.crm-accordion-wrapper -->
134
0aeb5a1e
CW
135<table class="form-layout-compressed">
136 <tr>
137 <td class="label-left">{$form.document_type.label}</td>
138 <td>{$form.document_type.html}</td>
139 </tr>
140</table>
141
6a488035
TO
142{include file="CRM/Mailing/Form/InsertTokens.tpl"}
143
144{literal}
145<script type="text/javascript">
3cc60a06 146CRM.$(function($) {
b50fdacc 147 var $form = $('form.{/literal}{$form.formClass}{literal}');
04a76231 148
149 {/literal}{if $form.formName eq 'PDF'}{literal}
8d63890e 150 $('.crm-document-accordion').hide();
151 $('#document_file').on('change', function() {
152 if (this.value) {
4c9dc59f 153 $('.crm-html_email-accordion, .crm-document-accordion, .crm-pdf-format-accordion').hide();
b3088211 154 cj('#document_type').closest('tr').hide();
8d63890e 155 $('#template').val('');
156 }
157 });
04a76231 158 {/literal}{/if}{literal}
159
160
a7916823
CW
161 $('#format_id', $form).on('change', function() {
162 selectFormat($(this).val());
163 });
623ba9d2
CW
164 // After the pdf downloads, the user has to manually close the dialog (which would be nice to fix)
165 // But at least we can trigger the underlying list of activities to refresh
ea033ee7
CW
166 $('[name=_qf_PDF_submit]', $form).click(function() {
167 var $dialog = $(this).closest('.ui-dialog-content.crm-ajax-container');
168 if ($dialog.length) {
169 $dialog.on('dialogbeforeclose', function () {
170 $(this).trigger('crmFormSuccess');
171 });
172 $dialog.dialog('option', 'buttons', [{
173 text: {/literal}"{ts escape='js'}Done{/ts}"{literal},
c7e59a6f 174 icons: {primary: 'fa-times'},
ea033ee7
CW
175 click: function() {$(this).dialog('close');}
176 }]);
177 }
623ba9d2 178 });
f2536217
CW
179 $('[name^=_qf_PDF_submit]', $form).click(function() {
180 CRM.status({/literal}"{ts escape='js'}Downloading...{/ts}"{literal});
181 });
14638f88
CW
182 showSaveDetails($('input[name=saveTemplate]', $form)[0]);
183
184 function showSaveTemplate() {
185 $('#updateDetails').toggle(!!$(this).val());
186 }
187 $('[name=template]', $form).each(showSaveTemplate).change(showSaveTemplate);
6a488035
TO
188});
189
190var currentWidth;
191var currentHeight;
192var currentMetric = document.getElementById('metric').value;
193showBindFormatChkBox();
194selectPaper( document.getElementById('paper_size').value );
195
6a488035
TO
196function showBindFormatChkBox()
197{
198 var templateExists = true;
199 if ( document.getElementById('template') == null || document.getElementById('template').value == '' ) {
200 templateExists = false;
201 }
a7916823 202 var formatExists = !!cj('#format_id').val();
6a488035
TO
203 if ( templateExists && formatExists ) {
204 document.getElementById("bindFormat").style.display = "block";
205 } else if ( formatExists && document.getElementById("saveTemplate") != null && document.getElementById("saveTemplate").checked ) {
206 document.getElementById("bindFormat").style.display = "block";
207 var yes = confirm( '{/literal}{$useThisPageFormat}{literal}' );
208 if ( yes ) {
209 document.getElementById("bind_format").checked = true;
210 }
211 } else {
212 document.getElementById("bindFormat").style.display = "none";
213 document.getElementById("bind_format").checked = false;
214 }
215}
216
217function showUpdateFormatChkBox()
218{
a7916823
CW
219 if (cj('#format_id').val()) {
220 cj("#updateFormat").show();
6a488035
TO
221 }
222}
223
a7916823
CW
224function updateFormatLabel() {
225 cj('.pdf-format-header-label').html(cj('#format_id option:selected').text() || cj('#format_id').attr('placeholder'));
6a488035
TO
226}
227
a7916823
CW
228updateFormatLabel();
229
65861501 230function fillFormatInfo( data, bind ) {
231 cj("#format_id").val( data.id );
232 cj("#paper_size").val( data.paper_size );
233 cj("#orientation").val( data.orientation );
234 cj("#metric").val( data.metric );
235 cj("#margin_top").val( data.margin_top );
236 cj("#margin_bottom").val( data.margin_bottom );
237 cj("#margin_left").val( data.margin_left );
238 cj("#margin_right").val( data.margin_right );
239 selectPaper( data.paper_size );
240 cj("#update_format").prop({checked: false}).parent().hide();
241 document.getElementById('bind_format').checked = bind;
242 showBindFormatChkBox();
243}
244
245function selectFormat( val, bind ) {
a7916823 246 updateFormatLabel();
65861501 247 if (!val) {
248 val = 0;
249 bind = false;
c7e59a6f 250 }
2d25b5b1
ML
251
252 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/pdfFormat' h=0 }"{literal};
253 cj.post( dataUrl, {formatId: val}, function( data ) {
65861501 254 fillFormatInfo(data, bind);
2d25b5b1 255 }, 'json');
6a488035
TO
256}
257
258function selectPaper( val )
259{
260 dataUrl = {/literal}"{crmURL p='civicrm/ajax/paperSize' h=0 }"{literal};
261 cj.post( dataUrl, {paperSizeName: val}, function( data ) {
262 cj("#paper_size").val( data.name );
263 metric = document.getElementById('metric').value;
264 currentWidth = convertMetric( data.width, data.metric, metric );
265 currentHeight = convertMetric( data.height, data.metric, metric );
266 updatePaperDimensions( );
267 }, 'json');
268}
269
270function selectMetric( metric )
271{
272 convertField( 'margin_top', currentMetric, metric );
273 convertField( 'margin_bottom', currentMetric, metric );
274 convertField( 'margin_left', currentMetric, metric );
275 convertField( 'margin_right', currentMetric, metric );
276 currentWidth = convertMetric( currentWidth, currentMetric, metric );
277 currentHeight = convertMetric( currentHeight, currentMetric, metric );
278 updatePaperDimensions( );
279}
280
281function updatePaperDimensions( )
282{
283 metric = document.getElementById('metric').value;
284 width = new String( currentWidth.toFixed( 2 ) );
285 height = new String( currentHeight.toFixed( 2 ) );
286 if ( document.getElementById('orientation').value == 'landscape' ) {
287 width = new String( currentHeight.toFixed( 2 ) );
288 height = new String( currentWidth.toFixed( 2 ) );
289 }
290 document.getElementById('paper_dimensions').innerHTML = parseFloat( width ) + ' ' + metric + ' x ' + parseFloat( height ) + ' ' + metric;
291 currentMetric = metric;
292}
293
294function convertField( id, from, to )
295{
296 val = document.getElementById( id ).value;
297 if ( val == '' || isNaN( val ) ) return;
298 val = convertMetric( val, from, to );
299 val = new String( val.toFixed( 3 ) );
300 document.getElementById( id ).value = parseFloat( val );
301}
302
303function convertMetric( value, from, to ) {
304 switch( from + to ) {
305 case 'incm': return value * 2.54;
306 case 'inmm': return value * 25.4;
307 case 'inpt': return value * 72;
308 case 'cmin': return value / 2.54;
309 case 'cmmm': return value * 10;
310 case 'cmpt': return value * 72 / 2.54;
311 case 'mmin': return value / 25.4;
312 case 'mmcm': return value / 10;
313 case 'mmpt': return value * 72 / 25.4;
314 case 'ptin': return value / 72;
315 case 'ptcm': return value * 2.54 / 72;
316 case 'ptmm': return value * 25.4 / 72;
317 }
318 return value;
319}
320
321function showSaveDetails(chkbox) {
322 var formatSelected = ( document.getElementById('format_id').value > 0 );
323 var templateSelected = ( document.getElementById('template') != null && document.getElementById('template').value > 0 );
324 if (chkbox.checked) {
325 document.getElementById("saveDetails").style.display = "block";
326 document.getElementById("saveTemplateName").disabled = false;
327 if ( formatSelected && ! templateSelected ) {
328 document.getElementById("bindFormat").style.display = "block";
329 var yes = confirm( '{/literal}{$useSelectedPageFormat}{literal}' );
330 if ( yes ) {
331 document.getElementById("bind_format").checked = true;
332 }
333 }
334 } else {
335 document.getElementById("saveDetails").style.display = "none";
336 document.getElementById("saveTemplateName").disabled = true;
337 if ( ! templateSelected ) {
338 document.getElementById("bindFormat").style.display = "none";
339 document.getElementById("bind_format").checked = false;
340 }
341 }
342}
343
344</script>
345{/literal}