2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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}} {{$displayParams.field}}
43 {{if isset($displayParams.javascript)}}{{$displayParams.javascript}}{{/if}}>
45 {if isset({{sugarvar key='value' string=true}}) && {{sugarvar key='value' string=true}} != ''}
46 {html_options options={{sugarvar key='options' string=true}} selected={{sugarvar key='value' string=true}}}
48 {html_options options={{sugarvar key='options' string=true}} selected={{sugarvar key='default' string=true}}}
52 {assign var="field_options" value={{sugarvar key='options' string="true"}} }
53 {capture name="field_val"}{{sugarvar key='value'}}{/capture}
54 {assign var="field_val" value=$smarty.capture.field_val}
55 {capture name="ac_key"}{{sugarvar key='name'}}{/capture}
56 {assign var="ac_key" value=$smarty.capture.ac_key}
58 {{if empty($vardef.autocomplete_ajax)}}
59 <select style='display:none' name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
60 id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
61 title='{{$vardef.help}}' {{if !empty($tabindex)}} tabindex="{{$tabindex}}" {{/if}} {{$displayParams.field}}
62 {{if isset($displayParams.javascript)}}{{$displayParams.javascript}}{{/if}}>
64 {if isset({{sugarvar key='value' string=true}}) && {{sugarvar key='value' string=true}} != ''}
65 {html_options options={{sugarvar key='options' string=true}} selected={{sugarvar key='value' string=true}}}
67 {html_options options={{sugarvar key='options' string=true}} selected={{sugarvar key='default' string=true}}}
72 id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
73 name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
74 value="{{sugarvar key='value'}}">
78 id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input"
79 name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input"
81 value="{$field_val|lookup:$field_options}"
82 type="text" style="vertical-align: top;">
85 <span class="id-ff multiple">
86 <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"
87 id="btn-clear-{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input"
89 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>
94 SUGAR.AutoComplete.{/literal}{$ac_key}{literal} = [];
97 {{if empty($vardef.autocomplete_ajax)}}
100 var selectElem = document.getElementById("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}");
102 if (typeof select_defaults =="undefined")
103 select_defaults = [];
105 select_defaults[selectElem.id] = {key:selectElem.value,text:''};
108 for (i=0;i<selectElem.options.length;i++){
109 if (selectElem.options[i].value==selectElem.value)
110 select_defaults[selectElem.id].text = selectElem.options[i].innerHTML;
113 //SUGAR.AutoComplete.{$ac_key}.ds =
114 //get options array from vardefs
115 var options = SUGAR.AutoComplete.getOptionsArray("{{$vardef.autocomplete_options}}");
117 YUI().use('datasource', 'datasource-jsonschema',function (Y) {
118 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds = new Y.DataSource.Function({
119 source: function (request) {
121 for (i=0;i<selectElem.options.length;i++)
122 if (!(selectElem.options[i].value=='' && selectElem.options[i].innerHTML==''))
123 ret.push({'key':selectElem.options[i].value,'text':selectElem.options[i].innerHTML});
132 // Create a new YUI instance and populate it with the required modules.
133 YUI().use('datasource', 'datasource-jsonschema',function (Y) {
134 // DataSource is available and ready for use.
135 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds = new Y.DataSource.Get({
136 source: 'index.php?module=Accounts&action=ajaxautocomplete&to_pdf=1'
138 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds.plug(Y.Plugin.DataSourceJSONSchema, {
140 resultListLocator: "option_items",
141 resultFields: ["text", "key"],
150 YUI().use("autocomplete", "autocomplete-filters", "autocomplete-highlighters", "node","node-event-simulate", function (Y) {
153 SUGAR.AutoComplete.{$ac_key}.inputNode = Y.one('#{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input');
154 SUGAR.AutoComplete.{$ac_key}.inputImage = Y.one('#{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-image');
155 SUGAR.AutoComplete.{$ac_key}.inputHidden = Y.one('#{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}');
157 {{if empty($vardef.autocomplete_ajax)}}
159 function SyncToHidden(selectme){
160 var selectElem = document.getElementById("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}");
161 var doSimulateChange = false;
163 if (selectElem.value!=selectme)
164 doSimulateChange=true;
166 selectElem.value=selectme;
168 for (i=0;i<selectElem.options.length;i++){
169 selectElem.options[i].selected=false;
170 if (selectElem.options[i].value==selectme)
171 selectElem.options[i].selected=true;
174 if (doSimulateChange)
175 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('change');
179 sync_{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal} = function(){
182 function syncFromHiddenToWidget(){
184 var selectElem = document.getElementById("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}");
186 //if select no longer on page, kill timer
187 if (selectElem==null || selectElem.options == null)
190 var currentvalue = SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.get('value');
192 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.simulate('keyup');
194 for (i=0;i<selectElem.options.length;i++){
196 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}'))
197 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.set('value',selectElem.options[i].innerHTML);
201 YAHOO.util.Event.onAvailable("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}", syncFromHiddenToWidget);
204 SUGAR.AutoComplete.{$ac_key}.minQLen = 0;
205 SUGAR.AutoComplete.{$ac_key}.queryDelay = 0;
206 SUGAR.AutoComplete.{$ac_key}.numOptions = {$field_options|@count};
207 if(SUGAR.AutoComplete.{$ac_key}.numOptions >= 300) {literal}{
209 SUGAR.AutoComplete.{$ac_key}.minQLen = 1;
210 SUGAR.AutoComplete.{$ac_key}.queryDelay = 200;
214 if(SUGAR.AutoComplete.{$ac_key}.numOptions >= 3000) {literal}{
216 SUGAR.AutoComplete.{$ac_key}.minQLen = 1;
217 SUGAR.AutoComplete.{$ac_key}.queryDelay = 500;
223 function SyncToHidden(e){
224 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.set('value', e);
228 SUGAR.AutoComplete.{$ac_key}.minQLen = 1;
229 SUGAR.AutoComplete.{$ac_key}.queryDelay = 500;
232 SUGAR.AutoComplete.{$ac_key}.optionsVisible = false;
235 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.plug(Y.Plugin.AutoComplete, {
236 activateFirstItem: true,
238 minQueryLength: SUGAR.AutoComplete.{$ac_key}.minQLen,
239 queryDelay: SUGAR.AutoComplete.{$ac_key}.queryDelay,
242 {{if !empty($vardef.autocomplete_ajax)}}
243 requestTemplate: '&options={{$vardef.autocomplete_options}}&q={literal}{query}{/literal}',
247 source: SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds,
249 resultTextLocator: 'text',
250 resultHighlighter: 'phraseMatch',
251 resultFilters: 'phraseMatch',
254 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.expandHover = function(ex){
255 var hover = YAHOO.util.Dom.getElementsByClassName('dccontent');
256 if(hover[0] != null){
259 hover[0].style.height = h;
262 hover[0].style.height = '';
267 if({/literal}SUGAR.AutoComplete.{$ac_key}.minQLen{literal} == 0){
268 // expand the dropdown options upon focus
269 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('focus', function () {
270 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.sendRequest('');
271 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.optionsVisible = true;
275 {{if empty($vardef.autocomplete_ajax)}}
276 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('click', function(e) {
277 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('click');
280 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('dblclick', function(e) {
281 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('dblclick');
284 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('focus', function(e) {
285 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('focus');
288 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('mouseup', function(e) {
289 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('mouseup');
292 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('mousedown', function(e) {
293 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('mousedown');
296 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('blur', function(e) {
297 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('blur');
298 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.optionsVisible = false;
299 var selectElem = document.getElementById("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}");
300 //if typed value is a valid option, do nothing
301 for (i=0;i<selectElem.options.length;i++)
302 if (selectElem.options[i].innerHTML==SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.get('value'))
305 //typed value is invalid, so set the text and the hidden to blank
306 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.set('value', select_defaults[selectElem.id].text);
307 SyncToHidden(select_defaults[selectElem.id].key);
310 // when they focus away from the field...
311 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('blur', function(e) {
312 if (SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.get('value') != '') { // value entered
313 if (SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.get('value') == '') { // none selected, we clear their text and hide
314 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.set('value', '');
316 else{ // they have something selected, we accept their selection and contract
319 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.optionsVisible = false;
323 // when they click on the arrow image, toggle the visibility of the options
324 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputImage.ancestor().on('click', function () {
325 if (SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.optionsVisible) {
326 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.blur();
328 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.focus();
332 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.on('query', function () {
333 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.set('value', '');
336 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.on('visibleChange', function (e) {
337 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.expandHover(e.newVal); // expand
340 // when they select an option, set the hidden input with the KEY, to be saved
341 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.on('select', function(e) {
342 SyncToHidden(e.result.raw.key);