From f5ce8505b07bae461ceb07d5f249fb3a5a02cbb5 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sun, 5 Jan 2014 22:39:32 +0100 Subject: Restored TAutoComplete --- .../source/prado/activecontrols/autocomplete.js | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 framework/Web/Javascripts/source/prado/activecontrols/autocomplete.js (limited to 'framework/Web/Javascripts') diff --git a/framework/Web/Javascripts/source/prado/activecontrols/autocomplete.js b/framework/Web/Javascripts/source/prado/activecontrols/autocomplete.js new file mode 100644 index 00000000..180ceecf --- /dev/null +++ b/framework/Web/Javascripts/source/prado/activecontrols/autocomplete.js @@ -0,0 +1,84 @@ +jQuery.noConflict(); + +/** + * TAutoComplete control. + */ +Prado.WebUI.TAutoComplete = Class.create(Autocompleter.Base, Prado.WebUI.TActiveTextBox.prototype); +Prado.WebUI.TAutoComplete = Class.create(Prado.WebUI.TAutoComplete, +{ + initialize : function(options) + { + this.options = options; + this.observers = new Array(); + this.hasResults = false; + this.baseInitialize(options.ID, options.ResultPanel, options); + Object.extend(this.options, + { + onSuccess : this.onComplete.bind(this) + }); + + if(options.AutoPostBack) + this.onInit(options); + + Prado.Registry[options.ID] = this; + }, + + doCallback : function(event, options) + { + if(!this.active) + { + var request = new Prado.CallbackRequest(this.options.EventTarget, options); + request.dispatch(); + Event.stop(event); + } + }, + + //Overrides parent implementation, fires onchange event. + onClick: function(event) + { + var element = Event.findElement(event, 'LI'); + this.index = element.autocompleteIndex; + this.selectEntry(); + this.hide(); + Event.fire(this.element, "change"); + }, + + getUpdatedChoices : function() + { + var options = new Array(this.getToken(),"__TAutoComplete_onSuggest__"); + Prado.Callback(this.options.EventTarget, options, null, this.options); + }, + + /** + * Overrides parent implements, don't update if no results. + */ + selectEntry: function() + { + if(this.hasResults) + { + this.active = false; + this.updateElement(this.getCurrentEntry()); + var options = [this.index, "__TAutoComplete_onSuggestionSelected__"]; + Prado.Callback(this.options.EventTarget, options, null, this.options); + } + }, + + onComplete : function(request, boundary) + { + var result = request.extractContent(boundary); + if(typeof(result) == "string") + { + if(result.length > 0) + { + this.hasResults = true; + this.updateChoices(result); + } + else + { + this.active = false; + this.hasResults = false; + this.hide(); + } + } + } +}); \ No newline at end of file -- cgit v1.2.3