2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 <script type="text/javascript">
29 //bind the click event for action icon
30 cj('.action-icon').click( function( ) {
31 copyFieldValues( cj(this).attr('fname') );
36 * This function use to copy fieldsi
38 * @param fname string field name
41 function copyFieldValues( fname ) {
42 // this is the most common pattern for elements, so first check if it exits
43 // this check field starting with "field[" and contains [fname] and is not
44 // hidden ( for checkbox hidden element is created )
45 var elementId = cj('.crm-copy-fields [name^="field["][name*="[' + fname +']"][type!=hidden]');
47 // get the first element and it's value
48 var firstElement = elementId.eq(0);
49 var firstElementValue = firstElement.val();
51 //console.log( elementId );
52 //console.log( firstElement );
53 //console.log( firstElementValue );
55 //check if it is date element
56 var isDateElement = elementId.attr('format');
58 // check if it is wysiwyg element
59 var editor = elementId.attr('editor');
61 //get the element type
62 var elementType = elementId.attr('type');
64 // set the value for all the elements, elements needs to be handled are
65 // select, checkbox, radio, date fields, text, textarea, multi-select
66 // wysiwyg editor, advanced multi-select ( to do )
67 if ( elementType == 'radio' ) {
68 firstElementValue = elementId.filter(':checked').eq(0).val();
69 elementId.filter("[value=" + firstElementValue + "]").prop("checked",true).change();
71 else if ( elementType == 'checkbox' ) {
73 // get the entity id of first element
74 var firstEntityId = cj('.crm-copy-fields > tbody > tr');
76 if ( firstEntityId.length == 0 ) {
77 firstEntityId = firstElement.closest('div.crm-grid-row');
80 firstEntityId = firstEntityId.attr('entity_id');
82 var firstCheckElement = cj('.crm-copy-fields [type=checkbox][name^="field['+ firstEntityId +']['+ fname +']"][type!=hidden]');
84 if ( firstCheckElement.length > 1 ) {
85 // lets uncheck all the checkbox except first one
86 cj('.crm-copy-fields [type=checkbox][name^="field["][name*="[' + fname +']"][type=checkbox]:not([name^="field['+ firstEntityId +']['+ fname +']["])').prop('checked', false);
88 //here for each checkbox for first row, check if it is checked and set remaining checkboxes
89 firstCheckElement.each(function() {
90 if (cj(this).prop('checked') ) {
91 var elementName = cj(this).attr('name');
92 var correctIndex = elementName.split('field['+ firstEntityId +']['+ fname +'][');
93 correctIndexValue = correctIndex[1].replace(']', '');
94 cj('.crm-copy-fields [type=checkbox][name^="field["][name*="['+ fname +']['+ correctIndexValue+']"][type!=hidden]').prop('checked',true).change();
99 if ( firstCheckElement.prop('checked') ) {
100 cj('.crm-copy-fields [type=checkbox][name^="field["][name*="['+ fname +']"][type!=hidden]').prop('checked',true).change();
103 cj('.crm-copy-fields [type=checkbox][name^="field["][name*="['+ fname +']"][type!=hidden]').prop('checked', false).change();
108 var firstElementId = firstElement.attr('id');
111 //get the content of first element
112 oEditor = CKEDITOR.instances[firstElementId];
113 var htmlContent = oEditor.getData( );
115 // copy first element content to all the elements
116 elementId.each( function() {
117 var elemtId = cj(this).attr('id');
118 oEditor = CKEDITOR.instances[elemtId];
119 oEditor.setData( htmlContent );
123 //get the content of first element
124 var htmlContent = tinyMCE.get( firstElementId ).getContent();
126 // copy first element content to all the elements
127 elementId.each( function() {
128 var elemtId = cj(this).attr('id');
129 tinyMCE.get( elemtId ).setContent( htmlContent );
134 case 'drupalwysiwyg':
137 elementId.val( firstElementValue ).change();
142 if (elementId.is('select') === true && firstElement.parent().find(':input').select().index() >= 1 && firstElement.parent().find('select').select().index < 1) {
143 // its a multiselect case
144 firstElement.parent().find(':input').select().each( function(count) {
145 var firstElementValue = cj(this).val();
146 var elementId = cj('.crm-copy-fields [name^="field["][name*="[' + fname +'][' + count + '"][type!=hidden]');
147 elementId.val(firstElementValue).not(":first").change();
151 elementId.val(firstElementValue).change();
155 // since we use different display field for date we also need to set it.
156 // also check for date time field and set the value correctly
157 if ( isDateElement ) {
158 copyValuesDate( fname );
163 * Special function to handle setting values for date fields
165 * @param fname string field name
168 function copyValuesDate(fname) {
169 var fnameDisplay = fname + '_display';
170 var fnameTime = fname + '_time';
172 var displayElement = cj('.crm-copy-fields [name^="field_"][name$="_' + fnameDisplay +'"][type!=hidden]');
173 var timeElement = cj('.crm-copy-fields [name^="field["][name*="[' + fnameTime +']"][type!=hidden]');
175 displayElement.val( displayElement.eq(0).val() );
176 timeElement.val( timeElement.eq(0).val() );