CRM-12337 - Encapsulate menu within a script
[civicrm-core.git] / templates / CRM / common / Navigation.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
232624b1 3 | CiviCRM version 4.4 |
6a488035
TO
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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*}
76fd69ba
CW
26{capture assign=menuMarkup}
27 <ul id="civicrm-menu">
e0f7ceee 28 {if call_user_func(array('CRM_Core_Permission','giveMeAllACLs'))}
6a488035 29 <li id="crm-qsearch" class="menumain crm-link-home">
e0f7ceee 30 <form action="{crmURL p='civicrm/contact/search/advanced' h=0 }" name="search_block" id="id_search_block" method="post">
6a488035
TO
31 <div id="quickSearch">
32 <input type="text" class="form-text" id="sort_name_navigation" placeholder="{ts}Find Contacts{/ts}" name="sort_name" style="width: 12em;" />
81aa6678
CW
33 <input type="text" id="sort_contact_id" style="display: none" />
34 <input type="hidden" name="hidden_location" value="1" />
6a488035 35 <input type="hidden" name="qfKey" value="{crmKey name='CRM_Contact_Controller_Search' addSequence=1}" />
81aa6678 36 <div style="height:1px; overflow:hidden;"><input type="submit" value="{ts}Go{/ts}" name="_qf_Advanced_refresh" class="form-submit default" /></div>
6a488035
TO
37 </div>
38 </form>
39 <ul>
40 <li><label class="crm-quickSearchField"><input type="radio" checked="" data-tablename="cc" checked="checked" value="" name="quickSearchField">{ts}Name/Email{/ts}</label></li>
c8ef633b 41 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" value="contact_id" name="quickSearchField">{ts}CiviCRM ID{/ts}</label></li>
6a488035
TO
42 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" value="external_identifier" name="quickSearchField">{ts}External ID{/ts}</label></li>
43 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" value="first_name" name="quickSearchField">{ts}First Name{/ts}</label></li>
44 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" value="last_name" name="quickSearchField">{ts}Last Name{/ts}</label></li>
45 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="eml" value="email" name="quickSearchField">{ts}Email{/ts}</label></li>
46 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="phe" value="phone_numeric" name="quickSearchField">{ts}Phone{/ts}</label></li>
47 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="sts" value="street_address" name="quickSearchField">{ts}Street Address{/ts}</label></li>
48 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="sts" value="city" name="quickSearchField">{ts}City{/ts}</label></li>
49 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="sts" value="postal_code" name="quickSearchField">{ts}Postal Code{/ts}</label></li>
50 <li><label class="crm-quickSearchField"><input type="radio" data-tablename="cc" value="job_title" name="quickSearchField">{ts}Job Title{/ts}</label></li>
51 </ul>
52 </li>
e0f7ceee
CW
53 {/if}
54 {$navigation}
76fd69ba 55 </ul>{/capture}
6a488035
TO
56{literal}
57<script type="text/javascript">
76fd69ba
CW
58(function($) {
59 var menuMarkup = {/literal}{$menuMarkup|@json_encode}{literal};
81aa6678 60cj(function( ) {
6a488035
TO
61 cj("#civicrm-menu >li").each(function(i){
62 cj(this).attr("tabIndex",i+2);
63 });
6a488035
TO
64
65 var contactUrl = {/literal}"{crmURL p='civicrm/ajax/rest' q='className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=navigation' h=0 }"{literal};
66
67 cj( '#sort_name_navigation' ).autocomplete( contactUrl, {
68 width: 200,
69 selectFirst: false,
70 minChars: 1,
71 matchContains: true,
72 delay: 400,
ef3309b6 73 max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal},
6a488035 74 extraParams:{
6a488035
TO
75 fieldName:function () {
76 return cj('input[name=quickSearchField]:checked').val();
77 },
78 tableName:function () {
79 return cj('input[name=quickSearchField]:checked').attr("data-tablename");
80 }
81 }
82 }).result(function(event, data, formatted) {
81aa6678 83 document.location = CRM.url('civicrm/contact/view', {reset: 1, cid: data[1]});
6a488035
TO
84 return false;
85 });
86 cj('#sort_name_navigation').keydown(function() {
87 cj.Menu.closeAll();
88 });
89 cj('.crm-quickSearchField').click(function() {
90 var label = cj(this).text();
81aa6678
CW
91 var value = cj('input', this).val();
92 // These fields are not supported by advanced search
93 if (value === 'first_name' || value === 'last_name') {
94 value = 'sort_name';
95 }
96 cj('#sort_name_navigation').attr({name: value, placeholder: label}).flushCache().focus();
6a488035 97 });
e0f7ceee
CW
98 // check if there is only one contact and redirect to view page
99 cj('#id_search_block').on('submit', function() {
100 var contactId, sortValue = cj('#sort_name_navigation').val();
101 if (sortValue && cj('#sort_name_navigation').attr('name') == 'sort_name') {
102 {/literal}{*
103 // FIXME: async:false == bad,
104 // we should just check the autocomplete results instead of firing a new request
105 // when we fix this, the civicrm/ajax/contact server-side callback can be removed as well
106 // also that would fix the fact that this only works with sort_name search
107 // (and we can remove the above conditional)
108 *}{literal}
109 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/contact' h=0 q='name='}"{literal} + sortValue;
110 contactId = cj.ajax({
111 url: dataUrl,
112 async: false
113 }).responseText;
6a488035 114 }
e0f7ceee
CW
115 if (contactId && !isNaN(parseInt(contactId))) {
116 var url = {/literal}"{crmURL p='civicrm/contact/view' h=0 q='reset=1&cid='}"{literal} + contactId;
117 this.action = url;
6a488035 118 }
e0f7ceee
CW
119 });
120});
121
f83b237d 122{/literal}{if $config->userFramework neq 'Joomla' and $config->userFrameworkFrontend ne 1}{literal}
76fd69ba 123 cj('body').prepend(menuMarkup);
6a488035
TO
124
125 //Track Scrolling
126 cj(window).scroll( function () {
127 var scroll = document.documentElement.scrollTop || document.body.scrollTop;
128 cj('#civicrm-menu').css({top: "scroll", position: "fixed", top: "0px"});
129 cj('div.sticky-header').css({ 'top' : "23px", position: "fixed" });
130 });
131
132 if ( cj('#edit-shortcuts').length > 0 ) {
133 cj('#civicrm-menu').css({ 'width': '97%' });
134 }
4ce6105a 135{/literal}{elseif $config->userFrameworkFrontend ne 1}{* Special menu hacks for Joomla *}{literal}
53ef0226 136 // below div is present in older version of joomla 2.5.x
137 var elementExists = cj('div#toolbar-box div.m').length;
138 if ( elementExists > 0 ) {
76fd69ba 139 cj('div#toolbar-box div.m').html(menuMarkup);
53ef0226 140 }
141 else {
76fd69ba 142 // Fixme
53ef0226 143 cj("#menu-container").show().css({'padding-bottom': '10px'});
144 }
c8ef633b 145
735c0c34
CW
146 cj('#civicrm-menu').ready(function() {
147 cj('#root-menu-div .outerbox').css({ 'margin-top': '6px'});
148 cj('#root-menu-div .outerbox').first().css({ 'margin-top': '20px'});
149 cj('#root-menu-div .menu-ul li').css({ 'padding-bottom' : '2px', 'margin-top' : '2px' });
150 cj('img.menu-item-arrow').css({ 'top' : '4px' });
151 });
53ef0226 152 {/literal}{/if}{literal}
6a488035 153 cj('#civicrm-menu').menu( {arrowSrc: CRM.config.resourceBase + 'packages/jquery/css/images/arrow.png'} );
76fd69ba 154})(cj);
6a488035
TO
155</script>
156{/literal}