CRM-14408 - get rid of unnecessary calls to crmAccordions
[civicrm-core.git] / templates / CRM / Contact / Form / Task / PDFLetterCommon.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
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>
30 <td class="label-left">{$form.template.label}</td>
31 <td>{$form.template.html}</td>
32 </tr>
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>
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>
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>
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>
75 </table>
76 <div id="bindFormat">{$form.bind_format.html}&nbsp;{$form.bind_format.label}</div>
77 <div id="updateFormat" style="display: none">{$form.update_format.html}&nbsp;{$form.update_format.label}</div>
78 </div>
79 </div>
80 </div>
81
82 <div class="crm-accordion-wrapper crm-html_email-accordion ">
83 <div class="crm-accordion-header">
84 {$form.html_message.label}
85 </div><!-- /.crm-accordion-header -->
86 <div class="crm-accordion-body">
87 <div class="helpIcon" id="helphtml">
88 <input class="crm-token-selector big" data-field="html_message" />
89 {help id="id-token-html" tplFile=$tplFile isAdmin=$isAdmin editor=$editor file="CRM/Contact/Form/Task/Email.hlp"}
90 </div>
91 <div class="clear"></div>
92 <div class='html'>
93 {if $editor EQ 'textarea'}
94 <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>
95 {/if}
96 {$form.html_message.html}<br />
97 </div>
98
99 <div id="editMessageDetails">
100 <div id="updateDetails" >
101 {$form.updateTemplate.html}&nbsp;{$form.updateTemplate.label}
102 </div>
103 <div>
104 {$form.saveTemplate.html}&nbsp;{$form.saveTemplate.label}
105 </div>
106 </div>
107
108 <div id="saveDetails" class="section">
109 <div class="label">{$form.saveTemplateName.label}</div>
110 <div class="content">{$form.saveTemplateName.html|crmAddClass:huge}</div>
111 </div>
112
113 </div><!-- /.crm-accordion-body -->
114 </div><!-- /.crm-accordion-wrapper -->
115
116 {include file="CRM/Mailing/Form/InsertTokens.tpl"}
117
118 {literal}
119 <script type="text/javascript">
120 CRM.$(function($) {
121 var $form = $('form#{/literal}{$form.formName}{literal}');
122 $('#format_id', $form).on('change', function() {
123 selectFormat($(this).val());
124 });
125 });
126
127 var currentWidth;
128 var currentHeight;
129 var currentMetric = document.getElementById('metric').value;
130 showBindFormatChkBox();
131 selectPaper( document.getElementById('paper_size').value );
132
133 function showBindFormatChkBox()
134 {
135 var templateExists = true;
136 if ( document.getElementById('template') == null || document.getElementById('template').value == '' ) {
137 templateExists = false;
138 }
139 var formatExists = !!cj('#format_id').val();
140 if ( templateExists && formatExists ) {
141 document.getElementById("bindFormat").style.display = "block";
142 } else if ( formatExists && document.getElementById("saveTemplate") != null && document.getElementById("saveTemplate").checked ) {
143 document.getElementById("bindFormat").style.display = "block";
144 var yes = confirm( '{/literal}{$useThisPageFormat}{literal}' );
145 if ( yes ) {
146 document.getElementById("bind_format").checked = true;
147 }
148 } else {
149 document.getElementById("bindFormat").style.display = "none";
150 document.getElementById("bind_format").checked = false;
151 }
152 }
153
154 function showUpdateFormatChkBox()
155 {
156 if (cj('#format_id').val()) {
157 cj("#updateFormat").show();
158 }
159 }
160
161 function updateFormatLabel() {
162 cj('.pdf-format-header-label').html(cj('#format_id option:selected').text() || cj('#format_id').attr('placeholder'));
163 }
164
165 updateFormatLabel();
166
167 function selectFormat( val, bind )
168 {
169 updateFormatLabel();
170 if (!val) {
171 val = 0;
172 bind = false;
173 }
174 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/pdfFormat' h=0 }"{literal};
175 cj.post( dataUrl, {formatId: val}, function( data ) {
176 cj("#format_id").val( data.id );
177 cj("#paper_size").val( data.paper_size );
178 cj("#orientation").val( data.orientation );
179 cj("#metric").val( data.metric );
180 cj("#margin_top").val( data.margin_top );
181 cj("#margin_bottom").val( data.margin_bottom );
182 cj("#margin_left").val( data.margin_left );
183 cj("#margin_right").val( data.margin_right );
184 selectPaper( data.paper_size );
185 cj("#update_format").prop({checked: false}).parent().hide();
186 document.getElementById('bind_format').checked = bind;
187 showBindFormatChkBox();
188 }, 'json');
189 }
190
191 function selectPaper( val )
192 {
193 dataUrl = {/literal}"{crmURL p='civicrm/ajax/paperSize' h=0 }"{literal};
194 cj.post( dataUrl, {paperSizeName: val}, function( data ) {
195 cj("#paper_size").val( data.name );
196 metric = document.getElementById('metric').value;
197 currentWidth = convertMetric( data.width, data.metric, metric );
198 currentHeight = convertMetric( data.height, data.metric, metric );
199 updatePaperDimensions( );
200 }, 'json');
201 }
202
203 function selectMetric( metric )
204 {
205 convertField( 'margin_top', currentMetric, metric );
206 convertField( 'margin_bottom', currentMetric, metric );
207 convertField( 'margin_left', currentMetric, metric );
208 convertField( 'margin_right', currentMetric, metric );
209 currentWidth = convertMetric( currentWidth, currentMetric, metric );
210 currentHeight = convertMetric( currentHeight, currentMetric, metric );
211 updatePaperDimensions( );
212 }
213
214 function updatePaperDimensions( )
215 {
216 metric = document.getElementById('metric').value;
217 width = new String( currentWidth.toFixed( 2 ) );
218 height = new String( currentHeight.toFixed( 2 ) );
219 if ( document.getElementById('orientation').value == 'landscape' ) {
220 width = new String( currentHeight.toFixed( 2 ) );
221 height = new String( currentWidth.toFixed( 2 ) );
222 }
223 document.getElementById('paper_dimensions').innerHTML = parseFloat( width ) + ' ' + metric + ' x ' + parseFloat( height ) + ' ' + metric;
224 currentMetric = metric;
225 }
226
227 function convertField( id, from, to )
228 {
229 val = document.getElementById( id ).value;
230 if ( val == '' || isNaN( val ) ) return;
231 val = convertMetric( val, from, to );
232 val = new String( val.toFixed( 3 ) );
233 document.getElementById( id ).value = parseFloat( val );
234 }
235
236 function convertMetric( value, from, to ) {
237 switch( from + to ) {
238 case 'incm': return value * 2.54;
239 case 'inmm': return value * 25.4;
240 case 'inpt': return value * 72;
241 case 'cmin': return value / 2.54;
242 case 'cmmm': return value * 10;
243 case 'cmpt': return value * 72 / 2.54;
244 case 'mmin': return value / 25.4;
245 case 'mmcm': return value / 10;
246 case 'mmpt': return value * 72 / 25.4;
247 case 'ptin': return value / 72;
248 case 'ptcm': return value * 2.54 / 72;
249 case 'ptmm': return value * 25.4 / 72;
250 }
251 return value;
252 }
253
254 function showSaveDetails(chkbox) {
255 var formatSelected = ( document.getElementById('format_id').value > 0 );
256 var templateSelected = ( document.getElementById('template') != null && document.getElementById('template').value > 0 );
257 if (chkbox.checked) {
258 document.getElementById("saveDetails").style.display = "block";
259 document.getElementById("saveTemplateName").disabled = false;
260 if ( formatSelected && ! templateSelected ) {
261 document.getElementById("bindFormat").style.display = "block";
262 var yes = confirm( '{/literal}{$useSelectedPageFormat}{literal}' );
263 if ( yes ) {
264 document.getElementById("bind_format").checked = true;
265 }
266 }
267 } else {
268 document.getElementById("saveDetails").style.display = "none";
269 document.getElementById("saveTemplateName").disabled = true;
270 if ( ! templateSelected ) {
271 document.getElementById("bindFormat").style.display = "none";
272 document.getElementById("bind_format").checked = false;
273 }
274 }
275 }
276
277 </script>
278 {/literal}
279