From 9d88eee04a211c8d28190b2822befee93cd8bad6 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 9 Oct 2013 16:32:33 +0200 Subject: [PATCH] Code so far for property name autocompletion --- public_html/static/js/openng.js | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/public_html/static/js/openng.js b/public_html/static/js/openng.js index 80f1cfa..045fbb4 100644 --- a/public_html/static/js/openng.js +++ b/public_html/static/js/openng.js @@ -97,6 +97,9 @@ function placeHooksForWindow(win) console.log("Hooking", this, "using callback", callback); hookSubmitEvent($(this), window[callback], window[error_callback]); } + + /*$ + $("#thing").autoComplete(autocompleter_propertyname, new PropertyNameCompletionSource($("#thing")));*/ }); } @@ -212,6 +215,37 @@ SearchCompletionSource.prototype.updateItems = function(query, callback) { }); } +function PropertyNameCompletionSource(element) +{ + this.element = element; + this.results = []; +} + +PropertyNameCompletionSource.prototype.getItemCount = function() { + return this.results.length; +} + +PropertyNameCompletionSource.prototype.getAll = function() { + return this.results; +} + +PropertyNameCompletionSource.prototype.getItem = function(index) { + return this.results[index]; +} + +PropertyNameCompletionSource.prototype.updateItems = function(query, callback) { + if(typeof this.request !== "undefined") + { + this.request.abort(); + } + + this.request = $.ajax({ + url: "/autocomplete/propertyname/?q=" + escape(query), + dataType: "json", + success: function(result) { this.results = result; callback(); }.bind(this) + }); +} + $(function(){ hookSubmitEvent($("#form_search")); @@ -280,3 +314,5 @@ $(function(){ } }); }); + +autocompleter_propertyname = new AutoCompleter("propertyname");