Move wsf_js_widget library under draft/library/server/wsf_js_widget

This commit is contained in:
2014-07-07 10:26:10 +02:00
parent 3c8dc0a9e1
commit fe4c283336
106 changed files with 16 additions and 16 deletions

View File

@@ -0,0 +1,86 @@
note
description: "[
A control that can be used for autocompletion. A customizable
template can be passed to this class in a WSF_AUTOCOMPLETION
instance.
]"
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_AUTOCOMPLETE_CONTROL
inherit
WSF_INPUT_CONTROL
rename
make as make_input
redefine
handle_callback,
state
end
create
make, make_with_agent
feature {NONE} -- Initialization
make (c: WSF_AUTOCOMPLETION)
-- Initialize with specified autocompletion
do
make_with_agent (agent c.autocompletion)
if attached c.template as t then
template := t
end
end
make_with_agent (c: FUNCTION [ANY, TUPLE [READABLE_STRING_GENERAL], JSON_ARRAY])
-- Initialize with autocompletion function
do
make_input ("")
create_json_list := c
template := "{{=value}}"
end
feature -- State
state: WSF_JSON_OBJECT
do
Result := Precursor {WSF_INPUT_CONTROL}
Result.put_string (template, "template")
end
feature -- Callback
handle_callback (cname: LIST [READABLE_STRING_GENERAL]; event: READABLE_STRING_GENERAL; event_parameter: detachable ANY)
-- <Precursor>
do
Precursor {WSF_INPUT_CONTROL} (cname, event, event_parameter)
if
cname.first.same_string (control_name) and
event.same_string ("autocomplete")
then
state_changes.put (create_json_list.item ([text]), "suggestions")
end
end
feature -- Properties
create_json_list: FUNCTION [ANY, TUPLE [READABLE_STRING_GENERAL], JSON_ARRAY]
-- The function which is called to give a list of suggestions to a given user input
template: READABLE_STRING_32
-- The template
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,116 @@
note
description: "[
Representation of an HTML checkbox.
]"
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_CHECKBOX_CONTROL
inherit
WSF_VALUE_CONTROL [BOOLEAN]
rename
make as make_value_control,
value as checked,
set_value as set_checked
end
create
make
feature {NONE} -- Initialization
make (a_label, a_value: STRING_32)
-- Initialize with specified label `a_label' and value `a_value'.
require
a_value_not_empty: not a_value.is_empty
do
make_value_control ("input")
label := a_label
checked_value := a_value
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
-- Restore text from json
do
if attached {JSON_BOOLEAN} new_state.item ("checked") as new_checked then
checked := new_checked.item
end
end
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_boolean (checked, "checked")
Result.put_string (checked_value, "checked_value")
Result.put_boolean (attached change_event, "callback_change")
end
feature --Event handling
set_change_event (e: attached like change_event)
-- Set text change event handle
do
change_event := e
end
handle_callback (cname: LIST [READABLE_STRING_GENERAL]; event: READABLE_STRING_GENERAL; event_parameter: detachable ANY)
do
if
control_name.same_string_general (cname.first) and
attached change_event as cevent and then
event.same_string ("change")
then
cevent.call (Void)
end
end
feature -- Implementation
render: STRING_32
local
attrs: STRING_32
do
attrs := "type=%"checkbox%""
if checked then
attrs := attrs + " checked"
end
Result := render_tag_with_tagname ("div", render_tag_with_tagname ("label", render_tag ("", attrs) + " " + label, "", ""), "", "checkbox")
end
set_checked (v: BOOLEAN)
-- Set if the checkbox is checked
do
checked := v
end
feature -- Properties
label: STRING_32
-- The label of the checkbox control
checked: BOOLEAN
-- The checked value of the checkbox control
checked_value: STRING_32
-- The value of this checkbox
change_event: detachable PROCEDURE [ANY, TUPLE]
-- Function to be executed on change
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,65 @@
note
description: "[
Representation of a list of HTML checkboxes.
]"
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_CHECKBOX_LIST_CONTROL
inherit
WSF_VALUE_CONTROL [LIST [STRING_32]]
rename
make as make_control
undefine
load_state,
full_state,
read_state_changes
end
WSF_MULTI_CONTROL [WSF_CHECKBOX_CONTROL]
rename
make as make_multi_control
end
create
make
feature {NONE} -- Initializaton
make
-- Initialize with specified control name
do
make_multi_control
end
feature -- Implementation
value: LIST [STRING_32]
-- Returns the values of all selected checkboxes in this list
do
create {ARRAYED_LIST [STRING_32]} Result.make (0)
across
controls as c
loop
if c.item.checked then
Result.extend (c.item.checked_value)
end
end
end
set_value (v: LIST [STRING_32])
-- Sets the checked state of each of the checkboxes in this list according to whether the value
-- of a checkbox occurs in the specified list or not
do
across
controls as c
loop
c.item.set_checked (v.has (c.item.checked_value))
end
end
end

View File

@@ -0,0 +1,24 @@
note
description:"[
This class is only used because the code viewer has a specific
mapping in javascript. The Eiffel class does not provide
special functionality itself.
]"
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_CODEVIEW_CONTROL
inherit
WSF_TEXTAREA_CONTROL
rename
make as make_codeview
end
create
make_codeview
end

View File

@@ -0,0 +1,231 @@
note
description: "[
A control that represents a file upload.
]"
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_FILE_CONTROL
inherit
WSF_VALUE_CONTROL [detachable WSF_FILE_DEFINITION]
rename
make as make_value_control
end
create
make, make_with_image_preview
feature {NONE} -- Initialization
make
-- Initialize
do
make_value_control ("input")
end
make_with_image_preview
-- Initialize with image_preview set to true
do
make
image_preview := True
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
-- Restore text from json
local
id: detachable STRING_32
do
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
if attached {JSON_STRING} new_state.item ("file_id") as a_id then
id := a_id.unescaped_string_32
end
create file.make (new_name.unescaped_string_32, new_type.unescaped_string_32, new_size.item.to_integer_32, id)
end
if attached {JSON_BOOLEAN} new_state.item ("disabled") as a_disabled then
disabled := a_disabled.item
end
if attached {JSON_BOOLEAN} new_state.item ("image_preview") as a_image_preview then
image_preview := a_image_preview.item
end
end
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_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
Result.put_boolean (disabled, "disabled")
Result.put_boolean (image_preview, "image_preview")
end
feature -- Event handling
handle_callback (cname: LIST [READABLE_STRING_GENERAL]; event: READABLE_STRING_GENERAL; event_parameter: detachable ANY)
local
f_name: detachable STRING_32
f_type: detachable STRING_32
f_size: detachable INTEGER
f_id: detachable STRING_32
do
if control_name.same_string_general (cname.first) then
if attached change_event as cevent and event.same_string ("change") then
cevent.call (Void)
elseif attached upload_done_event as udevent and event.same_string ("uploaddone") then
udevent.call (Void)
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
feature -- Upload
start_upload
-- Add start upload command to action list which then executes the javascript function to start upload on client side
local
upload: WSF_JSON_OBJECT
do
create upload.make
upload.put_string ("start_upload", "type")
actions.add (upload)
end
feature -- Implementation
value: detachable WSF_FILE_DEFINITION
do
Result := file
end
render: STRING_32
local
attr: STRING_32
do
attr := "type=%"file%" "
if attached attributes as a then
attr.append (a)
end
if disabled then
attr.append ("disabled=%"disabled%" ")
end
Result := render_tag_with_tagname ("div", render_tag ("", attr), Void, "")
end
feature -- Change
set_change_event (e: attached like change_event)
-- Set text change event handle
do
change_event := e
ensure
change_event_set: change_event = e
end
set_upload_done_event (e: attached like upload_done_event)
-- Set text change event handle
do
upload_done_event := e
ensure
upload_done_event_set: upload_done_event = e
end
set_upload_function (e: attached like upload_function)
-- Set button click event handle
do
upload_function := e
ensure
upload_function_set: upload_function = e
end
set_disabled (b: BOOLEAN)
-- Set the disabled state of this file control
do
if disabled /= b then
disabled := b
state_changes.replace_with_boolean (disabled, "disabled")
end
ensure
disabled_set: disabled = b
state_changes_registered: old disabled /= disabled implies state_changes.has_key ("disabled")
end
set_value (v: detachable WSF_FILE_DEFINITION)
-- Set the file definition of this file control
do
file := v
ensure then
file_set: file = v
end
set_image_preview (b: BOOLEAN)
-- Set if the image should be previewed in the control
do
if image_preview /= b then
image_preview := b
state_changes.replace_with_boolean (image_preview, "image_preview")
end
ensure
image_preview_set: image_preview = b
state_changes_registered: old image_preview /= image_preview implies state_changes.has_key ("image_preview")
end
feature -- Properties
disabled: BOOLEAN
-- Defines if the a file is selectable and if a file can be removed once it is uploaded
image_preview: BOOLEAN
-- Preview uploaded image
file: detachable WSF_FILE_DEFINITION
-- Text to be displayed
change_event: detachable PROCEDURE [ANY, TUPLE]
-- Procedure to be execued on change
upload_done_event: detachable PROCEDURE [ANY, TUPLE]
-- Procedure to be execued when upload was successful
upload_function: detachable FUNCTION [ANY, TUPLE [ITERABLE [WSF_UPLOADED_FILE]], detachable STRING_32]
-- Store uploaded file and return server side file id
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,54 @@
note
description: "[
A container to encapsulate file information which is used by
WSF_FILE_CONTROL, such as name or type of the file.
]"
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_FILE_DEFINITION
create
make
feature {NONE}
make (a_name, a_type: STRING_32; a_size: INTEGER; a_id: detachable STRING_32)
do
name := a_name
type := a_type
size := a_size
id := a_id
end
feature -- Change
set_id (a_id: detachable STRING_32)
-- Set the id of this abstract file.
do
id := a_id
end
feature --Properties
is_uploaded: BOOLEAN
-- Whether the file denoted by this abstract file has been uploaded.
do
Result := attached id
end
name: STRING_32
-- File name
type: STRING_32
-- File mime type
size: INTEGER
-- File size
id: detachable STRING_32
-- Server side file id (e.g. S3 filename)
end

View File

@@ -0,0 +1,172 @@
note
description: "[
The basic <input> HTML element is represented by this control.
All controls that are used to gather some input from the user
basically can inherit from this class.
]"
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_INPUT_CONTROL
inherit
WSF_VALUE_CONTROL [STRING_32]
rename
make as make_value_control
end
create
make
feature {NONE} -- Initialization
make (v: STRING_32)
-- Initialize with specified value
do
make_value_control ("input")
type := "text"
text := v
ensure
text_set: text = v
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
set_state (new_state: JSON_OBJECT)
-- Restore text from json
do
if attached {JSON_STRING} new_state.item ("text") as new_text then
text := new_text.unescaped_string_32
end
end
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_string (text, "text")
Result.put_boolean (disabled, "disabled")
Result.put_boolean (attached change_event, "callback_change")
end
feature --Event handling
set_change_event (e: attached like change_event)
-- Set text change event handle
do
change_event := e
ensure
change_event_set: change_event = e
end
handle_callback (cname: LIST [READABLE_STRING_GENERAL]; event: READABLE_STRING_GENERAL; event_parameter: detachable ANY)
do
if
control_name.same_string_general (cname.first) and
attached change_event as cevent and then
event.same_string ("change")
then
cevent.call (Void)
end
end
feature -- Rendering
render: STRING_32
local
attr: STRING_32
do
create attr.make (25)
attr.append ("type=%"")
attr.append (type)
attr.append ("%" value=%"")
attr.append (text)
attr.append ("%" ")
if attached attributes as l_attributes then
attr.append (l_attributes)
end
if disabled then
attr.append (" disabled=%"disabled%" ")
end
Result := render_tag ("", attr)
end
feature -- Change
set_text (t: STRING_32)
-- Set text to be displayed
do
if not t.same_string (text) then
text := t
state_changes.replace (create {JSON_STRING}.make_json_from_string_32 (t), "text")
end
ensure
text_same_string_as_t: text.same_string (t)
state_changes_registered: old text /= text implies state_changes.has_key ("text")
end
set_disabled (b: BOOLEAN)
-- Set the disabled state of this control
do
if disabled /= b then
disabled := b
state_changes.replace_with_boolean (disabled, "disabled")
else
check has_key_disabled: (b = False) or else state_changes.has_key ("disabled") end
end
ensure
disabled_set: disabled = b
state_changes_registered: (old b) /= b implies state_changes.has_key ("disabled")
end
set_type (t: READABLE_STRING_32)
-- Set the type of this input control (HTML 'type' attribute)
do
type := t
ensure
type_set: type = t
end
feature -- Implementation
value: STRING_32
-- The value of this input control
do
Result := text
end
set_value (v: STRING_32)
-- Set the value of this input control
do
text := v
ensure then
value_set: text = v
end
feature -- Properties
disabled: BOOLEAN
-- Defines if the input field is editable
text: READABLE_STRING_32
-- Text to be displayed
type: READABLE_STRING_32
-- Type of this input control
change_event: detachable PROCEDURE [ANY, TUPLE]
-- Procedure to be execued on change
;note
copyright: "2011-2014, Yassin Hassan, Severin Munger, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,32 @@
note
description: "[
This control represents an HTML input control with the 'type'
attribute set to 'password'.
]"
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_PASSWORD_CONTROL
inherit
WSF_INPUT_CONTROL
rename
make as make_input
end
create
make
feature {NONE} -- Initialization
make (v: STRING_32)
-- Initialize with specified control name and text
do
make_input (v)
type := "password"
end
end

View File

@@ -0,0 +1,42 @@
note
description: "[
This control represents a textarea (the HTML 'textarea' tag).
It basically just inherits the functionality of an input
control.
]"
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_TEXTAREA_CONTROL
inherit
WSF_INPUT_CONTROL
rename
make as make_input
redefine
render
end
create
make
feature {NONE} -- Initialization
make (t: STRING_32)
-- Initialize with specified control name and text to be displayed in this textarea
do
make_input (t)
tag_name := "textarea"
end
feature -- Rendering
render: STRING_32
do
Result := render_tag (text, "")
end
end