Merge branch 'widget' of github.com:ynh/EWF into widget
This commit is contained in:
49
draft/library/wsf_js_widget/kernel/input/wsf_file.e
Normal file
49
draft/library/wsf_js_widget/kernel/input/wsf_file.e
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
is_uploaded: BOOLEAN
|
||||||
|
do
|
||||||
|
Result := attached id
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
@@ -28,12 +28,14 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
|
|
||||||
set_state (new_state: JSON_OBJECT)
|
set_state (new_state: JSON_OBJECT)
|
||||||
-- Restore text from json
|
-- Restore text from json
|
||||||
|
local
|
||||||
|
id: detachable STRING
|
||||||
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_name") as new_name and attached {JSON_STRING} new_state.item ("file_type") as new_type and attached {JSON_NUMBER} new_state.item ("file_size") as new_size then
|
||||||
create file.make (new_name.unescaped_string_32, new_type.unescaped_string_32, new_size.item.to_integer_32);
|
if attached {JSON_STRING} new_state.item ("file_id") as a_id then
|
||||||
|
id := a_id.unescaped_string_32
|
||||||
end
|
end
|
||||||
if attached {JSON_STRING} new_state.item ("upload_file") as f then
|
create file.make (new_name.unescaped_string_32, new_type.unescaped_string_32, new_size.item.to_integer_32, id);
|
||||||
upload_file:=f.unescaped_string_32;
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -42,41 +44,44 @@ 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")
|
||||||
|
Result.put_boolean (attached upload_done_event, "callback_uploaddone")
|
||||||
|
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
|
||||||
|
Result.put_boolean (disabled, "disabled")
|
||||||
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
|
end
|
||||||
|
|
||||||
feature -- Event handling
|
feature -- Event handling
|
||||||
|
|
||||||
set_change_event (e: attached like change_event)
|
|
||||||
-- Set text change event handle
|
|
||||||
do
|
|
||||||
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)
|
handle_callback (cname: LIST [STRING]; event: STRING; event_parameter: detachable ANY)
|
||||||
|
local
|
||||||
|
f_name: detachable STRING
|
||||||
|
f_type: detachable STRING
|
||||||
|
f_size: detachable INTEGER
|
||||||
|
f_id: detachable STRING
|
||||||
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_done_event as udevent and event.same_string ("uploaddone") then
|
||||||
|
udevent.call (Void)
|
||||||
set_uploaded_file(ufunction.item ([files]))
|
elseif event.same_string ("uploadfile") and attached {ITERABLE [WSF_UPLOADED_FILE]} event_parameter as files then
|
||||||
|
if attached file as f then
|
||||||
|
if attached upload_function as ufunction then
|
||||||
|
f.set_id (ufunction.item ([files]))
|
||||||
|
end
|
||||||
|
f_name := f.name
|
||||||
|
f_type := f.type
|
||||||
|
f_size := f.size
|
||||||
|
f_id := f.id
|
||||||
|
end
|
||||||
|
state_changes.replace_with_string (f_name, "file_name")
|
||||||
|
state_changes.replace_with_string (f_type, "file_type")
|
||||||
|
state_changes.replace_with_integer (f_size, "file_size")
|
||||||
|
state_changes.replace_with_string (f_id, "file_id")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -94,28 +99,68 @@ feature -- Upload
|
|||||||
|
|
||||||
feature -- Implementation
|
feature -- Implementation
|
||||||
|
|
||||||
value: detachable WSF_PENDING_FILE
|
value: detachable WSF_FILE
|
||||||
do
|
do
|
||||||
Result := file
|
Result := file
|
||||||
end
|
end
|
||||||
|
|
||||||
render: STRING
|
render: STRING
|
||||||
|
local
|
||||||
|
attr: STRING
|
||||||
do
|
do
|
||||||
Result := render_tag ("", "type=%"file%" ")
|
attr := "type=%"file%" "
|
||||||
|
if attached attributes as a then
|
||||||
|
attr.append (a)
|
||||||
|
end
|
||||||
|
if disabled then
|
||||||
|
attr.append ("disabled=%"disabled%" ")
|
||||||
|
end
|
||||||
|
Result := render_tag ("", attr)
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Change
|
||||||
|
|
||||||
|
set_change_event (e: attached like change_event)
|
||||||
|
-- Set text change event handle
|
||||||
|
do
|
||||||
|
change_event := e
|
||||||
|
end
|
||||||
|
|
||||||
|
set_upload_done_event (e: attached like upload_done_event)
|
||||||
|
-- Set text change event handle
|
||||||
|
do
|
||||||
|
upload_done_event := e
|
||||||
|
end
|
||||||
|
|
||||||
|
set_upload_function (e: attached like upload_function)
|
||||||
|
-- Set button click event handle
|
||||||
|
do
|
||||||
|
upload_function := e
|
||||||
|
end
|
||||||
|
|
||||||
|
set_disabled (b: BOOLEAN)
|
||||||
|
do
|
||||||
|
if disabled /= b then
|
||||||
|
disabled := b
|
||||||
|
state_changes.replace_with_boolean (disabled, "disabled")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Properties
|
feature -- Properties
|
||||||
|
|
||||||
file: detachable WSF_PENDING_FILE
|
disabled: BOOLEAN
|
||||||
|
-- Defines if the a file is selectable and if a file can be removed once it is uploaded
|
||||||
|
|
||||||
|
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_done_event: detachable PROCEDURE [ANY, TUPLE]
|
||||||
-- Procedure to be execued on change
|
-- Procedure to be execued when upload was successful
|
||||||
|
|
||||||
upload_file: detachable STRING
|
upload_function: detachable FUNCTION [ANY, TUPLE [ITERABLE [WSF_UPLOADED_FILE]], detachable STRING]
|
||||||
-- Link to uploaded file
|
-- Store uploaded file and return server side file id
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
Result.put_string (text, "text")
|
Result.put_string (text, "text")
|
||||||
|
Result.put_boolean (disabled, "disabled")
|
||||||
Result.put_boolean (attached change_event, "callback_change")
|
Result.put_boolean (attached change_event, "callback_change")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -65,8 +66,17 @@ feature --Event handling
|
|||||||
feature -- Rendering
|
feature -- Rendering
|
||||||
|
|
||||||
render: STRING
|
render: STRING
|
||||||
|
local
|
||||||
|
attr: STRING
|
||||||
do
|
do
|
||||||
Result := render_tag ("", "type=%"" + type + "%" value=%"" + text + "%"")
|
attr := "type=%"" + type + "%" value=%"" + text + "%" "
|
||||||
|
if attached attributes as a then
|
||||||
|
attr.append (a)
|
||||||
|
end
|
||||||
|
if disabled then
|
||||||
|
attr.append ("disabled=%"disabled%" ")
|
||||||
|
end
|
||||||
|
Result := render_tag ("", attr)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Change
|
feature -- Change
|
||||||
@@ -80,6 +90,14 @@ feature -- Change
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
set_disabled (b: BOOLEAN)
|
||||||
|
do
|
||||||
|
if disabled /= b then
|
||||||
|
disabled := b
|
||||||
|
state_changes.replace_with_boolean (disabled, "disabled")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Implementation
|
feature -- Implementation
|
||||||
|
|
||||||
value: STRING
|
value: STRING
|
||||||
@@ -89,6 +107,9 @@ feature -- Implementation
|
|||||||
|
|
||||||
feature -- Properties
|
feature -- Properties
|
||||||
|
|
||||||
|
disabled: BOOLEAN
|
||||||
|
-- Defines if the input field is editable
|
||||||
|
|
||||||
text: STRING
|
text: STRING
|
||||||
-- Text to be displayed
|
-- Text to be displayed
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
|||||||
do
|
do
|
||||||
create Result.make
|
create Result.make
|
||||||
Result.put_string (text, "text")
|
Result.put_string (text, "text")
|
||||||
|
Result.put_boolean (disabled, "disabled")
|
||||||
Result.put_boolean (attached click_event, "callback_click")
|
Result.put_boolean (attached click_event, "callback_click")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -65,8 +66,17 @@ feature -- Rendering
|
|||||||
|
|
||||||
render: STRING
|
render: STRING
|
||||||
-- HTML representation of this control
|
-- HTML representation of this control
|
||||||
|
local
|
||||||
|
attr: STRING
|
||||||
do
|
do
|
||||||
Result := render_tag (text, attributes)
|
create attr.make_empty
|
||||||
|
if attached attributes as a then
|
||||||
|
attr.append (a)
|
||||||
|
end
|
||||||
|
if disabled then
|
||||||
|
attr.append ("disabled=%"disabled%" ")
|
||||||
|
end
|
||||||
|
Result := render_tag (text, attr)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Change
|
feature -- Change
|
||||||
@@ -76,12 +86,23 @@ feature -- Change
|
|||||||
do
|
do
|
||||||
if not t.same_string (text) then
|
if not t.same_string (text) then
|
||||||
text := t
|
text := t
|
||||||
state_changes.replace (create {JSON_STRING}.make_json (text), "text")
|
state_changes.replace_with_string (text, "text")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
set_disabled (b: BOOLEAN)
|
||||||
|
do
|
||||||
|
if disabled /= b then
|
||||||
|
disabled := b
|
||||||
|
state_changes.replace_with_boolean (disabled, "disabled")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Properties
|
feature -- Properties
|
||||||
|
|
||||||
|
disabled: BOOLEAN
|
||||||
|
-- Defines if the button is editable
|
||||||
|
|
||||||
text: STRING
|
text: STRING
|
||||||
-- The text currently displayed on this button
|
-- The text currently displayed on this button
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ feature {NONE} -- Initialization
|
|||||||
make_multi_control
|
make_multi_control
|
||||||
tag_name := "form"
|
tag_name := "form"
|
||||||
label_width := w
|
label_width := w
|
||||||
|
add_class ("form-horizontal")
|
||||||
end
|
end
|
||||||
|
|
||||||
feature
|
feature
|
||||||
|
|||||||
@@ -36,12 +36,13 @@ feature {NONE} -- Initialization
|
|||||||
do
|
do
|
||||||
make_control ("div")
|
make_control ("div")
|
||||||
add_class ("form-group")
|
add_class ("form-group")
|
||||||
if attached {WSF_HTML_CONTROL} c then
|
if not attached {WSF_VALUE_CONTROL [LIST[ANY]]} c then
|
||||||
c.add_class ("form-control-static")
|
|
||||||
elseif not attached {WSF_VALUE_CONTROL [LIST[ANY]]} c then
|
|
||||||
|
|
||||||
c.add_class ("form-control")
|
c.add_class ("form-control")
|
||||||
|
else
|
||||||
|
c.add_class ("form-control-static")
|
||||||
end
|
end
|
||||||
|
|
||||||
label_width := 2
|
label_width := 2
|
||||||
value_control := c
|
value_control := c
|
||||||
validators := v
|
validators := v
|
||||||
|
|||||||
@@ -16,114 +16,133 @@ create
|
|||||||
|
|
||||||
feature
|
feature
|
||||||
|
|
||||||
put_string (value: READABLE_STRING_GENERAL; key: JSON_STRING)
|
put_string (value: detachable READABLE_STRING_GENERAL; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
require
|
require
|
||||||
key_not_present: not has_key (key)
|
key_not_present: not has_key (key)
|
||||||
local
|
local
|
||||||
l_value: JSON_STRING
|
l_value: detachable JSON_STRING
|
||||||
do
|
do
|
||||||
|
if attached value as a_value then
|
||||||
|
create l_value.make_json_from_string_32 (a_value.as_string_32)
|
||||||
|
end
|
||||||
|
put (l_value, key)
|
||||||
|
end
|
||||||
|
|
||||||
|
put_integer (value: detachable 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: detachable JSON_NUMBER
|
||||||
|
do
|
||||||
|
if attached value as a_value then
|
||||||
|
create l_value.make_integer (a_value)
|
||||||
|
end
|
||||||
|
put (l_value, key)
|
||||||
|
end
|
||||||
|
|
||||||
|
put_natural (value: detachable 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: detachable JSON_NUMBER
|
||||||
|
do
|
||||||
|
if attached value as a_value then
|
||||||
|
create l_value.make_natural (a_value)
|
||||||
|
end
|
||||||
|
put (l_value, key)
|
||||||
|
end
|
||||||
|
|
||||||
|
put_real (value: detachable 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: detachable JSON_NUMBER
|
||||||
|
do
|
||||||
|
if attached value as a_value then
|
||||||
|
create l_value.make_real (a_value)
|
||||||
|
end
|
||||||
|
put (l_value, key)
|
||||||
|
end
|
||||||
|
|
||||||
|
put_boolean (value: detachable 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: detachable JSON_BOOLEAN
|
||||||
|
do
|
||||||
|
if attached value as a_value then
|
||||||
|
create l_value.make_boolean (a_value)
|
||||||
|
end
|
||||||
|
put (l_value, key)
|
||||||
|
end
|
||||||
|
|
||||||
|
replace_with_string (value: detachable READABLE_STRING_GENERAL; key: JSON_STRING)
|
||||||
|
-- Assuming there is no item of key `key',
|
||||||
|
-- insert `value' with `key'.
|
||||||
|
local
|
||||||
|
l_value: detachable JSON_STRING
|
||||||
|
do
|
||||||
|
if attached value as a_value then
|
||||||
create l_value.make_json_from_string_32 (value.as_string_32)
|
create l_value.make_json_from_string_32 (value.as_string_32)
|
||||||
put (l_value, key)
|
|
||||||
end
|
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)
|
replace (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
replace_with_integer (value: INTEGER_64; key: JSON_STRING)
|
replace_with_integer (value: detachable INTEGER_64; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
local
|
local
|
||||||
l_value: JSON_NUMBER
|
l_value: detachable JSON_NUMBER
|
||||||
do
|
do
|
||||||
create l_value.make_integer (value)
|
if attached value as a_value then
|
||||||
|
create l_value.make_integer (a_value)
|
||||||
|
end
|
||||||
replace (l_value, key)
|
replace (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
replace_with_with_natural (value: NATURAL_64; key: JSON_STRING)
|
replace_with_with_natural (value: detachable NATURAL_64; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
local
|
local
|
||||||
l_value: JSON_NUMBER
|
l_value: detachable JSON_NUMBER
|
||||||
do
|
do
|
||||||
create l_value.make_natural (value)
|
if attached value as a_value then
|
||||||
|
create l_value.make_natural (a_value)
|
||||||
|
end
|
||||||
replace (l_value, key)
|
replace (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
replace_with_real (value: DOUBLE; key: JSON_STRING)
|
replace_with_real (value: detachable DOUBLE; key: JSON_STRING)
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'
|
||||||
local
|
local
|
||||||
l_value: JSON_NUMBER
|
l_value: detachable JSON_NUMBER
|
||||||
do
|
do
|
||||||
create l_value.make_real (value)
|
if attached value as a_value then
|
||||||
|
create l_value.make_real (a_value)
|
||||||
|
end
|
||||||
replace (l_value, key)
|
replace (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
replace_with_boolean (value: detachable BOOLEAN; key: JSON_STRING)
|
||||||
replace_with_boolean (value: BOOLEAN; key: JSON_STRING)
|
|
||||||
-- Assuming there is no item of key `key',
|
-- Assuming there is no item of key `key',
|
||||||
-- insert `value' with `key'.
|
-- insert `value' with `key'.
|
||||||
local
|
local
|
||||||
l_value: JSON_BOOLEAN
|
l_value: detachable JSON_BOOLEAN
|
||||||
do
|
do
|
||||||
create l_value.make_boolean (value)
|
if attached value as a_value then
|
||||||
|
create l_value.make_boolean (a_value)
|
||||||
|
end
|
||||||
replace (l_value, key)
|
replace (l_value, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ feature -- Router and Filter
|
|||||||
map_agent_uri ("/grid", agent grid_demo, Void)
|
map_agent_uri ("/grid", agent grid_demo, Void)
|
||||||
map_agent_uri ("/repeater", agent repeater_demo, Void)
|
map_agent_uri ("/repeater", agent repeater_demo, Void)
|
||||||
map_agent_uri ("/slider", agent slider_demo, Void)
|
map_agent_uri ("/slider", agent slider_demo, Void)
|
||||||
|
map_agent_uri ("/upload", agent upload_demo, Void)
|
||||||
map_agent_uri ("/codeview", agent codeview, Void)
|
map_agent_uri ("/codeview", agent codeview, Void)
|
||||||
|
|
||||||
-- NOTE: you could put all those files in a specific folder, and use WSF_FILE_SYSTEM_HANDLER with "/"
|
-- NOTE: you could put all those files in a specific folder, and use WSF_FILE_SYSTEM_HANDLER with "/"
|
||||||
@@ -137,6 +138,16 @@ feature -- Execution
|
|||||||
page.execute
|
page.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
|
upload_demo (request: WSF_REQUEST; response: WSF_RESPONSE)
|
||||||
|
local
|
||||||
|
page: UPLOAD_PAGE
|
||||||
|
do
|
||||||
|
-- To send a response we need to setup, the status code and
|
||||||
|
-- the response headers.
|
||||||
|
create page.make (request, response)
|
||||||
|
page.execute
|
||||||
|
end
|
||||||
|
|
||||||
codeview (request: WSF_REQUEST; response: WSF_RESPONSE)
|
codeview (request: WSF_REQUEST; response: WSF_RESPONSE)
|
||||||
local
|
local
|
||||||
page: CODEVIEW_PAGE
|
page: CODEVIEW_PAGE
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ class WSF_CONTROL
|
|||||||
@controls=(build_control(control_name, state, @) for control_name, state of @fullstate.controls)
|
@controls=(build_control(control_name, state, @) for control_name, state of @fullstate.controls)
|
||||||
else
|
else
|
||||||
@controls = []
|
@controls = []
|
||||||
|
return
|
||||||
|
|
||||||
attach_events: ()->
|
attach_events: ()->
|
||||||
console.log "Attached #{@control_name}"
|
console.log "Attached #{@control_name}"
|
||||||
@@ -190,6 +191,7 @@ class WSF_CONTROL
|
|||||||
fn(action)
|
fn(action)
|
||||||
catch e
|
catch e
|
||||||
console.log "Failed preforming action #{action.type}"
|
console.log "Failed preforming action #{action.type}"
|
||||||
|
return
|
||||||
|
|
||||||
process_update: (new_states)->
|
process_update: (new_states)->
|
||||||
try
|
try
|
||||||
@@ -204,8 +206,6 @@ class WSF_CONTROL
|
|||||||
return
|
return
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
get_context_state : ()->
|
get_context_state : ()->
|
||||||
if @parent_control? and not @isolation
|
if @parent_control? and not @isolation
|
||||||
return @parent_control.get_context_state()
|
return @parent_control.get_context_state()
|
||||||
@@ -340,6 +340,9 @@ class WSF_BUTTON_CONTROL extends WSF_CONTROL
|
|||||||
@trigger_callback(@control_name, 'click')
|
@trigger_callback(@control_name, 'click')
|
||||||
|
|
||||||
update: (state) ->
|
update: (state) ->
|
||||||
|
if state.disabled != undefined
|
||||||
|
@state['disabled'] = state.disabled
|
||||||
|
@$el.prop('disabled', state.disabled)
|
||||||
if state.text?
|
if state.text?
|
||||||
@state['text'] = state.text
|
@state['text'] = state.text
|
||||||
@$el.text(state.text)
|
@$el.text(state.text)
|
||||||
@@ -362,6 +365,9 @@ class WSF_INPUT_CONTROL extends WSF_CONTROL
|
|||||||
return @$el.val()
|
return @$el.val()
|
||||||
|
|
||||||
update: (state) ->
|
update: (state) ->
|
||||||
|
if state.disabled != undefined
|
||||||
|
@state['disabled'] = state.disabled
|
||||||
|
@$el.prop('disabled', state.disabled)
|
||||||
if state.text?
|
if state.text?
|
||||||
@state['text'] = state.text
|
@state['text'] = state.text
|
||||||
@$el.val(state.text)
|
@$el.val(state.text)
|
||||||
@@ -372,6 +378,8 @@ class WSF_FILE_CONTROL extends WSF_CONTROL
|
|||||||
@uploading = false
|
@uploading = false
|
||||||
|
|
||||||
start_upload: ()->
|
start_upload: ()->
|
||||||
|
if @$el[0].files.length==0
|
||||||
|
return
|
||||||
if @uploading
|
if @uploading
|
||||||
return
|
return
|
||||||
@uploading = true
|
@uploading = true
|
||||||
@@ -415,14 +423,15 @@ class WSF_FILE_CONTROL extends WSF_CONTROL
|
|||||||
|
|
||||||
change: ()->
|
change: ()->
|
||||||
#update local state
|
#update local state
|
||||||
@state['file'] = null
|
@state['file_name'] = null
|
||||||
@state['type'] = null
|
@state['file_type'] = null
|
||||||
@state['size'] = null
|
@state['file_size'] = null
|
||||||
|
@state['file_id'] = null
|
||||||
if @$el[0].files.length>0
|
if @$el[0].files.length>0
|
||||||
file = @$el[0].files[0]
|
file = @$el[0].files[0]
|
||||||
@state['file'] = file.name
|
@state['file_name'] = file.name
|
||||||
@state['type'] = file.type
|
@state['file_type'] = file.type
|
||||||
@state['size'] = file.size
|
@state['file_size'] = file.size
|
||||||
if @state['callback_change']
|
if @state['callback_change']
|
||||||
@trigger_callback(@control_name, 'change')
|
@trigger_callback(@control_name, 'change')
|
||||||
@trigger('change')
|
@trigger('change')
|
||||||
@@ -431,10 +440,49 @@ class WSF_FILE_CONTROL extends WSF_CONTROL
|
|||||||
return @$el.val()
|
return @$el.val()
|
||||||
|
|
||||||
update: (state) ->
|
update: (state) ->
|
||||||
if state.upload_file?
|
if state.disabled != undefined
|
||||||
@progressbar.hide()
|
@state['disabled'] = state.disabled
|
||||||
@$el.parent().append($("""<p></p>""").addClass("form-control-static").text(@state['file']))
|
@$el.prop('disabled', state.disabled)
|
||||||
@state['upload_file'] = state.upload_file
|
@refresh()
|
||||||
|
if state.file_name != undefined
|
||||||
|
@state['file_name'] = state.file_name
|
||||||
|
if state.file_type != undefined
|
||||||
|
@state['file_type'] = state.file_type
|
||||||
|
if state.file_size != undefined
|
||||||
|
@state['file_size'] = state.file_size
|
||||||
|
if state.file_id != undefined
|
||||||
|
if @state['file_id'] != state.file_id
|
||||||
|
@state['file_id'] = state.file_id
|
||||||
|
if @state['callback_uploaddone']
|
||||||
|
@trigger_callback(@control_name, 'uploaddone')
|
||||||
|
@uploading = false
|
||||||
|
@refresh()
|
||||||
|
|
||||||
|
refresh: ()->
|
||||||
|
if @uploading
|
||||||
|
return
|
||||||
|
@progressbar.remove()
|
||||||
|
@$el.parent().find("p").remove()
|
||||||
|
if @state['file_id'] != null
|
||||||
|
@$el.hide()
|
||||||
|
fname = $("""<p></p>""").addClass("form-control-static").text(@state['file_name'])
|
||||||
|
@$el.parent().append(fname)
|
||||||
|
if not @state['disabled']
|
||||||
|
fname.append(" ");
|
||||||
|
removebtn = $("<button />").text("Remove").addClass("btn btn-xs btn-danger")
|
||||||
|
self = @
|
||||||
|
removebtn.click ()->
|
||||||
|
self.progressbar.remove()
|
||||||
|
self.$el.parent().find("p").remove()
|
||||||
|
self.$el.show()
|
||||||
|
self.$el.val('')
|
||||||
|
self.change()
|
||||||
|
fname.append(removebtn)
|
||||||
|
else
|
||||||
|
@$el.show()
|
||||||
|
@$el.val('')
|
||||||
|
@change()
|
||||||
|
|
||||||
|
|
||||||
class WSF_PASSWORD_CONTROL extends WSF_INPUT_CONTROL
|
class WSF_PASSWORD_CONTROL extends WSF_INPUT_CONTROL
|
||||||
|
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ WSF_CONTROL = (function() {
|
|||||||
WSF_CONTROL.prototype.load_subcontrols = function() {
|
WSF_CONTROL.prototype.load_subcontrols = function() {
|
||||||
var control_name, state;
|
var control_name, state;
|
||||||
if (this.fullstate.controls != null) {
|
if (this.fullstate.controls != null) {
|
||||||
return this.controls = (function() {
|
this.controls = (function() {
|
||||||
var _ref, _results;
|
var _ref, _results;
|
||||||
_ref = this.fullstate.controls;
|
_ref = this.fullstate.controls;
|
||||||
_results = [];
|
_results = [];
|
||||||
@@ -274,7 +274,7 @@ WSF_CONTROL = (function() {
|
|||||||
return _results;
|
return _results;
|
||||||
}).call(this);
|
}).call(this);
|
||||||
} else {
|
} else {
|
||||||
return this.controls = [];
|
this.controls = [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -293,24 +293,22 @@ WSF_CONTROL = (function() {
|
|||||||
WSF_CONTROL.prototype.update = function(state) {};
|
WSF_CONTROL.prototype.update = function(state) {};
|
||||||
|
|
||||||
WSF_CONTROL.prototype.process_actions = function(actions) {
|
WSF_CONTROL.prototype.process_actions = function(actions) {
|
||||||
var action, fn, _i, _len, _results;
|
var action, fn, _i, _len;
|
||||||
_results = [];
|
|
||||||
for (_i = 0, _len = actions.length; _i < _len; _i++) {
|
for (_i = 0, _len = actions.length; _i < _len; _i++) {
|
||||||
action = actions[_i];
|
action = actions[_i];
|
||||||
try {
|
try {
|
||||||
fn = null;
|
fn = null;
|
||||||
if (this[action.type] != null) {
|
if (this[action.type] != null) {
|
||||||
fn = this[action.type];
|
fn = this[action.type];
|
||||||
_results.push(fn.call(this, action));
|
fn.call(this, action);
|
||||||
} else {
|
} else {
|
||||||
fn = eval(action.type);
|
fn = eval(action.type);
|
||||||
_results.push(fn(action));
|
fn(action);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_results.push(console.log("Failed preforming action " + action.type));
|
console.log("Failed preforming action " + action.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _results;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
WSF_CONTROL.prototype.process_update = function(new_states) {
|
WSF_CONTROL.prototype.process_update = function(new_states) {
|
||||||
@@ -552,6 +550,10 @@ WSF_BUTTON_CONTROL = (function(_super) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
WSF_BUTTON_CONTROL.prototype.update = function(state) {
|
WSF_BUTTON_CONTROL.prototype.update = function(state) {
|
||||||
|
if (state.disabled !== void 0) {
|
||||||
|
this.state['disabled'] = state.disabled;
|
||||||
|
this.$el.prop('disabled', state.disabled);
|
||||||
|
}
|
||||||
if (state.text != null) {
|
if (state.text != null) {
|
||||||
this.state['text'] = state.text;
|
this.state['text'] = state.text;
|
||||||
return this.$el.text(state.text);
|
return this.$el.text(state.text);
|
||||||
@@ -592,6 +594,10 @@ WSF_INPUT_CONTROL = (function(_super) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
WSF_INPUT_CONTROL.prototype.update = function(state) {
|
WSF_INPUT_CONTROL.prototype.update = function(state) {
|
||||||
|
if (state.disabled !== void 0) {
|
||||||
|
this.state['disabled'] = state.disabled;
|
||||||
|
this.$el.prop('disabled', state.disabled);
|
||||||
|
}
|
||||||
if (state.text != null) {
|
if (state.text != null) {
|
||||||
this.state['text'] = state.text;
|
this.state['text'] = state.text;
|
||||||
return this.$el.val(state.text);
|
return this.$el.val(state.text);
|
||||||
@@ -613,6 +619,9 @@ WSF_FILE_CONTROL = (function(_super) {
|
|||||||
|
|
||||||
WSF_FILE_CONTROL.prototype.start_upload = function() {
|
WSF_FILE_CONTROL.prototype.start_upload = function() {
|
||||||
var action, file, formData;
|
var action, file, formData;
|
||||||
|
if (this.$el[0].files.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this.uploading) {
|
if (this.uploading) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -665,14 +674,15 @@ WSF_FILE_CONTROL = (function(_super) {
|
|||||||
|
|
||||||
WSF_FILE_CONTROL.prototype.change = function() {
|
WSF_FILE_CONTROL.prototype.change = function() {
|
||||||
var file;
|
var file;
|
||||||
this.state['file'] = null;
|
this.state['file_name'] = null;
|
||||||
this.state['type'] = null;
|
this.state['file_type'] = null;
|
||||||
this.state['size'] = null;
|
this.state['file_size'] = null;
|
||||||
|
this.state['file_id'] = null;
|
||||||
if (this.$el[0].files.length > 0) {
|
if (this.$el[0].files.length > 0) {
|
||||||
file = this.$el[0].files[0];
|
file = this.$el[0].files[0];
|
||||||
this.state['file'] = file.name;
|
this.state['file_name'] = file.name;
|
||||||
this.state['type'] = file.type;
|
this.state['file_type'] = file.type;
|
||||||
this.state['size'] = file.size;
|
this.state['file_size'] = file.size;
|
||||||
}
|
}
|
||||||
if (this.state['callback_change']) {
|
if (this.state['callback_change']) {
|
||||||
this.trigger_callback(this.control_name, 'change');
|
this.trigger_callback(this.control_name, 'change');
|
||||||
@@ -685,10 +695,60 @@ WSF_FILE_CONTROL = (function(_super) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
WSF_FILE_CONTROL.prototype.update = function(state) {
|
WSF_FILE_CONTROL.prototype.update = function(state) {
|
||||||
if (state.upload_file != null) {
|
if (state.disabled !== void 0) {
|
||||||
this.progressbar.hide();
|
this.state['disabled'] = state.disabled;
|
||||||
this.$el.parent().append($("<p></p>").addClass("form-control-static").text(this.state['file']));
|
this.$el.prop('disabled', state.disabled);
|
||||||
return this.state['upload_file'] = state.upload_file;
|
this.refresh();
|
||||||
|
}
|
||||||
|
if (state.file_name !== void 0) {
|
||||||
|
this.state['file_name'] = state.file_name;
|
||||||
|
}
|
||||||
|
if (state.file_type !== void 0) {
|
||||||
|
this.state['file_type'] = state.file_type;
|
||||||
|
}
|
||||||
|
if (state.file_size !== void 0) {
|
||||||
|
this.state['file_size'] = state.file_size;
|
||||||
|
}
|
||||||
|
if (state.file_id !== void 0) {
|
||||||
|
if (this.state['file_id'] !== state.file_id) {
|
||||||
|
this.state['file_id'] = state.file_id;
|
||||||
|
if (this.state['callback_uploaddone']) {
|
||||||
|
this.trigger_callback(this.control_name, 'uploaddone');
|
||||||
|
}
|
||||||
|
this.uploading = false;
|
||||||
|
}
|
||||||
|
return this.refresh();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
WSF_FILE_CONTROL.prototype.refresh = function() {
|
||||||
|
var fname, removebtn, self;
|
||||||
|
if (this.uploading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.progressbar.remove();
|
||||||
|
this.$el.parent().find("p").remove();
|
||||||
|
if (this.state['file_id'] !== null) {
|
||||||
|
this.$el.hide();
|
||||||
|
fname = $("<p></p>").addClass("form-control-static").text(this.state['file_name']);
|
||||||
|
this.$el.parent().append(fname);
|
||||||
|
if (!this.state['disabled']) {
|
||||||
|
fname.append(" ");
|
||||||
|
removebtn = $("<button />").text("Remove").addClass("btn btn-xs btn-danger");
|
||||||
|
self = this;
|
||||||
|
removebtn.click(function() {
|
||||||
|
self.progressbar.remove();
|
||||||
|
self.$el.parent().find("p").remove();
|
||||||
|
self.$el.show();
|
||||||
|
self.$el.val('');
|
||||||
|
return self.change();
|
||||||
|
});
|
||||||
|
return fname.append(removebtn);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.$el.show();
|
||||||
|
this.$el.val('');
|
||||||
|
return this.change();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ feature
|
|||||||
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/grid%"", "Grid"))
|
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/grid%"", "Grid"))
|
||||||
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/repeater%"", "Repeater"))
|
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/repeater%"", "Repeater"))
|
||||||
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/slider%"", "Slider"))
|
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/slider%"", "Slider"))
|
||||||
|
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/upload%"", "File Upload"))
|
||||||
navbar.add_element (dropdown)
|
navbar.add_element (dropdown)
|
||||||
navbar.add_list_element_right (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/about%"", "About"))
|
navbar.add_list_element_right (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/about%"", "About"))
|
||||||
create btn.make ("Show Code")
|
create btn.make ("Show Code")
|
||||||
|
|||||||
@@ -20,13 +20,9 @@ create
|
|||||||
feature -- Implementation
|
feature -- Implementation
|
||||||
|
|
||||||
initialize_controls
|
initialize_controls
|
||||||
local
|
|
||||||
form: WSF_FORM_CONTROL
|
|
||||||
do
|
do
|
||||||
Precursor
|
Precursor
|
||||||
create slider.make
|
create slider.make
|
||||||
create form.make
|
|
||||||
form.add_control (create {WSF_FORM_ELEMENT_CONTROL [STRING]}.make ("Input", create {WSF_INPUT_CONTROL}.make ("Test")))
|
|
||||||
--slider.add_control (form, Void)
|
--slider.add_control (form, Void)
|
||||||
--slider.add_image ("http://www.placesmustseen.com/wp-content/uploads/2013/01/paris-eiffel-tower.jpg", "Eiffel Tower")
|
--slider.add_image ("http://www.placesmustseen.com/wp-content/uploads/2013/01/paris-eiffel-tower.jpg", "Eiffel Tower")
|
||||||
slider.add_image ("http://31.media.tumblr.com/43f3edae3fb569943047077cddf93c79/tumblr_mtw7wdX9cm1st5lhmo1_1280.jpg", "car")
|
slider.add_image ("http://31.media.tumblr.com/43f3edae3fb569943047077cddf93c79/tumblr_mtw7wdX9cm1st5lhmo1_1280.jpg", "car")
|
||||||
|
|||||||
@@ -26,14 +26,11 @@ feature
|
|||||||
n3_container: WSF_FORM_ELEMENT_CONTROL [STRING]
|
n3_container: WSF_FORM_ELEMENT_CONTROL [STRING]
|
||||||
n4_container: WSF_FORM_ELEMENT_CONTROL [STRING]
|
n4_container: WSF_FORM_ELEMENT_CONTROL [STRING]
|
||||||
n5_container: WSF_FORM_ELEMENT_CONTROL [STRING]
|
n5_container: WSF_FORM_ELEMENT_CONTROL [STRING]
|
||||||
n6_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_PENDING_FILE]
|
|
||||||
n7_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_PENDING_FILE]
|
|
||||||
cats_container: WSF_FORM_ELEMENT_CONTROL [LIST [STRING]]
|
cats_container: WSF_FORM_ELEMENT_CONTROL [LIST [STRING]]
|
||||||
source: INCREASING_PROGRESSSOURCE
|
source: INCREASING_PROGRESSSOURCE
|
||||||
do
|
do
|
||||||
Precursor
|
Precursor
|
||||||
create form.make
|
create form.make
|
||||||
form.add_class ("form-horizontal")
|
|
||||||
--Number 1
|
--Number 1
|
||||||
create textbox1.make ("1")
|
create textbox1.make ("1")
|
||||||
create n1_container.make ("Number1", textbox1)
|
create n1_container.make ("Number1", textbox1)
|
||||||
@@ -66,21 +63,6 @@ feature
|
|||||||
cats_container.add_validator (create {WSF_MIN_VALIDATOR [LIST [STRING]]}.make (1, "Choose at least one category"))
|
cats_container.add_validator (create {WSF_MIN_VALIDATOR [LIST [STRING]]}.make (1, "Choose at least one category"))
|
||||||
cats_container.add_validator (create {WSF_MAX_VALIDATOR [LIST [STRING]]}.make (2, "Choose at most two category"))
|
cats_container.add_validator (create {WSF_MAX_VALIDATOR [LIST [STRING]]}.make (2, "Choose at most two category"))
|
||||||
form.add_control (cats_container)
|
form.add_control (cats_container)
|
||||||
--File
|
|
||||||
create filebox.make
|
|
||||||
filebox.set_upload_function (agent upload_file)
|
|
||||||
create n6_container.make ("File Upload", filebox)
|
|
||||||
n6_container.add_validator (create {WSF_FILESIZE_VALIDATOR}.make (10000000, "File must be smaller than 10MB"))
|
|
||||||
form.add_control (n6_container)
|
|
||||||
--File
|
|
||||||
create filebox2.make
|
|
||||||
filebox2.set_upload_function (agent upload_file)
|
|
||||||
filebox2.set_change_event (agent do
|
|
||||||
filebox2.start_upload
|
|
||||||
end)
|
|
||||||
create n7_container.make ("Auto Upload", filebox2)
|
|
||||||
n7_container.add_validator (create {WSF_FILESIZE_VALIDATOR}.make (10000000, "File must be smaller than 10MB"))
|
|
||||||
form.add_control (n7_container)
|
|
||||||
--Button 1
|
--Button 1
|
||||||
create button1.make ("Update")
|
create button1.make ("Update")
|
||||||
button1.set_click_event (agent handle_click)
|
button1.set_click_event (agent handle_click)
|
||||||
@@ -105,23 +87,12 @@ feature
|
|||||||
navbar.set_active (1)
|
navbar.set_active (1)
|
||||||
end
|
end
|
||||||
|
|
||||||
upload_file (f: ITERABLE [WSF_UPLOADED_FILE]): detachable String
|
|
||||||
do
|
|
||||||
-- Store file on server and return link
|
|
||||||
across
|
|
||||||
f as i
|
|
||||||
loop
|
|
||||||
Result:=i.item.filename
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
handle_click
|
handle_click
|
||||||
local
|
local
|
||||||
text: STRING
|
text: STRING
|
||||||
do
|
do
|
||||||
form.validate
|
form.validate
|
||||||
if form.is_valid then
|
if form.is_valid then
|
||||||
filebox.start_upload
|
|
||||||
--progress.set_progress ((textbox1.text.to_integer_64 / textbox2.text.to_integer_64 * 100).ceiling)
|
--progress.set_progress ((textbox1.text.to_integer_64 / textbox2.text.to_integer_64 * 100).ceiling)
|
||||||
text := textbox1.text + " + " + textbox2.text + " = " + (textbox1.text.to_integer_64 + textbox2.text.to_integer_64).out
|
text := textbox1.text + " + " + textbox2.text + " = " + (textbox1.text.to_integer_64 + textbox2.text.to_integer_64).out
|
||||||
text.append ("<ul>")
|
text.append ("<ul>")
|
||||||
@@ -150,10 +121,6 @@ feature
|
|||||||
|
|
||||||
button2: WSF_BUTTON_CONTROL
|
button2: WSF_BUTTON_CONTROL
|
||||||
|
|
||||||
filebox: WSF_FILE_CONTROL
|
|
||||||
|
|
||||||
filebox2: WSF_FILE_CONTROL
|
|
||||||
|
|
||||||
textbox1: WSF_INPUT_CONTROL
|
textbox1: WSF_INPUT_CONTROL
|
||||||
|
|
||||||
textbox2: WSF_INPUT_CONTROL
|
textbox2: WSF_INPUT_CONTROL
|
||||||
|
|||||||
106
examples/widgetapp/upload_page.e
Normal file
106
examples/widgetapp/upload_page.e
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {UPLOAD_PAGE}."
|
||||||
|
author: ""
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
UPLOAD_PAGE
|
||||||
|
|
||||||
|
inherit
|
||||||
|
|
||||||
|
BASE_PAGE
|
||||||
|
redefine
|
||||||
|
initialize_controls
|
||||||
|
end
|
||||||
|
|
||||||
|
create
|
||||||
|
make
|
||||||
|
|
||||||
|
feature -- Implementation
|
||||||
|
|
||||||
|
initialize_controls
|
||||||
|
local
|
||||||
|
do
|
||||||
|
Precursor
|
||||||
|
control.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("h1", "", "File Upload Demo"))
|
||||||
|
create form.make
|
||||||
|
--File
|
||||||
|
create filebox.make
|
||||||
|
filebox.set_upload_function (agent upload_file)
|
||||||
|
filebox.set_upload_done_event (agent submit_form)
|
||||||
|
create n0_container.make ("File Upload", filebox)
|
||||||
|
n0_container.add_validator (create {WSF_FILESIZE_VALIDATOR}.make (10000000, "File must be smaller than 10MB"))
|
||||||
|
form.add_control (n0_container)
|
||||||
|
--File
|
||||||
|
create filebox2.make
|
||||||
|
filebox2.set_upload_function (agent upload_file)
|
||||||
|
create n1_container.make ("Auto start Upload", filebox2)
|
||||||
|
filebox2.set_change_event (agent
|
||||||
|
do
|
||||||
|
n1_container.validate
|
||||||
|
if n1_container.is_valid then
|
||||||
|
filebox2.start_upload
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
n1_container.add_validator (create {WSF_FILESIZE_VALIDATOR}.make (10000000, "File must be smaller than 10MB"))
|
||||||
|
form.add_control (n1_container)
|
||||||
|
|
||||||
|
--Button 1
|
||||||
|
create button1.make ("Update")
|
||||||
|
button1.set_click_event (agent submit_form)
|
||||||
|
button1.add_class ("col-lg-offset-2")
|
||||||
|
form.add_control (button1)
|
||||||
|
control.add_control (form)
|
||||||
|
navbar.set_active (5)
|
||||||
|
end
|
||||||
|
|
||||||
|
submit_form
|
||||||
|
do
|
||||||
|
form.validate
|
||||||
|
if form.is_valid then
|
||||||
|
if attached filebox.file as f then
|
||||||
|
if not f.is_uploaded then
|
||||||
|
filebox.set_disabled (true)
|
||||||
|
filebox.start_upload
|
||||||
|
filebox2.set_disabled (true)
|
||||||
|
button1.set_disabled (true)
|
||||||
|
button1.set_text ("Uploading ...")
|
||||||
|
else
|
||||||
|
button1.set_text ("Done")
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
upload_file (f: ITERABLE [WSF_UPLOADED_FILE]): detachable String
|
||||||
|
do
|
||||||
|
-- Store file on server and return link
|
||||||
|
across
|
||||||
|
f as i
|
||||||
|
loop
|
||||||
|
Result := i.item.filename
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
process
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Properties
|
||||||
|
|
||||||
|
form: WSF_FORM_CONTROL
|
||||||
|
|
||||||
|
button1: WSF_BUTTON_CONTROL
|
||||||
|
|
||||||
|
filebox: WSF_FILE_CONTROL
|
||||||
|
|
||||||
|
filebox2: WSF_FILE_CONTROL
|
||||||
|
|
||||||
|
n0_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_FILE]
|
||||||
|
|
||||||
|
n1_container: WSF_FORM_ELEMENT_CONTROL [detachable WSF_FILE]
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user