Pretty Print

This commit is contained in:
YNH Webdev
2013-08-27 16:00:24 +02:00
parent 74995101d1
commit 850a05d6bb
3 changed files with 90 additions and 81 deletions

View File

@@ -8,44 +8,52 @@ class
WSF_BUTTON_CONTROL WSF_BUTTON_CONTROL
inherit inherit
WSF_CONTROL WSF_CONTROL
create create
make make
feature {NONE} 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 make (n: STRING; v: STRING)
donothing(p:WSF_PAGE_CONTROL) do
do make_control
control_name := n
end text := v
handle_callback(event: STRING ; cname: STRING ; page: WSF_PAGE_CONTROL) click_event := agent donothing
do
if Current.control_name = cname and attached click_event then
click_event.call([page])
end 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 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 text: STRING
click_event: PROCEDURE [ANY, TUPLE [WSF_PAGE_CONTROL]] click_event: PROCEDURE [ANY, TUPLE [WSF_PAGE_CONTROL]]
end end

View File

@@ -6,32 +6,35 @@ note
deferred class deferred class
WSF_CONTROL WSF_CONTROL
feature {NONE} feature {NONE}
make_control make_control
do do
control_name:="" control_name := ""
end end
feature feature
control_name: STRING control_name: STRING
feature {WSF_PAGE_CONTROL} feature {WSF_PAGE_CONTROL}
handle_callback(event: STRING ; cname: STRING ; page: WSF_PAGE_CONTROL) handle_callback (event: STRING; cname: STRING; page: WSF_PAGE_CONTROL)
deferred deferred
end end
render: STRING render: STRING
deferred deferred
end end
state: JSON_OBJECT state: JSON_OBJECT
deferred deferred
end end
read_state(states:JSON_OBJECT) read_state (states: JSON_OBJECT)
do do
states.put (state, create {JSON_STRING}.make_json(control_name)) states.put (state, create {JSON_STRING}.make_json (control_name))
end end
end end

View File

@@ -24,57 +24,55 @@ feature -- Access
feature feature
initialize_controls initialize_controls
deferred deferred
end end
process process
deferred deferred
end end
feature feature
execute execute
local local
event: detachable STRING event: detachable STRING
control_name: detachable STRING control_name: detachable STRING
states:JSON_OBJECT states: JSON_OBJECT
do do
initialize_controls initialize_controls
control_name := get_parameter("control_name") control_name := get_parameter ("control_name")
event := get_parameter("event") event := get_parameter ("event")
if attached event and attached control_name and attached control then if attached event and attached control_name and attached control then
control.handle_callback (control_name,event, Current) control.handle_callback (control_name, event, Current)
create states.make create states.make
control.read_state(states) control.read_state (states)
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "application/json"]>>) response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "application/json"]>>)
response.put_string (states.representation) response.put_string (states.representation)
else else
process process
render render
end
end end
end
render render
local local
data: STRING data: STRING
do do
data := control.render data := control.render
response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/plain"], ["Content-Length", data.count.out]>>) response.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-Type", "text/plain"], ["Content-Length", data.count.out]>>)
response.put_string (data) response.put_string (data)
end
get_parameter(key: STRING) : detachable STRING
local
value: detachable WSF_VALUE
do
Result := VOID
value := request.query_parameter (key)
if attached value then
Result := value.as_string.value
end end
end get_parameter (key: STRING): detachable STRING
local
value: detachable WSF_VALUE
do
Result := VOID
value := request.query_parameter (key)
if attached value then
Result := value.as_string.value
end
end
feature {NONE} feature {NONE}