5
5
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6
6
*
7
7
* SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
8
- * Copyright (C) 2011 - 2018 SalesAgility Ltd.
8
+ * Copyright (C) 2011 - 2020 SalesAgility Ltd.
9
9
*
10
10
* This program is free software; you can redistribute it and/or modify it under
11
11
* the terms of the GNU Affero General Public License version 3 as published by the
40
40
41
41
*}
42
42
43
- { if ! isset($config .enable_autocomplete) || $config .enable_autocomplete== false }
44
- <select name =" { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } "
45
- id =" { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } "
46
- title =' { { $vardef .help} } ' { { if ! empty($tabindex )} } tabindex =" { { $tabindex } } " { { /if } }
47
- { { if ! empty($displayParams .accesskey)} } accesskey =' { { $displayParams .accesskey} } ' { { /if } } { { $displayParams .field} }
48
- { { if isset($displayParams .javascript)} } { { $displayParams .javascript} } { { /if } } >
49
-
50
- { if isset({{sugarvar key= ' value' string= true } }) && { {sugarvar key= ' value' string= true } } != ''}
51
- { html_options options= {{sugarvar key= ' options' string= true } } selected={ {sugarvar key= ' value' string= true } }}
52
- { else }
53
- { html_options options= {{sugarvar key= ' options' string= true } } selected={ {sugarvar key= ' default' string= true } }}
54
- { /if }
55
- </select >
56
- { else }
57
- { assign var= " field_options" value= {{sugarvar key= ' options' string= " true" } } }
58
- { capture name= " field_val" } { {sugarvar key= ' value' } }{ /capture }
59
- { assign var= " field_val" value= $smarty .capture .field_val}
60
- { capture name= " ac_key" } { {sugarvar key= ' name' } }{ /capture }
61
- { assign var= " ac_key" value= $smarty .capture .ac_key}
62
-
63
- { {if empty($vardef .autocomplete_ajax)} }
64
- <select style =' display :none ' name =" { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } "
65
- id =" { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } "
66
- title =' { { $vardef .help} } ' { { if ! empty($tabindex )} } tabindex =" { { $tabindex } } " { { /if } }
67
- { { if ! empty($displayParams .accesskey)} } accesskey =' { { $displayParams .accesskey} } ' { { /if } } { { $displayParams .field} }
68
- { { if isset($displayParams .javascript)} } { { $displayParams .javascript} } { { /if } } >
69
-
70
- { if isset({{sugarvar key= ' value' string= true } }) && { {sugarvar key= ' value' string= true } } != ''}
71
- { html_options options= {{sugarvar key= ' options' string= true } } selected={ {sugarvar key= ' value' string= true } }}
72
- { else }
73
- { html_options options= {{sugarvar key= ' options' string= true } } selected={ {sugarvar key= ' default' string= true } }}
74
- { /if }
75
- </select >
76
- { {else } }
77
- <input type =" hidden"
78
- id =" { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } "
79
- name =" { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } "
80
- value =" { { sugarvar key= ' value' } } " >
81
- { {/if } }
82
-
83
- <input
84
- id =" { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } -input"
85
- name =" { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } -input"
86
- size =" 30"
87
- value =" { $field_val |lookup:$field_options } "
88
- type =" text" style =" vertical-align : top ;" >
89
-
90
-
91
- <span class =" id-ff multiple" >
92
- <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"
93
- id =" btn-clear-{ { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } -input"
94
- title =" Clear"
95
- 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 } } ()" ><span class =" suitepicon suitepicon-action-clear" ></span ></button >
96
- </span >
97
-
98
- {literal }
99
- <script>
100
- SUGAR.AutoComplete.{/literal } { $ac_key } {literal } = [];
101
- {/literal }
102
-
103
- { {if empty($vardef .autocomplete_ajax)} }
104
- {literal }
105
- (function (){
106
- var selectElem = document.getElementById(" {/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}" );
107
-
108
- if (typeof select_defaults == " undefined" )
109
- select_defaults = [];
110
-
111
- select_defaults[selectElem.id] = {key:selectElem.value,text:' ' } ;
112
-
113
- //get default
114
- for (i=0;i<selectElem.options.length;i++){
115
- if (selectElem.options[i].value= =selectElem.value)
116
- select_defaults[selectElem.id].text = selectElem.options[i].innerHTML;
117
- }
118
-
119
- //SUGAR.AutoComplete.{ $ac_key } .ds =
120
- //get options array from vardefs
121
- var options = SUGAR.AutoComplete.getOptionsArray("{ {$vardef .autocomplete_options} }");
122
-
123
- YUI().use('datasource', 'datasource-jsonschema',function (Y) {
124
- SUGAR.AutoComplete.{/literal } { $ac_key } {literal }.ds = new Y.DataSource.Function({
125
- source: function (request) {
126
- var ret = [];
127
- for (i=0;i<selectElem .options.length;i++)
128
- if (!(selectElem.options[i].value ==' ' && selectElem.options[i].innerHTML ==' ' ))
129
- ret.push({ ' key' :selectElem.options[i].value, ' text' :selectElem.options[i].innerHTML});
130
- return ret;
131
- }
132
- });
133
- });
134
- })();
135
- { /literal }
136
- { { else } }
137
- {literal }
138
- // Create a new YUI instance and populate it with the required modules.
139
- YUI().use('datasource', 'datasource-jsonschema',function (Y) {
140
- // DataSource is available and ready for use.
141
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.ds = new Y.DataSource.Get({
142
- source: ' index.php?module=Accounts&action=ajaxautocomplete&to_pdf=1'
143
- } );
144
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.ds.plug(Y.Plugin.DataSourceJSONSchema, {
145
- schema: {
146
- resultListLocator: " option_items" ,
147
- resultFields: [" text" , " key" ],
148
- matchKey: " text" ,
149
- }
150
- } );
151
- });
152
- { /literal }
153
- { { /if } }
154
-
155
- {literal }
156
- YUI().use("autocomplete", "autocomplete-filters", "autocomplete-highlighters", "node","node-event-simulate", function (Y) {
157
- { /literal }
158
-
159
- SUGAR.AutoComplete.{ $ac_key } .inputNode = Y.one(' #{ { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } -input' );
160
- SUGAR.AutoComplete.{ $ac_key } .inputImage = Y.one(' #{ { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } -image' );
161
- SUGAR.AutoComplete.{ $ac_key } .inputHidden = Y.one(' #{ { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } ' );
162
-
163
- { { if empty($vardef .autocomplete_ajax)} }
164
- {literal }
165
- function SyncToHidden(selectme){
166
- var selectElem = document.getElementById(" { /literal } { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } {literal }");
167
- var doSimulateChange = false;
168
-
169
- if (selectElem.value!=selectme)
170
- doSimulateChange=true;
171
-
172
- selectElem.value=selectme;
173
-
174
- for (i=0;i<selectElem .options.length;i++){
175
- selectElem.options[i].selected =false;
176
- if (selectElem.options[i].value ==selectme)
177
- selectElem.options[i].selected =true;
178
- }
179
-
180
- if (doSimulateChange)
181
- SUGAR.AutoComplete.{ /literal}{$ac_key}{literal}.inputHidden.simulate( ' change' );
182
- }
183
-
184
- //global variable
185
- sync_{ /literal}{{if empty($displayParams.idName)}}{{sugarvar key =' name' }}{{else}}{{$displayParams.idName}}{{ /if}}{literal} = function(){
186
- SyncToHidden();
187
- }
188
- function syncFromHiddenToWidget(){
189
-
190
- var selectElem = document.getElementById( " { /literal } { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } {literal }");
191
-
192
- //if select no longer on page, kill timer
193
- if (selectElem==null || selectElem.options == null)
194
- return;
195
-
196
- var currentvalue = SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.get('value');
197
-
198
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.simulate('keyup');
199
-
200
- for (i=0;i<selectElem .options.length;i++){
201
-
202
- 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 }'))
203
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.set('value',selectElem.options[i].innerHTML);
204
- }
205
- }
206
-
207
- YAHOO.util.Event.onAvailable("{ /literal } { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } {literal }", syncFromHiddenToWidget);
208
- { /literal }
209
-
210
- SUGAR.AutoComplete.{ $ac_key } .minQLen = 0;
211
- SUGAR.AutoComplete.{ $ac_key } .queryDelay = 0;
212
- SUGAR.AutoComplete.{ $ac_key } .numOptions = { $field_options |@count} ;
213
- if(SUGAR.AutoComplete.{ $ac_key } .numOptions >= 300) {literal }{
214
- { /literal }
215
- SUGAR.AutoComplete.{ $ac_key } .minQLen = 1;
216
- SUGAR.AutoComplete.{ $ac_key } .queryDelay = 200;
217
- {literal }
218
- }
219
- { /literal }
220
- if(SUGAR.AutoComplete.{ $ac_key } .numOptions >= 3000) {literal }{
221
- { /literal }
222
- SUGAR.AutoComplete.{ $ac_key } .minQLen = 1;
223
- SUGAR.AutoComplete.{ $ac_key } .queryDelay = 500;
224
- {literal }
225
- }
226
- { /literal }
227
- { { else } }
228
- {literal }
229
- function SyncToHidden(e){
230
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputHidden.set('value', e);
231
- }
232
- { /literal }
233
-
234
- SUGAR.AutoComplete.{ $ac_key } .minQLen = 1;
235
- SUGAR.AutoComplete.{ $ac_key } .queryDelay = 500;
236
- { { /if } }
237
-
238
- SUGAR.AutoComplete.{ $ac_key } .optionsVisible = false;
239
-
240
- {literal }
241
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.plug(Y.Plugin.AutoComplete, {
242
- activateFirstItem: true ,
243
- { /literal }
244
- minQueryLength: SUGAR.AutoComplete.{ $ac_key } .minQLen,
245
- queryDelay: SUGAR.AutoComplete.{ $ac_key } .queryDelay,
246
- zIndex: 99999,
247
-
248
- { { if ! empty($vardef .autocomplete_ajax)} }
249
- requestTemplate: ' &options={ { $vardef .autocomplete_options} } &q={literal }{ query} { /literal } ',
250
- { { /if } }
251
-
252
- {literal }
253
- source: SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.ds,
254
-
255
- resultTextLocator: 'text',
256
- resultHighlighter: 'phraseMatch',
257
- resultFilters: 'phraseMatch',
258
- });
259
-
260
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.expandHover = function(ex){
261
- var hover = YAHOO.util.Dom.getElementsByClassName(' dccontent' );
262
- if (hover[0] != null){
263
- if (ex) {
264
- var h = ' 1000px' ;
265
- hover[0].style.height = h;
266
- }
267
- else {
268
- hover[0].style.height = ' ' ;
269
- }
270
- }
271
- }
272
-
273
- if({ /literal } SUGAR.AutoComplete.{ $ac_key } .minQLen{literal } == 0){
274
- // expand the dropdown options upon focus
275
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.on('focus', function () {
276
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.ac.sendRequest('');
277
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.optionsVisible = true;
278
- });
279
- }
280
-
281
- { { if empty($vardef .autocomplete_ajax)} }
282
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.on('click', function(e) {
283
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputHidden.simulate('click');
284
- });
285
-
286
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.on('dblclick', function(e) {
287
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputHidden.simulate('dblclick');
288
- });
289
-
290
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.on('focus', function(e) {
291
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputHidden.simulate('focus');
292
- });
293
-
294
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.on('mouseup', function(e) {
295
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputHidden.simulate('mouseup');
296
- });
297
-
298
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.on('mousedown', function(e) {
299
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputHidden.simulate('mousedown');
300
- });
301
-
302
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.on('blur', function(e) {
303
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputHidden.simulate('blur');
304
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.optionsVisible = false;
305
- var selectElem = document.getElementById("{ /literal } { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } {literal }");
306
- //if typed value is a valid option, do nothing
307
- for (i=0;i<selectElem .options.length;i++)
308
- if (selectElem.options[i].innerHTML ==SUGAR.AutoComplete.{ /literal}{$ac_key}{literal}.inputNode.get( ' value' ))
309
- return;
310
-
311
- //typed value is invalid, so set the text and the hidden to blank
312
- SUGAR.AutoComplete.{ /literal}{$ac_key}{literal}.inputNode.set( ' value' , select_defaults[selectElem.id].text);
313
- SyncToHidden(select_defaults[selectElem.id].key);
314
- });
315
- { { else } }
316
- // when they focus away from the field...
317
- SUGAR.AutoComplete.{ /literal}{$ac_key}{literal}.inputNode.on( ' blur' , function(e) {
318
- if (SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.get('value') != '') { // value entered
319
- if (SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputHidden.get('value') == '') { // none selected, we clear their text and hide
320
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.set('value', '');
321
- }
322
- else{ // they have something selected, we accept their selection and contract
323
- }
324
- }
325
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.optionsVisible = false;
326
- });
327
- { { /if } }
328
-
329
- // when they click on the arrow image, toggle the visibility of the options
330
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputImage.ancestor().on('click', function () {
331
- if (SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.optionsVisible) {
332
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.blur();
333
- } else {
334
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.focus();
335
- }
336
- });
337
-
338
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.ac.on('query', function () {
339
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputHidden.set('value', '');
340
- });
341
-
342
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.ac.on('visibleChange', function (e) {
343
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.expandHover(e.newVal); // expand
344
- });
345
-
346
- // when they select an option, set the hidden input with the KEY, to be saved
347
- SUGAR.AutoComplete.{ /literal } { $ac_key } {literal }.inputNode.ac.on('select', function(e) {
348
- SyncToHidden(e.result.raw.key);
349
- } );
350
-
351
- });
352
- </script >
353
-
354
- { /literal }
355
-
356
- { /if }
43
+ <select name =" { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } "
44
+ id =" { { if empty($displayParams .idName)} } { { sugarvar key= ' name' } } { { else } } { { $displayParams .idName} } { { /if } } "
45
+ title =' { { $vardef .help} } ' { { if ! empty($tabindex )} } tabindex =" { { $tabindex } } " { { /if } }
46
+ { { if ! empty($displayParams .accesskey)} }
47
+ accesskey =' { { $displayParams .accesskey} } ' { { /if } } { { $displayParams .field} }
48
+ { { if isset($displayParams .javascript)} } { { $displayParams .javascript} } { { /if } } >
49
+
50
+ { if isset({{sugarvar key= ' value' string= true } }) && { {sugarvar key= ' value' string= true } } != ''}
51
+ { html_options options= {{sugarvar key= ' options' string= true } } selected={ {sugarvar key= ' value' string= true } }}
52
+ { else }
53
+ { html_options options= {{sugarvar key= ' options' string= true } } selected={ {sugarvar key= ' default' string= true } }}
54
+ { /if }
55
+ </select >
0 commit comments