commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / templates / CRM / common / batchCopy.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2015 |
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 {literal}
27 <script type="text/javascript">
28 CRM.$(function($) {
29 /**
30 * This function use to copy fields
31 *
32 * @param fname string field name
33 * @return void
34 */
35 function copyFieldValues( fname ) {
36 // this is the most common pattern for elements, so first check if it exits
37 // this check field starting with "field[" and contains [fname] and is not
38 // hidden ( for checkbox hidden element is created )
39 var elementId = $('.crm-copy-fields [name^="field["][name*="[' + fname +']"][type!=hidden]');
40
41 // get the first element and it's value
42 var firstElement = elementId.eq(0);
43 var firstElementValue = firstElement.val();
44
45 //check if it is date element
46 var isDateElement = elementId.attr('format');
47
48 // check if it is wysiwyg element
49 var editor = elementId.attr('editor');
50
51 //get the element type
52 var elementType = elementId.attr('type');
53
54 // set the value for all the elements, elements needs to be handled are
55 // select, checkbox, radio, date fields, text, textarea, multi-select
56 // wysiwyg editor, advanced multi-select ( to do )
57 if ( elementType == 'radio' ) {
58 firstElementValue = elementId.filter(':checked').eq(0).val();
59 elementId.filter("[value=" + firstElementValue + "]").prop("checked",true).change();
60 }
61 else if ( elementType == 'checkbox' ) {
62 // handle checkbox
63 // get the entity id of first element
64 var firstEntityId = $('.crm-copy-fields > tbody > tr');
65
66 if ( firstEntityId.length == 0 ) {
67 firstEntityId = firstElement.closest('div.crm-grid-row');
68 }
69
70 firstEntityId = firstEntityId.attr('entity_id');
71
72 var firstCheckElement = $('.crm-copy-fields [type=checkbox][name^="field['+ firstEntityId +']['+ fname +']"][type!=hidden]');
73
74 if ( firstCheckElement.length > 1 ) {
75 // lets uncheck all the checkbox except first one
76 $('.crm-copy-fields [type=checkbox][name^="field["][name*="[' + fname +']"][type=checkbox]:not([name^="field['+ firstEntityId +']['+ fname +']["])').prop('checked', false);
77
78 //here for each checkbox for first row, check if it is checked and set remaining checkboxes
79 firstCheckElement.each(function() {
80 if ($(this).prop('checked') ) {
81 var elementName = $(this).attr('name');
82 var correctIndex = elementName.split('field['+ firstEntityId +']['+ fname +'][');
83 correctIndexValue = correctIndex[1].replace(']', '');
84 $('.crm-copy-fields [type=checkbox][name^="field["][name*="['+ fname +']['+ correctIndexValue+']"][type!=hidden]').prop('checked',true).change();
85 }
86 });
87 }
88 else {
89 if ( firstCheckElement.prop('checked') ) {
90 $('.crm-copy-fields [type=checkbox][name^="field["][name*="['+ fname +']"][type!=hidden]').prop('checked',true).change();
91 }
92 else {
93 $('.crm-copy-fields [type=checkbox][name^="field["][name*="['+ fname +']"][type!=hidden]').prop('checked', false).change();
94 }
95 }
96 }
97 else if ( editor ) {
98 var firstElementId = firstElement.attr('id');
99 switch ( editor ) {
100 case 'ckeditor':
101 //get the content of first element
102 oEditor = CKEDITOR.instances[firstElementId];
103 var htmlContent = oEditor.getData( );
104
105 // copy first element content to all the elements
106 elementId.each( function() {
107 var elemtId = $(this).attr('id');
108 oEditor = CKEDITOR.instances[elemtId];
109 oEditor.setData( htmlContent );
110 });
111 break;
112 case 'tinymce':
113 //get the content of first element
114 var htmlContent = tinyMCE.get( firstElementId ).getContent();
115
116 // copy first element content to all the elements
117 elementId.each( function() {
118 var elemtId = $(this).attr('id');
119 tinyMCE.get( elemtId ).setContent( htmlContent );
120 });
121 break;
122 case 'joomlaeditor':
123 // TO DO
124 case 'drupalwysiwyg':
125 // TO DO
126 default:
127 elementId.val( firstElementValue ).change();
128
129 }
130 }
131 else {
132 if (elementId.is('select') === true && firstElement.parent().find(':input').select().index() >= 1 && firstElement.parent().find('select').select().index < 1) {
133 // its a multiselect case
134 firstElement.parent().find(':input').select().each( function(count) {
135 var firstElementValue = $(this).val();
136 var elementId = $('.crm-copy-fields [name^="field["][name*="[' + fname +'][' + count + '"][type!=hidden]');
137 elementId.val(firstElementValue).not(":first").change();
138 });
139 }
140 else {
141 elementId.val(firstElementValue).change();
142 }
143 }
144
145 // since we use different display field for date we also need to set it.
146 // also check for date time field and set the value correctly
147 if ( isDateElement ) {
148 copyValuesDate( fname );
149 }
150 }
151
152 /**
153 * Special function to handle setting values for date fields
154 *
155 * @param fname string field name
156 * @return void
157 */
158 function copyValuesDate(fname) {
159 var displayElement = $('.crm-copy-fields [name^="field_"][name*="_' + fname +'_display"]:visible');
160 var timeElement = $('.crm-copy-fields [name^="field["][name*="[' + fname +'_time]"][type!=hidden]');
161
162 displayElement.val( displayElement.eq(0).val() );
163 timeElement.val( timeElement.eq(0).val() );
164 }
165
166 //bind the click event for action icon
167 $('.action-icon').click(function( ) {
168 copyFieldValues($(this).attr('fname'));
169 });
170 });
171
172
173 </script>
174 {/literal}