2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.3 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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 if ((typeof(Drupal) != 'undefined') && Drupal.attachBehaviors) {
84 Drupal.attachBehaviors(cj('#' + blockName + '_Block_'+ currentInstance)[0]);
89 if ( blockName == 'Address' ) {
90 checkLocation('address_' + currentInstance + '_location_type_id', true );
91 /* FIX: for IE, To get the focus after adding new address block on first element */
92 cj('#address_' + currentInstance + '_location_type_id').focus();
96 //select single for is_bulk & is_primary
97 function singleSelect( object ) {
98 var element = object.split( '_', 3 );
100 var block = (element['0'] == 'Address') ? 'Primary' : element['2'].slice('2');
101 var execBlock = '#' + element['0'] + '-' + block + '-html Input[id*="' + element['2'] + '"]';
103 //element to check for checkbox
104 var elementChecked = cj( '#' + object ).attr('checked');
105 if ( elementChecked ) {
106 cj( execBlock ).each( function() {
107 if ( cj(this).attr('id') != object ) {
108 cj(this).attr( 'checked', false );
112 cj( '#' + object ).attr( 'checked', false );
115 //check if non of elements is set Primary / Allowed to Login.
116 if( cj.inArray( element['2'].slice('2'), [ 'Primary', 'Login' ] ) != -1 ) {
118 cj( execBlock ).each( function( ) {
119 if ( cj(this).attr( 'checked' ) ) {
124 cj('#' + object).attr( 'checked', true );
129 function removeBlock( blockName, blockId ) {
130 var element = cj("#addressBlock > div").size();
131 if ( ( blockName == 'Address' ) && element == 1 ) {
132 return clearFirstBlock(blockName , blockId);
135 if ( cj( "#"+ blockName + "_" + blockId + "_IsPrimary").attr('checked') ) {
136 var primaryBlockId = 1;
137 // consider next block as a primary,
138 // when user delete first block
139 if ( blockId >= 1 ) {
140 var blockIds = getAddressBlock('next');
141 for ( var i = 0; i <= blockIds.length; i++) {
142 var curBlockId = blockIds[i];
143 if ( curBlockId != blockId ) {
144 primaryBlockId = curBlockId;
150 // finally sets the primary address
151 cj( '#'+ blockName + '_' + primaryBlockId + '_IsPrimary').attr('checked', true);
154 //remove the spacer for address block only.
155 if ( blockName == 'Address' && cj( "#"+ blockName + "_Block_" + blockId ).prev().attr('class') == 'spacer' ){
156 cj( "#"+ blockName + "_Block_" + blockId ).prev().remove();
159 //unset block from html
160 cj( "#"+ blockName + "_Block_" + blockId ).empty().remove();
162 //show the link 'add address' to last element of Address Block
163 if ( blockName == 'Address' ) {
164 var lastAddressBlock = cj('div[id^=Address_Block_]').last().attr('id');
165 var lastBlockId = lastAddressBlock.split( '_' );
166 if ( lastBlockId[2] ) {
167 cj( '#addMoreAddress' + lastBlockId[2] ).show();
172 function clearFirstBlock( blockName , blockId ) {
173 var element = blockName + '_Block_' + blockId;
174 cj("#" + element +" input, " + "#" + element + " select").each(function () {
177 cj("#addressBlockId:not(.collapsed)").crmAccordionToggle();
178 cj("#addressBlockId .active").removeClass('active');
181 function getAddressBlock( position ) {
182 var addressBlockIds = new Array();
184 switch ( position ) {
186 var lastBlockInfo = cj("#addressBlockId > div").children(':last').attr('id').split( '_', 3);
187 addressBlockIds[i] = lastBlockInfo['2'];
190 cj("#addressBlockId > div").children().each( function() {
191 if ( cj(this).attr('id') ) {
192 var blockInfo = cj(this).attr('id').split( '_', 3);
193 addressBlockIds[i] = blockInfo['2'];
199 return addressBlockIds;