Merge pull request #6964 from colemanw/CRM-17176
[civicrm-core.git] / templates / CRM / Event / Form / ManageEvent / Location.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.7 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2015 |
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 template used to build location block *}
27 {if !$addBlock}
28 <div id="help">
29 {ts}Use this form to configure the location and optional contact information for the event. This information will be displayed on the Event Information page. It will also be included in online registration pages and confirmation emails if these features are enabled.{/ts}
30 </div>
31 {/if}
32
33 {if $addBlock}
34 {include file="CRM/Contact/Form/Edit/$blockName.tpl"}
35 {else}
36 <div class="crm-block crm-form-block crm-event-manage-location-form-block">
37 <div class="crm-submit-buttons">
38 {include file="CRM/common/formButtons.tpl" location="top"}
39 </div>
40 {if $locEvents}
41 <table class="form-layout-compressed">
42 <tr id="optionType" class="crm-event-manage-location-form-block-location_option">
43 <td class="labels">
44 {$form.location_option.label}
45 </td>
46 {foreach from=$form.location_option key=key item =item}
47 {if $key|is_numeric}
48 <td class="value"><strong>{$item.html}</strong></td>
49 {/if}
50 {/foreach}
51 </tr>
52 <tr id="existingLoc" class="crm-event-manage-location-form-block-loc_event_id">
53 <td class="labels">
54 {$form.loc_event_id.label}
55 </td>
56 <td class="value" colspan="2">
57 {$form.loc_event_id.html|crmAddClass:huge}
58 </td>
59 </tr>
60 <tr>
61 <td id="locUsedMsg" colspan="3">
62 </td>
63 </tr>
64
65 </table>
66 {/if}
67
68
69
70 <div id="newLocation">
71 <h3>Address</h3>
72 {* Display the address block *}
73 {include file="CRM/Contact/Form/Edit/Address.tpl"}
74 <table class="form-layout-compressed">
75 {* Display the email block(s) *}
76 {include file="CRM/Contact/Form/Edit/Email.tpl"}
77
78 {* Display the phone block(s) *}
79 {include file="CRM/Contact/Form/Edit/Phone.tpl"}
80 </table>
81 <table class="form-layout-compressed">
82 <tr class="crm-event-is_show_location">
83 <td colspan="2">{$form.is_show_location.label}</td>
84 <td colspan="2">
85 {$form.is_show_location.html}<br />
86 <span class="description">{ts}Uncheck this box if you want to HIDE the event Address on Event Information and Registration pages as well as on email confirmations.{/ts}
87 </td>
88 </tr>
89 </table>
90 <div class="crm-submit-buttons">
91 {include file="CRM/common/formButtons.tpl" location="bottom"}
92 </div>
93 </div>
94
95 {* Include Javascript to hide and display the appropriate blocks as directed by the php code *}
96 {*include file="CRM/common/showHide.tpl"*}
97 {if $locEvents}
98 {* include common additional blocks tpl *}
99 {include file="CRM/common/additionalBlocks.tpl"}
100
101 <script type="text/javascript">
102 {literal}
103 CRM.$(function($) {
104 //FIX ME: by default load 2 blocks and hide add and delete links
105 //we should make additional block function more flexible to set max block limit
106 buildBlocks('Email');
107 buildBlocks('Phone');
108
109 var $form = $('form.{/literal}{$form.formClass}{literal}'),
110 locBlockId = {/literal}"{$form.loc_event_id.value.0}"{literal};
111
112 displayMessage({/literal}{$locUsed}{literal});
113
114 // build blocks only if it is not built
115 function buildBlocks(element) {
116 if (!$('[id='+ element +'_Block_2]').length) {
117 buildAdditionalBlocks(element, 'CRM_Event_Form_ManageEvent_Location');
118 }
119 }
120
121 hideAddDeleteLinks('Email');
122 hideAddDeleteLinks('Phone');
123 function hideAddDeleteLinks(element) {
124 $('#add'+ element, $form).hide();
125 $('[id='+ element +'_Block_2] a:last', $form).hide();
126 }
127
128 $('#loc_event_id', $form).change(function() {
129 $.ajax({
130 url: CRM.url('civicrm/ajax/locBlock', 'reset=1'),
131 data: {'lbid': $(this).val()},
132 dataType: 'json',
133 success: function(data) {
134 var selectLocBlockId = $('#loc_event_id').val();
135 // Only change state when options are loaded
136 if (data.address_1_state_province_id) {
137 var defaultState = data.address_1_state_province_id;
138 $('#address_1_state_province_id', $form).one('crmOptionsUpdated', function() {
139 $(this).val(defaultState).change();
140 });
141 delete data.address_1_state_province_id;
142 }
143 for(i in data) {
144 if ( i == 'count_loc_used' ) {
145 if ( ((selectLocBlockId == locBlockId) && data.count_loc_used > 1) ||
146 ((selectLocBlockId != locBlockId) && data.count_loc_used > 0) ) {
147 displayMessage(data.count_loc_used);
148 } else {
149 displayMessage(0);
150 }
151 } else {
152 $('#'+i, $form).val(data[i]).change();
153 }
154 }
155 }
156 });
157 return false;
158 });
159
160 function showLocFields(clear) {
161 var createNew = document.getElementsByName("location_option")[0].checked;
162 if (createNew) {
163 $('#existingLoc', $form).hide();
164 //clear all location fields values.
165 if (clear !== false) {
166 $(":input[id *= 'address_1_'], :input[id *= 'email_1_'], :input[id *= 'phone_1_']", $form).val("").change();
167 {/literal}{if $config->defaultContactCountry}
168 {if $config->defaultContactStateProvince}
169 // Set default state once options are loaded
170 var defaultState = {$config->defaultContactStateProvince}
171 {literal}
172 $('#address_1_state_province_id', $form).one('crmOptionsUpdated', function() {
173 $(this).val(defaultState).change();
174 });
175 {/literal}
176 {/if}
177 // Set default country
178 $('#address_1_country_id', $form).val({$config->defaultContactCountry}).change();
179 {/if}{literal}
180 }
181 displayMessage(0);
182 } else {
183 $('#existingLoc', $form).show();
184 if (clear !== false) {
185 $('#loc_event_id', $form).change();
186 }
187 }
188 }
189
190 $('input[name=location_option]').click(showLocFields);
191 showLocFields(false);
192
193 function displayMessage(count) {
194 if (count) {
195 var msg = {/literal}'{ts escape="js" 1="%1"}This location is used by %1 other events. Modifying location information will change values for all events.{/ts}'{literal};
196 $('#locUsedMsg', $form).text(ts(msg, {1: count})).addClass('status');
197 } else {
198 $('#locUsedMsg', $form).text(' ').removeClass('status');
199 }
200 }
201 });
202 {/literal}
203 </script>
204 {/if}
205
206 {/if} {* add block if end*}