Merge pull request #2 from jocelyn/widget_first_review

Minor changes
This commit is contained in:
ynh
2013-09-20 03:34:36 -07:00
22 changed files with 201 additions and 161 deletions

View File

@@ -9,12 +9,22 @@ class
inherit inherit
WSF_ROUTED_SERVICE WSF_ROUTED_SERVICE
rename
execute as execute_router
end
WSF_FILTERED_SERVICE
WSF_DEFAULT_SERVICE WSF_DEFAULT_SERVICE
redefine redefine
initialize initialize
end end
WSF_FILTER
rename
execute as execute_router
end
create create
make_and_launch make_and_launch
@@ -24,10 +34,47 @@ feature {NONE} -- Initialization
-- Initialize current service. -- Initialize current service.
do do
initialize_router initialize_router
initialize_filter
Precursor
set_service_option ("port", 9090) set_service_option ("port", 9090)
end end
feature {NONE} -- Initialization feature -- Router and Filter
create_filter
-- Create `filter'
local
f, l_filter: detachable WSF_FILTER
do
l_filter := Void
-- Maintenance
create {WSF_MAINTENANCE_FILTER} f
f.set_next (l_filter)
l_filter := f
-- Logging
create {WSF_LOGGING_FILTER} f
f.set_next (l_filter)
l_filter := f
filter := l_filter
end
setup_filter
-- Setup `filter'
local
f: WSF_FILTER
do
from
f := filter
until
not attached f.next as l_next
loop
f := l_next
end
f.set_next (Current)
end
setup_router setup_router
do do
@@ -35,6 +82,9 @@ feature {NONE} -- Initialization
map_agent_uri ("/", agent execute_hello, Void) map_agent_uri ("/", agent execute_hello, Void)
map_agent_uri ("/grid", agent grid_demo, Void) map_agent_uri ("/grid", agent grid_demo, Void)
map_agent_uri ("/repeater", agent repeater_demo, Void) map_agent_uri ("/repeater", agent repeater_demo, Void)
-- NOTE: you could put all those files in a specific folder, and use WSF_FILE_SYSTEM_HANDLER with "/"
-- this way, it handles the caching and so on
map_agent_uri ("/widget.js", agent load_file("widget.js", ?, ?), Void) map_agent_uri ("/widget.js", agent load_file("widget.js", ?, ?), Void)
map_agent_uri ("/jquery.min.js", agent load_file("jquery.min.js", ?, ?), Void) map_agent_uri ("/jquery.min.js", agent load_file("jquery.min.js", ?, ?), Void)
map_agent_uri ("/typeahead.min.js", agent load_file("typeahead.min.js", ?, ?), Void) map_agent_uri ("/typeahead.min.js", agent load_file("typeahead.min.js", ?, ?), Void)

View File

@@ -16,7 +16,7 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make () make
do do
template := "{{=value}}"; template := "{{=value}}";
end end
@@ -25,26 +25,24 @@ feature -- Implementation
autocompletion (input: STRING): JSON_ARRAY autocompletion (input: STRING): JSON_ARRAY
local local
cl: LIBCURL_HTTP_CLIENT
sess: HTTP_CLIENT_SESSION
l_json: detachable READABLE_STRING_8
o: JSON_OBJECT o: JSON_OBJECT
l_result: INTEGER
l_curl_string: CURL_STRING
json_parser: JSON_PARSER json_parser: JSON_PARSER
query_str: STRING query_str: STRING
do do
query_str := input query_str := input
query_str.replace_substring_all (" ", "+") query_str.replace_substring_all (" ", "+")
curl_handle := curl_easy.init create cl.make
sess := cl.new_session ("http://google.com")
if attached sess.get ("/complete/search?client=chrome&q=" + query_str, Void) as resp and then not resp.error_occurred then
l_json := resp.body
end
create Result.make_array create Result.make_array
if curl_handle /= default_pointer then if l_json /= Void and then not l_json.is_empty then
create l_curl_string.make_empty create json_parser.make_parser (l_json)
curl_easy.setopt_string (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_url, "http://google.com/complete/search?client=chrome&q=" + query_str)
curl_easy.set_write_function (curl_handle)
curl_easy.setopt_integer (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_writedata, l_curl_string.object_id)
l_result := curl_easy.perform (curl_handle)
-- Always cleanup
curl_easy.cleanup (curl_handle)
create json_parser.make_parser (l_curl_string.out)
if attached {JSON_ARRAY} json_parser.parse_json as data and then attached {JSON_ARRAY} data.i_th (2) as list then if attached {JSON_ARRAY} json_parser.parse_json as data and then attached {JSON_ARRAY} data.i_th (2) as list then
across across
1 |..| list.count as c 1 |..| list.count as c
@@ -59,14 +57,4 @@ feature -- Implementation
end end
end end
feature {NONE} -- Implementation
curl_easy: CURL_EASY_EXTERNALS
once
create Result
end
curl_handle: POINTER;
-- cURL handle
end end

View File

@@ -18,18 +18,21 @@ feature {NONE}
make_from_json (json: JSON_OBJECT) make_from_json (json: JSON_OBJECT)
do do
if attached {JSON_STRING} json.item (create {JSON_STRING}.make_json ("title")) as a_title then if attached {JSON_STRING} json.item ("title") as l_title then
title := a_title.unescaped_string_32 title := l_title.unescaped_string_32
end end
if attached {JSON_STRING} json.item (create {JSON_STRING}.make_json ("content")) as a_content then if attached {JSON_STRING} json.item ("content") as l_content then
content := a_content.unescaped_string_32 content := l_content.unescaped_string_32
end end
if attached {JSON_OBJECT} json.item (create {JSON_STRING}.make_json ("image")) as img and then attached {JSON_STRING} img.item (create {JSON_STRING}.make_json ("url")) as a_image then if
image := a_image.item attached {JSON_OBJECT} json.item ("image") as img and then
attached {JSON_STRING} img.item ("url") as l_image
then
image := l_image.item
end end
end end
feature feature -- Access
title: detachable STRING title: detachable STRING
@@ -37,13 +40,14 @@ feature
image: detachable STRING image: detachable STRING
get (field: STRING): detachable ANY item (a_field: READABLE_STRING_GENERAL): detachable ANY
-- <Precursor>
do do
if field.is_equal ("title") then if a_field.same_string ("title") then
Result := title Result := title
elseif field.is_equal ("content") then elseif a_field.same_string ("content") then
Result := content Result := content
elseif field.is_equal ("image") then elseif a_field.same_string ("image") then
Result := image Result := image
end end
end end

View File

@@ -47,26 +47,28 @@ feature
data: ITERABLE [GOOGLE_NEWS] data: ITERABLE [GOOGLE_NEWS]
local local
list: LINKED_LIST [GOOGLE_NEWS] list: LINKED_LIST [GOOGLE_NEWS]
l_result: INTEGER l_json: detachable READABLE_STRING_8
l_curl_string: CURL_STRING
json_parser: JSON_PARSER json_parser: JSON_PARSER
query_str: STRING query_str: STRING
cl: LIBCURL_HTTP_CLIENT
sess: HTTP_CLIENT_SESSION
do do
curl_handle := curl_easy.init
create list.make create list.make
row_count := 0 row_count := 0
if curl_handle /= default_pointer then
create l_curl_string.make_empty
query_str := query.out query_str := query.out
query_str.replace_substring_all (" ", "+") query_str.replace_substring_all (" ", "+")
curl_easy.setopt_string (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_url, "https://ajax.googleapis.com/ajax/services/search/news?v=1.0&q=" + query_str + "&rsz=" + page_size.out + "&start=" + (page_size * (page - 1)).out) create cl.make
curl_easy.set_write_function (curl_handle) sess := cl.new_session ("https://ajax.googleapis.com/ajax/services/search")
curl_easy.setopt_integer (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_writedata, l_curl_string.object_id) sess.set_is_insecure (True)
l_result := curl_easy.perform (curl_handle) if sess.is_available then
if attached {HTTP_CLIENT_RESPONSE} sess.get ("/news?v=1.0&q=" + query_str + "&rsz=" + page_size.out + "&start=" + (page_size * (page - 1)).out, Void) as l_response then
-- Always cleanup if not l_response.error_occurred then
curl_easy.cleanup (curl_handle) l_json := l_response.body
create json_parser.make_parser (l_curl_string.out) end
end
end
if l_json /= Void and then not l_json.is_empty then
create json_parser.make_parser (l_json)
if attached {JSON_OBJECT} json_parser.parse_json as sp then if attached {JSON_OBJECT} json_parser.parse_json as sp then
if attached {JSON_OBJECT} sp.item (create {JSON_STRING}.make_json ("responseData")) as responsedata and then attached {JSON_ARRAY} responsedata.item (create {JSON_STRING}.make_json ("results")) as results then if attached {JSON_OBJECT} sp.item (create {JSON_STRING}.make_json ("responseData")) as responsedata and then attached {JSON_ARRAY} responsedata.item (create {JSON_STRING}.make_json ("results")) as results then
if attached {JSON_OBJECT} responsedata.item (create {JSON_STRING}.make_json ("cursor")) as cursor and then attached {JSON_STRING} cursor.item (create {JSON_STRING}.make_json ("estimatedResultCount")) as count then if attached {JSON_OBJECT} responsedata.item (create {JSON_STRING}.make_json ("cursor")) as cursor and then attached {JSON_STRING} cursor.item (create {JSON_STRING}.make_json ("estimatedResultCount")) as count then
@@ -94,14 +96,4 @@ feature
query: STRING query: STRING
feature {NONE} -- Implementation
curl_easy: CURL_EASY_EXTERNALS
once
create Result
end
curl_handle: POINTER;
-- cURL handle
end end

View File

@@ -29,7 +29,8 @@ feature
search_query.set_change_event (agent change_query) search_query.set_change_event (agent change_query)
container.add_control (search_query) container.add_control (search_query)
container.add_control (create {WSF_BASIC_CONTROL}.make_with_body("h2","","Results")) container.add_control (create {WSF_BASIC_CONTROL}.make_with_body("h2","","Results"))
create grid.make_grid ("mygrid", <<create {WSF_GRID_COLUMN}.make_column ("Title", "title"), create {WSF_GRID_COLUMN}.make_column ("Content", "content")>>, datasource) create grid.make_grid ("mygrid", <<create {WSF_GRID_COLUMN}.make ("Title", "title"),
create {WSF_GRID_COLUMN}.make ("Content", "content")>>, datasource)
container.add_control (grid) container.add_control (grid)
control := container control := container
end end

View File

@@ -8,7 +8,6 @@ class
REPEATER_PAGE REPEATER_PAGE
inherit inherit
BASE_PAGE BASE_PAGE
redefine redefine
initialize_controls initialize_controls
@@ -22,13 +21,13 @@ feature
initialize_controls initialize_controls
do do
Precursor Precursor
container.add_control (create {WSF_BASIC_CONTROL}.make_with_body("h1","","Repeater Demo")) container.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("h1", ""," Repeater Demo"))
create datasource.make_news create datasource.make_news
create search_query.make_autocomplete ("query", create {GOOGLE_AUTOCOMPLETION}.make) create search_query.make_autocomplete ("query", create {GOOGLE_AUTOCOMPLETION}.make)
search_query.add_class ("form-control") search_query.add_class ("form-control")
search_query.set_change_event (agent change_query) search_query.set_change_event (agent change_query)
container.add_control (search_query) container.add_control (search_query)
container.add_control (create {WSF_BASIC_CONTROL}.make_with_body("h2","","Results")) container.add_control (create {WSF_BASIC_CONTROL}.make_with_body("h2", "", "Results"))
create repeater.make_repeater ("myrepeater", datasource) create repeater.make_repeater ("myrepeater", datasource)
container.add_control (repeater) container.add_control (repeater)
end end

View File

@@ -1,33 +1,32 @@
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="widgetapp" uuid="C28C4F53-9963-46C0-A080-8F13E94E7486" library_target="widgetapp"> <system xmlns="http://www.eiffel.com/developers/xml/configuration-1-11-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-11-0 http://www.eiffel.com/developers/xml/configuration-1-11-0.xsd" name="widgetapp" uuid="C28C4F53-9963-46C0-A080-8F13E94E7486" library_target="widgetapp">
<target name="common" abstract="true"> <target name="common" abstract="true">
<file_rule> <file_rule>
<exclude>/EIFGENs$</exclude> <exclude>/EIFGENs$</exclude>
<exclude>/CVS$</exclude> <exclude>/CVS$</exclude>
<exclude>/.svn$</exclude> <exclude>/.svn$</exclude>
</file_rule> </file_rule>
<option warning="true" is_attached_by_default="true" void_safety="all" syntax="transitional"> <option warning="true" full_class_checking="false" is_attached_by_default="true" void_safety="transitional" syntax="transitional">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/> <assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option> </option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/> <library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="curl" location="$ISE_LIBRARY\library\cURL\cURL-safe.ecf"/>
<library name="http" location="..\..\library\network\protocol\http\http-safe.ecf"/> <library name="http" location="..\..\library\network\protocol\http\http-safe.ecf"/>
<library name="http_client" location="$ISE_LIBRARY\contrib\library\network\http_client\http_client-safe.ecf"/>
<library name="wsf" location="..\..\library\server\wsf\wsf-safe.ecf"/> <library name="wsf" location="..\..\library\server\wsf\wsf-safe.ecf"/>
<library name="wsf_html" location="..\..\library\server\wsf_html\wsf_html-safe.ecf"/> <library name="wsf_html" location="..\..\library\server\wsf_html\wsf_html-safe.ecf" readonly="false"/>
</target> </target>
<target name="widgetapp_nino" extends="common"> <target name="widgetapp_nino" extends="common">
<root class="APPLICATION" feature="make_and_launch"/> <root class="APPLICATION" feature="make_and_launch"/>
<option warning="true" is_attached_by_default="true" void_safety="all" syntax="transitional"> <option warning="true" is_attached_by_default="true" void_safety="transitional" syntax="transitional">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/> <assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option> </option>
<library name="default_nino" location="..\..\library\server\wsf\default\nino-safe.ecf"/> <library name="default_nino" location="..\..\library\server\wsf\default\nino-safe.ecf"/>
<library name="json" location="..\..\contrib\library\text\parser\json\library\json-safe.ecf"/> <library name="json" location="..\..\contrib\library\text\parser\json\library\json-safe.ecf"/>
<cluster name="widgetapp" location=".\" recursive="true"> <cluster name="widgetapp" location=".\" recursive="true"/>
</cluster>
</target> </target>
<target name="widgetapp_cgi" extends="common"> <target name="widgetapp_cgi" extends="common">
<root class="APPLICATION" feature="make_and_launch"/> <root class="APPLICATION" feature="make_and_launch"/>
<option warning="true" is_attached_by_default="true" void_safety="all" syntax="transitional"> <option warning="true" is_attached_by_default="true" void_safety="transitional" syntax="transitional">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/> <assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option> </option>
<library name="default_cgi" location="..\..\library\server\wsf\default\cgi-safe.ecf"/> <library name="default_cgi" location="..\..\library\server\wsf\default\cgi-safe.ecf"/>
@@ -35,7 +34,7 @@
</target> </target>
<target name="widgetapp_libfcgi" extends="common"> <target name="widgetapp_libfcgi" extends="common">
<root class="APPLICATION" feature="make_and_launch"/> <root class="APPLICATION" feature="make_and_launch"/>
<option warning="true" is_attached_by_default="true" void_safety="all" syntax="transitional"> <option warning="true" is_attached_by_default="true" void_safety="transitional" syntax="transitional">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/> <assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option> </option>
<library name="default_libfcgi" location="..\..\library\server\wsf\default\libfcgi-safe.ecf"/> <library name="default_libfcgi" location="..\..\library\server\wsf\default\libfcgi-safe.ecf"/>

View File

@@ -9,7 +9,7 @@ deferred class
feature -- Update event feature -- Update event
set_on_update_agent (f: PROCEDURE [ANY, TUPLE []]) set_on_update_agent (f: PROCEDURE [ANY, TUPLE])
do do
on_update_agent := f on_update_agent := f
end end
@@ -17,11 +17,11 @@ feature -- Update event
update update
do do
if attached on_update_agent as a then if attached on_update_agent as a then
a.call ([]) a.call (Void)
end end
end end
on_update_agent: detachable PROCEDURE [ANY, TUPLE []] on_update_agent: detachable PROCEDURE [ANY, TUPLE]
feature --State feature --State
@@ -30,27 +30,27 @@ feature --State
do do
create Result.make create Result.make
if attached sort_column as a_sort_column then if attached sort_column as a_sort_column then
Result.put (create {JSON_STRING}.make_json (a_sort_column), create {JSON_STRING}.make_json ("sort_column")) Result.put (create {JSON_STRING}.make_json (a_sort_column), "sort_column")
else else
Result.put (create {JSON_NULL}, create {JSON_STRING}.make_json ("sort_column")) Result.put (create {JSON_NULL}, "sort_column")
end end
Result.put (create {JSON_BOOLEAN}.make_boolean (sort_direction), create {JSON_STRING}.make_json ("sort_direction")) Result.put (create {JSON_BOOLEAN}.make_boolean (sort_direction), "sort_direction")
end end
set_state (new_state: JSON_OBJECT) set_state (new_state: JSON_OBJECT)
do do
if attached {JSON_NUMBER} new_state.item (create {JSON_STRING}.make_json ("page")) as new_page then if attached {JSON_NUMBER} new_state.item ("page") as new_page then
page := new_page.integer_type page := new_page.integer_type
end end
if attached {JSON_NUMBER} new_state.item (create {JSON_STRING}.make_json ("page_size")) as new_page_size then if attached {JSON_NUMBER} new_state.item ("page_size") as new_page_size then
page_size := new_page_size.integer_type page_size := new_page_size.integer_type
end end
if attached {JSON_STRING} new_state.item (create {JSON_STRING}.make_json ("sort_column")) as new_sort_column then if attached {JSON_STRING} new_state.item ("sort_column") as new_sort_column then
sort_column := new_sort_column.unescaped_string_32 sort_column := new_sort_column.unescaped_string_32 -- Implicit Conversion !
elseif attached {JSON_NULL} new_state.item (create {JSON_STRING}.make_json ("sort_column")) as new_sort_column then elseif attached {JSON_NULL} new_state.item ("sort_column") as new_sort_column then
sort_column := VOID sort_column := Void
end end
if attached {JSON_BOOLEAN} new_state.item (create {JSON_STRING}.make_json ("sort_direction")) as new_sort_direction then if attached {JSON_BOOLEAN} new_state.item ("sort_direction") as new_sort_direction then
sort_direction := new_sort_direction.item sort_direction := new_sort_direction.item
end end
end end

View File

@@ -1,15 +1,15 @@
note note
description: "Summary description for {WSF_ENTITY}." description: "Summary description for {WSF_ENTITY}."
author: ""
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
deferred class deferred class
WSF_ENTITY WSF_ENTITY
feature feature -- Access
get (field: STRING): detachable ANY item (a_field: READABLE_STRING_GENERAL): detachable ANY
-- Value for field item `a_field'.
deferred deferred
end end

View File

@@ -8,11 +8,11 @@ class
WSF_GRID_COLUMN WSF_GRID_COLUMN
create create
make_column make
feature {NONE} feature {NONE}
make_column (a_header, a_field: STRING) make (a_header, a_field: STRING)
do do
header := a_header header := a_header
field_name := a_field field_name := a_field
@@ -31,7 +31,7 @@ feature
render_column (e: WSF_ENTITY): STRING render_column (e: WSF_ENTITY): STRING
do do
if attached e.get (field_name) as data then if attached e.item (field_name) as data then
Result := data.out Result := data.out
else else
Result := "[VOID]" Result := "[VOID]"

View File

@@ -10,16 +10,18 @@ class
inherit inherit
WSF_GRID_COLUMN WSF_GRID_COLUMN
rename
make as make_column
redefine redefine
render_column render_column
end end
create create
make_image_column make
feature {NONE} feature {NONE}
make_image_column (a_header, a_field: STRING) make (a_header, a_field: STRING)
do do
make_column (a_header, a_field) make_column (a_header, a_field)
end end
@@ -28,7 +30,7 @@ feature
render_column (e: WSF_ENTITY): STRING render_column (e: WSF_ENTITY): STRING
do do
if attached e.get (field_name) as data then if attached e.item (field_name) as data then
Result := "<img src=%"" + data.out + "%" />" Result := "<img src=%"" + data.out + "%" />"
else else
Result := "[VOID]" Result := "[VOID]"

View File

@@ -58,7 +58,7 @@ feature
update update
do do
state_changes.replace (create {JSON_STRING}.make_json (render), create {JSON_STRING}.make_json ("_html")) state_changes.replace (create {JSON_STRING}.make_json (render), "_html")
end end
render: STRING render: STRING

View File

@@ -34,14 +34,14 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
update update
do do
state_changes.replace (create {JSON_STRING}.make_json (render_body), create {JSON_STRING}.make_json ("_body")) state_changes.replace (create {JSON_STRING}.make_json (render_body), "_body")
state_changes.replace (datasource.state, create {JSON_STRING}.make_json ("datasource")) state_changes.replace (datasource.state, "datasource")
end end
set_state (new_state: JSON_OBJECT) set_state (new_state: JSON_OBJECT)
-- Restore html from json -- Restore html from json
do do
if attached {JSON_OBJECT} new_state.item (create {JSON_STRING}.make_json ("datasource")) as datasource_state then if attached {JSON_OBJECT} new_state.item ("datasource") as datasource_state then
datasource.set_state (datasource_state) datasource.set_state (datasource_state)
end end
end end
@@ -50,7 +50,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
-- Return state which contains the current html and if there is an event handle attached -- Return state which contains the current html and if there is an event handle attached
do do
create Result.make create Result.make
Result.put (datasource.state, create {JSON_STRING}.make_json ("datasource")) Result.put (datasource.state, "datasource")
end end
feature --EVENT HANDLING feature --EVENT HANDLING

View File

@@ -28,7 +28,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
set_state (new_state: JSON_OBJECT) set_state (new_state: JSON_OBJECT)
-- Restore text from json -- Restore text from json
do do
if attached {JSON_BOOLEAN} new_state.item (create {JSON_STRING}.make_json ("checked")) as new_checked then if attached {JSON_BOOLEAN} new_state.item ("checked") as new_checked then
checked := new_checked.item checked := new_checked.item
end end
end end
@@ -37,9 +37,9 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
-- Return state which contains the current text and if there is an event handle attached -- Return state which contains the current text and if there is an event handle attached
do do
create Result.make create Result.make
Result.put (create {JSON_BOOLEAN}.make_boolean (checked), create {JSON_STRING}.make_json ("checked")) Result.put (create {JSON_BOOLEAN}.make_boolean (checked), "checked")
Result.put (create {JSON_STRING}.make_json (checked_value), create {JSON_STRING}.make_json ("checked_value")) Result.put (create {JSON_STRING}.make_json (checked_value), "checked_value")
Result.put (create {JSON_BOOLEAN}.make_boolean (attached change_event), create {JSON_STRING}.make_json ("callback_change")) Result.put (create {JSON_BOOLEAN}.make_boolean (attached change_event), "callback_change")
end end
feature --EVENT HANDLING feature --EVENT HANDLING
@@ -52,9 +52,9 @@ feature --EVENT HANDLING
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING) handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
do do
if Current.control_name.is_equal (cname) and attached change_event as cevent then if Current.control_name.same_string (cname) and attached change_event as cevent then
if event.is_equal ("change") then if event.same_string ("change") then
cevent.call ([]) cevent.call (Void)
end end
end end
end end
@@ -85,6 +85,6 @@ feature
checked_value: STRING checked_value: STRING
change_event: detachable PROCEDURE [ANY, TUPLE []] change_event: detachable PROCEDURE [ANY, TUPLE]
end end

View File

@@ -32,7 +32,7 @@ feature
value: LIST [STRING] value: LIST [STRING]
do do
create {LINKED_LIST [STRING]} Result.make create {ARRAYED_LIST [STRING]} Result.make (0)
across across
controls as c controls as c
loop loop

View File

@@ -70,7 +70,7 @@ feature {NONE} -- Initialization
collapse_button.add_control (icon_bar) collapse_button.add_control (icon_bar)
collapse_button.add_control (icon_bar) collapse_button.add_control (icon_bar)
collapse_button.add_control (icon_bar) collapse_button.add_control (icon_bar)
--collapse_button.set_attributes ("data-target=%".navbar-collapse%" data-toggle=%"collapse%" type=%"button%"") -- collapse_button.set_attributes ("data-target=%".navbar-collapse%" data-toggle=%"collapse%" type=%"button%"")
brand.add_class ("navbar-brand") brand.add_class ("navbar-brand")
brand.set_attributes ("href=%"#%"") brand.set_attributes ("href=%"#%"")
brand.set_content (b) brand.set_content (b)

View File

@@ -17,15 +17,9 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
attributes: STRING
content: STRING
make_control (t: STRING) make_control (t: STRING)
do do
make (t) make_with_body (t, "", "")
attributes := ""
content := ""
end end
make_with_body (t,attr,a_content: STRING) make_with_body (t,attr,a_content: STRING)
@@ -35,6 +29,12 @@ feature {NONE} -- Initialization
content := a_content content := a_content
end end
feature -- Access
attributes: STRING
content: STRING
feature -- Rendering feature -- Rendering
render: STRING render: STRING

View File

@@ -34,7 +34,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
load_state (new_states: JSON_OBJECT) load_state (new_states: JSON_OBJECT)
-- Select state stored with `control_name` as key -- Select state stored with `control_name` as key
do do
if attached {JSON_OBJECT} new_states.item (create {JSON_STRING}.make_json (control_name)) as new_state_obj then if attached {JSON_OBJECT} new_states.item (control_name) as new_state_obj then
set_state (new_state_obj) set_state (new_state_obj)
end end
end end
@@ -47,14 +47,14 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
read_state (states: JSON_OBJECT) read_state (states: JSON_OBJECT)
-- Add a new entry in the `states` JSON object with the `control_name` as key and the `state` as value -- Add a new entry in the `states` JSON object with the `control_name` as key and the `state` as value
do do
states.put (state, create {JSON_STRING}.make_json (control_name)) states.put (state, control_name)
end end
read_state_changes (states: JSON_OBJECT) read_state_changes (states: JSON_OBJECT)
-- Add a new entry in the `states_changes` JSON object with the `control_name` as key and the `state` as value -- Add a new entry in the `states_changes` JSON object with the `control_name` as key and the `state` as value
do do
if state_changes.count > 0 then if state_changes.count > 0 then
states.put (state_changes, create {JSON_STRING}.make_json (control_name)) states.put (state_changes, control_name)
end end
end end
@@ -69,7 +69,7 @@ feature -- Rendering
render_tag (body, attrs: STRING): STRING render_tag (body, attrs: STRING): STRING
do do
Result:=render_tag_with_generator_name (generator, body, attrs) Result := render_tag_with_generator_name (generator, body, attrs)
end end
render_tag_with_generator_name (a_generator, body, attrs: STRING): STRING render_tag_with_generator_name (a_generator, body, attrs: STRING): STRING
@@ -87,7 +87,7 @@ feature -- Rendering
Result := render_tag_with_tagname (tag_name, body, l_attributes, css_classes_string) Result := render_tag_with_tagname (tag_name, body, l_attributes, css_classes_string)
end end
feature --EVENT HANDLING feature -- EVENT HANDLING
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING) handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Method called if any callback received. 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

View File

@@ -24,14 +24,11 @@ create
feature {NONE} feature {NONE}
make_form_element (a_label: STRING; c: WSF_VALUE_CONTROL [G]) make_form_element (a_label: STRING; c: WSF_VALUE_CONTROL [G])
local
a_validators: LINKED_LIST [WSF_VALIDATOR [G]]
do do
create a_validators.make make_form_element_with_validators (a_label, c, create {ARRAYED_LIST [WSF_VALIDATOR [G]]}.make (0))
make_form_element_with_validators (a_label, c, a_validators)
end end
make_form_element_with_validators (a_label: STRING; c: WSF_VALUE_CONTROL [G]; v: LINKED_LIST [WSF_VALIDATOR [G]]) make_form_element_with_validators (a_label: STRING; c: WSF_VALUE_CONTROL [G]; v: LIST [WSF_VALIDATOR [G]])
do do
make_control (c.control_name + "_container", "div") make_control (c.control_name + "_container", "div")
add_class ("form-group") add_class ("form-group")
@@ -87,8 +84,8 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
loop loop
validator_description.add (v.item.state) validator_description.add (v.item.state)
end end
Result.put (create {JSON_STRING}.make_json (value_control.control_name), create {JSON_STRING}.make_json ("value_control")) Result.put (create {JSON_STRING}.make_json (value_control.control_name), "value_control")
Result.put (validator_description, create {JSON_STRING}.make_json ("validators")) Result.put (validator_description, "validators")
end end
feature --EVENT HANDLING feature --EVENT HANDLING
@@ -96,8 +93,8 @@ feature --EVENT HANDLING
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING) handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Pass callback to subcontrols -- Pass callback to subcontrols
do do
if equal (cname, control_name) then if cname.same_string (control_name) then
if event.is_equal ("validate") then if event.same_string ("validate") then
validate validate
end end
else else
@@ -113,11 +110,11 @@ feature --Implementation
do do
body := "" body := ""
if not label.is_empty then if not label.is_empty then
body := "<label class=%"col-lg-2 control-label%" for=%"" + value_control.control_name + "%">" + label + "</label>" body.append ("<label class=%"col-lg-2 control-label%" for=%"" + value_control.control_name + "%">" + label + "</label>")
end end
body := body + "<div class=%"col-lg-10%">" body.append ("<div class=%"col-lg-10%">")
body := body + value_control.render body.append (value_control.render)
body := body + "</div>" body.append ("</div>")
Result := render_tag (body, "") Result := render_tag (body, "")
end end
@@ -161,7 +158,7 @@ feature
value_control: WSF_VALUE_CONTROL [G] value_control: WSF_VALUE_CONTROL [G]
validators: LINKED_LIST [WSF_VALIDATOR [G]] validators: LIST [WSF_VALIDATOR [G]]
label: STRING label: STRING

View File

@@ -52,7 +52,6 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
do do
end end
read_state (states: JSON_OBJECT) read_state (states: JSON_OBJECT)
-- Read states in subcontrols -- Read states in subcontrols
do do
@@ -85,7 +84,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
create Result.make create Result.make
end end
feature --EVENT HANDLING feature -- EVENT HANDLING
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING) handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Pass callback to subcontrols -- Pass callback to subcontrols

View File

@@ -7,40 +7,40 @@ note
deferred class deferred class
WSF_STATELESS_CONTROL WSF_STATELESS_CONTROL
feature
tag_name: STRING
css_classes: LINKED_LIST [STRING]
--TODO: Maybe improve
feature {NONE} feature {NONE}
make (a_tag_name: STRING) make (a_tag_name: STRING)
do do
tag_name := a_tag_name tag_name := a_tag_name
create css_classes.make create css_classes.make (0)
ensure ensure
attached css_classes attached css_classes
end end
feature feature -- Access
tag_name: STRING
css_classes: ARRAYED_LIST [STRING]
--TODO: Maybe improve
feature -- Change
add_class (c: STRING) add_class (c: STRING)
do do
css_classes.extend (c) css_classes.force (c)
end end
render_tag (body, attrs: STRING): STRING render_tag (body, attrs: STRING): STRING
local local
css_classes_string: STRING css_classes_string: STRING
do do
css_classes_string := "" create css_classes_string.make_empty
across across
css_classes as c css_classes as c
loop loop
css_classes_string := css_classes_string + " " + c.item css_classes_string.append (" " + c.item)
end end
Result := render_tag_with_tagname (tag_name, body, attrs, css_classes_string) Result := render_tag_with_tagname (tag_name, body, attrs, css_classes_string)
end end
@@ -49,20 +49,28 @@ feature
local local
l_attributes: STRING l_attributes: STRING
do do
l_attributes := attrs create l_attributes.make_from_string (attrs)
if not css_classes_string.is_empty then if not css_classes_string.is_empty then
l_attributes := l_attributes + " class=%"" + css_classes_string + "%"" l_attributes.append (" class=%"")
l_attributes.append (css_classes_string)
l_attributes.append_character ('%"')
end end
Result := "<" + tag + " " + l_attributes Result := "<" + tag + " " + l_attributes
if body.is_empty and not tag.is_equal ("textarea") and not tag.is_equal ("span") and not tag.is_equal ("button") and not tag.is_equal ("ul") then if
Result := Result + " />" body.is_empty and
not tag.same_string ("textarea") and
not tag.same_string ("span") and
not tag.same_string ("button") and
not tag.same_string ("ul")
then
Result.append (" />")
else else
Result := Result + " >" + body + "</" + tag + ">" Result.append (" >" + body + "</" + tag + ">")
end end
end end
render: STRING render: STRING
-- Return html representaion of control -- Return html representation of control
deferred deferred
end end

View File

@@ -56,6 +56,7 @@
<library name="wsf_openshift" location="..\library\server\wsf\connector\openshift-safe.ecf" readonly="false"/> <library name="wsf_openshift" location="..\library\server\wsf\connector\openshift-safe.ecf" readonly="false"/>
<library name="wsf_router_context" location="..\library\server\wsf\wsf_router_context-safe.ecf" readonly="false"/> <library name="wsf_router_context" location="..\library\server\wsf\wsf_router_context-safe.ecf" readonly="false"/>
<library name="wsf_session" location="..\library\server\wsf\wsf_session-safe.ecf" readonly="false"/> <library name="wsf_session" location="..\library\server\wsf\wsf_session-safe.ecf" readonly="false"/>
<library name="widgetapp" location="..\examples\widgetapp\widgetapp.ecf" readonly="false"/>
</target> </target>
<target name="all_windows" extends="all"> <target name="all_windows" extends="all">
<description>Compiling as Windows , on other platforms than Windows</description> <description>Compiling as Windows , on other platforms than Windows</description>