| 1 | {* |
| 2 | +--------------------------------------------------------------------+ |
| 3 | | Copyright CiviCRM LLC. All rights reserved. | |
| 4 | | | |
| 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 | |
| 8 | +--------------------------------------------------------------------+ |
| 9 | *}// http://civicrm.org/licensing |
| 10 | {capture assign=menuMarkup}{strip} |
| 11 | <ul id="civicrm-menu"> |
| 12 | <li id="crm-qsearch" class="menumain"> |
| 13 | <form action="{crmURL p='civicrm/contact/search/advanced' h=0 }" name="search_block" id="id_search_block" method="post"> |
| 14 | <div id="quickSearch"> |
| 15 | <input type="text" class="form-text" id="sort_name_navigation" placeholder="{ts}Contacts{/ts}" name="sort_name" style="width: 6em;" /> |
| 16 | <input type="text" id="sort_contact_id" style="display: none" /> |
| 17 | <input type="hidden" name="hidden_location" value="1" /> |
| 18 | <input type="hidden" name="hidden_custom" value="1" /> |
| 19 | <input type="hidden" name="qfKey" value="" /> |
| 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> |
| 21 | </div> |
| 22 | </form> |
| 23 | <ul> |
| 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} |
| 27 | </ul> |
| 28 | </li> |
| 29 | {$navigation} |
| 30 | </ul> |
| 31 | {/strip}{/capture}// <script> Generated {$smarty.now|date_format:'%d %b %Y %H:%M:%S'} |
| 32 | {literal} |
| 33 | (function($) { |
| 34 | var menuMarkup = {/literal}{$menuMarkup|@json_encode}{literal}; |
| 35 | |
| 36 | //Track Scrolling |
| 37 | if ($('div.sticky-header').length) { |
| 38 | $(window).scroll(function () { |
| 39 | $('div.sticky-header').css({top: $('#civicrm-menu').height() + "px", position: "fixed"}); |
| 40 | }); |
| 41 | } |
| 42 | |
| 43 | if ($('div#toolbar-box div.m').length) { |
| 44 | $('div#toolbar-box div.m').html(menuMarkup); |
| 45 | } |
| 46 | else if ($("#crm-nav-menu-container").length) { |
| 47 | $("#crm-nav-menu-container").html(menuMarkup).css({'padding-bottom': '10px'}); |
| 48 | } |
| 49 | else { |
| 50 | $('body').append(menuMarkup); |
| 51 | } |
| 52 | |
| 53 | // CRM-15493 get the current qfKey |
| 54 | $("input[name=qfKey]", "#quickSearch").val($('#civicrm-navigation-menu').data('qfkey')); |
| 55 | |
| 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'}); |
| 59 | $("#civicrm-menu >li").each(function(i){ |
| 60 | $(this).attr("tabIndex",i+2); |
| 61 | }); |
| 62 | |
| 63 | $('#sort_name_navigation') |
| 64 | .autocomplete({ |
| 65 | source: function(request, response) { |
| 66 | //start spinning the civi logo |
| 67 | $('.crm-logo-sm').addClass('crm-i fa-spin'); |
| 68 | var |
| 69 | option = $('input[name=quickSearchField]:checked'), |
| 70 | params = { |
| 71 | name: request.term, |
| 72 | field_name: option.val() |
| 73 | }; |
| 74 | CRM.api3('contact', 'getquick', params).done(function(result) { |
| 75 | var ret = []; |
| 76 | if (result.values.length > 0) { |
| 77 | $('#sort_name_navigation').autocomplete('widget').menu('option', 'disabled', false); |
| 78 | $.each(result.values, function(k, v) { |
| 79 | ret.push({value: v.id, label: v.data}); |
| 80 | }); |
| 81 | } else { |
| 82 | $('#sort_name_navigation').autocomplete('widget').menu('option', 'disabled', true); |
| 83 | var label = option.closest('label').text(); |
| 84 | var msg = ts('{/literal}{ts escape='js' 1='%1'}%1 not found.{/ts}'{literal}, {1: label}); |
| 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}); |
| 90 | } |
| 91 | response(ret); |
| 92 | //stop spinning the civi logo |
| 93 | $('.crm-logo-sm').removeClass('crm-i fa-spin'); |
| 94 | }) |
| 95 | }, |
| 96 | focus: function (event, ui) { |
| 97 | return false; |
| 98 | }, |
| 99 | select: function (event, ui) { |
| 100 | if (ui.item.value > 0) { |
| 101 | document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: ui.item.value}); |
| 102 | } |
| 103 | return false; |
| 104 | }, |
| 105 | create: function() { |
| 106 | // Place menu in front |
| 107 | $(this).autocomplete('widget') |
| 108 | .addClass('crm-quickSearch-results') |
| 109 | .css('z-index', $('#civicrm-menu').css('z-index')); |
| 110 | } |
| 111 | }) |
| 112 | .keydown(function() { |
| 113 | $.Menu.closeAll(); |
| 114 | }) |
| 115 | .on('focus', function() { |
| 116 | setQuickSearchValue(); |
| 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 | } |
| 126 | }); |
| 127 | $('.crm-hidemenu').click(function(e) { |
| 128 | $('#civicrm-menu').slideUp(); |
| 129 | if ($('#crm-notification-container').length) { |
| 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') |
| 132 | .button({icons: {primary: 'fa-undo'}}) |
| 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 | ; |
| 140 | } |
| 141 | e.preventDefault(); |
| 142 | }); |
| 143 | function setQuickSearchValue() { |
| 144 | var $selection = $('.crm-quickSearchField input:checked'), |
| 145 | label = $selection.parent().text(), |
| 146 | value = $selection.val(); |
| 147 | $('#sort_name_navigation').attr({name: value, placeholder: label}); |
| 148 | } |
| 149 | $('.crm-quickSearchField').click(function() { |
| 150 | setQuickSearchValue(); |
| 151 | $.Menu.closeAll(); |
| 152 | $('#sort_name_navigation').focus().autocomplete("search"); |
| 153 | }); |
| 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 | } |
| 163 | // redirect to view page if there is only one contact |
| 164 | $('#id_search_block').on('submit', function() { |
| 165 | var $menu = $('#sort_name_navigation').autocomplete('widget'); |
| 166 | if ($('li.ui-menu-item', $menu).length === 1) { |
| 167 | var cid = $('li.ui-menu-item', $menu).data('ui-autocomplete-item').value; |
| 168 | if (cid > 0) { |
| 169 | document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: cid}); |
| 170 | return false; |
| 171 | } |
| 172 | } |
| 173 | }); |
| 174 | // Close menu after selecting an item |
| 175 | $('#root-menu-div').on('click', 'a', $.Menu.closeAll); |
| 176 | }); |
| 177 | $('#civicrm-menu').menuBar({arrowClass: 'crm-i fa-caret-right'}); |
| 178 | $('#civicrm-menu').trigger('crmLoad'); |
| 179 | $(window).on("beforeunload", function() { |
| 180 | $('.crm-logo-sm', '#civicrm-menu').addClass('crm-i fa-spin'); |
| 181 | }); |
| 182 | })(CRM.$);{/literal} |