{*
+--------------------------------------------------------------------+
- | CiviCRM version 4.6 |
+ | CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015 |
+ | Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
};
CRM.api3('contact', 'getquick', params).done(function(result) {
var ret = [];
- if (result.values) {
+ if (result.values.length > 0) {
+ $('#sort_name_navigation').autocomplete('widget').menu('option', 'disabled', false);
$.each(result.values, function(k, v) {
ret.push({value: v.id, label: v.data});
- })
+ });
+ } else {
+ $('#sort_name_navigation').autocomplete('widget').menu('option', 'disabled', true);
+ ret.push({value: '0', label: {/literal}'{ts escape='js'}None found.{/ts}'{literal}});
}
response(ret);
})
return false;
},
select: function (event, ui) {
- document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: ui.item.value});
+ if (ui.item.value > 0) {
+ document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: ui.item.value});
+ }
return false;
},
create: function() {
// Place menu in front
- $(this).autocomplete('widget').css('z-index', $('#civicrm-menu').css('z-index'));
+ $(this).autocomplete('widget')
+ .addClass('crm-quickSearch-results')
+ .css('z-index', $('#civicrm-menu').css('z-index'));
}
})
.keydown(function() {
$.Menu.closeAll();
})
.on('focus', function() {
+ setQuickSearchValue();
if ($(this).attr('style').indexOf('14em') < 0) {
$(this).animate({width: '14em'});
}
if ($('#crm-notification-container').length) {
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});
$('#crm-restore-menu')
- .button({icons: {primary: 'ui-icon-arrowreturnthick-1-w'}})
+ .button({icons: {primary: 'fa-undo'}})
.click(function(e) {
e.preventDefault();
alert.close();
}
e.preventDefault();
});
- $('.crm-quickSearchField').click(function() {
- var label = $(this).text();
- var value = $('input', this).val();
+ function setQuickSearchValue() {
+ var $selection = $('.crm-quickSearchField input:checked'),
+ label = $selection.parent().text(),
+ value = $selection.val();
// These fields are not supported by advanced search
if (value === 'first_name' || value === 'last_name') {
value = 'sort_name';
}
- $('#sort_name_navigation').attr({name: value, placeholder: label}).focus();
+ $('#sort_name_navigation').attr({name: value, placeholder: label});
+ }
+ $('.crm-quickSearchField').click(function() {
+ setQuickSearchValue();
+ $('#sort_name_navigation').focus();
});
+ // Set & retrieve default value
+ if (window.localStorage) {
+ $('.crm-quickSearchField').click(function() {
+ localStorage.quickSearchField = $('input', this).val();
+ });
+ if (localStorage.quickSearchField) {
+ $('.crm-quickSearchField input[value=' + localStorage.quickSearchField + ']').prop('checked', true);
+ }
+ }
// redirect to view page if there is only one contact
$('#id_search_block').on('submit', function() {
var $menu = $('#sort_name_navigation').autocomplete('widget');
if ($('li.ui-menu-item', $menu).length === 1) {
var cid = $('li.ui-menu-item', $menu).data('ui-autocomplete-item').value;
- document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: cid});
- return false;
+ if (cid > 0) {
+ document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: cid});
+ return false;
+ }
}
});
// Close menu after selecting an item