Add a json state to each control
This commit is contained in:
51
library/server/wsf_html/webcontrol/wsf_button_control.e
Normal file
51
library/server/wsf_html/webcontrol/wsf_button_control.e
Normal file
@@ -0,0 +1,51 @@
|
||||
note
|
||||
description: "Summary description for {WSF_BUTTON_CONTROL}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_BUTTON_CONTROL
|
||||
|
||||
inherit
|
||||
WSF_CONTROL
|
||||
create
|
||||
make
|
||||
feature {NONE}
|
||||
make (n:STRING; v:STRING)
|
||||
do
|
||||
make_control
|
||||
control_name:=n
|
||||
text:=v
|
||||
click_event:= agent donothing
|
||||
end
|
||||
feature
|
||||
|
||||
--UGLY HACK MUST BE REMOVED
|
||||
donothing(p:WSF_PAGE_CONTROL)
|
||||
do
|
||||
|
||||
end
|
||||
handle_callback(event: STRING ; cname: STRING ; page: WSF_PAGE_CONTROL)
|
||||
do
|
||||
if Current.control_name = cname and attached click_event then
|
||||
click_event.call([page])
|
||||
end
|
||||
end
|
||||
|
||||
render:STRING
|
||||
do
|
||||
Result:="<button>"+text+"</button>"
|
||||
end
|
||||
|
||||
state:JSON_OBJECT
|
||||
do
|
||||
create Result.make
|
||||
Result.put (create {JSON_STRING}.make_json(text), create {JSON_STRING}.make_json("text"))
|
||||
end
|
||||
|
||||
|
||||
feature
|
||||
text: STRING
|
||||
click_event: PROCEDURE [ANY, TUPLE [WSF_PAGE_CONTROL]]
|
||||
end
|
||||
@@ -6,16 +6,32 @@ note
|
||||
|
||||
deferred class
|
||||
WSF_CONTROL
|
||||
feature {NONE}
|
||||
make_control
|
||||
do
|
||||
control_name:=""
|
||||
end
|
||||
|
||||
feature
|
||||
name: STRING
|
||||
control_name: STRING
|
||||
|
||||
feature {WSF_PAGE_CONTROL}
|
||||
|
||||
handle_callback(event: STRING ; control_name: STRING ; page: WSF_PAGE_CONTROL)
|
||||
handle_callback(event: STRING ; cname: STRING ; page: WSF_PAGE_CONTROL)
|
||||
deferred
|
||||
end
|
||||
|
||||
render:STRING
|
||||
render: STRING
|
||||
deferred
|
||||
end
|
||||
|
||||
state: JSON_OBJECT
|
||||
deferred
|
||||
end
|
||||
|
||||
read_state(states:JSON_OBJECT)
|
||||
do
|
||||
states.put (state, create {JSON_STRING}.make_json(control_name))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -38,12 +38,17 @@ feature
|
||||
local
|
||||
event: detachable STRING
|
||||
control_name: detachable STRING
|
||||
states:JSON_OBJECT
|
||||
do
|
||||
initialize_controls
|
||||
control_name := get_parameter("control_name")
|
||||
event := get_parameter("event")
|
||||
if attached event and attached control_name and attached control then
|
||||
control.handle_callback (control_name,event, Current)
|
||||
create states.make
|
||||
control.read_state(states)
|
||||
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "application/json"]>>)
|
||||
response.put_string (states.representation)
|
||||
else
|
||||
process
|
||||
render
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="encoder" location="..\..\text\encoder\encoder-safe.ecf"/>
|
||||
<library name="http" location="..\..\network\protocol\http\http-safe.ecf"/>
|
||||
<library name="json" location="..\..\..\contrib\library\text\parser\json\library\json-safe.ecf"/>
|
||||
<library name="uri_template" location="..\..\text\parser\uri_template\uri_template-safe.ecf"/>
|
||||
<library name="wsf" location="..\wsf\wsf-safe.ecf"/>
|
||||
<cluster name="api" location=".\api\" recursive="true"/>
|
||||
|
||||
Reference in New Issue
Block a user