Workin file upload
This commit is contained in:
@@ -32,6 +32,9 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
if attached {JSON_STRING} new_state.item ("file") as new_name and attached {JSON_STRING} new_state.item ("type") as new_type and attached {JSON_NUMBER} new_state.item ("size") as new_size then
|
||||
create file.make (new_name.unescaped_string_32, new_type.unescaped_string_32, new_size.item.to_integer_32);
|
||||
end
|
||||
if attached {JSON_STRING} new_state.item ("upload_file") as f then
|
||||
upload_file:=f.unescaped_string_32;
|
||||
end
|
||||
end
|
||||
|
||||
state: WSF_JSON_OBJECT
|
||||
@@ -41,7 +44,18 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
Result.put_boolean (attached change_event, "callback_change")
|
||||
end
|
||||
|
||||
feature --Event handling
|
||||
feature -- Uploaded Files
|
||||
|
||||
set_uploaded_file (p: detachable STRING)
|
||||
-- Store link to uploaded file in control state. In order to make it availabe for future callbacks
|
||||
do
|
||||
if attached p as a_p then
|
||||
upload_file := a_p
|
||||
state_changes.put_string (a_p, "upload_file")
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Event handling
|
||||
|
||||
set_change_event (e: attached like change_event)
|
||||
-- Set text change event handle
|
||||
@@ -49,11 +63,20 @@ feature --Event handling
|
||||
change_event := e
|
||||
end
|
||||
|
||||
set_upload_function (e: attached like upload_function)
|
||||
-- Set button click event handle
|
||||
do
|
||||
upload_function := e
|
||||
end
|
||||
|
||||
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable ANY)
|
||||
do
|
||||
if Current.control_name.same_string (cname [1]) and attached change_event as cevent then
|
||||
if event.same_string ("change") then
|
||||
if Current.control_name.same_string (cname [1]) then
|
||||
if attached change_event as cevent and event.same_string ("change") then
|
||||
cevent.call (Void)
|
||||
elseif attached upload_function as ufunction and event.same_string ("uploadfile") and attached {ITERABLE[WSF_UPLOADED_FILE]}event_parameter as files then
|
||||
|
||||
set_uploaded_file(ufunction.item ([files]))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -89,4 +112,10 @@ feature -- Properties
|
||||
change_event: detachable PROCEDURE [ANY, TUPLE]
|
||||
-- Procedure to be execued on change
|
||||
|
||||
upload_function: detachable FUNCTION [ANY, TUPLE[ITERABLE[WSF_UPLOADED_FILE]],detachable STRING]
|
||||
-- Procedure to be execued on change
|
||||
|
||||
upload_file: detachable STRING
|
||||
-- Link to uploaded file
|
||||
|
||||
end
|
||||
|
||||
@@ -23,8 +23,8 @@ feature {NONE} -- Initialization
|
||||
make (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Initialize
|
||||
do
|
||||
control_name:=req.request_time_stamp.out
|
||||
make_control ( "body")
|
||||
control_name := req.request_time_stamp.out
|
||||
make_control ("body")
|
||||
request := req
|
||||
response := res
|
||||
initialize_controls
|
||||
@@ -69,16 +69,21 @@ feature -- Implementation
|
||||
event := get_parameter ("event")
|
||||
event_parameter := get_parameter ("event_parameter")
|
||||
if attached event and attached event_control_name and attached control then
|
||||
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
|
||||
set_state (sp)
|
||||
else
|
||||
if attached request.form_parameter ("file") as o then
|
||||
response.put_string (o.name)
|
||||
if not event.is_equal ("uploadfile") then
|
||||
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
|
||||
set_state (sp)
|
||||
end
|
||||
|
||||
else
|
||||
if attached request.form_parameter ("state") as statedata then
|
||||
create json_parser.make_parser (statedata.as_string.value)
|
||||
if attached {JSON_OBJECT} json_parser.parse_json as sp then
|
||||
set_state (sp)
|
||||
end
|
||||
end
|
||||
event_parameter:=request.uploaded_files
|
||||
end
|
||||
handle_callback (event_control_name.split ('-'), event, event_parameter)
|
||||
create states_changes.make
|
||||
@@ -128,7 +133,6 @@ feature -- Implementation
|
||||
Result.append (");page.initialize();});</script>")
|
||||
Result.append ("</div>")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
read_state_changes (states: WSF_JSON_OBJECT)
|
||||
@@ -152,7 +156,7 @@ feature -- Implementation
|
||||
|
||||
feature -- Event handling
|
||||
|
||||
handle_callback (cname: LIST[STRING]; event: STRING; event_parameter: detachable ANY)
|
||||
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable ANY)
|
||||
-- Forward callback to control
|
||||
do
|
||||
control.handle_callback (cname, event, event_parameter)
|
||||
@@ -185,8 +189,10 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
Result.put (controls_state, "controls")
|
||||
Result.put (state, "state")
|
||||
end
|
||||
|
||||
feature
|
||||
control_name:STRING
|
||||
|
||||
control_name: STRING
|
||||
|
||||
feature {NONE} -- Root control
|
||||
|
||||
|
||||
Reference in New Issue
Block a user