-- CRM-12682 applied patch and made some modifications
[civicrm-core.git] / templates / CRM / Contact / Form / Task / PDFLetterCommon.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.3 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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}</td><td>{$form.format_id.html}{help id="id-pdf-format" file="CRM/Contact/Form/Task/PDFLetterCommon.hlp"}</td>
53 <td colspan="2">&nbsp;</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 {if $action neq 4}
88 <span class="helpIcon" id="helphtml">
89 <a href="#" onClick="return showToken('Html', 1);">{$form.token1.label}</a>
90 {help id="id-token-html" file="CRM/Contact/Form/Task/Email.hlp" tplFile=$tplFile isAdmin=$isAdmin editor=$editor}
91 <div id="tokenHtml" style="display:none;">
92 <input style="border:1px solid #999999;" type="text" id="filter1" size="20" name="filter1" onkeyup="filter(this, 1)"/><br />
93 <span class="description">{ts}Begin typing to filter list of tokens{/ts}</span><br/>
94 {$form.token1.html}
95 </div>
96 </span>
97 {/if}
98 <div class="clear"></div>
99 <div class='html'>
100 {if $editor EQ 'textarea'}
101 <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; Configure &raquo; Global Settings &raquo; Site Preferences).{/ts}</div>
102 {/if}
103 {$form.html_message.html}<br />
104 </div>
105
106 <div id="editMessageDetails">
107 <div id="updateDetails" >
108 {$form.updateTemplate.html}&nbsp;{$form.updateTemplate.label}
109 </div>
110 <div>
111 {$form.saveTemplate.html}&nbsp;{$form.saveTemplate.label}
112 </div>
113 </div>
114
115 <div id="saveDetails" class="section">
116 <div class="label">{$form.saveTemplateName.label}</div>
117 <div class="content">{$form.saveTemplateName.html|crmAddClass:huge}</div>
118 </div>
119
120 </div><!-- /.crm-accordion-body -->
121 </div><!-- /.crm-accordion-wrapper -->
122
123 {include file="CRM/Mailing/Form/InsertTokens.tpl"}
124
125 {literal}
126 <script type="text/javascript">
127 cj(function() {
128 cj().crmAccordions();
129 });
130
131 var currentWidth;
132 var currentHeight;
133 var currentMetric = document.getElementById('metric').value;
134 showBindFormatChkBox();
135 selectPaper( document.getElementById('paper_size').value );
136
137 function tokenReplHtml ( )
138 {
139 var token1 = cj("#token1").val( )[0];
140 var editor = {/literal}"{$editor}"{literal};
141 if ( editor == "tinymce" ) {
142 var content= tinyMCE.get('html_message').getContent() +token1;
143 tinyMCE.get('html_message').setContent(content);
144 } else if ( editor == "joomlaeditor" ) {
145 tinyMCE.execCommand('mceInsertContent',false, token1);
146 var msg = document.getElementById(html_message).value;
147 var cursorlen = document.getElementById(html_message).selectionStart;
148 var textlen = msg.length;
149 document.getElementById(html_message).value = msg.substring(0, cursorlen) + token1 + msg.substring(cursorlen, textlen);
150 var cursorPos = (cursorlen + token1.length);
151 document.getElementById(html_message).selectionStart = cursorPos;
152 document.getElementById(html_message).selectionEnd = cursorPos;
153 document.getElementById(html_message).focus();
154 } else if ( editor == "ckeditor" ) {
155 oEditor = CKEDITOR.instances[html_message];
156 oEditor.insertHtml(token1.toString() );
157 } else if ( editor == "drupalwysiwyg" ) {
158 Drupal.wysiwyg.instances[html_message].insert(token1.toString());
159 } else {
160 var msg = document.getElementById(html_message).value;
161 var cursorlen = document.getElementById(html_message).selectionStart;
162 var textlen = msg.length;
163 document.getElementById(html_message).value = msg.substring(0, cursorlen) + token1 + msg.substring(cursorlen, textlen);
164 var cursorPos = (cursorlen + token1.length);
165 document.getElementById(html_message).selectionStart = cursorPos;
166 document.getElementById(html_message).selectionEnd = cursorPos;
167 document.getElementById(html_message).focus();
168 }
169 verify();
170 }
171
172 function showBindFormatChkBox()
173 {
174 var templateExists = true;
175 if ( document.getElementById('template') == null || document.getElementById('template').value == '' ) {
176 templateExists = false;
177 }
178 var formatExists = true;
179 if ( document.getElementById('format_id').value == 0 ) {
180 formatExists = false;
181 }
182 if ( templateExists && formatExists ) {
183 document.getElementById("bindFormat").style.display = "block";
184 } else if ( formatExists && document.getElementById("saveTemplate") != null && document.getElementById("saveTemplate").checked ) {
185 document.getElementById("bindFormat").style.display = "block";
186 var yes = confirm( '{/literal}{$useThisPageFormat}{literal}' );
187 if ( yes ) {
188 document.getElementById("bind_format").checked = true;
189 }
190 } else {
191 document.getElementById("bindFormat").style.display = "none";
192 document.getElementById("bind_format").checked = false;
193 }
194 }
195
196 function showUpdateFormatChkBox()
197 {
198 if ( document.getElementById('format_id').value != 0 ) {
199 document.getElementById("updateFormat").style.display = "block";
200 }
201 }
202
203 function hideUpdateFormatChkBox()
204 {
205 document.getElementById("update_format").checked = false;
206 document.getElementById("updateFormat").style.display = "none";
207 }
208
209 function selectFormat( val, bind )
210 {
211 if ( val == null || val == 0 ) {
212 val = 0;
213 bind = false;
214 }
215 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/pdfFormat' h=0 }"{literal};
216 cj.post( dataUrl, {formatId: val}, function( data ) {
217 cj("#format_id").val( data.id );
218 cj("#paper_size").val( data.paper_size );
219 cj("#orientation").val( data.orientation );
220 cj("#metric").val( data.metric );
221 cj("#margin_top").val( data.margin_top );
222 cj("#margin_bottom").val( data.margin_bottom );
223 cj("#margin_left").val( data.margin_left );
224 cj("#margin_right").val( data.margin_right );
225 selectPaper( data.paper_size );
226 hideUpdateFormatChkBox();
227 document.getElementById('bind_format').checked = bind;
228 showBindFormatChkBox();
229 }, 'json');
230 }
231
232 function 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
244 function 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
255 function 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
268 function 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
277 function 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
295 function 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}
320