Create new JSON_OBJECT
This commit is contained in:
@@ -27,7 +27,7 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
set_state (new_state: JSON_OBJECT)
|
||||
set_state (new_state: WSF_JSON_OBJECT)
|
||||
-- Restore text from json
|
||||
do
|
||||
if attached {JSON_STRING} new_state.item ("text") as new_text then
|
||||
@@ -35,12 +35,12 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
end
|
||||
end
|
||||
|
||||
state: JSON_OBJECT
|
||||
state: WSF_JSON_OBJECT
|
||||
-- Return state which contains the current text and if there is an event handle attached
|
||||
do
|
||||
create Result.make
|
||||
Result.put (create {JSON_STRING}.make_json (text), "text")
|
||||
Result.put (create {JSON_BOOLEAN}.make_boolean (attached click_event), "callback_click")
|
||||
Result.put_string (text, "text")
|
||||
Result.put_boolean (attached click_event, "callback_click")
|
||||
end
|
||||
|
||||
feature --Event handling
|
||||
|
||||
@@ -40,49 +40,49 @@ feature -- Actions
|
||||
start_modal(url:STRING; title:STRING)
|
||||
--Start a modal window containg an other or the same page
|
||||
local
|
||||
modal:JSON_OBJECT
|
||||
modal:WSF_JSON_OBJECT
|
||||
do
|
||||
create modal.make
|
||||
modal.put (create {JSON_STRING}.make_json("start_modal"), "type")
|
||||
modal.put (create {JSON_STRING}.make_json(url), "url")
|
||||
modal.put (create {JSON_STRING}.make_json(title), "title")
|
||||
modal.put_string ("start_modal", "type")
|
||||
modal.put_string (url, "url")
|
||||
modal.put_string (title, "title")
|
||||
actions.add (modal)
|
||||
end
|
||||
|
||||
show_alert(mesage:STRING)
|
||||
--Start a modal window containg an other or the same page
|
||||
local
|
||||
modal:JSON_OBJECT
|
||||
modal:WSF_JSON_OBJECT
|
||||
do
|
||||
create modal.make
|
||||
modal.put (create {JSON_STRING}.make_json("show_alert"), "type")
|
||||
modal.put (create {JSON_STRING}.make_json(mesage), "message")
|
||||
modal.put_string ("show_alert", "type")
|
||||
modal.put_string (mesage, "message")
|
||||
actions.add (modal)
|
||||
end
|
||||
|
||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
||||
|
||||
load_state (new_states: JSON_OBJECT)
|
||||
load_state (new_states: WSF_JSON_OBJECT)
|
||||
-- Select state stored with `control_name` as key
|
||||
do
|
||||
if attached {JSON_OBJECT} new_states.item ("state") as new_state_obj then
|
||||
if attached {WSF_JSON_OBJECT} new_states.item ("state") as new_state_obj then
|
||||
set_state (new_state_obj)
|
||||
end
|
||||
end
|
||||
|
||||
set_state (new_state: JSON_OBJECT)
|
||||
set_state (new_state: WSF_JSON_OBJECT)
|
||||
-- Before we process the callback. We restore the state of control.
|
||||
deferred
|
||||
end
|
||||
|
||||
full_state: JSON_OBJECT
|
||||
full_state: WSF_JSON_OBJECT
|
||||
-- Return state of object
|
||||
do
|
||||
create Result.make
|
||||
Result.put (state, "state")
|
||||
end
|
||||
|
||||
read_state_changes (states: JSON_OBJECT)
|
||||
read_state_changes (states: WSF_JSON_OBJECT)
|
||||
-- Add a new entry in the `states_changes` JSON object with the `control_name` as key and the `state` as value
|
||||
do
|
||||
if state_changes.count > 0 then
|
||||
@@ -102,14 +102,14 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
|
||||
end
|
||||
end
|
||||
|
||||
state: JSON_OBJECT
|
||||
state: WSF_JSON_OBJECT
|
||||
-- Returns the current state of the Control as JSON. This state will be transfered to the client.
|
||||
deferred
|
||||
ensure
|
||||
controls_not_defined: not (attached Result.item ("controls"))
|
||||
end
|
||||
|
||||
state_changes: JSON_OBJECT
|
||||
state_changes: WSF_JSON_OBJECT
|
||||
|
||||
feature -- Rendering
|
||||
|
||||
|
||||
@@ -48,24 +48,24 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
load_state (new_states: JSON_OBJECT)
|
||||
load_state (new_states: WSF_JSON_OBJECT)
|
||||
-- Pass new_states to subcontrols
|
||||
do
|
||||
Precursor (new_states)
|
||||
if attached {JSON_OBJECT} new_states.item ("controls") as ct and then attached {JSON_OBJECT} ct.item (value_control.control_name) as value_state then
|
||||
if attached {WSF_JSON_OBJECT} new_states.item ("controls") as ct and then attached {WSF_JSON_OBJECT} ct.item (value_control.control_name) as value_state then
|
||||
value_control.load_state (value_state)
|
||||
end
|
||||
end
|
||||
|
||||
set_state (new_state: JSON_OBJECT)
|
||||
set_state (new_state: WSF_JSON_OBJECT)
|
||||
-- Set new state
|
||||
do
|
||||
value_control.set_state (new_state)
|
||||
end
|
||||
|
||||
full_state: JSON_OBJECT
|
||||
full_state: WSF_JSON_OBJECT
|
||||
local
|
||||
controls_state: JSON_OBJECT
|
||||
controls_state: WSF_JSON_OBJECT
|
||||
do
|
||||
Result := Precursor
|
||||
create controls_state.make
|
||||
@@ -73,14 +73,14 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
Result.put (controls_state, "controls")
|
||||
end
|
||||
|
||||
read_state_changes (states: JSON_OBJECT)
|
||||
read_state_changes (states: WSF_JSON_OBJECT)
|
||||
-- Read states_changes in subcontrols
|
||||
do
|
||||
Precursor (states)
|
||||
value_control.read_state_changes (states)
|
||||
end
|
||||
|
||||
state: JSON_OBJECT
|
||||
state: WSF_JSON_OBJECT
|
||||
-- Read state
|
||||
local
|
||||
validator_description: JSON_ARRAY
|
||||
@@ -92,7 +92,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
loop
|
||||
validator_description.add (v.item.state)
|
||||
end
|
||||
Result.put (create {JSON_STRING}.make_json (value_control.control_name), "value_control")
|
||||
Result.put_string (value_control.control_name, "value_control")
|
||||
Result.put (validator_description, "validators")
|
||||
end
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
set_state (new_state: JSON_OBJECT)
|
||||
set_state (new_state: WSF_JSON_OBJECT)
|
||||
-- Restore html from json
|
||||
do
|
||||
if attached {JSON_STRING} new_state.item ("html") as new_html then
|
||||
@@ -33,11 +33,11 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
end
|
||||
end
|
||||
|
||||
state: JSON_OBJECT
|
||||
state: WSF_JSON_OBJECT
|
||||
-- Return state which contains the current html and if there is an event handle attached
|
||||
do
|
||||
create Result.make
|
||||
Result.put (create {JSON_STRING}.make_json (html), "html")
|
||||
Result.put_string (html, "html")
|
||||
end
|
||||
|
||||
feature --Event handling
|
||||
@@ -58,7 +58,7 @@ feature -- Implementation
|
||||
do
|
||||
if not t.same_string (html) then
|
||||
html := t
|
||||
state_changes.replace (create {JSON_STRING}.make_json (html), "html")
|
||||
state_changes.replace_with_string (html, "html")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
130
draft/library/wsf_js_widget/kernel/webcontrol/wsf_json_object.e
Normal file
130
draft/library/wsf_js_widget/kernel/webcontrol/wsf_json_object.e
Normal file
@@ -0,0 +1,130 @@
|
||||
note
|
||||
description: "Summary description for {WSF_JSON_OBJECT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_JSON_OBJECT
|
||||
|
||||
inherit
|
||||
|
||||
JSON_OBJECT
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature
|
||||
|
||||
put_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
require
|
||||
key_not_present: not has_key (key)
|
||||
local
|
||||
l_value: JSON_STRING
|
||||
do
|
||||
create l_value.make_json_from_string_32 (value.as_string_32)
|
||||
put (l_value, key)
|
||||
end
|
||||
|
||||
put_integer (value: INTEGER_64; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
require
|
||||
key_not_present: not has_key (key)
|
||||
local
|
||||
l_value: JSON_NUMBER
|
||||
do
|
||||
create l_value.make_integer (value)
|
||||
put (l_value, key)
|
||||
end
|
||||
|
||||
put_natural (value: NATURAL_64; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
require
|
||||
key_not_present: not has_key (key)
|
||||
local
|
||||
l_value: JSON_NUMBER
|
||||
do
|
||||
create l_value.make_natural (value)
|
||||
put (l_value, key)
|
||||
end
|
||||
|
||||
put_real (value: DOUBLE; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
require
|
||||
key_not_present: not has_key (key)
|
||||
local
|
||||
l_value: JSON_NUMBER
|
||||
do
|
||||
create l_value.make_real (value)
|
||||
put (l_value, key)
|
||||
end
|
||||
|
||||
put_boolean (value: BOOLEAN; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
require
|
||||
key_not_present: not has_key (key)
|
||||
local
|
||||
l_value: JSON_BOOLEAN
|
||||
do
|
||||
create l_value.make_boolean (value)
|
||||
put (l_value, key)
|
||||
end
|
||||
|
||||
replace_with_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
local
|
||||
l_value: JSON_STRING
|
||||
do
|
||||
create l_value.make_json_from_string_32 (value.as_string_32)
|
||||
replace (l_value, key)
|
||||
end
|
||||
|
||||
replace_with_integer (value: INTEGER_64; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
local
|
||||
l_value: JSON_NUMBER
|
||||
do
|
||||
create l_value.make_integer (value)
|
||||
replace (l_value, key)
|
||||
end
|
||||
|
||||
replace_with_with_natural (value: NATURAL_64; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
local
|
||||
l_value: JSON_NUMBER
|
||||
do
|
||||
create l_value.make_natural (value)
|
||||
replace (l_value, key)
|
||||
end
|
||||
|
||||
replace_with_real (value: DOUBLE; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
local
|
||||
l_value: JSON_NUMBER
|
||||
do
|
||||
create l_value.make_real (value)
|
||||
replace (l_value, key)
|
||||
end
|
||||
|
||||
|
||||
replace_with_boolean (value: BOOLEAN; key: JSON_STRING)
|
||||
-- Assuming there is no item of key `key',
|
||||
-- insert `value' with `key'.
|
||||
local
|
||||
l_value: JSON_BOOLEAN
|
||||
do
|
||||
create l_value.make_boolean (value)
|
||||
replace (l_value, key)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -36,16 +36,16 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
load_state (new_states: JSON_OBJECT)
|
||||
load_state (new_states: WSF_JSON_OBJECT)
|
||||
-- Pass new_states to subcontrols
|
||||
do
|
||||
Precursor (new_states)
|
||||
if attached {JSON_OBJECT} new_states.item ("controls") as ct then
|
||||
if attached {WSF_JSON_OBJECT} new_states.item ("controls") as ct then
|
||||
across
|
||||
controls as c
|
||||
loop
|
||||
if attached {WSF_CONTROL} c.item as cont then
|
||||
if attached {JSON_OBJECT} ct.item (cont.control_name) as value_state then
|
||||
if attached {WSF_JSON_OBJECT} ct.item (cont.control_name) as value_state then
|
||||
cont.load_state (value_state)
|
||||
end
|
||||
end
|
||||
@@ -53,15 +53,15 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
end
|
||||
end
|
||||
|
||||
set_state (new_state: JSON_OBJECT)
|
||||
set_state (new_state: WSF_JSON_OBJECT)
|
||||
-- Before we process the callback. We restore the state of control.
|
||||
do
|
||||
end
|
||||
|
||||
full_state: JSON_OBJECT
|
||||
full_state: WSF_JSON_OBJECT
|
||||
-- Read states in subcontrols
|
||||
local
|
||||
controls_state: JSON_OBJECT
|
||||
controls_state: WSF_JSON_OBJECT
|
||||
do
|
||||
Result := Precursor
|
||||
create controls_state.make
|
||||
@@ -75,7 +75,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
Result.put (controls_state, "controls")
|
||||
end
|
||||
|
||||
read_state_changes (states: JSON_OBJECT)
|
||||
read_state_changes (states: WSF_JSON_OBJECT)
|
||||
-- Read states_changes in subcontrols
|
||||
do
|
||||
Precursor (states)
|
||||
@@ -88,7 +88,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
end
|
||||
end
|
||||
|
||||
state: JSON_OBJECT
|
||||
state: WSF_JSON_OBJECT
|
||||
--Read state
|
||||
do
|
||||
create Result.make
|
||||
|
||||
@@ -60,7 +60,7 @@ feature -- Implementation
|
||||
event_parameter: detachable STRING
|
||||
event_control_name: detachable STRING
|
||||
states: STRING
|
||||
states_changes: JSON_OBJECT
|
||||
states_changes: WSF_JSON_OBJECT
|
||||
json_parser: JSON_PARSER
|
||||
do
|
||||
event_control_name := get_parameter ("control_name")
|
||||
@@ -70,7 +70,7 @@ feature -- Implementation
|
||||
create states.make_empty
|
||||
request.read_input_data_into (states)
|
||||
create json_parser.make_parser (states)
|
||||
if attached {JSON_OBJECT} json_parser.parse_json as sp then
|
||||
if attached {WSF_JSON_OBJECT} json_parser.parse_json as sp then
|
||||
set_state (sp)
|
||||
end
|
||||
handle_callback (event_control_name, event, event_parameter)
|
||||
@@ -126,7 +126,7 @@ feature -- Implementation
|
||||
|
||||
end
|
||||
|
||||
read_state_changes (states: JSON_OBJECT)
|
||||
read_state_changes (states: WSF_JSON_OBJECT)
|
||||
-- Add a new entry in the `states_changes` JSON object with the `control_name` as key and the `state` as value
|
||||
do
|
||||
Precursor (states)
|
||||
@@ -155,24 +155,24 @@ feature -- Event handling
|
||||
|
||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
state: JSON_OBJECT
|
||||
state: WSF_JSON_OBJECT
|
||||
do
|
||||
create Result.make
|
||||
Result.put (create {JSON_STRING}.make_json (control_name), "id")
|
||||
Result.put (create {JSON_STRING}.make_json (request.path_info), "url")
|
||||
Result.put (create {JSON_STRING}.make_json (request.query_string), "url_params")
|
||||
Result.put_string (control_name, "id")
|
||||
Result.put_string (request.path_info, "url")
|
||||
Result.put_string (request.query_string, "url_params")
|
||||
end
|
||||
|
||||
set_state (sp: JSON_OBJECT)
|
||||
set_state (sp: WSF_JSON_OBJECT)
|
||||
do
|
||||
if attached {JSON_OBJECT} sp.item ("controls") as ct and then attached {JSON_OBJECT} ct.item (control.control_name) as value_state then
|
||||
if attached {WSF_JSON_OBJECT} sp.item ("controls") as ct and then attached {WSF_JSON_OBJECT} ct.item (control.control_name) as value_state then
|
||||
control.load_state (value_state)
|
||||
end
|
||||
end
|
||||
|
||||
full_state: JSON_OBJECT
|
||||
full_state: WSF_JSON_OBJECT
|
||||
local
|
||||
controls_state: JSON_OBJECT
|
||||
controls_state: WSF_JSON_OBJECT
|
||||
do
|
||||
create Result.make
|
||||
create controls_state.make
|
||||
|
||||
Reference in New Issue
Block a user