Merge to DOCx or ODT template
[civicrm-core.git] / templates / CRM / Contact / Form / Task / PDFLetterCommon.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
2c4c49ca 3 | CiviCRM version 4.7 |
6a488035 4 +--------------------------------------------------------------------+
fa938177 5 | Copyright CiviCRM LLC (c) 2004-2016 |
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>
4c71ccb4 30 <td class="label-left">{$form.template.label}</td>
6a488035
TO
31 <td>{$form.template.html}</td>
32 </tr>
4c71ccb4
RN
33 <tr>
34 <td class="label-left">{$form.subject.label}</td>
35 <td>{$form.subject.html}</td>
36 </tr>
37 <tr>
38 <td class="label-left">{$form.campaign_id.label}</td>
39 <td>{$form.campaign_id.html}</td>
40 </tr>
6a488035
TO
41</table>
42{/if}
43
44<div class="crm-accordion-wrapper collapsed">
45 <div class="crm-accordion-header">
46 {$form.pdf_format_header.html}
47 </div>
48 <div class="crm-accordion-body">
49 <div class="crm-block crm-form-block crm-pdf-format-form-block">
50 <table class="form-layout-compressed">
51 <tr>
a7916823
CW
52 <td class="label-left">{$form.format_id.label} {help id="id-pdf-format" file="CRM/Contact/Form/Task/PDFLetterCommon.hlp"}</td>
53 <td>{$form.format_id.html}</td>
54 </tr>
6a488035
TO
55 <tr>
56 <td class="label-left">{$form.paper_size.label}</td><td>{$form.paper_size.html}</td>
57 <td class="label-left">{$form.orientation.label}</td><td>{$form.orientation.html}</td>
58 </tr>
59 <tr>
60 <td class="label-left">{$form.metric.label}</td><td>{$form.metric.html}</td>
61 <td colspan="2">&nbsp;</td>
62 </tr>
63 <tr>
64 <td>{$form.paper_dimensions.html}</td><td id="paper_dimensions">&nbsp;</td>
65 <td colspan="2">&nbsp;</td>
66 </tr>
67 <tr>
68 <td class="label-left">{$form.margin_top.label}</td><td>{$form.margin_top.html}</td>
69 <td class="label-left">{$form.margin_bottom.label}</td><td>{$form.margin_bottom.html}</td>
70 </tr>
71 <tr>
72 <td class="label-left">{$form.margin_left.label}</td><td>{$form.margin_left.html}</td>
73 <td class="label-left">{$form.margin_right.label}</td><td>{$form.margin_right.html}</td>
74 </tr>
586b8780 75 {* CRM-15883 Suppressing stationery until switch from DOMPDF.
bdfa67c3 76 <tr>
77 <td class="label-left">{$form.stationery.label}</td><td>{$form.stationery.html}</td>
78 <td colspan="2">&nbsp;</td>
79 </tr>
586b8780 80 *}
6a488035
TO
81 </table>
82 <div id="bindFormat">{$form.bind_format.html}&nbsp;{$form.bind_format.label}</div>
83 <div id="updateFormat" style="display: none">{$form.update_format.html}&nbsp;{$form.update_format.label}</div>
84 </div>
85 </div>
86</div>
87
88<div class="crm-accordion-wrapper crm-html_email-accordion ">
89<div class="crm-accordion-header">
90 {$form.html_message.label}
91</div><!-- /.crm-accordion-header -->
92 <div class="crm-accordion-body">
ac0a3db5
CW
93 <div class="helpIcon" id="helphtml">
94 <input class="crm-token-selector big" data-field="html_message" />
13d9bc82 95 {help id="id-token-html" tplFile=$tplFile isAdmin=$isAdmin file="CRM/Contact/Form/Task/Email.hlp"}
ac0a3db5 96 </div>
6a488035
TO
97 <div class="clear"></div>
98 <div class='html'>
6a488035
TO
99 {$form.html_message.html}<br />
100 </div>
101
102<div id="editMessageDetails">
103 <div id="updateDetails" >
104 {$form.updateTemplate.html}&nbsp;{$form.updateTemplate.label}
105 </div>
106 <div>
107 {$form.saveTemplate.html}&nbsp;{$form.saveTemplate.label}
108 </div>
109</div>
110
111<div id="saveDetails" class="section">
112 <div class="label">{$form.saveTemplateName.label}</div>
113 <div class="content">{$form.saveTemplateName.html|crmAddClass:huge}</div>
114</div>
115
116 </div><!-- /.crm-accordion-body -->
117</div><!-- /.crm-accordion-wrapper -->
118
0aeb5a1e
CW
119<table class="form-layout-compressed">
120 <tr>
121 <td class="label-left">{$form.document_type.label}</td>
122 <td>{$form.document_type.html}</td>
123 </tr>
124</table>
125
6a488035
TO
126{include file="CRM/Mailing/Form/InsertTokens.tpl"}
127
128{literal}
129<script type="text/javascript">
3cc60a06 130CRM.$(function($) {
b50fdacc 131 var $form = $('form.{/literal}{$form.formClass}{literal}');
a7916823
CW
132 $('#format_id', $form).on('change', function() {
133 selectFormat($(this).val());
134 });
623ba9d2
CW
135 // After the pdf downloads, the user has to manually close the dialog (which would be nice to fix)
136 // But at least we can trigger the underlying list of activities to refresh
ea033ee7
CW
137 $('[name=_qf_PDF_submit]', $form).click(function() {
138 var $dialog = $(this).closest('.ui-dialog-content.crm-ajax-container');
139 if ($dialog.length) {
140 $dialog.on('dialogbeforeclose', function () {
141 $(this).trigger('crmFormSuccess');
142 });
143 $dialog.dialog('option', 'buttons', [{
144 text: {/literal}"{ts escape='js'}Done{/ts}"{literal},
c7e59a6f 145 icons: {primary: 'fa-times'},
ea033ee7
CW
146 click: function() {$(this).dialog('close');}
147 }]);
148 }
623ba9d2 149 });
f2536217
CW
150 $('[name^=_qf_PDF_submit]', $form).click(function() {
151 CRM.status({/literal}"{ts escape='js'}Downloading...{/ts}"{literal});
152 });
14638f88
CW
153 showSaveDetails($('input[name=saveTemplate]', $form)[0]);
154
155 function showSaveTemplate() {
156 $('#updateDetails').toggle(!!$(this).val());
157 }
158 $('[name=template]', $form).each(showSaveTemplate).change(showSaveTemplate);
6a488035
TO
159});
160
161var currentWidth;
162var currentHeight;
163var currentMetric = document.getElementById('metric').value;
164showBindFormatChkBox();
165selectPaper( document.getElementById('paper_size').value );
166
6a488035
TO
167function showBindFormatChkBox()
168{
169 var templateExists = true;
170 if ( document.getElementById('template') == null || document.getElementById('template').value == '' ) {
171 templateExists = false;
172 }
a7916823 173 var formatExists = !!cj('#format_id').val();
6a488035
TO
174 if ( templateExists && formatExists ) {
175 document.getElementById("bindFormat").style.display = "block";
176 } else if ( formatExists && document.getElementById("saveTemplate") != null && document.getElementById("saveTemplate").checked ) {
177 document.getElementById("bindFormat").style.display = "block";
178 var yes = confirm( '{/literal}{$useThisPageFormat}{literal}' );
179 if ( yes ) {
180 document.getElementById("bind_format").checked = true;
181 }
182 } else {
183 document.getElementById("bindFormat").style.display = "none";
184 document.getElementById("bind_format").checked = false;
185 }
186}
187
188function showUpdateFormatChkBox()
189{
a7916823
CW
190 if (cj('#format_id').val()) {
191 cj("#updateFormat").show();
6a488035
TO
192 }
193}
194
a7916823
CW
195function updateFormatLabel() {
196 cj('.pdf-format-header-label').html(cj('#format_id option:selected').text() || cj('#format_id').attr('placeholder'));
6a488035
TO
197}
198
a7916823
CW
199updateFormatLabel();
200
65861501 201function fillFormatInfo( data, bind ) {
202 cj("#format_id").val( data.id );
203 cj("#paper_size").val( data.paper_size );
204 cj("#orientation").val( data.orientation );
205 cj("#metric").val( data.metric );
206 cj("#margin_top").val( data.margin_top );
207 cj("#margin_bottom").val( data.margin_bottom );
208 cj("#margin_left").val( data.margin_left );
209 cj("#margin_right").val( data.margin_right );
210 selectPaper( data.paper_size );
211 cj("#update_format").prop({checked: false}).parent().hide();
212 document.getElementById('bind_format').checked = bind;
213 showBindFormatChkBox();
214}
215
216function selectFormat( val, bind ) {
a7916823 217 updateFormatLabel();
65861501 218 if (!val) {
219 val = 0;
220 bind = false;
6a488035
TO
221 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/pdfFormat' h=0 }"{literal};
222 cj.post( dataUrl, {formatId: val}, function( data ) {
65861501 223 fillFormatInfo(data, bind);
224 }, 'json');
c7e59a6f 225 }
65861501 226 else {
227 data=JSON.parse(val);
228 fillFormatInfo(data, bind);
229 }
6a488035
TO
230}
231
232function selectPaper( val )
233{
234 dataUrl = {/literal}"{crmURL p='civicrm/ajax/paperSize' h=0 }"{literal};
235 cj.post( dataUrl, {paperSizeName: val}, function( data ) {
236 cj("#paper_size").val( data.name );
237 metric = document.getElementById('metric').value;
238 currentWidth = convertMetric( data.width, data.metric, metric );
239 currentHeight = convertMetric( data.height, data.metric, metric );
240 updatePaperDimensions( );
241 }, 'json');
242}
243
244function selectMetric( metric )
245{
246 convertField( 'margin_top', currentMetric, metric );
247 convertField( 'margin_bottom', currentMetric, metric );
248 convertField( 'margin_left', currentMetric, metric );
249 convertField( 'margin_right', currentMetric, metric );
250 currentWidth = convertMetric( currentWidth, currentMetric, metric );
251 currentHeight = convertMetric( currentHeight, currentMetric, metric );
252 updatePaperDimensions( );
253}
254
255function updatePaperDimensions( )
256{
257 metric = document.getElementById('metric').value;
258 width = new String( currentWidth.toFixed( 2 ) );
259 height = new String( currentHeight.toFixed( 2 ) );
260 if ( document.getElementById('orientation').value == 'landscape' ) {
261 width = new String( currentHeight.toFixed( 2 ) );
262 height = new String( currentWidth.toFixed( 2 ) );
263 }
264 document.getElementById('paper_dimensions').innerHTML = parseFloat( width ) + ' ' + metric + ' x ' + parseFloat( height ) + ' ' + metric;
265 currentMetric = metric;
266}
267
268function convertField( id, from, to )
269{
270 val = document.getElementById( id ).value;
271 if ( val == '' || isNaN( val ) ) return;
272 val = convertMetric( val, from, to );
273 val = new String( val.toFixed( 3 ) );
274 document.getElementById( id ).value = parseFloat( val );
275}
276
277function convertMetric( value, from, to ) {
278 switch( from + to ) {
279 case 'incm': return value * 2.54;
280 case 'inmm': return value * 25.4;
281 case 'inpt': return value * 72;
282 case 'cmin': return value / 2.54;
283 case 'cmmm': return value * 10;
284 case 'cmpt': return value * 72 / 2.54;
285 case 'mmin': return value / 25.4;
286 case 'mmcm': return value / 10;
287 case 'mmpt': return value * 72 / 25.4;
288 case 'ptin': return value / 72;
289 case 'ptcm': return value * 2.54 / 72;
290 case 'ptmm': return value * 25.4 / 72;
291 }
292 return value;
293}
294
295function showSaveDetails(chkbox) {
296 var formatSelected = ( document.getElementById('format_id').value > 0 );
297 var templateSelected = ( document.getElementById('template') != null && document.getElementById('template').value > 0 );
298 if (chkbox.checked) {
299 document.getElementById("saveDetails").style.display = "block";
300 document.getElementById("saveTemplateName").disabled = false;
301 if ( formatSelected && ! templateSelected ) {
302 document.getElementById("bindFormat").style.display = "block";
303 var yes = confirm( '{/literal}{$useSelectedPageFormat}{literal}' );
304 if ( yes ) {
305 document.getElementById("bind_format").checked = true;
306 }
307 }
308 } else {
309 document.getElementById("saveDetails").style.display = "none";
310 document.getElementById("saveTemplateName").disabled = true;
311 if ( ! templateSelected ) {
312 document.getElementById("bindFormat").style.display = "none";
313 document.getElementById("bind_format").checked = false;
314 }
315 }
316}
317
318</script>
319{/literal}