1 | /** |
---|
2 | * ----------------------------------------------------------------------------- |
---|
3 | * file: ui.inputList.js |
---|
4 | * file version: 1.0.0 |
---|
5 | * date: 2010-11-02 |
---|
6 | * |
---|
7 | * A jQuery plugin provided by the piwigo's plugin "GrumPluginClasses" |
---|
8 | * |
---|
9 | * ----------------------------------------------------------------------------- |
---|
10 | * Author : Grum |
---|
11 | * email : grum@piwigo.com |
---|
12 | * website : http://photos.grum.fr |
---|
13 | * PWG user : http://forum.phpwebgallery.net/profile.php?id=3706 |
---|
14 | * |
---|
15 | * << May the Little SpaceFrog be with you ! >> |
---|
16 | * ----------------------------------------------------------------------------- |
---|
17 | * |
---|
18 | * |
---|
19 | * |
---|
20 | * |
---|
21 | * :: HISTORY :: |
---|
22 | * |
---|
23 | * | release | date | |
---|
24 | * | 1.0.0 | 2010/10/10 | first release |
---|
25 | * | | | |
---|
26 | * | | | |
---|
27 | * | | | |
---|
28 | * | | | |
---|
29 | * | | | |
---|
30 | * | | | |
---|
31 | * |
---|
32 | */ |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | ( |
---|
37 | function($) |
---|
38 | { |
---|
39 | /* |
---|
40 | * plugin 'public' functions |
---|
41 | */ |
---|
42 | var publicMethods = |
---|
43 | { |
---|
44 | init : function (opt) |
---|
45 | { |
---|
46 | return this.each(function() |
---|
47 | { |
---|
48 | // default values for the plugin |
---|
49 | var $this=$(this), |
---|
50 | data = $this.data('options'), |
---|
51 | objects = $this.data('objects'), |
---|
52 | properties = $this.data('properties'), |
---|
53 | options = |
---|
54 | { |
---|
55 | serverUrl:'', |
---|
56 | autoLoad:true, |
---|
57 | listMaxWidth:0, |
---|
58 | listMaxHeight:0, |
---|
59 | multiple:false, |
---|
60 | downArrow:'⇓', |
---|
61 | popupMode:'click', |
---|
62 | colsWidth:[], |
---|
63 | colsDisplayed:[], |
---|
64 | colsCss:[], |
---|
65 | disabled:false, |
---|
66 | popup:null, |
---|
67 | change:null, |
---|
68 | load:null, |
---|
69 | returnMode:'selected' |
---|
70 | }; |
---|
71 | |
---|
72 | // if options given, merge it |
---|
73 | // if(opt) $.extend(options, opt); ==> options are set by setters |
---|
74 | |
---|
75 | $this.data('options', options); |
---|
76 | |
---|
77 | if(!properties) |
---|
78 | { |
---|
79 | $this.data('properties', |
---|
80 | { |
---|
81 | index:-1, |
---|
82 | initialized:false, |
---|
83 | selectorVisible:false, |
---|
84 | items:[], |
---|
85 | mouseOver:false, |
---|
86 | isValid:true, |
---|
87 | firstPopup:true |
---|
88 | } |
---|
89 | ); |
---|
90 | properties=$this.data('properties'); |
---|
91 | } |
---|
92 | |
---|
93 | if(!objects) |
---|
94 | { |
---|
95 | objects = |
---|
96 | { |
---|
97 | container:$('<div/>', |
---|
98 | { |
---|
99 | 'class':'ui-inputList', |
---|
100 | tabindex:0, |
---|
101 | css:{ |
---|
102 | width:'100%' |
---|
103 | } |
---|
104 | } |
---|
105 | ).bind('click.inputList', |
---|
106 | function () |
---|
107 | { |
---|
108 | privateMethods.displaySelector($this, !$this.data('properties').selectorVisible); |
---|
109 | $(this).focus(); |
---|
110 | } |
---|
111 | ), |
---|
112 | containerValue:$('<div/>', |
---|
113 | { |
---|
114 | html: ' ', |
---|
115 | 'class':'ui-inputList-value', |
---|
116 | css:{ |
---|
117 | overflow:'hidden' |
---|
118 | } |
---|
119 | } |
---|
120 | ), |
---|
121 | containerList:null, |
---|
122 | containerArrow:$('<div/>', |
---|
123 | { |
---|
124 | html: '⇓', |
---|
125 | 'class':'ui-inputList-arrow', |
---|
126 | css: { |
---|
127 | 'float':'right', |
---|
128 | cursor:'pointer' |
---|
129 | } |
---|
130 | } |
---|
131 | ).bind('mousedown', |
---|
132 | function () |
---|
133 | { |
---|
134 | $(this).addClass('ui-inputList-arrow-active'); |
---|
135 | } |
---|
136 | ).bind('mouseup', |
---|
137 | function () |
---|
138 | { |
---|
139 | $(this).removeClass('ui-inputList-arrow-active'); |
---|
140 | } |
---|
141 | ), |
---|
142 | listContainer:$('<div/>', |
---|
143 | { |
---|
144 | html: "", |
---|
145 | 'class':'ui-inputList-list', |
---|
146 | css: { |
---|
147 | overflow:"auto", |
---|
148 | display:'none', |
---|
149 | position:'absolute' |
---|
150 | } |
---|
151 | } |
---|
152 | ), |
---|
153 | list:$('<ul/>', |
---|
154 | { |
---|
155 | css: { |
---|
156 | listStyle:'none', |
---|
157 | padding:'0px', |
---|
158 | margin:'0px' |
---|
159 | } |
---|
160 | } |
---|
161 | ) |
---|
162 | }; |
---|
163 | } |
---|
164 | |
---|
165 | $this.data('objects', objects); |
---|
166 | privateMethods.setOptions($this, opt); |
---|
167 | |
---|
168 | if($this.text()!='') |
---|
169 | { |
---|
170 | var tmp=$.parseJSON($.trim($this.text())), |
---|
171 | selectedValues=[], |
---|
172 | values=[]; |
---|
173 | |
---|
174 | if($.isArray(tmp)) |
---|
175 | { |
---|
176 | values=tmp; |
---|
177 | } |
---|
178 | else if(tmp.values!=null) |
---|
179 | { |
---|
180 | values=tmp.values; |
---|
181 | } |
---|
182 | |
---|
183 | if(tmp.selected!=null) selectedValues=tmp.selected; |
---|
184 | |
---|
185 | privateMethods.setItems($this, values); |
---|
186 | privateMethods.setValue($this, selectedValues); |
---|
187 | |
---|
188 | } |
---|
189 | |
---|
190 | $this |
---|
191 | .html('') |
---|
192 | .append(objects.container.append(objects.containerArrow).append(objects.containerValue)) |
---|
193 | .append(objects.listContainer.append(objects.list)); |
---|
194 | |
---|
195 | } |
---|
196 | ); |
---|
197 | }, // init |
---|
198 | destroy : function () |
---|
199 | { |
---|
200 | return this.each( |
---|
201 | function() |
---|
202 | { |
---|
203 | // default values for the plugin |
---|
204 | var $this=$(this), |
---|
205 | objects = $this.data('objects'); |
---|
206 | objects.container.unbind().remove(); |
---|
207 | objects.list.children().unbind(); |
---|
208 | objects.listContainer.remove(); |
---|
209 | $this |
---|
210 | .unbind('.inputList') |
---|
211 | .css( |
---|
212 | { |
---|
213 | width:'', |
---|
214 | height:'' |
---|
215 | } |
---|
216 | ); |
---|
217 | } |
---|
218 | ); |
---|
219 | }, // destroy |
---|
220 | |
---|
221 | options: function (value) |
---|
222 | { |
---|
223 | return this.each(function() |
---|
224 | { |
---|
225 | privateMethods.setOptions($(this), value); |
---|
226 | } |
---|
227 | ); |
---|
228 | }, // autoLoad |
---|
229 | |
---|
230 | autoLoad: function (value) |
---|
231 | { |
---|
232 | if(value!=null) |
---|
233 | { |
---|
234 | return this.each(function() |
---|
235 | { |
---|
236 | privateMethods.setAutoLoad($(this), value); |
---|
237 | } |
---|
238 | ); |
---|
239 | } |
---|
240 | else |
---|
241 | { |
---|
242 | var options = this.data('options'); |
---|
243 | |
---|
244 | if(options) |
---|
245 | { |
---|
246 | return(options.autoLoad); |
---|
247 | } |
---|
248 | else |
---|
249 | { |
---|
250 | return(true); |
---|
251 | } |
---|
252 | } |
---|
253 | }, // autoLoad |
---|
254 | |
---|
255 | listMaxWidth: function (value) |
---|
256 | { |
---|
257 | if(value!=null) |
---|
258 | { |
---|
259 | return this.each(function() |
---|
260 | { |
---|
261 | privateMethods.setListMaxWidth($(this), value); |
---|
262 | } |
---|
263 | ); |
---|
264 | } |
---|
265 | else |
---|
266 | { |
---|
267 | var options = this.data('options'); |
---|
268 | |
---|
269 | if(options) |
---|
270 | { |
---|
271 | return(options.listMaxWidth); |
---|
272 | } |
---|
273 | else |
---|
274 | { |
---|
275 | return(0); |
---|
276 | } |
---|
277 | } |
---|
278 | }, // listMaxWidth |
---|
279 | |
---|
280 | listMaxHeight: function (value) |
---|
281 | { |
---|
282 | if(value!=null) |
---|
283 | { |
---|
284 | return this.each(function() |
---|
285 | { |
---|
286 | privateMethods.setListMaxHeight($(this), value); |
---|
287 | } |
---|
288 | ); |
---|
289 | } |
---|
290 | else |
---|
291 | { |
---|
292 | var options = this.data('options'); |
---|
293 | |
---|
294 | if(options) |
---|
295 | { |
---|
296 | return(options.listMaxHeight); |
---|
297 | } |
---|
298 | else |
---|
299 | { |
---|
300 | return(0); |
---|
301 | } |
---|
302 | } |
---|
303 | }, // listMaxHeight |
---|
304 | |
---|
305 | serverUrl: function (value) |
---|
306 | { |
---|
307 | if(value!=null) |
---|
308 | { |
---|
309 | return this.each(function() |
---|
310 | { |
---|
311 | privateMethods.setServerUrl($(this), value); |
---|
312 | } |
---|
313 | ); |
---|
314 | } |
---|
315 | else |
---|
316 | { |
---|
317 | var options = this.data('options'); |
---|
318 | |
---|
319 | if(options) |
---|
320 | { |
---|
321 | return(options.serverUrl); |
---|
322 | } |
---|
323 | else |
---|
324 | { |
---|
325 | return(''); |
---|
326 | } |
---|
327 | } |
---|
328 | }, // serverUrl |
---|
329 | |
---|
330 | cols: function () |
---|
331 | { |
---|
332 | var options=this.data('options'), |
---|
333 | properties=this.data('properties'); |
---|
334 | |
---|
335 | if(!options.multiple) |
---|
336 | { |
---|
337 | return(properties.items[properties.index].cols); |
---|
338 | } |
---|
339 | else |
---|
340 | { |
---|
341 | var listCols=[]; |
---|
342 | for(var i=0;i<properties.index.length;i++) |
---|
343 | { |
---|
344 | listCols.push(properties.items[properties.index[i]].cols); |
---|
345 | } |
---|
346 | return(listCols); |
---|
347 | } |
---|
348 | }, // name |
---|
349 | |
---|
350 | popupMode: function (value) |
---|
351 | { |
---|
352 | if(value!=null) |
---|
353 | { |
---|
354 | return this.each(function() |
---|
355 | { |
---|
356 | privateMethods.setPopupMode($(this), value); |
---|
357 | } |
---|
358 | ); |
---|
359 | } |
---|
360 | else |
---|
361 | { |
---|
362 | var options = this.data('options'); |
---|
363 | |
---|
364 | if(options) |
---|
365 | { |
---|
366 | return(options.popupMode); |
---|
367 | } |
---|
368 | else |
---|
369 | { |
---|
370 | return(0); |
---|
371 | } |
---|
372 | } |
---|
373 | }, // popupMode |
---|
374 | |
---|
375 | downArrow: function (value) |
---|
376 | { |
---|
377 | if(value!=null) |
---|
378 | { |
---|
379 | return this.each(function() |
---|
380 | { |
---|
381 | privateMethods.setDownArrow($(this), value); |
---|
382 | } |
---|
383 | ); |
---|
384 | } |
---|
385 | else |
---|
386 | { |
---|
387 | var options = this.data('options'); |
---|
388 | |
---|
389 | if(options) |
---|
390 | { |
---|
391 | return(options.downArrow); |
---|
392 | } |
---|
393 | else |
---|
394 | { |
---|
395 | return(''); |
---|
396 | } |
---|
397 | } |
---|
398 | }, // downArrow |
---|
399 | |
---|
400 | |
---|
401 | returnMode: function (value) |
---|
402 | { |
---|
403 | if(value!=null) |
---|
404 | { |
---|
405 | return this.each(function() |
---|
406 | { |
---|
407 | privateMethods.setReturnMode($(this), value); |
---|
408 | } |
---|
409 | ); |
---|
410 | } |
---|
411 | else |
---|
412 | { |
---|
413 | var options = this.data('options'); |
---|
414 | |
---|
415 | if(options) |
---|
416 | { |
---|
417 | return(options.returnMode); |
---|
418 | } |
---|
419 | else |
---|
420 | { |
---|
421 | return('selected'); |
---|
422 | } |
---|
423 | } |
---|
424 | }, // returnMode |
---|
425 | |
---|
426 | colsWidth: function (value) |
---|
427 | { |
---|
428 | if(value!=null) |
---|
429 | { |
---|
430 | return this.each(function() |
---|
431 | { |
---|
432 | privateMethods.setColsWidth($(this), value); |
---|
433 | } |
---|
434 | ); |
---|
435 | } |
---|
436 | else |
---|
437 | { |
---|
438 | var options = this.data('options'); |
---|
439 | |
---|
440 | if(options) |
---|
441 | { |
---|
442 | return(options.colsWidth); |
---|
443 | } |
---|
444 | else |
---|
445 | { |
---|
446 | return(''); |
---|
447 | } |
---|
448 | } |
---|
449 | }, // colsWidth |
---|
450 | |
---|
451 | colsDisplayed: function (value) |
---|
452 | { |
---|
453 | if(value!=null) |
---|
454 | { |
---|
455 | return this.each(function() |
---|
456 | { |
---|
457 | privateMethods.setColsDisplayed($(this), value); |
---|
458 | } |
---|
459 | ); |
---|
460 | } |
---|
461 | else |
---|
462 | { |
---|
463 | var options = this.data('options'); |
---|
464 | |
---|
465 | if(options) |
---|
466 | { |
---|
467 | return(options.colsDisplayed); |
---|
468 | } |
---|
469 | else |
---|
470 | { |
---|
471 | return(''); |
---|
472 | } |
---|
473 | } |
---|
474 | }, // colsDisplayed |
---|
475 | |
---|
476 | colsCss: function (value) |
---|
477 | { |
---|
478 | if(value!=null) |
---|
479 | { |
---|
480 | return this.each(function() |
---|
481 | { |
---|
482 | privateMethods.setColsCss($(this), value); |
---|
483 | } |
---|
484 | ); |
---|
485 | } |
---|
486 | else |
---|
487 | { |
---|
488 | var options = this.data('options'); |
---|
489 | |
---|
490 | if(options) |
---|
491 | { |
---|
492 | return(options.colsCss); |
---|
493 | } |
---|
494 | else |
---|
495 | { |
---|
496 | return(''); |
---|
497 | } |
---|
498 | } |
---|
499 | }, // colsCss |
---|
500 | |
---|
501 | |
---|
502 | items: function (value) |
---|
503 | { |
---|
504 | if(value!=null) |
---|
505 | { |
---|
506 | return this.each(function() |
---|
507 | { |
---|
508 | privateMethods.setItems($(this), value); |
---|
509 | } |
---|
510 | ); |
---|
511 | } |
---|
512 | else |
---|
513 | { |
---|
514 | var properties = this.data('properties'); |
---|
515 | |
---|
516 | if(properties) |
---|
517 | { |
---|
518 | return(properties.items); |
---|
519 | } |
---|
520 | else |
---|
521 | { |
---|
522 | return(''); |
---|
523 | } |
---|
524 | } |
---|
525 | }, //items |
---|
526 | |
---|
527 | value: function (value) |
---|
528 | { |
---|
529 | if(value!=null) |
---|
530 | { |
---|
531 | // set selected value |
---|
532 | return this.each(function() |
---|
533 | { |
---|
534 | privateMethods.setValue($(this), value); |
---|
535 | } |
---|
536 | ); |
---|
537 | } |
---|
538 | else |
---|
539 | { |
---|
540 | // return the selected value |
---|
541 | var properties=this.data('properties'), |
---|
542 | options = this.data('options'); |
---|
543 | |
---|
544 | if(properties && properties.index!=null && !options.multiple && properties.index>-1 && properties.index<properties.items.length) |
---|
545 | { |
---|
546 | return(properties.items[properties.index].value); |
---|
547 | } |
---|
548 | else if(properties && properties.index!=null && options.multiple) |
---|
549 | { |
---|
550 | var returned=[]; |
---|
551 | if(options.returnMode=='selected') |
---|
552 | { |
---|
553 | for(var i=0;i<properties.index.length;i++) |
---|
554 | { |
---|
555 | if(properties.index[i]>-1 && properties.index[i]<properties.items.length) |
---|
556 | returned.push(properties.items[properties.index[i]].value); |
---|
557 | } |
---|
558 | } |
---|
559 | else |
---|
560 | { |
---|
561 | for(var i=0;i<properties.items.length;i++) |
---|
562 | { |
---|
563 | if($.inArray(i, properties.index)==-1) |
---|
564 | returned.push(properties.items[i].value); |
---|
565 | } |
---|
566 | } |
---|
567 | return(returned); |
---|
568 | } |
---|
569 | else |
---|
570 | { |
---|
571 | return(null); |
---|
572 | } |
---|
573 | } |
---|
574 | }, // value |
---|
575 | |
---|
576 | isValid: function (value) |
---|
577 | { |
---|
578 | if(value!=null) |
---|
579 | { |
---|
580 | // set selected value |
---|
581 | return this.each(function() |
---|
582 | { |
---|
583 | privateMethods.setIsValid($(this), value); |
---|
584 | } |
---|
585 | ); |
---|
586 | } |
---|
587 | else |
---|
588 | { |
---|
589 | // return the selected tags |
---|
590 | var properties=this.data('properties'); |
---|
591 | return(properties.isValid); |
---|
592 | } |
---|
593 | }, // isValid |
---|
594 | |
---|
595 | load: function (value) |
---|
596 | { |
---|
597 | /* |
---|
598 | * two functionnalities : |
---|
599 | * - if value is set, use it to set the load event function |
---|
600 | * - if no value, loads data from server |
---|
601 | */ |
---|
602 | if(value && $.isFunction(value)) |
---|
603 | { |
---|
604 | // set selected value |
---|
605 | return this.each(function() |
---|
606 | { |
---|
607 | privateMethods.setEventLoad($(this), value); |
---|
608 | } |
---|
609 | ); |
---|
610 | } |
---|
611 | else |
---|
612 | { |
---|
613 | // loads data from server |
---|
614 | privateMethods.load(this); |
---|
615 | } |
---|
616 | }, |
---|
617 | |
---|
618 | popup: function (value) |
---|
619 | { |
---|
620 | if(value && $.isFunction(value)) |
---|
621 | { |
---|
622 | // set selected value |
---|
623 | return this.each(function() |
---|
624 | { |
---|
625 | privateMethods.setEventPopup($(this), value); |
---|
626 | } |
---|
627 | ); |
---|
628 | } |
---|
629 | else |
---|
630 | { |
---|
631 | // return the selected value |
---|
632 | var options=this.data('options'); |
---|
633 | |
---|
634 | if(options) |
---|
635 | { |
---|
636 | return(options.popup); |
---|
637 | } |
---|
638 | else |
---|
639 | { |
---|
640 | return(null); |
---|
641 | } |
---|
642 | } |
---|
643 | }, // popup |
---|
644 | |
---|
645 | change: function (value) |
---|
646 | { |
---|
647 | if(value && $.isFunction(value)) |
---|
648 | { |
---|
649 | // set selected value |
---|
650 | return this.each(function() |
---|
651 | { |
---|
652 | privateMethods.setEventChange($(this), value); |
---|
653 | } |
---|
654 | ); |
---|
655 | } |
---|
656 | else |
---|
657 | { |
---|
658 | // return the selected value |
---|
659 | var options=this.data('options'); |
---|
660 | |
---|
661 | if(options) |
---|
662 | { |
---|
663 | return(options.change); |
---|
664 | } |
---|
665 | else |
---|
666 | { |
---|
667 | return(null); |
---|
668 | } |
---|
669 | } |
---|
670 | }, // popup |
---|
671 | |
---|
672 | numberOfItems: function () |
---|
673 | { |
---|
674 | var properties=this.data('properties'); |
---|
675 | |
---|
676 | if(properties) |
---|
677 | { |
---|
678 | return(properties.items.length); |
---|
679 | } |
---|
680 | else |
---|
681 | { |
---|
682 | return(null); |
---|
683 | } |
---|
684 | }, // numberOfItems |
---|
685 | |
---|
686 | properties: function (value) |
---|
687 | { |
---|
688 | var properties=this.data('properties'), |
---|
689 | options=this.data('options'); |
---|
690 | |
---|
691 | if(properties && value==':first' && properties.items.length>0) |
---|
692 | { |
---|
693 | return(properties.items[0]); |
---|
694 | } |
---|
695 | else if(properties && properties.index!=null && (value==':selected' || value==null) && properties.items.length>0) |
---|
696 | { |
---|
697 | if(!options.multiple && properties.index>-1 && properties.index<properties.items.length) |
---|
698 | { |
---|
699 | return(properties.items[properties.index]); |
---|
700 | } |
---|
701 | else if(options.multiple) |
---|
702 | { |
---|
703 | var returned=[]; |
---|
704 | for(var i=0;i<properties.index.length;i++) |
---|
705 | { |
---|
706 | if(properties.index[i]>-1 && properties.index<properties.items.length) |
---|
707 | returned.push(properties.items[properties.index[i]]); |
---|
708 | } |
---|
709 | return(returned); |
---|
710 | } |
---|
711 | return(null); |
---|
712 | } |
---|
713 | else if(properties && value!=null) |
---|
714 | { |
---|
715 | var index=privateMethods.findIndexByValue(this, value); |
---|
716 | if(index>-1) |
---|
717 | { |
---|
718 | return(properties.items[index]); |
---|
719 | } |
---|
720 | return(null); |
---|
721 | } |
---|
722 | else |
---|
723 | { |
---|
724 | return(null); |
---|
725 | } |
---|
726 | } // properties |
---|
727 | }; // methods |
---|
728 | |
---|
729 | |
---|
730 | /* |
---|
731 | * plugin 'private' methods |
---|
732 | */ |
---|
733 | var privateMethods = |
---|
734 | { |
---|
735 | setOptions : function (object, value) |
---|
736 | { |
---|
737 | var properties=object.data('properties'), |
---|
738 | options=object.data('options'); |
---|
739 | |
---|
740 | if(!$.isPlainObject(value)) return(false); |
---|
741 | |
---|
742 | properties.initialized=false; |
---|
743 | |
---|
744 | privateMethods.setReturnMode(object, (value.returnMode!=null)?value.returnMode:options.returnMode); |
---|
745 | privateMethods.setAutoLoad(object, (value.autoLoad!=null)?value.autoLoad:options.autoLoad); |
---|
746 | privateMethods.setListMaxWidth(object, (value.listMaxWidth!=null)?value.listMaxWidth:options.listMaxWidth); |
---|
747 | privateMethods.setListMaxHeight(object, (value.listMaxHeight!=null)?value.listMaxHeight:options.listMaxHeight); |
---|
748 | privateMethods.setServerUrl(object, (value.serverUrl!=null)?value.serverUrl:options.serverUrl); |
---|
749 | privateMethods.setPopupMode(object, (value.popupMode!=null)?value.popupMode:options.popupMode); |
---|
750 | privateMethods.setDownArrow(object, (value.downArrow!=null)?value.downArrow:options.downArrow); |
---|
751 | privateMethods.setEventPopup(object, (value.popup!=null)?value.popup:options.popup); |
---|
752 | privateMethods.setEventChange(object, (value.change!=null)?value.change:options.change); |
---|
753 | privateMethods.setEventLoad(object, (value.load!=null)?value.load:options.load); |
---|
754 | privateMethods.setColsWidth(object, (value.colsWidth!=null)?value.colsWidth:options.colsWidth); |
---|
755 | privateMethods.setColsDisplayed(object, (value.colsDisplayed!=null)?value.colsDisplayed:options.colsDisplayed); |
---|
756 | privateMethods.setColsCss(object, (value.colsCss!=null)?value.colsCss:options.colsCss); |
---|
757 | privateMethods.setItems(object, (value.items!=null)?value.items:options.items); |
---|
758 | privateMethods.setMultiple(object, (value.multiple!=null)?value.multiple:options.multiple); // can be set only at the initialization |
---|
759 | |
---|
760 | if(options.autoLoad) privateMethods.load(object); |
---|
761 | |
---|
762 | properties.initialized=true; |
---|
763 | }, |
---|
764 | |
---|
765 | setIsValid : function (object, value) |
---|
766 | { |
---|
767 | var objects=object.data('objects'), |
---|
768 | properties=object.data('properties'); |
---|
769 | |
---|
770 | if(properties.isValid!=value) |
---|
771 | { |
---|
772 | properties.isValid=value; |
---|
773 | if(properties.isValid) |
---|
774 | { |
---|
775 | objects.container.removeClass('ui-error'); |
---|
776 | } |
---|
777 | else |
---|
778 | { |
---|
779 | objects.container.addClass('ui-error'); |
---|
780 | } |
---|
781 | } |
---|
782 | return(properties.isValid); |
---|
783 | }, |
---|
784 | |
---|
785 | setAutoLoad : function (object, value) |
---|
786 | { |
---|
787 | var options=object.data('options'), |
---|
788 | properties=object.data('properties'); |
---|
789 | |
---|
790 | if((!properties.initialized || options.autoLoad!=value) && (value==true || value==false)) |
---|
791 | { |
---|
792 | options.autoLoad=value; |
---|
793 | } |
---|
794 | return(options.autoLoad); |
---|
795 | }, |
---|
796 | |
---|
797 | setReturnMode : function (object, value) |
---|
798 | { |
---|
799 | var options=object.data('options'), |
---|
800 | properties=object.data('properties'); |
---|
801 | |
---|
802 | if((!properties.initialized || options.returnMode!=value) && (value=='selected' || value=='notSelected')) |
---|
803 | { |
---|
804 | options.returnMode=value; |
---|
805 | } |
---|
806 | return(options.returnMode); |
---|
807 | }, |
---|
808 | |
---|
809 | setColsWidth : function (object, value) |
---|
810 | { |
---|
811 | var options=object.data('options'), |
---|
812 | properties=object.data('properties'), |
---|
813 | width=0; |
---|
814 | |
---|
815 | if((!properties.initialized || options.colsWidth!=value) && $.isArray(value)) |
---|
816 | { |
---|
817 | options.colsWidth=value; |
---|
818 | } |
---|
819 | return(options.colsWidth); |
---|
820 | }, |
---|
821 | |
---|
822 | setColsDisplayed : function (object, value) |
---|
823 | { |
---|
824 | var options=object.data('options'), |
---|
825 | properties=object.data('properties'); |
---|
826 | |
---|
827 | if((!properties.initialized || options.colsDisplayed!=value) && $.isArray(value)) |
---|
828 | { |
---|
829 | options.colsDisplayed=value; |
---|
830 | } |
---|
831 | return(options.colsDisplayed); |
---|
832 | }, |
---|
833 | |
---|
834 | setColsCss : function (object, value) |
---|
835 | { |
---|
836 | var options=object.data('options'), |
---|
837 | properties=object.data('properties'); |
---|
838 | |
---|
839 | if((!properties.initialized || options.colsCss!=value) && $.isArray(value)) |
---|
840 | { |
---|
841 | options.colsCss=value; |
---|
842 | } |
---|
843 | return(options.colsCss); |
---|
844 | }, |
---|
845 | |
---|
846 | setListMaxWidth : function (object, value) |
---|
847 | { |
---|
848 | var options=object.data('options'), |
---|
849 | properties=object.data('properties'), |
---|
850 | objects=object.data('objects'); |
---|
851 | |
---|
852 | if((!properties.initialized || options.listMaxWidth!=value) && value>=0) |
---|
853 | { |
---|
854 | options.listMaxWidth=value; |
---|
855 | if(options.listMaxWidth>0) |
---|
856 | { |
---|
857 | objects.listContainer.css('max-width', options.listMaxWidth+'px'); |
---|
858 | } |
---|
859 | else |
---|
860 | { |
---|
861 | objects.listContainer.css('max-width', ''); |
---|
862 | } |
---|
863 | } |
---|
864 | return(options.listMaxWidth); |
---|
865 | }, |
---|
866 | |
---|
867 | setListMaxHeight : function (object, value) |
---|
868 | { |
---|
869 | var options=object.data('options'), |
---|
870 | properties=object.data('properties'), |
---|
871 | objects=object.data('objects'); |
---|
872 | |
---|
873 | if((!properties.initialized || options.listMaxHeight!=value) && value>=0) |
---|
874 | { |
---|
875 | options.listMaxHeight=value; |
---|
876 | if(options.listMaxHeight>0) |
---|
877 | { |
---|
878 | objects.listContainer.css('max-height', options.listMaxHeight+'px'); |
---|
879 | } |
---|
880 | else |
---|
881 | { |
---|
882 | objects.listContainer.css('max-height', ''); |
---|
883 | } |
---|
884 | } |
---|
885 | return(options.listMaxHeight); |
---|
886 | }, |
---|
887 | |
---|
888 | setServerUrl : function (object, value) |
---|
889 | { |
---|
890 | var options=object.data('options'), |
---|
891 | properties=object.data('properties'); |
---|
892 | |
---|
893 | if(!properties.initialized || options.serverUrl!=value) |
---|
894 | { |
---|
895 | options.serverUrl=value; |
---|
896 | if(options.autoLoad && properties.initialized) privateMethods.load(object); |
---|
897 | } |
---|
898 | return(options.serverUrl); |
---|
899 | }, |
---|
900 | |
---|
901 | setMultiple : function (object, value) |
---|
902 | { |
---|
903 | var options=object.data('options'), |
---|
904 | properties=object.data('properties'), |
---|
905 | objects=object.data('objects'); |
---|
906 | |
---|
907 | if((!properties.initialized || options.multiple!=value) && (value==true || value==false)) |
---|
908 | { |
---|
909 | if(!value) |
---|
910 | { |
---|
911 | properties.index=-1; |
---|
912 | if(objects.containerList!=null) |
---|
913 | { |
---|
914 | objects.containerList.remove(); |
---|
915 | objects.containerList=null; |
---|
916 | } |
---|
917 | } |
---|
918 | else |
---|
919 | { |
---|
920 | properties.index=[]; |
---|
921 | objects.listContainer.addClass('ui-inputList-multiple'); |
---|
922 | if(objects.containerList==null) |
---|
923 | { |
---|
924 | objects.containerList=$('<ul/>', |
---|
925 | { |
---|
926 | html:'<li> </li>' |
---|
927 | } |
---|
928 | ); |
---|
929 | objects.containerValue.html('').append(objects.containerList); |
---|
930 | } |
---|
931 | } |
---|
932 | options.multiple=value; |
---|
933 | } |
---|
934 | return(options.multiple); |
---|
935 | }, //setMultiple |
---|
936 | |
---|
937 | setPopupMode : function (object, value) |
---|
938 | { |
---|
939 | var options=object.data('options'), |
---|
940 | properties=object.data('properties'), |
---|
941 | objects=object.data('objects'); |
---|
942 | |
---|
943 | if((!properties.initialized || options.popupMode!=value) && (value=='click' || value=='mouseout')) |
---|
944 | { |
---|
945 | options.popupMode=value; |
---|
946 | |
---|
947 | if(value=='mouseout') |
---|
948 | { |
---|
949 | objects.listContainer |
---|
950 | .unbind('mouseleave.inputList') |
---|
951 | .unbind('mouseenter.inputList') |
---|
952 | .bind('mouseleave.inputList', |
---|
953 | function () |
---|
954 | { |
---|
955 | privateMethods.displaySelector(object, false); |
---|
956 | } |
---|
957 | ); |
---|
958 | } |
---|
959 | else |
---|
960 | { |
---|
961 | objects.listContainer |
---|
962 | .unbind('mouseleave.inputList') |
---|
963 | .bind('mouseleave.inputList', |
---|
964 | function () |
---|
965 | { |
---|
966 | properties.mouseOver=false; |
---|
967 | } |
---|
968 | ) |
---|
969 | .bind('mouseenter.inputList', |
---|
970 | function () |
---|
971 | { |
---|
972 | properties.mouseOver=true; |
---|
973 | } |
---|
974 | ); |
---|
975 | $(document).bind('focusout focusin', |
---|
976 | function (event) |
---|
977 | { |
---|
978 | if(!properties.mouseOver) privateMethods.displaySelector(object, false); |
---|
979 | event.stopPropagation(); |
---|
980 | } |
---|
981 | ); |
---|
982 | } |
---|
983 | } |
---|
984 | return(options.popupMode); |
---|
985 | }, //setPopupMode |
---|
986 | |
---|
987 | setDownArrow : function (object, value) |
---|
988 | { |
---|
989 | var options=object.data('options'), |
---|
990 | properties=object.data('properties'), |
---|
991 | objects=object.data('objects'); |
---|
992 | |
---|
993 | if(!properties.initialized || options.downArrow!=value) |
---|
994 | { |
---|
995 | options.downArrow=value; |
---|
996 | objects.containerArrow.html(options.downArrow); |
---|
997 | } |
---|
998 | return(options.downArrow); |
---|
999 | }, //setDownArrow |
---|
1000 | |
---|
1001 | setItems : function (object, value) |
---|
1002 | { |
---|
1003 | var properties=object.data('properties'); |
---|
1004 | |
---|
1005 | if(value=='' || value==null) |
---|
1006 | { |
---|
1007 | value=[]; |
---|
1008 | } |
---|
1009 | else if(!$.isArray(value)) |
---|
1010 | { |
---|
1011 | try |
---|
1012 | { |
---|
1013 | value=$.parseJSON($.trim(value)); |
---|
1014 | } |
---|
1015 | catch (e) |
---|
1016 | { |
---|
1017 | return(false); |
---|
1018 | } |
---|
1019 | } |
---|
1020 | |
---|
1021 | privateMethods.listClear(object); |
---|
1022 | if(value.length>0) privateMethods.listAddItems(object, value); |
---|
1023 | }, |
---|
1024 | |
---|
1025 | |
---|
1026 | setValue : function (object, value, trigger) |
---|
1027 | { |
---|
1028 | var options=object.data('options'), |
---|
1029 | properties=object.data('properties'), |
---|
1030 | objects=object.data('objects'), |
---|
1031 | index=-1; |
---|
1032 | |
---|
1033 | re=/^(:invert|:all|:none)(?:(=|<|>)(\d+))$/i; |
---|
1034 | target=re.exec(value); |
---|
1035 | if(target!=null) value=target[1]; |
---|
1036 | |
---|
1037 | switch(value) |
---|
1038 | { |
---|
1039 | case ':first': |
---|
1040 | if(properties.items.length>0) index=0; |
---|
1041 | break; |
---|
1042 | case ':last': |
---|
1043 | index=properties.items.length-1; |
---|
1044 | break; |
---|
1045 | case ':invert': |
---|
1046 | if(!options.multiple) return(false); |
---|
1047 | properties.index=[]; |
---|
1048 | objects.list.find('.ui-inputList-item').each( |
---|
1049 | function () |
---|
1050 | { |
---|
1051 | var $this=$(this), |
---|
1052 | apply=true; |
---|
1053 | |
---|
1054 | if(target!=null) |
---|
1055 | { |
---|
1056 | switch(target[2]) |
---|
1057 | { |
---|
1058 | case '=': |
---|
1059 | apply=($this.attr('level')==target[3]); |
---|
1060 | break; |
---|
1061 | case '>': |
---|
1062 | apply=($this.attr('level')>=target[3]); |
---|
1063 | break; |
---|
1064 | case '<': |
---|
1065 | apply=($this.attr('level')<=target[3]); |
---|
1066 | break; |
---|
1067 | } |
---|
1068 | } |
---|
1069 | |
---|
1070 | if(apply) |
---|
1071 | { |
---|
1072 | if($this.hasClass('ui-inputList-selected-item')) |
---|
1073 | { |
---|
1074 | $this.removeClass('ui-inputList-selected-item'); |
---|
1075 | } |
---|
1076 | else |
---|
1077 | { |
---|
1078 | $this.addClass('ui-inputList-selected-item'); |
---|
1079 | tmp=privateMethods.findIndexByValue(object, $this.attr('idvalue')); |
---|
1080 | if(tmp>-1) properties.index.push(tmp); |
---|
1081 | } |
---|
1082 | } |
---|
1083 | } |
---|
1084 | ); |
---|
1085 | privateMethods.setValue(object, [], false); |
---|
1086 | return(false); |
---|
1087 | break; |
---|
1088 | case ':none': |
---|
1089 | if(!options.multiple) return(false); |
---|
1090 | |
---|
1091 | properties.index=[]; |
---|
1092 | objects.list.find('.ui-inputList-selected-item').each( |
---|
1093 | function () |
---|
1094 | { |
---|
1095 | var $this=$(this), |
---|
1096 | apply=true; |
---|
1097 | |
---|
1098 | if(target!=null) |
---|
1099 | { |
---|
1100 | switch(target[2]) |
---|
1101 | { |
---|
1102 | case '=': |
---|
1103 | apply=($this.attr('level')==target[3]); |
---|
1104 | break; |
---|
1105 | case '>': |
---|
1106 | apply=($this.attr('level')>=target[3]); |
---|
1107 | break; |
---|
1108 | case '<': |
---|
1109 | apply=($this.attr('level')<=target[3]); |
---|
1110 | break; |
---|
1111 | } |
---|
1112 | } |
---|
1113 | |
---|
1114 | if(apply) $this.removeClass('ui-inputList-selected-item'); |
---|
1115 | } |
---|
1116 | ); |
---|
1117 | privateMethods.setValue(object, [], false); |
---|
1118 | return(false); |
---|
1119 | break; |
---|
1120 | case ':all': |
---|
1121 | if(!options.multiple) return(false); |
---|
1122 | properties.index=[]; |
---|
1123 | objects.list.find('.ui-inputList-item').each( |
---|
1124 | function () |
---|
1125 | { |
---|
1126 | var $this=$(this), |
---|
1127 | apply=true; |
---|
1128 | |
---|
1129 | if(target!=null) |
---|
1130 | { |
---|
1131 | switch(target[2]) |
---|
1132 | { |
---|
1133 | case '=': |
---|
1134 | apply=($this.attr('level')==target[3]); |
---|
1135 | break; |
---|
1136 | case '>': |
---|
1137 | apply=($this.attr('level')>=target[3]); |
---|
1138 | break; |
---|
1139 | case '<': |
---|
1140 | apply=($this.attr('level')<=target[3]); |
---|
1141 | break; |
---|
1142 | } |
---|
1143 | } |
---|
1144 | if(apply) |
---|
1145 | { |
---|
1146 | tmp=privateMethods.findIndexByValue(object, $this.attr('idvalue')); |
---|
1147 | if(tmp>-1) properties.index.push(tmp); |
---|
1148 | |
---|
1149 | $this.addClass('ui-inputList-selected-item'); |
---|
1150 | } |
---|
1151 | } |
---|
1152 | ); |
---|
1153 | privateMethods.setValue(object, [], false); |
---|
1154 | return(false); |
---|
1155 | break; |
---|
1156 | default: |
---|
1157 | if($.isArray(value) && options.multiple) |
---|
1158 | { |
---|
1159 | index=[]; |
---|
1160 | for(var i=0;i<value.length;i++) |
---|
1161 | { |
---|
1162 | tmp=privateMethods.findIndexByValue(object, value[i]); |
---|
1163 | if(tmp>-1) index.push(tmp); |
---|
1164 | } |
---|
1165 | } |
---|
1166 | else |
---|
1167 | { |
---|
1168 | index=privateMethods.findIndexByValue(object, value); |
---|
1169 | } |
---|
1170 | |
---|
1171 | break; |
---|
1172 | } |
---|
1173 | |
---|
1174 | if(!options.multiple && (!properties.initialized || properties.index!=index) && index>-1) |
---|
1175 | { |
---|
1176 | objects.list.find('.ui-inputList-selected-item').removeClass('ui-inputList-selected-item'); |
---|
1177 | objects.list.find('[idvalue="'+value+'"]').addClass('ui-inputList-selected-item'); |
---|
1178 | properties.index=index; |
---|
1179 | |
---|
1180 | privateMethods.setItemContent(object, index, objects.containerValue); |
---|
1181 | if(trigger) object.trigger('inputListChange', [properties.items[properties.index].value]); |
---|
1182 | if(properties.index>-1) return(properties.items[properties.index].value); |
---|
1183 | } |
---|
1184 | else if(options.multiple) |
---|
1185 | { |
---|
1186 | if(!$.isArray(index)) |
---|
1187 | { |
---|
1188 | if(index<0 || index==null) return(-1); |
---|
1189 | index=[index]; |
---|
1190 | } |
---|
1191 | tmp=[]; |
---|
1192 | for(var i=0;i<index.length;i++) |
---|
1193 | { |
---|
1194 | var item=objects.list.find('[idvalue="'+properties.items[index[i]].value+'"]'); |
---|
1195 | tmp.push(properties.items[index[i]].value); |
---|
1196 | if(item.hasClass('ui-inputList-selected-item')) |
---|
1197 | { |
---|
1198 | item.removeClass('ui-inputList-selected-item'); |
---|
1199 | |
---|
1200 | tmpIndex=$.inArray(index[i] ,properties.index); |
---|
1201 | if(tmpIndex>-1) properties.index.splice(tmpIndex, 1); |
---|
1202 | } |
---|
1203 | else |
---|
1204 | { |
---|
1205 | item.addClass('ui-inputList-selected-item'); |
---|
1206 | properties.index.push(index[i]); |
---|
1207 | } |
---|
1208 | } |
---|
1209 | objects.containerList.html(''); |
---|
1210 | objects.list.children('.ui-inputList-selected-item').each( |
---|
1211 | function () |
---|
1212 | { |
---|
1213 | var value=$(this).attr('idvalue'), |
---|
1214 | index=privateMethods.findIndexByValue(object, value), |
---|
1215 | li=$('<li/>', |
---|
1216 | { |
---|
1217 | 'class':'ui-inputList-selected-item' |
---|
1218 | } |
---|
1219 | ); |
---|
1220 | privateMethods.setItemContent(object, index, li); |
---|
1221 | objects.containerList.append( |
---|
1222 | li.prepend( |
---|
1223 | $('<span/>', |
---|
1224 | { |
---|
1225 | 'html':'x', |
---|
1226 | 'class':'ui-inputList-delete-item' |
---|
1227 | } |
---|
1228 | ).bind('click.inputList', |
---|
1229 | {object:object, value:value}, |
---|
1230 | function (event) |
---|
1231 | { |
---|
1232 | event.stopPropagation(); |
---|
1233 | privateMethods.setValue(event.data.object, event.data.value, true); |
---|
1234 | } |
---|
1235 | ) |
---|
1236 | ) |
---|
1237 | ); |
---|
1238 | } |
---|
1239 | ); |
---|
1240 | |
---|
1241 | if(objects.containerList.children().length==0) objects.containerList.append('<li> </li>'); |
---|
1242 | |
---|
1243 | if(trigger) object.trigger('inputListChange', [tmp]); |
---|
1244 | return(tmp); |
---|
1245 | } |
---|
1246 | return(null); |
---|
1247 | }, |
---|
1248 | |
---|
1249 | displaySelector : function (object, value) |
---|
1250 | { |
---|
1251 | var options=object.data('options'), |
---|
1252 | properties=object.data('properties'), |
---|
1253 | objects=object.data('objects'), |
---|
1254 | scrollBarWidth=0; |
---|
1255 | |
---|
1256 | if(properties.selectorVisible!=value) |
---|
1257 | { |
---|
1258 | properties.selectorVisible=value; |
---|
1259 | |
---|
1260 | if(properties.selectorVisible && properties.items.length>0) |
---|
1261 | { |
---|
1262 | var index=0; |
---|
1263 | objects.listContainer |
---|
1264 | .css( |
---|
1265 | { |
---|
1266 | display:'block', |
---|
1267 | 'min-width':objects.listContainer.parent().css('width') |
---|
1268 | } |
---|
1269 | ); |
---|
1270 | |
---|
1271 | if($.isArray(properties.index)) |
---|
1272 | { |
---|
1273 | if (properties.index.length>0) index=properties.index[0]; |
---|
1274 | } |
---|
1275 | else if(properties.index>-1) |
---|
1276 | { |
---|
1277 | index=properties.index; |
---|
1278 | } |
---|
1279 | |
---|
1280 | scrollBarWidth=objects.listContainer.width()-objects.list.width(); |
---|
1281 | if(scrollBarWidth>0 && properties.firstPopup) |
---|
1282 | { |
---|
1283 | objects.listContainer.width(objects.listContainer.width()+scrollBarWidth); |
---|
1284 | properties.firstPopup=false; |
---|
1285 | } |
---|
1286 | |
---|
1287 | objects.listContainer.scrollTop(objects.listContainer.scrollTop()+objects.list.find('[idValue="'+properties.items[index].value+'"]').position().top); |
---|
1288 | } |
---|
1289 | else |
---|
1290 | { |
---|
1291 | objects.listContainer.css('display', 'none'); |
---|
1292 | } |
---|
1293 | if(options.popup) object.trigger('inputListPopup', [properties.selectorVisible]); |
---|
1294 | } |
---|
1295 | return(properties.selectorVisible); |
---|
1296 | }, |
---|
1297 | |
---|
1298 | load : function (object) |
---|
1299 | { |
---|
1300 | // load datas from server through an asynchronous ajax call |
---|
1301 | var options=object.data('options'), |
---|
1302 | properties=object.data('properties'), |
---|
1303 | objects=object.data('objects'); |
---|
1304 | |
---|
1305 | if(options.serverUrl=='') return(false); |
---|
1306 | |
---|
1307 | $.ajax( |
---|
1308 | { |
---|
1309 | type: "POST", |
---|
1310 | url: options.serverUrl, |
---|
1311 | async: true, |
---|
1312 | success: function(msg) |
---|
1313 | { |
---|
1314 | privateMethods.setItems(object, msg); |
---|
1315 | |
---|
1316 | properties.initialized=false; |
---|
1317 | if(options.multiple) |
---|
1318 | { |
---|
1319 | privateMethods.setValue(object, ':none'); |
---|
1320 | } |
---|
1321 | else |
---|
1322 | { |
---|
1323 | privateMethods.setValue(object, ':first'); |
---|
1324 | } |
---|
1325 | properties.initialized=true; |
---|
1326 | |
---|
1327 | if(options.load) object.trigger('inputListLoad'); |
---|
1328 | }, |
---|
1329 | error: function(msg) |
---|
1330 | { |
---|
1331 | objects.listContainer.html('Error ! '+msg); |
---|
1332 | } |
---|
1333 | } |
---|
1334 | ); |
---|
1335 | }, |
---|
1336 | |
---|
1337 | listClear : function (object) |
---|
1338 | { |
---|
1339 | // clear the items list |
---|
1340 | var objects=object.data('objects'), |
---|
1341 | options=object.data('options'), |
---|
1342 | properties=object.data('properties'); |
---|
1343 | |
---|
1344 | objects.list.children().unbind(); |
---|
1345 | objects.list.html(''); |
---|
1346 | if(options.multiple) |
---|
1347 | { |
---|
1348 | properties.index=[]; |
---|
1349 | } |
---|
1350 | else |
---|
1351 | { |
---|
1352 | properties.index=-1; |
---|
1353 | } |
---|
1354 | properties.items=[]; |
---|
1355 | properties.firstPopup=true; |
---|
1356 | }, |
---|
1357 | |
---|
1358 | listAddItems : function (object, listItems) |
---|
1359 | { |
---|
1360 | // add the items to the items list |
---|
1361 | var options=object.data('options'), |
---|
1362 | properties=object.data('properties'), |
---|
1363 | objects=object.data('objects'), |
---|
1364 | width=0; |
---|
1365 | |
---|
1366 | for(var i=0;i<listItems.length;i++) |
---|
1367 | { |
---|
1368 | properties.items.push( |
---|
1369 | { |
---|
1370 | value:listItems[i].value, |
---|
1371 | cols:listItems[i].cols |
---|
1372 | } |
---|
1373 | ); |
---|
1374 | |
---|
1375 | var content=$('<div/>', |
---|
1376 | { |
---|
1377 | 'class':'ui-inputList-value' |
---|
1378 | } |
---|
1379 | ), |
---|
1380 | li=$('<li/>', |
---|
1381 | { |
---|
1382 | 'class':'ui-inputList-item', |
---|
1383 | 'idValue':listItems[i].value |
---|
1384 | } |
---|
1385 | ).bind('click.inputList', |
---|
1386 | {object:object}, |
---|
1387 | function (event) |
---|
1388 | { |
---|
1389 | privateMethods.setValue(event.data.object, $(this).attr('idValue'), true); |
---|
1390 | if(options.multiple) |
---|
1391 | { |
---|
1392 | } |
---|
1393 | else |
---|
1394 | { |
---|
1395 | privateMethods.displaySelector(event.data.object, false); |
---|
1396 | } |
---|
1397 | |
---|
1398 | if(options.multiple) objects.container.focus(); |
---|
1399 | } |
---|
1400 | ); |
---|
1401 | |
---|
1402 | for(var j=0;j<listItems[i].cols.length;j++) |
---|
1403 | { |
---|
1404 | content.append($('<span/>', |
---|
1405 | { |
---|
1406 | html:listItems[i].cols[j], |
---|
1407 | css: |
---|
1408 | { |
---|
1409 | width:privateMethods.getColWidth(object, j) |
---|
1410 | }, |
---|
1411 | 'class':privateMethods.getColCss(object, j) |
---|
1412 | } |
---|
1413 | ) |
---|
1414 | ); |
---|
1415 | } |
---|
1416 | |
---|
1417 | li.append(content); |
---|
1418 | if(options.multiple) |
---|
1419 | { |
---|
1420 | li.children().prepend('<div class="ui-inputList-check"></div>'); |
---|
1421 | } |
---|
1422 | objects.list.append(li); |
---|
1423 | } |
---|
1424 | }, |
---|
1425 | |
---|
1426 | findIndexByValue : function (object, value) |
---|
1427 | { |
---|
1428 | /* |
---|
1429 | * search an item inside the item list and return the index |
---|
1430 | * in the array |
---|
1431 | */ |
---|
1432 | var properties=object.data('properties'); |
---|
1433 | |
---|
1434 | for(var i=0;i<properties.items.length;i++) |
---|
1435 | { |
---|
1436 | if(properties.items[i].value==value) return(i); |
---|
1437 | } |
---|
1438 | return(-1); |
---|
1439 | }, |
---|
1440 | |
---|
1441 | setEventPopup : function (object, value) |
---|
1442 | { |
---|
1443 | var options=object.data('options'); |
---|
1444 | |
---|
1445 | options.popup=value; |
---|
1446 | object.unbind('inputListPopup'); |
---|
1447 | if(value) object.bind('inputListPopup', options.popup); |
---|
1448 | return(options.popup); |
---|
1449 | }, |
---|
1450 | |
---|
1451 | setEventChange : function (object, value) |
---|
1452 | { |
---|
1453 | var options=object.data('options'); |
---|
1454 | |
---|
1455 | options.change=value; |
---|
1456 | object.unbind('inputListChange'); |
---|
1457 | if(value) object.bind('inputListChange', options.change); |
---|
1458 | return(options.change); |
---|
1459 | }, |
---|
1460 | |
---|
1461 | setEventLoad : function (object, value) |
---|
1462 | { |
---|
1463 | var options=object.data('options'); |
---|
1464 | |
---|
1465 | options.load=value; |
---|
1466 | object.unbind('inputListLoad'); |
---|
1467 | if(value) object.bind('inputListLoad', options.load); |
---|
1468 | return(options.load); |
---|
1469 | }, |
---|
1470 | |
---|
1471 | getColWidth : function (object, index) |
---|
1472 | { |
---|
1473 | var options=object.data('options'); |
---|
1474 | |
---|
1475 | if(index>=0 && index<options.colsWidth.length && options.colsWidth[index]!='' && options.colsWidth[index]!=0) |
---|
1476 | { |
---|
1477 | return(options.colsWidth[index]+'px'); |
---|
1478 | } |
---|
1479 | return(''); |
---|
1480 | }, |
---|
1481 | |
---|
1482 | getColCss : function (object, index) |
---|
1483 | { |
---|
1484 | var options=object.data('options'); |
---|
1485 | |
---|
1486 | if(index>=0 && index<options.colsCss.length) |
---|
1487 | { |
---|
1488 | return(options.colsCss[index]); |
---|
1489 | } |
---|
1490 | return(''); |
---|
1491 | }, |
---|
1492 | |
---|
1493 | getColContent : function (object, itemIndex, index) |
---|
1494 | { |
---|
1495 | var properties=object.data('properties'); |
---|
1496 | |
---|
1497 | if(index>=0 && index<=properties.items[itemIndex].cols.length) |
---|
1498 | { |
---|
1499 | return(properties.items[itemIndex].cols[index]); |
---|
1500 | } |
---|
1501 | return(''); |
---|
1502 | }, |
---|
1503 | |
---|
1504 | setItemContent : function (object, index, container) |
---|
1505 | { |
---|
1506 | var options=object.data('options'), |
---|
1507 | properties=object.data('properties'), |
---|
1508 | colContent='', |
---|
1509 | colsDisplayed=[]; |
---|
1510 | |
---|
1511 | container.html(''); |
---|
1512 | |
---|
1513 | if(options.colsDisplayed.length==0) |
---|
1514 | { |
---|
1515 | for(var j=0;j<properties.items[index].cols.length;j++) |
---|
1516 | { |
---|
1517 | colsDisplayed.push(j); |
---|
1518 | } |
---|
1519 | } |
---|
1520 | else |
---|
1521 | { |
---|
1522 | colsDisplayed=options.colsDisplayed; |
---|
1523 | } |
---|
1524 | |
---|
1525 | for(var j=0;j<colsDisplayed.length;j++) |
---|
1526 | { |
---|
1527 | colContent=privateMethods.getColContent(object, index, colsDisplayed[j]); |
---|
1528 | |
---|
1529 | if(colContent!=null) |
---|
1530 | { |
---|
1531 | container.append($('<span/>', |
---|
1532 | { |
---|
1533 | 'html':colContent, |
---|
1534 | css: |
---|
1535 | { |
---|
1536 | width:privateMethods.getColWidth(object, colsDisplayed[j]) |
---|
1537 | }, |
---|
1538 | 'class':privateMethods.getColCss(object, colsDisplayed[j]) |
---|
1539 | } |
---|
1540 | ) |
---|
1541 | ); |
---|
1542 | } |
---|
1543 | } |
---|
1544 | } |
---|
1545 | }; |
---|
1546 | |
---|
1547 | |
---|
1548 | $.fn.inputList = function(method) |
---|
1549 | { |
---|
1550 | if(publicMethods[method]) |
---|
1551 | { |
---|
1552 | return publicMethods[method].apply( this, Array.prototype.slice.call( arguments, 1 )); |
---|
1553 | } |
---|
1554 | else if(typeof method === 'object' || ! method) |
---|
1555 | { |
---|
1556 | return publicMethods.init.apply(this, arguments); |
---|
1557 | } |
---|
1558 | else |
---|
1559 | { |
---|
1560 | $.error( 'Method ' + method + ' does not exist on jQuery.inputList' ); |
---|
1561 | } |
---|
1562 | } // $.fn.inputList |
---|
1563 | |
---|
1564 | } |
---|
1565 | )(jQuery); |
---|
1566 | |
---|
1567 | |
---|