Autocompletion

This commit is contained in:
Severin Münger
2013-09-12 14:58:35 +02:00
parent 8fc405fef1
commit 27023283e7
8 changed files with 129 additions and 45 deletions

View File

@@ -0,0 +1,16 @@
note
description: "Summary description for {WSF_AUTOCOMPLETION}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_AUTOCOMPLETION
feature
autocompletion (input: STRING): JSON_ARRAY
deferred
end
end

View File

@@ -0,0 +1,46 @@
note
description: "Summary description for {WSF_SIMPLE_AUTOCOMPLETION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_SIMPLE_AUTOCOMPLETION
inherit
WSF_AUTOCOMPLETION
create
make
feature {NONE}
make (l: LIST [STRING])
do
list := l
end
feature -- Implementation
autocompletion (input: STRING): JSON_ARRAY
local
o: JSON_OBJECT
do
create Result.make_array
across
list as c
loop
if c.item.as_lower.has_substring (input.as_lower) then
create o.make
o.put (create {JSON_STRING}.make_json (c.item), "value")
Result.add (o)
end
end
end
feature
list: LIST [STRING]
end

View File

@@ -0,0 +1,47 @@
note
description: "Summary description for {WSF_AUTOCOMPLETE_CONTROL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_AUTOCOMPLETE_CONTROL
inherit
WSF_INPUT_CONTROL
redefine
handle_callback
end
create
make_autocomplete, make_autocomplete_with_agent
feature {NONE} -- Creation
make_autocomplete (n: STRING; c: WSF_AUTOCOMPLETION)
do
make_autocomplete_with_agent (n, agent c.autocompletion)
end
make_autocomplete_with_agent (n: STRING; c: FUNCTION [ANY, TUPLE [STRING], JSON_ARRAY])
do
make_input (n, "")
create_json_list := c
end
feature -- Callback
handle_callback (cname: STRING; event: STRING)
do
Precursor {WSF_INPUT_CONTROL} (cname, event)
if cname.is_equal (control_name) and event.is_equal ("autocomplete") then
state_changes.put (create_json_list.item ([text]), create {JSON_STRING}.make_json ("suggestions"))
end
end
feature -- Autocomplete
create_json_list: FUNCTION [ANY, TUPLE [STRING], JSON_ARRAY]
end

View File

@@ -5,10 +5,11 @@ note
revision: "$Revision$"
class
WSF_max_VALIDATOR[G]
WSF_max_VALIDATOR [G]
inherit
WSF_VALIDATOR [LIST[G]]
WSF_VALIDATOR [LIST [G]]
redefine
state
end
@@ -18,7 +19,7 @@ create
feature {NONE}
make_max_validator (m:INTEGER; e: STRING)
make_max_validator (m: INTEGER; e: STRING)
do
make (e)
max := m
@@ -26,10 +27,9 @@ feature {NONE}
feature -- Implementation
is_valid (input:LIST[G]): BOOLEAN
is_valid (input: LIST [G]): BOOLEAN
do
Result:= input.count < max or input.count = max
Result := input.count < max or input.count = max
end
feature

View File

@@ -67,7 +67,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
feature --EVENT HANDLING
handle_callback (cname: STRING; event: STRING)
-- Method called if any callback recived. In this method you can route the callback to the event handler
-- Method called if any callback received. In this method you can route the callback to the event handler
deferred
end

View File

@@ -84,6 +84,7 @@ feature
data.append (states.representation)
data.append (";</script>")
data.append ("<script src=%"//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js%"></script>")
data.append ("<script src=%"//cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.9.3/typeahead.min.js%"></script>")
data.append ("<script src=%"/widget.js%"></script>")
data.append ("</body></html>")
create page.make

View File

@@ -22,6 +22,7 @@
<cluster name="webcontrol" location=".\webcontrol\">
<cluster name="validators" location=".\webcontrol\validators\"/>
<cluster name="input" location=".\webcontrol\input\"/>
<cluster name="autocompletions" location="\home\severin\Documents\EWF\EWF\library\server\wsf_html\webcontrol\autocompletions\"/>
</cluster>
<cluster name="widget" location=".\widget\" recursive="true"/>
</target>