]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/Javascripts/source/prado/activecontrols/autocomplete.js
baculum: New Baculum API and Baculum Web
[bacula/bacula] / gui / baculum / framework / Web / Javascripts / source / prado / activecontrols / autocomplete.js
1 jQuery.noConflict();
2
3 /**
4  * TAutoComplete control.
5  */
6 Prado.WebUI.TAutoComplete = jQuery.klass(Autocompleter.Base, Prado.WebUI.TActiveTextBox.prototype,
7 {
8         initialize : function(options)
9         {
10                 this.options = options;
11                 this.observers = new Array();
12                 this.hasResults = false;
13                 this.baseInitialize(options.ID, options.ResultPanel, options);
14                 Object.extend(this.options,
15                 {
16                         onSuccess : this.onComplete.bind(this)
17                 });
18
19                 if(options.AutoPostBack)
20                         this.onInit(options);
21
22                 Prado.Registry[options.ID] = this;
23         },
24
25         doCallback : function(options, event)
26         {
27                 if(!this.active)
28                 {
29                         var request = new Prado.CallbackRequest(this.options.EventTarget, options);
30                         request.dispatch();
31                         event.preventDefault();
32                 }
33         },
34
35          //Overrides parent implementation, fires onchange event.
36         onClick: function(event)
37         {
38             var element = Event.findElement(event, 'LI');
39             this.index = element.autocompleteIndex;
40             this.selectEntry();
41             this.hide();
42             jQuery(this.element).trigger('change');
43         },
44
45         getUpdatedChoices : function()
46         {
47                 var options = new Array(this.getToken(),"__TAutoComplete_onSuggest__");
48                 Prado.Callback(this.options.EventTarget, options, null, this.options);
49         },
50
51         /**
52          * Overrides parent implements, don't update if no results.
53          */
54         selectEntry: function()
55         {
56                 if(this.hasResults)
57                 {
58                         this.active = false;
59                         this.updateElement(this.getCurrentEntry());
60                         var options = [this.index, "__TAutoComplete_onSuggestionSelected__"];
61                         Prado.Callback(this.options.EventTarget, options, null, this.options);
62                 }
63         },
64
65         onComplete : function(request, boundary)
66         {
67                 var result = request.extractContent(boundary);
68                 if(typeof(result) == "string")
69                 {
70                         if(result.length > 0)
71                         {
72                                 this.hasResults = true;
73                                 this.updateChoices(result);
74                         }
75                         else
76                         {
77                                 this.active = false;
78                                 this.hasResults = false;
79                                 this.hide();
80                         }
81                 }
82         }
83 });