Merge pull request #11964 from scardinius/core-56
[civicrm-core.git] / templates / CRM / common / navigation.js.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2018 |
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 *}// http://civicrm.org/licensing
26 {capture assign=menuMarkup}{strip}
27 <ul id="civicrm-menu">
28 <li id="crm-qsearch" class="menumain">
29 <form action="{crmURL p='civicrm/contact/search/advanced' h=0 }" name="search_block" id="id_search_block" method="post">
30 <div id="quickSearch">
31 <input type="text" class="form-text" id="sort_name_navigation" placeholder="{ts}Contacts{/ts}" name="sort_name" style="width: 6em;" />
32 <input type="text" id="sort_contact_id" style="display: none" />
33 <input type="hidden" name="hidden_location" value="1" />
34 <input type="hidden" name="qfKey" value="" />
35 <div style="height:1px; overflow:hidden;"><input type="submit" value="{ts}Go{/ts}" name="_qf_Advanced_refresh" class="crm-form-submit default" /></div>
36 </div>
37 </form>
38 <ul>
39 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" checked="checked" value="" name="quickSearchField"> {if $includeEmail}{ts}Name/Email{/ts}{else}{ts}Name{/ts}{/if}</label></li>
40 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" value="contact_id" name="quickSearchField"> {ts}Contact ID{/ts}</label></li>
41 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" value="external_identifier" name="quickSearchField"> {ts}External ID{/ts}</label></li>
42 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" value="first_name" name="quickSearchField"> {ts}First Name{/ts}</label></li>
43 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" value="last_name" name="quickSearchField"> {ts}Last Name{/ts}</label></li>
44 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="eml" value="email" name="quickSearchField"> {ts}Email{/ts}</label></li>
45 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="phe" value="phone_numeric" name="quickSearchField"> {ts}Phone{/ts}</label></li>
46 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="sts" value="street_address" name="quickSearchField"> {ts}Street Address{/ts}</label></li>
47 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="sts" value="city" name="quickSearchField"> {ts}City{/ts}</label></li>
48 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="sts" value="postal_code" name="quickSearchField"> {ts}Postal Code{/ts}</label></li>
49 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" value="job_title" name="quickSearchField"> {ts}Job Title{/ts}</label></li>
50 </ul>
51 </li>
52 {$navigation}
53 </ul>
54 {/strip}{/capture}// <script> Generated {$smarty.now|date_format:'%d %b %Y %H:%M:%S'}
55 {literal}
56 (function($) {
57 var menuMarkup = {/literal}{$menuMarkup|@json_encode};
58 {if $config->userFramework neq 'Joomla'}{literal}
59 $('body').append(menuMarkup);
60
61 $('#civicrm-menu').css({position: "fixed", top: "0px"});
62
63 //Track Scrolling
64 $(window).scroll(function () {
65 $('div.sticky-header').css({top: "23px", position: "fixed"});
66 });
67
68 if ($('#edit-shortcuts').length > 0) {
69 $('#civicrm-menu').css({'width': '97%'});
70 }
71 {/literal}{else}{* Special menu hacks for Joomla *}{literal}
72 // below div is present in older version of joomla 2.5.x
73 var elementExists = $('div#toolbar-box div.m').length;
74 if (elementExists > 0) {
75 $('div#toolbar-box div.m').html(menuMarkup);
76 }
77 else {
78 $("#crm-nav-menu-container").html(menuMarkup).css({'padding-bottom': '10px'});
79 }
80 {/literal}{/if}{literal}
81 // CRM-15493 get the current qfKey
82 $("input[name=qfKey]", "#quickSearch").val($('#civicrm-navigation-menu').data('qfkey'));
83
84 $('#civicrm-menu').ready(function() {
85 $('#root-menu-div .outerbox').css({'margin-top': '6px'});
86 $('#root-menu-div .menu-ul li').css({'padding-bottom': '2px', 'margin-top': '2px'});
87 $('img.menu-item-arrow').css({top: '4px'});
88 $("#civicrm-menu >li").each(function(i){
89 $(this).attr("tabIndex",i+2);
90 });
91
92 $('#sort_name_navigation')
93 .autocomplete({
94 source: function(request, response) {
95 //start spinning the civi logo
96 $('.crm-logo-sm').addClass('crm-i fa-spin');
97 var
98 option = $('input[name=quickSearchField]:checked'),
99 params = {
100 name: request.term,
101 field_name: option.val(),
102 table_name: option.attr("data-tablename")
103 };
104 CRM.api3('contact', 'getquick', params).done(function(result) {
105 var ret = [];
106 if (result.values.length > 0) {
107 $('#sort_name_navigation').autocomplete('widget').menu('option', 'disabled', false);
108 $.each(result.values, function(k, v) {
109 ret.push({value: v.id, label: v.data});
110 });
111 } else {
112 $('#sort_name_navigation').autocomplete('widget').menu('option', 'disabled', true);
113 var label = option.closest('label').text();
114 var msg = ts('{/literal}{ts escape='js' 1='%1'}%1 not found.{/ts}'{literal}, {1: label});
115 // Remind user they are not searching by contact name (unless they enter a number)
116 if (params.field_name && !(/[\d].*/.test(params.name))) {
117 msg += {/literal}' {ts escape='js'}Did you mean to search by Name/Email instead?{/ts}'{literal};
118 }
119 ret.push({value: '0', label: msg});
120 }
121 response(ret);
122 //stop spinning the civi logo
123 $('.crm-logo-sm').removeClass('crm-i fa-spin');
124 })
125 },
126 focus: function (event, ui) {
127 return false;
128 },
129 select: function (event, ui) {
130 if (ui.item.value > 0) {
131 document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: ui.item.value});
132 }
133 return false;
134 },
135 create: function() {
136 // Place menu in front
137 $(this).autocomplete('widget')
138 .addClass('crm-quickSearch-results')
139 .css('z-index', $('#civicrm-menu').css('z-index'));
140 }
141 })
142 .keydown(function() {
143 $.Menu.closeAll();
144 })
145 .on('focus', function() {
146 setQuickSearchValue();
147 if ($(this).attr('style').indexOf('14em') < 0) {
148 $(this).animate({width: '14em'});
149 }
150 })
151 .on('blur', function() {
152 // Shrink if no input and menu is not open
153 if (!$(this).val().length && $(this).attr('style').indexOf('6em') < 0 && !$('.crm-quickSearchField:visible', '#root-menu-div').length) {
154 $(this).animate({width: '6em'});
155 }
156 });
157 $('.crm-hidemenu').click(function(e) {
158 $('#civicrm-menu').slideUp();
159 if ($('#crm-notification-container').length) {
160 var alert = CRM.alert({/literal}'<a href="#" id="crm-restore-menu" style="text-align: center; margin-top: -8px;">{ts escape='js'}Restore CiviCRM Menu{/ts}</a>'{literal}, '', 'none', {expires: 10000});
161 $('#crm-restore-menu')
162 .button({icons: {primary: 'fa-undo'}})
163 .click(function(e) {
164 e.preventDefault();
165 alert.close();
166 $('#civicrm-menu').slideDown();
167 })
168 .parent().css('text-align', 'center').find('.ui-button-text').css({'padding-top': '4px', 'padding-bottom': '4px'})
169 ;
170 }
171 e.preventDefault();
172 });
173 function setQuickSearchValue() {
174 var $selection = $('.crm-quickSearchField input:checked'),
175 label = $selection.parent().text(),
176 value = $selection.val();
177 // These fields are not supported by advanced search
178 if (!value || value === 'first_name' || value === 'last_name') {
179 value = 'sort_name';
180 }
181 $('#sort_name_navigation').attr({name: value, placeholder: label});
182 }
183 $('.crm-quickSearchField').click(function() {
184 setQuickSearchValue();
185 $.Menu.closeAll();
186 $('#sort_name_navigation').focus().autocomplete("search");
187 });
188 // Set & retrieve default value
189 if (window.localStorage) {
190 $('.crm-quickSearchField').click(function() {
191 localStorage.quickSearchField = $('input', this).val();
192 });
193 if (localStorage.quickSearchField) {
194 $('.crm-quickSearchField input[value=' + localStorage.quickSearchField + ']').prop('checked', true);
195 }
196 }
197 // redirect to view page if there is only one contact
198 $('#id_search_block').on('submit', function() {
199 var $menu = $('#sort_name_navigation').autocomplete('widget');
200 if ($('li.ui-menu-item', $menu).length === 1) {
201 var cid = $('li.ui-menu-item', $menu).data('ui-autocomplete-item').value;
202 if (cid > 0) {
203 document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: cid});
204 return false;
205 }
206 }
207 });
208 // Close menu after selecting an item
209 $('#root-menu-div').on('click', 'a', $.Menu.closeAll);
210 });
211 $('#civicrm-menu').menuBar({arrowSrc: CRM.config.resourceBase + 'packages/jquery/css/images/arrow.png'});
212 $(window).on("beforeunload", function() {
213 $('.crm-logo-sm', '#civicrm-menu').addClass('crm-i fa-spin');
214 });
215 })(CRM.$);{/literal}