]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/SugarFields/Fields/Multienum/EditView.tpl
Release 6.3.0
[Github/sugarcrm.git] / include / SugarFields / Fields / Multienum / EditView.tpl
1 {*
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37 *}
38
39 {if !isset($config.enable_autocomplete) || $config.enable_autocomplete==false}
40
41         <input type="hidden" id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}_multiselect"
42         name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}_multiselect" value="true">
43         {multienum_to_array string={{sugarvar key='value' string=true}} default={{sugarvar key='default' string=true}} assign="values"}
44         <select id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
45         name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}[]"
46         multiple="true" size='{{$displayParams.size|default:6}}' style="width:150" title='{{$vardef.help}}' tabindex="{{$tabindex}}" {{$displayParams.field}} >
47         {html_options options={{sugarvar key='options' string=true}} selected=$values}
48         </select>
49
50 {else}
51
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}
57
58         {{if empty($vardef.autocomplete_ajax)}}
59                 <input type="hidden" id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}_multiselect"
60                 name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}_multiselect" value="true">
61                 {multienum_to_array string={{sugarvar key='value' string=true}} default={{sugarvar key='default' string=true}} assign="values"}
62                 <select style='display:none' id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
63                 name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}[]"
64                 multiple="true" size='{{$displayParams.size|default:6}}' style="width:150" title='{{$vardef.help}}' tabindex="{{$tabindex}}" {{$displayParams.field}}>
65                 {html_options options={{sugarvar key='options' string=true}} selected=$values}
66                 </select>
67
68                 <input
69             id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input"
70             name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input"
71             size="60"
72             type="text" style="vertical-align: top;">
73         {{else}}
74                 <input type="hidden"
75                     id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
76                     name="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}"
77                     value="{{sugarvar key='value'}}">
78
79                 <input
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"
82                     size="60"
83                     type="text" style="vertical-align: top;">
84         {{/if}}
85
86         <span class="id-ff multiple">
87             <button type="button">
88                 <img src="{sugar_getimagepath file="id-ff-down.png"}" id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-image">
89                 </button>
90                 <button type="button"
91                 id="btn-clear-{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input"
92                 title="Clear"
93                 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}};');SUGAR.AutoComplete.{$ac_key}.inputNode.updateHidden()"><img src="{sugar_getimagepath file="id-ff-clear.png"}"></button>
94         </span>
95
96         {literal}
97         <script>
98         SUGAR.AutoComplete.{/literal}{$ac_key}{literal} = [];
99         {/literal}
100
101         {{if empty($vardef.autocomplete_ajax)}}
102                 {literal}
103                 YUI().use('datasource', 'datasource-jsonschema', function (Y) {
104                                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds = new Y.DataSource.Function({
105                                             source: function (request) {
106                                                 var selectElem = document.getElementById("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}");
107                                                 var ret = [];
108                                                 for (i=0;i<selectElem.options.length;i++)
109                                                         if (!(selectElem.options[i].value=='' && selectElem.options[i].innerHTML==''))
110                                                                 ret.push({'key':selectElem.options[i].value,'text':selectElem.options[i].innerHTML});
111                                                 return ret;
112                                             }
113                                         });
114                                 });
115                 {/literal}
116         {{else}}
117                 {literal}
118                 // Create a new YUI instance and populate it with the required modules.
119                 YUI().use('datasource', 'datasource-jsonschema', function (Y) {
120                         // DataSource is available and ready for use.
121                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds = new Y.DataSource.Get({
122                                 source: 'index.php?module=Accounts&action=ajaxautocomplete&to_pdf=1'
123                         });
124                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds.plug(Y.Plugin.DataSourceJSONSchema, {
125                                 schema: {
126                                         resultListLocator: "option_items",
127                                         resultFields: ["text", "key"],
128                                         matchKey: "text",
129                                 }
130                         });
131                 });
132                 {/literal}
133         {{/if}}
134
135         {literal}
136         YUI().use("autocomplete", "autocomplete-filters", "autocomplete-highlighters","node-event-simulate", function (Y) {
137                 {/literal}
138                 
139             SUGAR.AutoComplete.{$ac_key}.inputNode = Y.one('#{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input');
140             SUGAR.AutoComplete.{$ac_key}.inputImage = Y.one('#{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-image');
141             SUGAR.AutoComplete.{$ac_key}.inputHidden = Y.one('#{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}');
142
143                 {{if empty($vardef.autocomplete_ajax)}}
144                         SUGAR.AutoComplete.{$ac_key}.minQLen = 0;
145                         SUGAR.AutoComplete.{$ac_key}.queryDelay = 0;
146                         SUGAR.AutoComplete.{$ac_key}.numOptions = {$field_options|@count};
147                         if(SUGAR.AutoComplete.{$ac_key}.numOptions >= 300) {literal}{
148                                 {/literal}
149                                 SUGAR.AutoComplete.{$ac_key}.minQLen = 1;
150                                 SUGAR.AutoComplete.{$ac_key}.queryDelay = 200;
151                                 {literal}
152                         }
153                         {/literal}
154                         if(SUGAR.AutoComplete.{$ac_key}.numOptions >= 3000) {literal}{
155                                 {/literal}
156                                 SUGAR.AutoComplete.{$ac_key}.minQLen = 1;
157                                 SUGAR.AutoComplete.{$ac_key}.queryDelay = 500;
158                                 {literal}
159                         }
160                         {/literal}
161                 {{else}}
162                         SUGAR.AutoComplete.{$ac_key}.minQLen = 1;
163                         SUGAR.AutoComplete.{$ac_key}.queryDelay = 500;
164                 {{/if}}
165                 
166                 {{if empty($vardef.autocomplete_ajax)}}
167                 {literal}
168             SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.plug(Y.Plugin.AutoComplete, {
169                 activateFirstItem: true,
170                 allowTrailingDelimiter: true,
171                         {/literal}
172                 minQueryLength: SUGAR.AutoComplete.{$ac_key}.minQLen,
173                 queryDelay: SUGAR.AutoComplete.{$ac_key}.queryDelay,
174                 queryDelimiter: ',',
175                 zIndex: 99999,
176
177                         {{if !empty($vardef.autocomplete_ajax)}}
178                                 requestTemplate: '&options={{$vardef.autocomplete_options}}&q={literal}{query}{/literal}',
179                         {{/if}}
180                         {literal}
181                         source: SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds,
182                         
183                 resultTextLocator: 'text',
184                 resultHighlighter: 'phraseMatch',
185                 resultFilters: 'phraseMatch',
186                 // Chain together a startsWith filter followed by a custom result filter
187                 // that only displays tags that haven't already been selected.
188                 resultFilters: ['phraseMatch', function (query, results) {
189                         // Split the current input value into an array based on comma delimiters.
190                         var selected = SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.get('value').split(/\s*,\s*/);
191                 
192                     // Convert the array into a hash for faster lookups.
193                     selected = Y.Array.hash(selected);
194
195                     // Filter out any results that are already selected, then return the
196                     // array of filtered results.
197                     return Y.Array.filter(results, function (result) {
198                        return !selected.hasOwnProperty(result.text);
199                     });
200                 }]
201             });
202                 {/literal}{{else}}{literal}
203                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.plug(Y.Plugin.AutoComplete, {
204                 activateFirstItem: true,
205                 allowTrailingDelimiter: true,
206                         {/literal}
207                 minQueryLength: SUGAR.AutoComplete.{$ac_key}.minQLen,
208                 queryDelay: SUGAR.AutoComplete.{$ac_key}.queryDelay,
209                 queryDelimiter: ',',
210                 zIndex: 99999,
211                                 requestTemplate: '&options={{$vardef.autocomplete_options}}&q={literal}{query}{/literal}',
212                         {literal}
213                         source: SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.ds,
214                         
215                 resultTextLocator: 'text',
216                 resultHighlighter: 'phraseMatch',
217                 resultFilters: 'phraseMatch',
218                 // Chain together a startsWith filter followed by a custom result filter
219                 // that only displays tags that haven't already been selected.
220                 resultFilters: ['phraseMatch', function (query, results) {
221                     // Split the current input value into an array based on comma delimiters.
222                     var selected = SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.get('value').split(/\s*,\s*/);
223
224                     // Pop the last item off the array, since it represents the current query
225                     // and we don't want to filter it out.
226                     //selected.pop();
227
228                     // Convert the array into a hash for faster lookups.
229                     selected = Y.Array.hash(selected);
230
231                     // Filter out any results that are already selected, then return the
232                     // array of filtered results.
233                     return Y.Array.filter(results, function (result) {
234                        return !selected.hasOwnProperty(result.text);
235                     });
236                 }]
237             });
238                 {/literal}{{/if}}{literal}
239                 if({/literal}SUGAR.AutoComplete.{$ac_key}.minQLen{literal} == 0){
240                     // expand the dropdown options upon focus
241                     SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('focus', function () {
242                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.sendRequest('');
243                     });
244                 }
245
246                 {{if empty($vardef.autocomplete_ajax)}}
247                     SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.updateHidden = function() {
248                                 var index_array = SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.get('value').split(/\s*,\s*/);
249
250                                 var selectElem = document.getElementById("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}");
251
252                                 var oTable = {};
253                         for (i=0;i<selectElem.options.length;i++){
254                                 if (selectElem.options[i].selected)
255                                         oTable[selectElem.options[i].value] = true;
256                         }
257
258                                 for (i=0;i<selectElem.options.length;i++){
259                                         selectElem.options[i].selected=false;
260                                 }
261
262                                 var nTable = {};
263
264                                 for (i=0;i<index_array.length;i++){
265                                         var key = index_array[i];
266                                         for (c=0;c<selectElem.options.length;c++)
267                                                 if (selectElem.options[c].innerHTML == key){
268                                                         selectElem.options[c].selected=true;
269                                                         nTable[selectElem.options[c].value]=1;
270                                                 }
271                                 }
272
273                                 //the following two loops check to see if the selected options are different from before.
274                                 //oTable holds the original select. nTable holds the new one
275                                 var fireEvent=false;
276                                 for (n in nTable){
277                                         if (n=='')
278                                                 continue;
279                                 if (!oTable.hasOwnProperty(n))
280                                         fireEvent = true; //the options are different, fire the event
281                         }
282                         
283                         for (o in oTable){
284                                 if (o=='')
285                                         continue;
286                                 if (!nTable.hasOwnProperty(o))
287                                         fireEvent=true; //the options are different, fire the event
288                         }
289
290                         //if the selected options are different from before, fire the 'change' event
291                         if (fireEvent){
292                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('change');
293                         }
294                     };
295
296                     SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.updateText = function() {
297                         //get last option typed into the input widget
298                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.set(SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.get('value'));
299                                 var index_array = SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.get('value').split(/\s*,\s*/);
300                                 //create a string ret_string as a comma-delimited list of text from selectElem options.
301                                 var selectElem = document.getElementById("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}{literal}");
302                                 var ret_array = [];
303
304                 if (selectElem==null || selectElem.options == null)
305                                         return;
306
307                                 for (i=0;i<selectElem.options.length;i++){
308                                         if (selectElem.options[i].selected && selectElem.options[i].innerHTML!=''){
309                                                 ret_array.push(selectElem.options[i].innerHTML);
310                                         }
311                                 }
312
313                                 //index array - array from input
314                                 //ret array - array from select
315
316                                 var sorted_array = [];
317                                 var notsorted_array = [];
318                                 for (i=0;i<index_array.length;i++){
319                                         for (c=0;c<ret_array.length;c++){
320                                                 if (ret_array[c]==index_array[i]){
321                                                         sorted_array.push(ret_array[c]);
322                                                         ret_array.splice(c,1);
323                                                 }
324                                         }
325                                 }
326                                 ret_string = ret_array.concat(sorted_array).join(', ');
327                                 if (ret_string.match(/^\s*$/))
328                                         ret_string='';
329                                 else
330                                         ret_string+=', ';
331                                 
332                                 //update the input widget
333                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.set('value', ret_string);
334                     };
335
336                     function updateTextOnInterval(){
337                         if (document.activeElement != document.getElementById("{/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}-input{literal}"))
338                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.updateText();
339                         setTimeout(updateTextOnInterval,100);
340                     }
341
342                     updateTextOnInterval();
343                 {{else}}
344                     SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.updateHidden = function() {
345                                 var index_array = SUGAR.MultiEnumAutoComplete.getMultiSelectKeysFromValues("{/literal}{{$vardef.autocomplete_options}}{literal}", SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.get('value'));
346                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.set('value', index_array.join("^,^"));
347                     };
348
349                     SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.updateText = function() {
350                                 var index_array = SUGAR.MultiEnumAutoComplete.getMultiSelectValuesFromKeys("{/literal}{{$vardef.autocomplete_options}}{literal}", SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.get('value'));
351                                 if(index_array.length < 1){
352                                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.set('value', '');
353                                 }
354                                 else{
355                                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.set('value', index_array.join(", ") + ", ");
356                                 }
357                     };  
358                     SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.updateText();
359                 {{/if}}
360
361                 {{if empty($vardef.autocomplete_ajax)}}
362                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('click', function(e) {
363                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('click');
364                         });
365                         
366                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('dblclick', function(e) {
367                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('dblclick');
368                         });
369
370                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('focus', function(e) {
371                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('focus');
372                         });
373
374                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('mouseup', function(e) {
375                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('mouseup');
376                         });
377
378                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('mousedown', function(e) {
379                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('mousedown');
380                         });
381
382                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('blur', function(e) {
383                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputHidden.simulate('blur');
384                         });
385                 {{/if}}
386
387                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.on('blur', function () {
388                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.updateHidden();
389                         SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.updateText();
390                 });
391         
392             // when they click on the arrow image, toggle the visibility of the options
393             SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputImage.on('click', function () {
394                         if({/literal}SUGAR.AutoComplete.{$ac_key}.minQLen{literal} == 0){
395                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.sendRequest('');
396                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.show();
397                         }
398                         else{
399                                 SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.focus();
400                         }
401             });
402         
403                 if({/literal}SUGAR.AutoComplete.{$ac_key}.minQLen{literal} == 0){
404                     // After a tag is selected, send an empty query to update the list of tags.
405                     SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.after('select', function () {
406                       SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.sendRequest('');
407                       SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.show();
408                           SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.updateHidden();
409                           SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.updateText();
410                     });
411                 } else {
412                     // After a tag is selected, send an empty query to update the list of tags.
413                     SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.ac.after('select', function () {
414                           SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.updateHidden();
415                           SUGAR.AutoComplete.{/literal}{$ac_key}{literal}.inputNode.updateText();
416                     });
417                 }
418         });
419         </script>
420         {/literal}
421 {/if}