PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/public_html/sites/all/modules/civicrm/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl

https://github.com/timstephenson/NatureBridge
Smarty Template | 300 lines | 246 code | 26 blank | 28 comment | 32 complexity | 36a9e211d84057de2355dbf0a6efbef6 MD5 | raw file
  1. {*
  2. +--------------------------------------------------------------------+
  3. | CiviCRM version 3.4 |
  4. +--------------------------------------------------------------------+
  5. | Copyright CiviCRM LLC (c) 2004-2011 |
  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. {* This file provides the HTML for the on-behalf-of form. Can also be used for related contact edit form. *}
  27. {if $buildOnBehalfForm or $onBehalfRequired}
  28. <fieldset id="for_organization" class="for_organization-group">
  29. <legend>{$fieldSetTitle}</legend>
  30. {if ( $relatedOrganizationFound or $onBehalfRequired ) and !$organizationName}
  31. <div id='orgOptions' class="section crm-section">
  32. <div class="content">
  33. {$form.org_option.html}
  34. </div>
  35. </div>
  36. {/if}
  37. <div id="select_org" class="crm-section">
  38. {foreach from=$form.onbehalf item=field key=fieldName}
  39. <div class="crm-section {$onBehalfOfFields.$fieldName.name}-section">
  40. {if $onBehalfOfFields.$fieldName.help_pre}
  41. &nbsp;&nbsp;<span class='description'>{$onBehalfOfFields.$fieldName.help_pre}</span>
  42. {/if}
  43. {if ( $fieldName eq 'organization_name' ) and $organizationName}
  44. <div id='org_name' class="label">{$field.label}</div>
  45. <div class="content">
  46. {$field.html|crmReplace:class:big}
  47. <span>
  48. ( <a id='createNewOrg' href="javascript:createNew( );">{ts}Enter a new organization{/ts}</a> )
  49. </span>
  50. <div id="id-onbehalf-orgname-enter-help" class="description">
  51. {ts}Organization details have been prefilled for you. If this is not the organization you want to use, click "Enter a new organization" above.{/ts}
  52. </div>
  53. {if $onBehalfOfFields.$fieldName.help_post}
  54. <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
  55. {/if}
  56. </div>
  57. {else}
  58. {if $onBehalfOfFields.$fieldName.options_per_line != 0}
  59. <div class="label option-label">{$field.label}</div>
  60. <div class="content 3">
  61. {assign var="count" value="1"}
  62. {strip}
  63. <table class="form-layout-compressed">
  64. <tr>
  65. {* sort by fails for option per line. Added a variable to iterate through the element array*}
  66. {assign var="index" value="1"}
  67. {foreach name=outer key=key item=item from=$field}
  68. {if $index < 10}
  69. {assign var="index" value=`$index+1`}
  70. {else}
  71. <td class="labels font-light">{$field.$key.html}</td>
  72. {if $count == $onBehalfOfFields.$fieldName.options_per_line}
  73. </tr>
  74. <tr>
  75. {assign var="count" value="1"}
  76. {else}
  77. {assign var="count" value=`$count+1`}
  78. {/if}
  79. {/if}
  80. {/foreach}
  81. </tr>
  82. </table>
  83. {/strip}
  84. {if $onBehalfOfFields.$fieldName.help_post}
  85. <span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
  86. {/if}
  87. </div>
  88. {else}
  89. <div class="label">{$field.label}</div>
  90. <div class="content">
  91. {$field.html}
  92. {if $fieldName eq 'organization_name'}
  93. <div id="id-onbehalf-orgname-help" class="description">{ts}Start typing the name of an organization that you have saved previously to use it again. Otherwise click "Enter a new organization" above.{/ts}</div>
  94. {/if}
  95. {if !empty($onBehalfOfFields.$fieldName.html_type) && $onBehalfOfFields.$fieldName.html_type eq 'Autocomplete-Select'}
  96. {assign var=elementName value=onbehalf[$fieldName]}
  97. {include file="CRM/Custom/Form/AutoComplete.tpl" element_name=$elementName}
  98. {/if}
  99. {if $onBehalfOfFields.$fieldName.help_post}
  100. <br /><span class='description'>{$onBehalfOfFields.$fieldName.help_post}</span>
  101. {/if}
  102. </div>
  103. {/if}
  104. {/if}
  105. <div class="clear"></div>
  106. </div>
  107. {/foreach}
  108. </div>
  109. <div>{$form.mode.html}</div>
  110. {/if}
  111. {literal}
  112. <script type="text/javascript">
  113. var reset = {/literal}"{$reset}"{literal};
  114. var onBehalfRequired = {/literal}"{$onBehalfRequired}"{literal};
  115. var mainDisplay = {/literal}"{$mainDisplay}"{literal};
  116. cj( "div#id-onbehalf-orgname-help").hide( );
  117. if ( mainDisplay ) {
  118. showOnBehalf( false );
  119. }
  120. cj( "#mode" ).hide( );
  121. cj( "#mode" ).attr( 'checked', 'checked' );
  122. if ( cj( "#mode" ).attr( 'checked' ) && !reset ) {
  123. $text = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
  124. cj( "#createNewOrg" ).text( $text );
  125. cj( "#mode" ).removeAttr( 'checked' );
  126. }
  127. function showOnBehalf( onBehalfRequired )
  128. {
  129. if ( cj( "#is_for_organization" ).attr( 'checked' ) || onBehalfRequired ) {
  130. cj( "#for_organization" ).html( '' );
  131. var urlPath = {/literal}"{crmURL p=$urlPath h=0 q='snippet=4&onbehalf=1'}"{literal};
  132. urlPath = urlPath + {/literal}"{$urlParams}"{literal};
  133. if ( reset ) {
  134. urlPath = urlPath + '&reset=' + reset;
  135. }
  136. cj.ajax({
  137. url : urlPath,
  138. async : false,
  139. global : false,
  140. success : function ( content ) {
  141. cj( "#onBehalfOfOrg" ).html( content );
  142. }
  143. });
  144. } else {
  145. cj( "#onBehalfOfOrg" ).html('');
  146. cj( "#for_organization" ).html( '' );
  147. return;
  148. }
  149. }
  150. function resetValues( filter )
  151. {
  152. if ( filter ) {
  153. cj( "#select_org div" ).find( 'input[type=text], select, textarea' ).each(function( ) {
  154. if ( cj(this).attr('name') != 'onbehalf[organization_name]' ) {
  155. cj(this).val( '' );
  156. }
  157. });
  158. } else {
  159. cj( "#select_org div" ).find( 'input[type=text], select, textarea' ).each(function( ) {
  160. cj(this).val( '' );
  161. });
  162. }
  163. cj( "#select_org tr td" ).find( 'input[type=radio], input[type=checkbox]' ).each(function( ) {
  164. cj(this).attr('checked', false);
  165. });
  166. }
  167. function createNew( )
  168. {
  169. if ( cj( "#mode" ).attr( 'checked' ) ) {
  170. $text = ' {/literal}{ts escape="js"}Use existing organization{/ts}{literal} ';
  171. cj( "#onbehalf_organization_name" ).removeAttr( 'readonly' );
  172. cj( "#mode" ).removeAttr( 'checked' );
  173. resetValues( false );
  174. } else {
  175. $text = ' {/literal}{ts escape="js"}Enter a new organization{/ts}{literal} ';
  176. cj( "#mode" ).attr( 'checked', 'checked' );
  177. setOrgName( );
  178. }
  179. cj( "#createNewOrg" ).text( $text );
  180. }
  181. function setOrgName( )
  182. {
  183. var orgName = "{/literal}{$organizationName}{literal}";
  184. var orgId = "{/literal}{$orgId}{literal}";
  185. cj( "#onbehalf_organization_name" ).val( orgName );
  186. cj( "#onbehalf_organization_name" ).attr( 'readonly', true );
  187. setLocationDetails( orgId );
  188. }
  189. function setLocationDetails( contactID )
  190. {
  191. resetValues( true );
  192. var locationUrl = {/literal}"{$locDataURL}"{literal} + contactID + "&ufId=" + {/literal}"{$profileId}"{literal};
  193. cj.ajax({
  194. url : locationUrl,
  195. dataType : "json",
  196. timeout : 5000, //Time in milliseconds
  197. success : function( data, status ) {
  198. for (var ele in data) {
  199. if ( data[ele].type == 'Radio' ) {
  200. if ( data[ele].value ) {
  201. cj( "input[name='"+ ele +"']" ).filter( "[value=" + data[ele].value + "]" ).attr( 'checked', 'checked' );
  202. }
  203. } else if ( data[ele].type == 'CheckBox' ) {
  204. if ( data[ele].value ) {
  205. cj( "input[name='"+ ele +"']" ).attr( 'checked','checked' );
  206. }
  207. } else {
  208. cj( "#" + ele ).val( data[ele].value );
  209. }
  210. }
  211. },
  212. error : function( XMLHttpRequest, textStatus, errorThrown ) {
  213. console.error("HTTP error status: ", textStatus);
  214. }
  215. });
  216. }
  217. var orgOption = '';
  218. cj( "input:radio[name='org_option']" ).click( function( ) {
  219. orgOption = cj( "input:radio[name='org_option']:checked" ).val( );
  220. selectCreateOrg( orgOption, true );
  221. });
  222. function selectCreateOrg( orgOption, reset )
  223. {
  224. if ( orgOption == 0 ) {
  225. cj( "div#id-onbehalf-orgname-help").show( );
  226. var dataUrl = {/literal}"{$employerDataURL}"{literal};
  227. cj( '#onbehalf_organization_name' ).autocomplete( dataUrl,
  228. { width : 180,
  229. selectFirst : false,
  230. matchContains : true
  231. }).result( function( event, data, formatted ) {
  232. cj('#onbehalf_organization_name').val( data[0] );
  233. cj('#onbehalfof_id').val( data[1] );
  234. setLocationDetails( data[1] );
  235. });
  236. } else if ( orgOption == 1 ) {
  237. cj( "input#onbehalf_organization_name" ).removeClass( 'ac_input' ).unautocomplete( );
  238. cj( "div#id-onbehalf-orgname-help").hide( );
  239. }
  240. if ( reset ) {
  241. resetValues( false );
  242. }
  243. }
  244. {/literal}
  245. {if ( $relatedOrganizationFound or $onBehalfRequired ) and $reset}
  246. {if $organizationName}
  247. {literal}
  248. setOrgName( );
  249. {/literal}{else}{literal}
  250. cj( "#orgOptions" ).show( );
  251. var orgOption = cj( "input:radio[name=org_option]:checked" ).val( );
  252. selectCreateOrg( orgOption, false );
  253. {/literal}{/if}
  254. {/if}{literal}
  255. </script>
  256. {/literal}
  257. </fieldset>
  258. {literal}
  259. <script type="text/javascript">
  260. {/literal}
  261. {* If mid present in the url, take the required action (poping up related existing contact ..etc) *}
  262. {if $membershipContactID}
  263. {literal}
  264. cj( function( ) {
  265. cj( '#organization_id' ).val("{/literal}{$membershipContactName}{literal}");
  266. cj( '#organization_name' ).val("{/literal}{$membershipContactName}{literal}");
  267. cj( '#onbehalfof_id' ).val("{/literal}{$membershipContactID}{literal}");
  268. setLocationDetails( "{/literal}{$membershipContactID}{literal}" );
  269. });
  270. {/literal}
  271. {/if}
  272. {literal}
  273. </script>
  274. {/literal}