CRM-16661 : Custom PDF page format margin bug
[civicrm-core.git] / templates / CRM / Contact / Form / Task / PDFLetterCommon.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
39de6fd5 3 | CiviCRM version 4.6 |
6a488035 4 +--------------------------------------------------------------------+
e7112fa7 5 | Copyright CiviCRM LLC (c) 2004-2015 |
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" />
95 {help id="id-token-html" tplFile=$tplFile isAdmin=$isAdmin editor=$editor file="CRM/Contact/Form/Task/Email.hlp"}
96 </div>
6a488035
TO
97 <div class="clear"></div>
98 <div class='html'>
99 {if $editor EQ 'textarea'}
149fb291 100 <div class="help description">{ts}NOTE: If you are composing HTML-formatted messages, you may want to enable a Rich Text (WYSIWYG) editor (Administer &raquo; Customize Data & Screens &raquo; Display Preferences).{/ts}</div>
6a488035
TO
101 {/if}
102 {$form.html_message.html}<br />
103 </div>
104
105<div id="editMessageDetails">
106 <div id="updateDetails" >
107 {$form.updateTemplate.html}&nbsp;{$form.updateTemplate.label}
108 </div>
109 <div>
110 {$form.saveTemplate.html}&nbsp;{$form.saveTemplate.label}
111 </div>
112</div>
113
114<div id="saveDetails" class="section">
115 <div class="label">{$form.saveTemplateName.label}</div>
116 <div class="content">{$form.saveTemplateName.html|crmAddClass:huge}</div>
117</div>
118
119 </div><!-- /.crm-accordion-body -->
120</div><!-- /.crm-accordion-wrapper -->
121
122{include file="CRM/Mailing/Form/InsertTokens.tpl"}
123
124{literal}
125<script type="text/javascript">
3cc60a06 126CRM.$(function($) {
b50fdacc 127 var $form = $('form.{/literal}{$form.formClass}{literal}');
a7916823
CW
128 $('#format_id', $form).on('change', function() {
129 selectFormat($(this).val());
130 });
623ba9d2
CW
131 // After the pdf downloads, the user has to manually close the dialog (which would be nice to fix)
132 // But at least we can trigger the underlying list of activities to refresh
133 $form.closest('.ui-dialog-content.crm-ajax-container').on('dialogbeforeclose', function() {
134 $(this).trigger('crmFormSuccess');
135 });
6a488035
TO
136});
137
138var currentWidth;
139var currentHeight;
140var currentMetric = document.getElementById('metric').value;
141showBindFormatChkBox();
142selectPaper( document.getElementById('paper_size').value );
143
6a488035
TO
144function showBindFormatChkBox()
145{
146 var templateExists = true;
147 if ( document.getElementById('template') == null || document.getElementById('template').value == '' ) {
148 templateExists = false;
149 }
a7916823 150 var formatExists = !!cj('#format_id').val();
6a488035
TO
151 if ( templateExists && formatExists ) {
152 document.getElementById("bindFormat").style.display = "block";
153 } else if ( formatExists && document.getElementById("saveTemplate") != null && document.getElementById("saveTemplate").checked ) {
154 document.getElementById("bindFormat").style.display = "block";
155 var yes = confirm( '{/literal}{$useThisPageFormat}{literal}' );
156 if ( yes ) {
157 document.getElementById("bind_format").checked = true;
158 }
159 } else {
160 document.getElementById("bindFormat").style.display = "none";
161 document.getElementById("bind_format").checked = false;
162 }
163}
164
165function showUpdateFormatChkBox()
166{
a7916823
CW
167 if (cj('#format_id').val()) {
168 cj("#updateFormat").show();
6a488035
TO
169 }
170}
171
a7916823
CW
172function updateFormatLabel() {
173 cj('.pdf-format-header-label').html(cj('#format_id option:selected').text() || cj('#format_id').attr('placeholder'));
6a488035
TO
174}
175
a7916823
CW
176updateFormatLabel();
177
65861501 178function fillFormatInfo( data, bind ) {
179 cj("#format_id").val( data.id );
180 cj("#paper_size").val( data.paper_size );
181 cj("#orientation").val( data.orientation );
182 cj("#metric").val( data.metric );
183 cj("#margin_top").val( data.margin_top );
184 cj("#margin_bottom").val( data.margin_bottom );
185 cj("#margin_left").val( data.margin_left );
186 cj("#margin_right").val( data.margin_right );
187 selectPaper( data.paper_size );
188 cj("#update_format").prop({checked: false}).parent().hide();
189 document.getElementById('bind_format').checked = bind;
190 showBindFormatChkBox();
191}
192
193function selectFormat( val, bind ) {
a7916823 194 updateFormatLabel();
65861501 195 if (!val) {
196 val = 0;
197 bind = false;
6a488035
TO
198 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/pdfFormat' h=0 }"{literal};
199 cj.post( dataUrl, {formatId: val}, function( data ) {
65861501 200 fillFormatInfo(data, bind);
201 }, 'json');
202 }
203 else {
204 data=JSON.parse(val);
205 fillFormatInfo(data, bind);
206 }
6a488035
TO
207}
208
209function selectPaper( val )
210{
211 dataUrl = {/literal}"{crmURL p='civicrm/ajax/paperSize' h=0 }"{literal};
212 cj.post( dataUrl, {paperSizeName: val}, function( data ) {
213 cj("#paper_size").val( data.name );
214 metric = document.getElementById('metric').value;
215 currentWidth = convertMetric( data.width, data.metric, metric );
216 currentHeight = convertMetric( data.height, data.metric, metric );
217 updatePaperDimensions( );
218 }, 'json');
219}
220
221function selectMetric( metric )
222{
223 convertField( 'margin_top', currentMetric, metric );
224 convertField( 'margin_bottom', currentMetric, metric );
225 convertField( 'margin_left', currentMetric, metric );
226 convertField( 'margin_right', currentMetric, metric );
227 currentWidth = convertMetric( currentWidth, currentMetric, metric );
228 currentHeight = convertMetric( currentHeight, currentMetric, metric );
229 updatePaperDimensions( );
230}
231
232function updatePaperDimensions( )
233{
234 metric = document.getElementById('metric').value;
235 width = new String( currentWidth.toFixed( 2 ) );
236 height = new String( currentHeight.toFixed( 2 ) );
237 if ( document.getElementById('orientation').value == 'landscape' ) {
238 width = new String( currentHeight.toFixed( 2 ) );
239 height = new String( currentWidth.toFixed( 2 ) );
240 }
241 document.getElementById('paper_dimensions').innerHTML = parseFloat( width ) + ' ' + metric + ' x ' + parseFloat( height ) + ' ' + metric;
242 currentMetric = metric;
243}
244
245function convertField( id, from, to )
246{
247 val = document.getElementById( id ).value;
248 if ( val == '' || isNaN( val ) ) return;
249 val = convertMetric( val, from, to );
250 val = new String( val.toFixed( 3 ) );
251 document.getElementById( id ).value = parseFloat( val );
252}
253
254function convertMetric( value, from, to ) {
255 switch( from + to ) {
256 case 'incm': return value * 2.54;
257 case 'inmm': return value * 25.4;
258 case 'inpt': return value * 72;
259 case 'cmin': return value / 2.54;
260 case 'cmmm': return value * 10;
261 case 'cmpt': return value * 72 / 2.54;
262 case 'mmin': return value / 25.4;
263 case 'mmcm': return value / 10;
264 case 'mmpt': return value * 72 / 25.4;
265 case 'ptin': return value / 72;
266 case 'ptcm': return value * 2.54 / 72;
267 case 'ptmm': return value * 25.4 / 72;
268 }
269 return value;
270}
271
272function showSaveDetails(chkbox) {
273 var formatSelected = ( document.getElementById('format_id').value > 0 );
274 var templateSelected = ( document.getElementById('template') != null && document.getElementById('template').value > 0 );
275 if (chkbox.checked) {
276 document.getElementById("saveDetails").style.display = "block";
277 document.getElementById("saveTemplateName").disabled = false;
278 if ( formatSelected && ! templateSelected ) {
279 document.getElementById("bindFormat").style.display = "block";
280 var yes = confirm( '{/literal}{$useSelectedPageFormat}{literal}' );
281 if ( yes ) {
282 document.getElementById("bind_format").checked = true;
283 }
284 }
285 } else {
286 document.getElementById("saveDetails").style.display = "none";
287 document.getElementById("saveTemplateName").disabled = true;
288 if ( ! templateSelected ) {
289 document.getElementById("bindFormat").style.display = "none";
290 document.getElementById("bind_format").checked = false;
291 }
292 }
293}
294
295</script>
296{/literal}
297