Add serverside file id to file structure
This commit is contained in:
44
draft/library/wsf_js_widget/kernel/input/wsf_file.e
Normal file
44
draft/library/wsf_js_widget/kernel/input/wsf_file.e
Normal file
@@ -0,0 +1,44 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FILE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FILE
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE}
|
||||
|
||||
make (a_name, a_type: STRING; a_size: INTEGER; a_id: detachable STRING)
|
||||
do
|
||||
name := a_name
|
||||
type := a_type
|
||||
size := a_size
|
||||
id := a_id
|
||||
end
|
||||
|
||||
feature
|
||||
|
||||
set_id (a_id: detachable STRING)
|
||||
do
|
||||
id := a_id
|
||||
end
|
||||
|
||||
feature --Properties
|
||||
|
||||
name: STRING
|
||||
-- File name
|
||||
|
||||
type: STRING
|
||||
-- File mime type
|
||||
|
||||
size: INTEGER
|
||||
-- File size
|
||||
|
||||
id: detachable STRING
|
||||
-- Server side file id (e.g. S3 filename)
|
||||
|
||||
end
|
||||
@@ -9,7 +9,7 @@ class
|
||||
|
||||
inherit
|
||||
|
||||
WSF_VALUE_CONTROL [detachable WSF_PENDING_FILE]
|
||||
WSF_VALUE_CONTROL [detachable WSF_FILE]
|
||||
rename
|
||||
make as make_value_control
|
||||
end
|
||||
@@ -30,10 +30,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
-- Restore text from json
|
||||
do
|
||||
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;
|
||||
create file.make (new_name.unescaped_string_32, new_type.unescaped_string_32, new_size.item.to_integer_32, VOID);
|
||||
end
|
||||
end
|
||||
|
||||
@@ -42,16 +39,11 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
do
|
||||
create Result.make
|
||||
Result.put_boolean (attached change_event, "callback_change")
|
||||
end
|
||||
|
||||
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")
|
||||
if attached file as f then
|
||||
Result.put_string (f.name, "file_name")
|
||||
Result.put_string (f.type, "file_type")
|
||||
Result.put_integer (f.size, "file_size")
|
||||
Result.put_string (f.id, "file_id")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,13 +62,19 @@ feature -- Event handling
|
||||
end
|
||||
|
||||
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable ANY)
|
||||
local
|
||||
a_file: WSF_FILE
|
||||
do
|
||||
if Current.control_name.same_string (cname [1]) then
|
||||
if attached change_event as cevent and event.same_string ("change") 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]))
|
||||
elseif attached upload_function as ufunction and event.same_string ("uploadfile") and attached {ITERABLE [WSF_UPLOADED_FILE]} event_parameter as files then
|
||||
if attached file as f then
|
||||
a_file := f
|
||||
else
|
||||
create a_file.make ("", "", 0, VOID)
|
||||
end
|
||||
a_file.set_id (ufunction.item ([files]))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -94,7 +92,7 @@ feature -- Upload
|
||||
|
||||
feature -- Implementation
|
||||
|
||||
value: detachable WSF_PENDING_FILE
|
||||
value: detachable WSF_FILE
|
||||
do
|
||||
Result := file
|
||||
end
|
||||
@@ -106,16 +104,13 @@ feature -- Implementation
|
||||
|
||||
feature -- Properties
|
||||
|
||||
file: detachable WSF_PENDING_FILE
|
||||
file: detachable WSF_FILE
|
||||
-- Text to be displayed
|
||||
|
||||
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
|
||||
upload_function: detachable FUNCTION [ANY, TUPLE [ITERABLE [WSF_UPLOADED_FILE]], detachable STRING]
|
||||
-- Store uploaded file and return server side file id
|
||||
|
||||
end
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {WSF_PENDING_FILE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_PENDING_FILE
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE}
|
||||
|
||||
make (a_name, a_type: STRING; a_size: INTEGER)
|
||||
do
|
||||
name := a_name
|
||||
type := a_type
|
||||
size := a_size
|
||||
end
|
||||
|
||||
feature --Properties
|
||||
|
||||
name: STRING
|
||||
|
||||
type: STRING
|
||||
|
||||
size: INTEGER
|
||||
|
||||
end
|
||||
@@ -9,7 +9,7 @@ class
|
||||
|
||||
inherit
|
||||
|
||||
WSF_VALIDATOR [detachable WSF_PENDING_FILE]
|
||||
WSF_VALIDATOR [detachable WSF_FILE]
|
||||
rename
|
||||
make as make_validator
|
||||
redefine
|
||||
@@ -30,7 +30,7 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature -- Implementation
|
||||
|
||||
is_valid (input: detachable WSF_PENDING_FILE): BOOLEAN
|
||||
is_valid (input: detachable WSF_FILE): BOOLEAN
|
||||
do
|
||||
Result := True
|
||||
if attached input as a_input then
|
||||
|
||||
@@ -87,9 +87,9 @@ feature -- Properties
|
||||
|
||||
filebox2: WSF_FILE_CONTROL
|
||||
|
||||
n0_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_PENDING_FILE]
|
||||
n0_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_FILE]
|
||||
|
||||
n1_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_PENDING_FILE]
|
||||
n1_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_FILE]
|
||||
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user