2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
39 {if !isset($config.enable_autocomplete) || $config.enable_autocomplete==false}
40 <select name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
41 id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
42 title='{{$vardef.help}}' {{if !empty($tabindex)}} tabindex="{{$tabindex}}" {{/if}}
43 {{if !empty($displayParams.accesskey)}} accesskey='{{$displayParams.accesskey}}' {{/if}} {{$displayParams.field}}
44 {{if isset($displayParams.javascript)}}{{$displayParams.javascript}}{{/if}}>
46 {if isset({{sugarvar key='value' string=true}}) && {{sugarvar key='value' string=true}} != ''}
47 {html_options options={{sugarvar key='options' string=true}} selected={{sugarvar key='value' string=true}}}
49 {html_options options={{sugarvar key='options' string=true}} selected={{sugarvar key='default' string=true}}}
53 {assign var="field_options" value={{sugarvar key='options' string="true"}} }
54 {capture name="field_val"}{{sugarvar key='value'}}{/capture}
55 {assign var="field_val" value=$smarty.capture.field_val}
56 {capture name="ac_key"}{{sugarvar key='name'}}{/capture}
57 {assign var="ac_key" value=$smarty.capture.ac_key}
59 {{if empty($vardef.autocomplete_ajax)}}
60 <select style='display:none' name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
61 id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
62 title='{{$vardef.help}}' {{if !empty($tabindex)}} tabindex="{{$tabindex}}" {{/if}}
63 {{if !empty($displayParams.accesskey)}} accesskey='{{$displayParams.accesskey}}' {{/if}} {{$displayParams.field}}
64 {{if isset($displayParams.javascript)}}{{$displayParams.javascript}}{{/if}}>
66 {if isset({{sugarvar key='value' string=true}}) && {{sugarvar key='value' string=true}} != ''}
67 {html_options options={{sugarvar key='options' string=true}} selected={{sugarvar key='value' string=true}}}
69 {html_options options={{sugarvar key='options' string=true}} selected={{sugarvar key='default' string=true}}}
74 id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
75 name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
76 value="{{sugarvar key='value'}}">
80 id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input"
81 name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input"
83 value="{$field_val|lookup:$field_options}"
84 type="text" style="vertical-align: top;">
87 <span class="id-ff multiple">
88 <button type="button"><img src="{sugar_getimagepath file="id-ff-down.png"}" id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-image"></button><button type="button"
89 id="btn-clear-{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input"
91 onclick="SUGAR.clearRelateField(this.form, '{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input', '{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}');sync_{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}()"><img src="{sugar_getimagepath file="id-ff-clear.png"}"></button>
96 SUGAR.AutoComplete.{/literal}{$ac_key}{literal} = [];
99 {{if empty($vardef.autocomplete_ajax)}}
102 var selectElem = document.getElementById("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}");
104 if (typeof select_defaults =="undefined")
105 select_defaults = [];
107 select_defaults[selectElem.id] = {key:selectElem.value,text:''};
110 for (i=0;i<selectElem.options.length;i++){
111 if (selectElem.options[i].value==selectElem.value)
112 select_defaults[selectElem.id].text = selectElem.options[i].innerHTML;
115 //SUGAR.AutoComplete.{$ac_key}.ds =
116 //get options array from vardefs
117 var options = SUGAR.AutoComplete.getOptionsArray("{{$vardef.autocomplete_options}}");
119 YUI().use('datasource', 'datasource-jsonschema',function (Y) {
120 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds = new Y.DataSource.Function({
121 source: function (request) {
123 for (i=0;i<selectElem.options.length;i++)
124 if (!(selectElem.options[i].value=='' && selectElem.options[i].innerHTML==''))
125 ret.push({'key':selectElem.options[i].value,'text':selectElem.options[i].innerHTML});
134 // Create a new YUI instance and populate it with the required modules.
135 YUI().use('datasource', 'datasource-jsonschema',function (Y) {
136 // DataSource is available and ready for use.
137 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds = new Y.DataSource.Get({
138 source: 'index.php?module=Accounts&action=ajaxautocomplete&to_pdf=1'
140 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds.plug(Y.Plugin.DataSourceJSONSchema, {
142 resultListLocator: "option_items",
143 resultFields: ["text", "key"],
152 YUI().use("autocomplete", "autocomplete-filters", "autocomplete-highlighters", "node","node-event-simulate", function (Y) {
155 SUGAR.AutoComplete.{$ac_key}.inputNode = Y.one('#{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input');
156 SUGAR.AutoComplete.{$ac_key}.inputImage = Y.one('#{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-image');
157 SUGAR.AutoComplete.{$ac_key}.inputHidden = Y.one('#{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}');
159 {{if empty($vardef.autocomplete_ajax)}}
161 function SyncToHidden(selectme){
162 var selectElem = document.getElementById("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}");
163 var doSimulateChange = false;
165 if (selectElem.value!=selectme)
166 doSimulateChange=true;
168 selectElem.value=selectme;
170 for (i=0;i<selectElem.options.length;i++){
171 selectElem.options[i].selected=false;
172 if (selectElem.options[i].value==selectme)
173 selectElem.options[i].selected=true;
176 if (doSimulateChange)
177 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('change');
181 sync_{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal} = function(){
184 function syncFromHiddenToWidget(){
186 var selectElem = document.getElementById("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}");
188 //if select no longer on page, kill timer
189 if (selectElem==null || selectElem.options == null)
192 var currentvalue = SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.get('value');
194 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.simulate('keyup');
196 for (i=0;i<selectElem.options.length;i++){
198 if (selectElem.options[i].value==selectElem.value && document.activeElement != document.getElementById('{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input{literal}'))
199 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.set('value',selectElem.options[i].innerHTML);
203 YAHOO.util.Event.onAvailable("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}", syncFromHiddenToWidget);
206 SUGAR.AutoComplete.{$ac_key}.minQLen = 0;
207 SUGAR.AutoComplete.{$ac_key}.queryDelay = 0;
208 SUGAR.AutoComplete.{$ac_key}.numOptions = {$field_options|@count};
209 if(SUGAR.AutoComplete.{$ac_key}.numOptions >= 300) {literal}{
211 SUGAR.AutoComplete.{$ac_key}.minQLen = 1;
212 SUGAR.AutoComplete.{$ac_key}.queryDelay = 200;
216 if(SUGAR.AutoComplete.{$ac_key}.numOptions >= 3000) {literal}{
218 SUGAR.AutoComplete.{$ac_key}.minQLen = 1;
219 SUGAR.AutoComplete.{$ac_key}.queryDelay = 500;
225 function SyncToHidden(e){
226 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.set('value', e);
230 SUGAR.AutoComplete.{$ac_key}.minQLen = 1;
231 SUGAR.AutoComplete.{$ac_key}.queryDelay = 500;
234 SUGAR.AutoComplete.{$ac_key}.optionsVisible = false;
237 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.plug(Y.Plugin.AutoComplete, {
238 activateFirstItem: true,
240 minQueryLength: SUGAR.AutoComplete.{$ac_key}.minQLen,
241 queryDelay: SUGAR.AutoComplete.{$ac_key}.queryDelay,
244 {{if !empty($vardef.autocomplete_ajax)}}
245 requestTemplate: '&options={{$vardef.autocomplete_options}}&q={literal}{query}{/literal}',
249 source: SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds,
251 resultTextLocator: 'text',
252 resultHighlighter: 'phraseMatch',
253 resultFilters: 'phraseMatch',
256 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.expandHover = function(ex){
257 var hover = YAHOO.util.Dom.getElementsByClassName('dccontent');
258 if(hover[0] != null){
261 hover[0].style.height = h;
264 hover[0].style.height = '';
269 if({/literal}SUGAR.AutoComplete.{$ac_key}.minQLen{literal} == 0){
270 // expand the dropdown options upon focus
271 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('focus', function () {
272 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.sendRequest('');
273 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.optionsVisible = true;
277 {{if empty($vardef.autocomplete_ajax)}}
278 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('click', function(e) {
279 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('click');
282 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('dblclick', function(e) {
283 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('dblclick');
286 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('focus', function(e) {
287 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('focus');
290 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('mouseup', function(e) {
291 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('mouseup');
294 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('mousedown', function(e) {
295 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('mousedown');
298 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('blur', function(e) {
299 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('blur');
300 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.optionsVisible = false;
301 var selectElem = document.getElementById("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}");
302 //if typed value is a valid option, do nothing
303 for (i=0;i<selectElem.options.length;i++)
304 if (selectElem.options[i].innerHTML==SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.get('value'))
307 //typed value is invalid, so set the text and the hidden to blank
308 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.set('value', select_defaults[selectElem.id].text);
309 SyncToHidden(select_defaults[selectElem.id].key);
312 // when they focus away from the field...
313 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('blur', function(e) {
314 if (SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.get('value') != '') { // value entered
315 if (SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.get('value') == '') { // none selected, we clear their text and hide
316 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.set('value', '');
318 else{ // they have something selected, we accept their selection and contract
321 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.optionsVisible = false;
325 // when they click on the arrow image, toggle the visibility of the options
326 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputImage.ancestor().on('click', function () {
327 if (SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.optionsVisible) {
328 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.blur();
330 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.focus();
334 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.on('query', function () {
335 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.set('value', '');
338 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.on('visibleChange', function (e) {
339 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.expandHover(e.newVal); // expand
342 // when they select an option, set the hidden input with the KEY, to be saved
343 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.on('select', function(e) {
344 SyncToHidden(e.result.raw.key);