2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
5 | This work is published under the GNU AGPLv3 license with some |
6 | permitted exceptions and without any warranty. For full license |
7 | and copyright information, see https://civicrm.org/licensing |
8 +--------------------------------------------------------------------+
11 <script type="text/javascript" >
14 {if $generateAjaxRequest}
15 {foreach from=$ajaxRequestBlocks key="blockName" item="instances"}
16 {foreach from=$instances key="instance" item="active"}
17 buildAdditionalBlocks( '{$blockName}', '{$className}' );
22 {if $loadShowHideAddressFields}
23 {foreach from=$showHideAddressFields key="blockId" item="fieldName"}
24 processAddressFields( '{$fieldName}', '{$blockId}', 0 );
30 function buildAdditionalBlocks( blockName, className ) {
31 var element = blockName + '_Block_';
33 //get blockcount of last element of relevant blockName
34 var previousInstance = cj( '[id^="'+ element +'"]:last' ).attr('id').slice( element.length );
35 var currentInstance = parseInt( previousInstance ) + 1;
37 //show primary option if block count = 2
38 if ( currentInstance == 2) {
39 cj("#" + blockName + '-Primary').show( );
40 cj("#" + blockName + '-Primary-html').show( );
43 var dataUrl = {/literal}"{crmURL h=0 q='snippet=4'}"{literal} + '&block=' + blockName + '&count=' + currentInstance;
45 if ( className == 'CRM_Event_Form_ManageEvent_Location' ) {
46 dataUrl = ( currentInstance <= 2 ) ? dataUrl + '&subPage=Location' : '';
51 dataUrl += "&qfKey={$qfKey}";
59 var fname = '#' + blockName + '_Block_'+ previousInstance;
61 cj('#addMore' + blockName + previousInstance ).hide( );
65 success : function(html){
66 cj(fname).after(html);
67 cj(fname).nextAll().trigger('crmLoad');
71 if ( blockName == 'Address' ) {
72 checkLocation('address_' + currentInstance + '_location_type_id', true );
73 /* FIX: for IE, To get the focus after adding new address block on first element */
74 cj('#address_' + currentInstance + '_location_type_id').focus();
78 //select single for is_bulk & is_primary
79 function singleSelect( object ) {
80 var element = object.split( '_', 3 );
82 var block = (element['0'] == 'Address') ? 'Primary' : element['2'].slice('2');
83 var execBlock = '#' + element['0'] + '-' + block + '-html Input[id*="' + element['2'] + '"]';
85 //element to check for checkbox
86 var elementChecked = cj( '#' + object ).prop('checked');
87 if ( elementChecked ) {
88 cj( execBlock ).each( function() {
89 if ( cj(this).attr('id') != object ) {
90 cj(this).prop('checked', false );
94 cj( '#' + object ).prop('checked', false );
97 //check if non of elements is set Primary / Allowed to Login.
98 if( cj.inArray( element['2'].slice('2'), [ 'Primary', 'Login' ] ) != -1 ) {
100 cj( execBlock ).each( function( ) {
101 if ( cj(this).prop('checked' ) ) {
106 cj('#' + object).prop('checked', true );
111 function removeBlock( blockName, blockId ) {
112 var element = cj("#addressBlock > div").size();
113 if ( ( blockName == 'Address' ) && element == 1 ) {
114 return clearFirstBlock(blockName , blockId);
117 if ( cj( "#"+ blockName + "_" + blockId + "_IsPrimary").prop('checked') ) {
118 var primaryBlockId = 1;
119 // consider next block as a primary,
120 // when user delete first block
121 if ( blockId >= 1 ) {
122 var blockIds = getAddressBlock('next');
123 for ( var i = 0; i <= blockIds.length; i++) {
124 var curBlockId = blockIds[i];
125 if ( curBlockId != blockId ) {
126 primaryBlockId = curBlockId;
132 // finally sets the primary address
133 cj( '#'+ blockName + '_' + primaryBlockId + '_IsPrimary').prop('checked', true);
136 //remove the spacer for address block only.
137 if ( blockName == 'Address' && cj( "#"+ blockName + "_Block_" + blockId ).prev().attr('class') == 'spacer' ){
138 cj( "#"+ blockName + "_Block_" + blockId ).prev().remove();
141 //unset block from html
142 cj( "#"+ blockName + "_Block_" + blockId ).empty().remove();
144 //show the link 'add address' to last element of Address Block
145 if ( blockName == 'Address' ) {
146 var lastAddressBlock = cj('div[id^=Address_Block_]').last().attr('id');
147 var lastBlockId = lastAddressBlock.split( '_' );
148 if ( lastBlockId[2] ) {
149 cj( '#addMoreAddress' + lastBlockId[2] ).show();
154 function clearFirstBlock( blockName , blockId ) {
155 var element = blockName + '_Block_' + blockId;
156 cj("#" + element +" input, " + "#" + element + " select").each(function () {
159 cj("#addressBlockId:not(.collapsed)").crmAccordionToggle();
160 cj("#addressBlockId .active").removeClass('active');
163 function getAddressBlock( position ) {
164 var addressBlockIds = [];
166 switch ( position ) {
168 var lastBlockInfo = cj("#addressBlockId > div").children(':last').attr('id').split( '_', 3);
169 addressBlockIds[i] = lastBlockInfo['2'];
172 cj("#addressBlockId > div").children().each( function() {
173 if ( cj(this).attr('id') ) {
174 var blockInfo = cj(this).attr('id').split( '_', 3);
175 addressBlockIds[i] = blockInfo['2'];
181 return addressBlockIds;