Merge pull request #2842 from totten/master-api-rollback-soft-errors
[civicrm-core.git] / templates / CRM / common / stateCountry.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
819d0d41 3 | CiviCRM version 4.5 |
6a488035 4 +--------------------------------------------------------------------+
819d0d41 5 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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{if $config->stateCountryMap}
75e14bbf
CW
27<script type="text/javascript">
28 {literal}
3cc60a06 29 CRM.$(function($) {
75e14bbf 30 function chainSelect(e) {
2f50fc92
CW
31 var info = $(this).data('chainSelect');
32 var val = info.target.val();
c7130c3e 33 var multiple = info.target.attr('multiple');
2f50fc92 34 var placeholder = $(this).val() ? "{/literal}{ts escape='js'}Loading{/ts}{literal}..." : info.placeholder;
c7130c3e 35 !multiple && info.target.html('<option value="">' + placeholder + '</option>');
75e14bbf 36 if ($(this).val()) {
258e2add 37 if (multiple) {
75e14bbf 38 var options = '';
258e2add 39 $.each($(this).val(), function(index, value) {
40 $.getJSON(info.callback, {_value: value}, function(data) {
41 $.each(data, function() {
42 if (this.value) {
43 options += '<option value="' + this.value + '">' + this.name + '</option>';
44 }
45 });
46 info.target.html(options).val(val).trigger('change');
47 });
75e14bbf 48 });
258e2add 49 }
50 else {
51 $.getJSON(info.callback, {_value: $(this).val()}, function(data) {
52 var options = '';
53 $.each(data, function() {
2b953f51 54 if (this.name) {
258e2add 55 options += '<option value="' + this.value + '">' + this.name + '</option>';
56 }
57 });
58 info.target.html(options).val(val).trigger('change');
59 });
60 }
75e14bbf
CW
61 }
62 }
6a488035 63 {/literal}
75e14bbf
CW
64 {foreach from=$config->stateCountryMap item=stateCountryMap}
65 {if $stateCountryMap.country && $stateCountryMap.state_province}
2f50fc92 66 $('select[name="{$stateCountryMap.country}"], #{$stateCountryMap.country}').data('chainSelect', {ldelim}
75e14bbf 67 callback: CRM.url('civicrm/ajax/jqState'),
2f50fc92
CW
68 target: $('select[name="{$stateCountryMap.state_province}"], #{$stateCountryMap.state_province}'),
69 placeholder: "{ts escape='js'}(choose country first){/ts}"
70 {rdelim}).on('change', chainSelect);
75e14bbf
CW
71 {/if}
72 {if $stateCountryMap.state_province && $stateCountryMap.county}
2f50fc92 73 $('select[name="{$stateCountryMap.state_province}"], #{$stateCountryMap.state_province}').data('chainSelect', {ldelim}
75e14bbf 74 callback: CRM.url('civicrm/ajax/jqCounty'),
2f50fc92
CW
75 target: $('select[name="{$stateCountryMap.county}"], #{$stateCountryMap.county}'),
76 placeholder: "{ts escape='js'}(choose state first){/ts}"
77 {rdelim}).on('change', chainSelect);
75e14bbf
CW
78 {/if}
79 {/foreach}
6a488035 80 {literal}
75e14bbf
CW
81 });
82 {/literal}
6a488035
TO
83</script>
84{/if}