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
|
inherit
|
||||||
|
|
||||||
WSF_VALUE_CONTROL [detachable WSF_PENDING_FILE]
|
WSF_VALUE_CONTROL [detachable WSF_FILE]
|
||||||
rename
|
rename
|
||||||
make as make_value_control
|
make as make_value_control
|
||||||
end
|
end
|
||||||
@@ -30,10 +30,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
-- Restore text from json
|
-- Restore text from json
|
||||||
do
|
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
|
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);
|
create file.make (new_name.unescaped_string_32, new_type.unescaped_string_32, new_size.item.to_integer_32, VOID);
|
||||||
end
|
|
||||||
if attached {JSON_STRING} new_state.item ("upload_file") as f then
|
|
||||||
upload_file:=f.unescaped_string_32;
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -42,16 +39,11 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
Result.put_boolean (attached change_event, "callback_change")
|
Result.put_boolean (attached change_event, "callback_change")
|
||||||
end
|
if attached file as f then
|
||||||
|
Result.put_string (f.name, "file_name")
|
||||||
feature -- Uploaded Files
|
Result.put_string (f.type, "file_type")
|
||||||
|
Result.put_integer (f.size, "file_size")
|
||||||
set_uploaded_file (p: detachable STRING)
|
Result.put_string (f.id, "file_id")
|
||||||
-- 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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -70,13 +62,19 @@ feature -- Event handling
|
|||||||
end
|
end
|
||||||
|
|
||||||
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable ANY)
|
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
|
local
|
||||||
|
a_file: WSF_FILE
|
||||||
do
|
do
|
||||||
if Current.control_name.same_string (cname [1]) then
|
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)
|
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
|
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
|
||||||
set_uploaded_file(ufunction.item ([files]))
|
a_file := f
|
||||||
|
else
|
||||||
|
create a_file.make ("", "", 0, VOID)
|
||||||
|
end
|
||||||
|
a_file.set_id (ufunction.item ([files]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -94,7 +92,7 @@ feature -- Upload
|
|||||||
|
|
||||||
feature -- Implementation
|
feature -- Implementation
|
||||||
|
|
||||||
value: detachable WSF_PENDING_FILE
|
value: detachable WSF_FILE
|
||||||
do
|
do
|
||||||
Result := file
|
Result := file
|
||||||
end
|
end
|
||||||
@@ -106,16 +104,13 @@ feature -- Implementation
|
|||||||
|
|
||||||
feature -- Properties
|
feature -- Properties
|
||||||
|
|
||||||
file: detachable WSF_PENDING_FILE
|
file: detachable WSF_FILE
|
||||||
-- Text to be displayed
|
-- Text to be displayed
|
||||||
|
|
||||||
change_event: detachable PROCEDURE [ANY, TUPLE]
|
change_event: detachable PROCEDURE [ANY, TUPLE]
|
||||||
-- Procedure to be execued on change
|
-- Procedure to be execued on change
|
||||||
|
|
||||||
upload_function: detachable FUNCTION [ANY, TUPLE [ITERABLE [WSF_UPLOADED_FILE]], detachable STRING]
|
upload_function: detachable FUNCTION [ANY, TUPLE [ITERABLE [WSF_UPLOADED_FILE]], detachable STRING]
|
||||||
-- Procedure to be execued on change
|
-- Store uploaded file and return server side file id
|
||||||
|
|
||||||
upload_file: detachable STRING
|
|
||||||
-- Link to uploaded file
|
|
||||||
|
|
||||||
end
|
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
|
inherit
|
||||||
|
|
||||||
WSF_VALIDATOR [detachable WSF_PENDING_FILE]
|
WSF_VALIDATOR [detachable WSF_FILE]
|
||||||
rename
|
rename
|
||||||
make as make_validator
|
make as make_validator
|
||||||
redefine
|
redefine
|
||||||
@@ -30,7 +30,7 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
feature -- Implementation
|
feature -- Implementation
|
||||||
|
|
||||||
is_valid (input: detachable WSF_PENDING_FILE): BOOLEAN
|
is_valid (input: detachable WSF_FILE): BOOLEAN
|
||||||
do
|
do
|
||||||
Result := True
|
Result := True
|
||||||
if attached input as a_input then
|
if attached input as a_input then
|
||||||
|
|||||||
@@ -87,9 +87,9 @@ feature -- Properties
|
|||||||
|
|
||||||
filebox2: WSF_FILE_CONTROL
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user