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" >
30 {if $generateAjaxRequest}
31 {foreach from=$ajaxRequestBlocks key="blockName" item="instances"}
32 {foreach from=$instances key="instance" item="active"}
33 buildAdditionalBlocks( '{$blockName}', '{$className}' );
38 {if $loadShowHideAddressFields}
39 {foreach from=$showHideAddressFields key="blockId" item="fieldName"}
40 processAddressFields( '{$fieldName}', '{$blockId}', 0 );
46 function buildAdditionalBlocks( blockName, className ) {
47 var element = blockName + '_Block_';
49 //get blockcount of last element of relevant blockName
50 var previousInstance = cj( '[id^="'+ element +'"]:last' ).attr('id').slice( element.length );
51 var currentInstance = parseInt( previousInstance ) + 1;
53 //show primary option if block count = 2
54 if ( currentInstance == 2) {
55 cj("#" + blockName + '-Primary').show( );
56 cj("#" + blockName + '-Primary-html').show( );
59 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&block=' + blockName + '&count=' + currentInstance;;
61 if ( className == 'CRM_Event_Form_ManageEvent_Location' ) {
62 dataUrl = ( currentInstance <= 2 ) ? dataUrl + '&subPage=Location' : '';
67 dataUrl += "&qfKey={$qfKey}";
75 var fname = '#' + blockName + '_Block_'+ previousInstance;
77 cj('#addMore' + blockName + previousInstance ).hide( );
81 success : function(html){
82 cj(fname).after(html);
83 cj(fname).next().trigger('crmLoad');
87 if ( blockName == 'Address' ) {
88 checkLocation('address_' + currentInstance + '_location_type_id', true );
89 /* FIX: for IE, To get the focus after adding new address block on first element */
90 cj('#address_' + currentInstance + '_location_type_id').focus();
94 //select single for is_bulk & is_primary
95 function singleSelect( object ) {
96 var element = object.split( '_', 3 );
98 var block = (element['0'] == 'Address') ? 'Primary' : element['2'].slice('2');
99 var execBlock = '#' + element['0'] + '-' + block + '-html Input[id*="' + element['2'] + '"]';
101 //element to check for checkbox
102 var elementChecked = cj( '#' + object ).prop('checked');
103 if ( elementChecked ) {
104 cj( execBlock ).each( function() {
105 if ( cj(this).attr('id') != object ) {
106 cj(this).prop('checked', false );
110 cj( '#' + object ).prop('checked', false );
113 //check if non of elements is set Primary / Allowed to Login.
114 if( cj.inArray( element['2'].slice('2'), [ 'Primary', 'Login' ] ) != -1 ) {
116 cj( execBlock ).each( function( ) {
117 if ( cj(this).prop('checked' ) ) {
122 cj('#' + object).prop('checked', true );
127 function removeBlock( blockName, blockId ) {
128 var element = cj("#addressBlock > div").size();
129 if ( ( blockName == 'Address' ) && element == 1 ) {
130 return clearFirstBlock(blockName , blockId);
133 if ( cj( "#"+ blockName + "_" + blockId + "_IsPrimary").prop('checked') ) {
134 var primaryBlockId = 1;
135 // consider next block as a primary,
136 // when user delete first block
137 if ( blockId >= 1 ) {
138 var blockIds = getAddressBlock('next');
139 for ( var i = 0; i <= blockIds.length; i++) {
140 var curBlockId = blockIds[i];
141 if ( curBlockId != blockId ) {
142 primaryBlockId = curBlockId;
148 // finally sets the primary address
149 cj( '#'+ blockName + '_' + primaryBlockId + '_IsPrimary').prop('checked', true);
152 //remove the spacer for address block only.
153 if ( blockName == 'Address' && cj( "#"+ blockName + "_Block_" + blockId ).prev().attr('class') == 'spacer' ){
154 cj( "#"+ blockName + "_Block_" + blockId ).prev().remove();
157 //unset block from html
158 cj( "#"+ blockName + "_Block_" + blockId ).empty().remove();
160 //show the link 'add address' to last element of Address Block
161 if ( blockName == 'Address' ) {
162 var lastAddressBlock = cj('div[id^=Address_Block_]').last().attr('id');
163 var lastBlockId = lastAddressBlock.split( '_' );
164 if ( lastBlockId[2] ) {
165 cj( '#addMoreAddress' + lastBlockId[2] ).show();
170 function clearFirstBlock( blockName , blockId ) {
171 var element = blockName + '_Block_' + blockId;
172 cj("#" + element +" input, " + "#" + element + " select").each(function () {
175 cj("#addressBlockId:not(.collapsed)").crmAccordionToggle();
176 cj("#addressBlockId .active").removeClass('active');
179 function getAddressBlock( position ) {
180 var addressBlockIds = [];
182 switch ( position ) {
184 var lastBlockInfo = cj("#addressBlockId > div").children(':last').attr('id').split( '_', 3);
185 addressBlockIds[i] = lastBlockInfo['2'];
188 cj("#addressBlockId > div").children().each( function() {
189 if ( cj(this).attr('id') ) {
190 var blockInfo = cj(this).attr('id').split( '_', 3);
191 addressBlockIds[i] = blockInfo['2'];
197 return addressBlockIds;