Merge pull request #22449 from mattwire/phpnotices
[civicrm-core.git] / templates / CRM / common / navigation.js.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
1188c7a8 3 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 4 | |
1188c7a8
TO
5 | This work is published under the GNU AGPLv3 license with some |
6 | permitted exceptions and without any warranty. For full license |
7 | and copyright information, see https://civicrm.org/licensing |
6a488035 8 +--------------------------------------------------------------------+
e203a505 9*}// http://civicrm.org/licensing
3a8e94ac 10{capture assign=menuMarkup}{strip}
76fd69ba 11 <ul id="civicrm-menu">
15a59011 12 <li id="crm-qsearch" class="menumain">
3a8e94ac
CW
13 <form action="{crmURL p='civicrm/contact/search/advanced' h=0 }" name="search_block" id="id_search_block" method="post">
14 <div id="quickSearch">
567b9207 15 <input type="text" class="form-text" id="sort_name_navigation" placeholder="{ts}Contacts{/ts}" name="sort_name" style="width: 6em;" />
3a8e94ac
CW
16 <input type="text" id="sort_contact_id" style="display: none" />
17 <input type="hidden" name="hidden_location" value="1" />
4235341b 18 <input type="hidden" name="hidden_custom" value="1" />
c3bcf6ba 19 <input type="hidden" name="qfKey" value="" />
cbd83dde 20 <div style="height:1px; overflow:hidden;"><button type="submit" name="_qf_Advanced_refresh" class="crm-button crm-form-submit default">{ts}Go{/ts}</button></div>
3a8e94ac
CW
21 </div>
22 </form>
23 <ul>
4235341b
CW
24 {foreach from=$quicksearchOptions item="optionLabel" key="optionKey"}
25 <li><label class="crm-quickSearchField"><input type="radio" {if $optionKey == 'sort_name'}checked="checked"{/if} value="{$optionKey}" name="quickSearchField"> {$optionLabel}</label></li>
26 {/foreach}
3a8e94ac
CW
27 </ul>
28 </li>
3a8e94ac
CW
29 {$navigation}
30 </ul>
51b81901 31{/strip}{/capture}// <script> Generated {$smarty.now|date_format:'%d %b %Y %H:%M:%S'}
e203a505
CW
32{literal}
33(function($) {
7eed4524 34 var menuMarkup = {/literal}{$menuMarkup|@json_encode}{literal};
54aca360 35
e203a505 36 //Track Scrolling
7eed4524 37 if ($('div.sticky-header').length) {
38 $(window).scroll(function () {
39 $('div.sticky-header').css({top: $('#civicrm-menu').height() + "px", position: "fixed"});
40 });
e203a505 41 }
7eed4524 42
43 if ($('div#toolbar-box div.m').length) {
e203a505
CW
44 $('div#toolbar-box div.m').html(menuMarkup);
45 }
7eed4524 46 else if ($("#crm-nav-menu-container").length) {
e203a505
CW
47 $("#crm-nav-menu-container").html(menuMarkup).css({'padding-bottom': '10px'});
48 }
7eed4524 49 else {
50 $('body').append(menuMarkup);
51 }
52
c3bcf6ba
CW
53 // CRM-15493 get the current qfKey
54 $("input[name=qfKey]", "#quickSearch").val($('#civicrm-navigation-menu').data('qfkey'));
55
e203a505
CW
56$('#civicrm-menu').ready(function() {
57 $('#root-menu-div .outerbox').css({'margin-top': '6px'});
58 $('#root-menu-div .menu-ul li').css({'padding-bottom': '2px', 'margin-top': '2px'});
e203a505
CW
59 $("#civicrm-menu >li").each(function(i){
60 $(this).attr("tabIndex",i+2);
61 });
6a488035 62
7cb72342 63 $('#sort_name_navigation')
49e5c704 64 .autocomplete({
7cb72342 65 source: function(request, response) {
f0908f2a 66 //start spinning the civi logo
96164880 67 $('.crm-logo-sm').addClass('crm-i fa-spin');
7cb72342
CW
68 var
69 option = $('input[name=quickSearchField]:checked'),
70 params = {
71 name: request.term,
4235341b 72 field_name: option.val()
7cb72342
CW
73 };
74 CRM.api3('contact', 'getquick', params).done(function(result) {
75 var ret = [];
106bb5da 76 if (result.values.length > 0) {
15220e8f 77 $('#sort_name_navigation').autocomplete('widget').menu('option', 'disabled', false);
7cb72342
CW
78 $.each(result.values, function(k, v) {
79 ret.push({value: v.id, label: v.data});
106bb5da
EE
80 });
81 } else {
15220e8f 82 $('#sort_name_navigation').autocomplete('widget').menu('option', 'disabled', true);
04c17d0c 83 var label = option.closest('label').text();
5a40df5c 84 var msg = ts('{/literal}{ts escape='js' 1='%1'}%1 not found.{/ts}'{literal}, {1: label});
04c17d0c
CW
85 // Remind user they are not searching by contact name (unless they enter a number)
86 if (params.field_name && !(/[\d].*/.test(params.name))) {
87 msg += {/literal}' {ts escape='js'}Did you mean to search by Name/Email instead?{/ts}'{literal};
88 }
89 ret.push({value: '0', label: msg});
7cb72342
CW
90 }
91 response(ret);
f0908f2a 92 //stop spinning the civi logo
96164880 93 $('.crm-logo-sm').removeClass('crm-i fa-spin');
7cb72342 94 })
e203a505 95 },
567b9207 96 focus: function (event, ui) {
5e0a1798 97 return false;
31037a42 98 },
7cb72342 99 select: function (event, ui) {
106bb5da
EE
100 if (ui.item.value > 0) {
101 document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: ui.item.value});
102 }
e203a505 103 return false;
3b4e4823
CW
104 },
105 create: function() {
106 // Place menu in front
15220e8f
CW
107 $(this).autocomplete('widget')
108 .addClass('crm-quickSearch-results')
109 .css('z-index', $('#civicrm-menu').css('z-index'));
7cb72342
CW
110 }
111 })
112 .keydown(function() {
113 $.Menu.closeAll();
567b9207
CW
114 })
115 .on('focus', function() {
62bed82d 116 setQuickSearchValue();
567b9207
CW
117 if ($(this).attr('style').indexOf('14em') < 0) {
118 $(this).animate({width: '14em'});
119 }
120 })
121 .on('blur', function() {
122 // Shrink if no input and menu is not open
123 if (!$(this).val().length && $(this).attr('style').indexOf('6em') < 0 && !$('.crm-quickSearchField:visible', '#root-menu-div').length) {
124 $(this).animate({width: '6em'});
125 }
7cb72342 126 });
877e5889 127 $('.crm-hidemenu').click(function(e) {
fb9daa75 128 $('#civicrm-menu').slideUp();
3c7172b9 129 if ($('#crm-notification-container').length) {
877e5889
CW
130 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});
131 $('#crm-restore-menu')
f4b168fd 132 .button({icons: {primary: 'fa-undo'}})
877e5889
CW
133 .click(function(e) {
134 e.preventDefault();
135 alert.close();
136 $('#civicrm-menu').slideDown();
137 })
138 .parent().css('text-align', 'center').find('.ui-button-text').css({'padding-top': '4px', 'padding-bottom': '4px'})
139 ;
3c7172b9 140 }
877e5889 141 e.preventDefault();
fb9daa75 142 });
62bed82d
CW
143 function setQuickSearchValue() {
144 var $selection = $('.crm-quickSearchField input:checked'),
145 label = $selection.parent().text(),
146 value = $selection.val();
62bed82d
CW
147 $('#sort_name_navigation').attr({name: value, placeholder: label});
148 }
149 $('.crm-quickSearchField').click(function() {
150 setQuickSearchValue();
dfe8e5d0 151 $.Menu.closeAll();
568164f4 152 $('#sort_name_navigation').focus().autocomplete("search");
e203a505 153 });
62bed82d
CW
154 // Set & retrieve default value
155 if (window.localStorage) {
156 $('.crm-quickSearchField').click(function() {
157 localStorage.quickSearchField = $('input', this).val();
158 });
159 if (localStorage.quickSearchField) {
160 $('.crm-quickSearchField input[value=' + localStorage.quickSearchField + ']').prop('checked', true);
161 }
162 }
03c752c4 163 // redirect to view page if there is only one contact
e203a505 164 $('#id_search_block').on('submit', function() {
49e5c704 165 var $menu = $('#sort_name_navigation').autocomplete('widget');
03c752c4
CW
166 if ($('li.ui-menu-item', $menu).length === 1) {
167 var cid = $('li.ui-menu-item', $menu).data('ui-autocomplete-item').value;
1a9a2abf
SL
168 if (cid > 0) {
169 document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: cid});
170 return false;
171 }
3a8e94ac 172 }
e203a505 173 });
75f04e33
CW
174 // Close menu after selecting an item
175 $('#root-menu-div').on('click', 'a', $.Menu.closeAll);
e203a505 176});
0e24eaa0 177$('#civicrm-menu').menuBar({arrowClass: 'crm-i fa-caret-right'});
c7e39a79 178$('#civicrm-menu').trigger('crmLoad');
9a39e3b7 179$(window).on("beforeunload", function() {
96164880 180 $('.crm-logo-sm', '#civicrm-menu').addClass('crm-i fa-spin');
9a39e3b7 181});
3cc60a06 182})(CRM.$);{/literal}