Commit | Line | Data |
---|---|---|
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> | |
8d63890e | 33 | <tr> |
34 | <td> <sub>OR</sub></td> | |
35 | </tr> | |
36 | <tr> | |
37 | <td class="label-left">{$form.document_file.label}</td> | |
38 | <td>{$form.document_file.html}<br/><br/></td> | |
39 | </tr> | |
4c71ccb4 RN |
40 | <tr> |
41 | <td class="label-left">{$form.subject.label}</td> | |
42 | <td>{$form.subject.html}</td> | |
43 | </tr> | |
44 | <tr> | |
45 | <td class="label-left">{$form.campaign_id.label}</td> | |
46 | <td>{$form.campaign_id.html}</td> | |
47 | </tr> | |
6a488035 TO |
48 | </table> |
49 | {/if} | |
50 | ||
51 | <div class="crm-accordion-wrapper collapsed"> | |
52 | <div class="crm-accordion-header"> | |
53 | {$form.pdf_format_header.html} | |
54 | </div> | |
55 | <div class="crm-accordion-body"> | |
56 | <div class="crm-block crm-form-block crm-pdf-format-form-block"> | |
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"> </td> | |
69 | </tr> | |
70 | <tr> | |
71 | <td>{$form.paper_dimensions.html}</td><td id="paper_dimensions"> </td> | |
72 | <td colspan="2"> </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"> </td> | |
86 | </tr> | |
586b8780 | 87 | *} |
6a488035 TO |
88 | </table> |
89 | <div id="bindFormat">{$form.bind_format.html} {$form.bind_format.label}</div> | |
90 | <div id="updateFormat" style="display: none">{$form.update_format.html} {$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"> | |
97 | {$form.html_message.label} | |
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} {$form.updateTemplate.label} | |
121 | </div> | |
122 | <div> | |
123 | {$form.saveTemplate.html} {$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 | 146 | CRM.$(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) { | |
b3088211 | 153 | $('.crm-html_email-accordion, .crm-document-accordion').hide(); |
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 | ||
190 | var currentWidth; | |
191 | var currentHeight; | |
192 | var currentMetric = document.getElementById('metric').value; | |
193 | showBindFormatChkBox(); | |
194 | selectPaper( document.getElementById('paper_size').value ); | |
195 | ||
6a488035 TO |
196 | function 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 | ||
217 | function showUpdateFormatChkBox() | |
218 | { | |
a7916823 CW |
219 | if (cj('#format_id').val()) { |
220 | cj("#updateFormat").show(); | |
6a488035 TO |
221 | } |
222 | } | |
223 | ||
a7916823 CW |
224 | function 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 |
228 | updateFormatLabel(); |
229 | ||
65861501 | 230 | function 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 | ||
245 | function selectFormat( val, bind ) { | |
a7916823 | 246 | updateFormatLabel(); |
65861501 | 247 | if (!val) { |
248 | val = 0; | |
249 | bind = false; | |
6a488035 TO |
250 | var dataUrl = {/literal}"{crmURL p='civicrm/ajax/pdfFormat' h=0 }"{literal}; |
251 | cj.post( dataUrl, {formatId: val}, function( data ) { | |
65861501 | 252 | fillFormatInfo(data, bind); |
253 | }, 'json'); | |
c7e59a6f | 254 | } |
65861501 | 255 | else { |
256 | data=JSON.parse(val); | |
257 | fillFormatInfo(data, bind); | |
258 | } | |
6a488035 TO |
259 | } |
260 | ||
261 | function selectPaper( val ) | |
262 | { | |
263 | dataUrl = {/literal}"{crmURL p='civicrm/ajax/paperSize' h=0 }"{literal}; | |
264 | cj.post( dataUrl, {paperSizeName: val}, function( data ) { | |
265 | cj("#paper_size").val( data.name ); | |
266 | metric = document.getElementById('metric').value; | |
267 | currentWidth = convertMetric( data.width, data.metric, metric ); | |
268 | currentHeight = convertMetric( data.height, data.metric, metric ); | |
269 | updatePaperDimensions( ); | |
270 | }, 'json'); | |
271 | } | |
272 | ||
273 | function selectMetric( metric ) | |
274 | { | |
275 | convertField( 'margin_top', currentMetric, metric ); | |
276 | convertField( 'margin_bottom', currentMetric, metric ); | |
277 | convertField( 'margin_left', currentMetric, metric ); | |
278 | convertField( 'margin_right', currentMetric, metric ); | |
279 | currentWidth = convertMetric( currentWidth, currentMetric, metric ); | |
280 | currentHeight = convertMetric( currentHeight, currentMetric, metric ); | |
281 | updatePaperDimensions( ); | |
282 | } | |
283 | ||
284 | function updatePaperDimensions( ) | |
285 | { | |
286 | metric = document.getElementById('metric').value; | |
287 | width = new String( currentWidth.toFixed( 2 ) ); | |
288 | height = new String( currentHeight.toFixed( 2 ) ); | |
289 | if ( document.getElementById('orientation').value == 'landscape' ) { | |
290 | width = new String( currentHeight.toFixed( 2 ) ); | |
291 | height = new String( currentWidth.toFixed( 2 ) ); | |
292 | } | |
293 | document.getElementById('paper_dimensions').innerHTML = parseFloat( width ) + ' ' + metric + ' x ' + parseFloat( height ) + ' ' + metric; | |
294 | currentMetric = metric; | |
295 | } | |
296 | ||
297 | function convertField( id, from, to ) | |
298 | { | |
299 | val = document.getElementById( id ).value; | |
300 | if ( val == '' || isNaN( val ) ) return; | |
301 | val = convertMetric( val, from, to ); | |
302 | val = new String( val.toFixed( 3 ) ); | |
303 | document.getElementById( id ).value = parseFloat( val ); | |
304 | } | |
305 | ||
306 | function convertMetric( value, from, to ) { | |
307 | switch( from + to ) { | |
308 | case 'incm': return value * 2.54; | |
309 | case 'inmm': return value * 25.4; | |
310 | case 'inpt': return value * 72; | |
311 | case 'cmin': return value / 2.54; | |
312 | case 'cmmm': return value * 10; | |
313 | case 'cmpt': return value * 72 / 2.54; | |
314 | case 'mmin': return value / 25.4; | |
315 | case 'mmcm': return value / 10; | |
316 | case 'mmpt': return value * 72 / 25.4; | |
317 | case 'ptin': return value / 72; | |
318 | case 'ptcm': return value * 2.54 / 72; | |
319 | case 'ptmm': return value * 25.4 / 72; | |
320 | } | |
321 | return value; | |
322 | } | |
323 | ||
324 | function showSaveDetails(chkbox) { | |
325 | var formatSelected = ( document.getElementById('format_id').value > 0 ); | |
326 | var templateSelected = ( document.getElementById('template') != null && document.getElementById('template').value > 0 ); | |
327 | if (chkbox.checked) { | |
328 | document.getElementById("saveDetails").style.display = "block"; | |
329 | document.getElementById("saveTemplateName").disabled = false; | |
330 | if ( formatSelected && ! templateSelected ) { | |
331 | document.getElementById("bindFormat").style.display = "block"; | |
332 | var yes = confirm( '{/literal}{$useSelectedPageFormat}{literal}' ); | |
333 | if ( yes ) { | |
334 | document.getElementById("bind_format").checked = true; | |
335 | } | |
336 | } | |
337 | } else { | |
338 | document.getElementById("saveDetails").style.display = "none"; | |
339 | document.getElementById("saveTemplateName").disabled = true; | |
340 | if ( ! templateSelected ) { | |
341 | document.getElementById("bindFormat").style.display = "none"; | |
342 | document.getElementById("bind_format").checked = false; | |
343 | } | |
344 | } | |
345 | } | |
346 | ||
347 | </script> | |
348 | {/literal} |