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