Extracted the WIDGET and FORM classes out of "cms" component
and build the wsf_html library which also include the previous css lib.
This commit is contained in:
154
library/server/wsf_html/form/wsf_form.e
Normal file
154
library/server/wsf_html/form/wsf_form.e
Normal file
@@ -0,0 +1,154 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM
|
||||
|
||||
inherit
|
||||
WSF_FORM_COMPOSITE
|
||||
|
||||
WSF_WITH_HTML_ATTRIBUTE
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_action: READABLE_STRING_8; a_id: READABLE_STRING_8)
|
||||
do
|
||||
action := a_action
|
||||
id := a_id
|
||||
initialize_with_count (10)
|
||||
create html_classes.make (2)
|
||||
set_method_post
|
||||
create validation_actions
|
||||
create submit_actions
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
action: READABLE_STRING_8
|
||||
-- URL for the web form
|
||||
|
||||
id: READABLE_STRING_8
|
||||
-- Id of the form
|
||||
|
||||
is_get_method: BOOLEAN
|
||||
do
|
||||
Result := method.same_string ("GET")
|
||||
end
|
||||
|
||||
is_post_method: BOOLEAN
|
||||
do
|
||||
Result := not is_get_method
|
||||
end
|
||||
|
||||
method: READABLE_STRING_8
|
||||
-- Form's method
|
||||
--| GET or POST
|
||||
|
||||
encoding_type: detachable READABLE_STRING_8
|
||||
-- Encoding type
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
process (req: WSF_REQUEST; a_before_callback, a_after_callback: detachable PROCEDURE [ANY, TUPLE [WSF_FORM_DATA]])
|
||||
-- Process Current form with request `req'
|
||||
-- agent `a_before_callback' is called before the validation
|
||||
-- agent `a_after_callback' is called after the validation
|
||||
local
|
||||
fd: WSF_FORM_DATA
|
||||
do
|
||||
create fd.make (req, Current)
|
||||
last_data := fd
|
||||
if a_before_callback /= Void then
|
||||
a_before_callback.call ([fd])
|
||||
end
|
||||
fd.validate
|
||||
fd.apply_to_associated_form -- Maybe only when has error?
|
||||
if fd.is_valid then
|
||||
fd.submit
|
||||
end
|
||||
if a_after_callback /= Void then
|
||||
a_after_callback.call ([fd])
|
||||
end
|
||||
end
|
||||
|
||||
last_data: detachable WSF_FORM_DATA
|
||||
|
||||
feature -- Validation
|
||||
|
||||
validation_actions: ACTION_SEQUENCE [TUPLE [WSF_FORM_DATA]]
|
||||
-- Procedure to validate the data
|
||||
-- report error if not valid
|
||||
|
||||
submit_actions: ACTION_SEQUENCE [TUPLE [WSF_FORM_DATA]]
|
||||
-- Submit actions
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_method_get
|
||||
do
|
||||
method := "GET"
|
||||
end
|
||||
|
||||
set_method_post
|
||||
do
|
||||
method := "POST"
|
||||
end
|
||||
|
||||
set_encoding_type (s: like encoding_type)
|
||||
do
|
||||
encoding_type := s
|
||||
end
|
||||
|
||||
set_multipart_form_data_encoding_type
|
||||
do
|
||||
encoding_type := "multipart/form-data"
|
||||
end
|
||||
|
||||
feature -- Optional
|
||||
|
||||
html_classes: ARRAYED_LIST [STRING_8]
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
local
|
||||
s: STRING_8
|
||||
do
|
||||
a_html.append ("<form action=%""+ action +"%" id=%""+ id +"%" method=%""+ method +"%"")
|
||||
if attached encoding_type as enctype then
|
||||
a_html.append (" enctype=%""+ enctype +"%"")
|
||||
end
|
||||
if not html_classes.is_empty then
|
||||
create s.make_empty
|
||||
across
|
||||
html_classes as cl
|
||||
loop
|
||||
if not s.is_empty then
|
||||
s.extend (' ')
|
||||
end
|
||||
s.append (cl.item)
|
||||
end
|
||||
a_html.append (" class=%"" + s + "%" ")
|
||||
end
|
||||
a_html.append (">%N")
|
||||
across
|
||||
items as c
|
||||
loop
|
||||
c.item.append_to_html (a_theme, a_html)
|
||||
end
|
||||
a_html.append ("</form>%N")
|
||||
end
|
||||
|
||||
to_html (a_theme: WSF_THEME): STRING_8
|
||||
do
|
||||
create Result.make_empty
|
||||
append_to_html (a_theme, Result)
|
||||
end
|
||||
|
||||
end
|
||||
20
library/server/wsf_html/form/wsf_form_button_input.e
Normal file
20
library/server/wsf_html/form/wsf_form_button_input.e
Normal file
@@ -0,0 +1,20 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_BUTTON_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_BUTTON_INPUT
|
||||
|
||||
inherit
|
||||
WSF_FORM_INPUT
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Access
|
||||
|
||||
input_type: STRING = "button"
|
||||
|
||||
end
|
||||
23
library/server/wsf_html/form/wsf_form_checkbox_input.e
Normal file
23
library/server/wsf_html/form/wsf_form_checkbox_input.e
Normal file
@@ -0,0 +1,23 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_CHECKBOX_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_CHECKBOX_INPUT
|
||||
|
||||
inherit
|
||||
WSF_FORM_SELECTABLE_INPUT
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_value
|
||||
|
||||
feature -- Access
|
||||
|
||||
input_type: STRING = "checkbox"
|
||||
|
||||
invariant
|
||||
|
||||
end
|
||||
89
library/server/wsf_html/form/wsf_form_composite.e
Normal file
89
library/server/wsf_html/form/wsf_form_composite.e
Normal file
@@ -0,0 +1,89 @@
|
||||
note
|
||||
description : "Objects that ..."
|
||||
author : "$Author$"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_FORM_COMPOSITE
|
||||
|
||||
inherit
|
||||
WSF_WIDGET_COMPOSITE
|
||||
redefine
|
||||
extend
|
||||
end
|
||||
|
||||
feature -- Status
|
||||
|
||||
has_field (a_name: READABLE_STRING_GENERAL): BOOLEAN
|
||||
do
|
||||
Result := container_has_field (Current, a_name)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
fields_by_name (a_name: READABLE_STRING_GENERAL): detachable LIST [WSF_FORM_FIELD]
|
||||
do
|
||||
Result := fields_by_name_from (Current, a_name)
|
||||
end
|
||||
|
||||
feature -- Change
|
||||
|
||||
extend (i: WSF_WIDGET)
|
||||
local
|
||||
n: READABLE_STRING_8
|
||||
do
|
||||
if attached {WSF_FORM_FIELD} i as l_field then
|
||||
n := l_field.name
|
||||
if n.is_empty then
|
||||
n := (items.count + 1).out
|
||||
l_field.update_name (n)
|
||||
end
|
||||
end
|
||||
Precursor (i)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation: Items
|
||||
|
||||
container_has_field (a_container: ITERABLE [WSF_WIDGET]; a_name: READABLE_STRING_GENERAL): BOOLEAN
|
||||
do
|
||||
across
|
||||
a_container as i
|
||||
until
|
||||
Result
|
||||
loop
|
||||
if attached {WSF_FORM_FIELD} i.item as l_field and then l_field.name.same_string_general (a_name) then
|
||||
Result := True
|
||||
elseif attached {ITERABLE [WSF_WIDGET]} i.item as l_cont then
|
||||
Result := container_has_field (l_cont, a_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
fields_by_name_from (a_container: ITERABLE [WSF_WIDGET]; a_name: READABLE_STRING_GENERAL): detachable ARRAYED_LIST [WSF_FORM_FIELD]
|
||||
local
|
||||
res: detachable ARRAYED_LIST [WSF_FORM_FIELD]
|
||||
do
|
||||
across
|
||||
a_container as i
|
||||
loop
|
||||
if attached {WSF_FORM_FIELD} i.item as l_field and then l_field.name.same_string_general (a_name) then
|
||||
if res = Void then
|
||||
create res.make (1)
|
||||
end
|
||||
res.force (l_field)
|
||||
elseif attached {ITERABLE [WSF_WIDGET]} i.item as l_cont then
|
||||
if attached fields_by_name_from (l_cont, a_name) as lst then
|
||||
if res = Void then
|
||||
res := lst
|
||||
else
|
||||
res.append (lst)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Result := res
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
329
library/server/wsf_html/form/wsf_form_data.e
Normal file
329
library/server/wsf_html/form/wsf_form_data.e
Normal file
@@ -0,0 +1,329 @@
|
||||
note
|
||||
description : "Objects that ..."
|
||||
author : "$Author$"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_DATA
|
||||
|
||||
inherit
|
||||
TABLE_ITERABLE [detachable WSF_VALUE, READABLE_STRING_8]
|
||||
|
||||
create {WSF_FORM}
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (req: WSF_REQUEST; a_form: WSF_FORM)
|
||||
-- Initialize `Current'.
|
||||
do
|
||||
form := a_form
|
||||
create items.make (a_form.count)
|
||||
get_items (req)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
form: WSF_FORM
|
||||
|
||||
feature -- Status
|
||||
|
||||
is_valid: BOOLEAN
|
||||
do
|
||||
Result := errors = Void
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
item_same_string (a_name: READABLE_STRING_GENERAL; s: READABLE_STRING_GENERAL): BOOLEAN
|
||||
-- Is there any item named `a_name' with a value `v'?
|
||||
do
|
||||
if attached item (a_name) as l_value then
|
||||
Result := l_value.same_string (s)
|
||||
end
|
||||
end
|
||||
|
||||
item (a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
|
||||
do
|
||||
Result := items.item (a_name.as_string_8)
|
||||
end
|
||||
|
||||
string_item (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
|
||||
do
|
||||
if attached {WSF_STRING} item (a_name) as s then
|
||||
Result := s.value
|
||||
end
|
||||
end
|
||||
|
||||
table_item (a_name: READABLE_STRING_GENERAL): detachable WSF_TABLE
|
||||
local
|
||||
s,k: READABLE_STRING_GENERAL
|
||||
p,q: INTEGER
|
||||
do
|
||||
if attached {WSF_TABLE} item (a_name) as tb then
|
||||
Result := tb
|
||||
else
|
||||
s := a_name + "["
|
||||
create Result.make (a_name.to_string_8) -- FIXME
|
||||
across
|
||||
items as c
|
||||
loop
|
||||
if attached c.item as v then
|
||||
k := c.key
|
||||
if k.starts_with (s) then
|
||||
if attached {WSF_TABLE} v as tb then
|
||||
across
|
||||
tb as t
|
||||
loop
|
||||
Result.add_value (t.item, t.item.name)
|
||||
end
|
||||
else
|
||||
p := k.index_of_code (91, 1) -- 91 '['
|
||||
if p > 0 then
|
||||
q := k.index_of_code (93, p + 1) -- 93 ']'
|
||||
if q > p then
|
||||
if q = p + 1 then
|
||||
-- []
|
||||
Result.add_value (v, (Result.count+1).out)
|
||||
else
|
||||
Result.add_value (v, k.substring (p + 1, q - 1))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
-- skip
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
integer_item (a_name: READABLE_STRING_GENERAL): INTEGER
|
||||
do
|
||||
if attached {WSF_STRING} item (a_name) as s and then s.is_integer then
|
||||
Result := s.integer_value
|
||||
end
|
||||
end
|
||||
|
||||
new_cursor: TABLE_ITERATION_CURSOR [detachable WSF_VALUE, READABLE_STRING_8]
|
||||
-- Fresh cursor associated with current structure
|
||||
do
|
||||
Result := items.new_cursor
|
||||
end
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
submit
|
||||
require
|
||||
is_valid: is_valid
|
||||
do
|
||||
form.submit_actions.call ([Current])
|
||||
end
|
||||
|
||||
validate
|
||||
do
|
||||
across
|
||||
form as f
|
||||
loop
|
||||
validate_item (f.item)
|
||||
end
|
||||
form.validation_actions.call ([Current])
|
||||
end
|
||||
|
||||
validate_item (w: WSF_WIDGET)
|
||||
do
|
||||
if attached {WSF_FORM_FIELD} w as l_field then
|
||||
l_field.validate (Current)
|
||||
elseif attached {ITERABLE [WSF_WIDGET]} w as lst then
|
||||
across
|
||||
lst as c
|
||||
loop
|
||||
validate_item (c.item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
set_fields_invalid (b: BOOLEAN; a_name: READABLE_STRING_GENERAL)
|
||||
do
|
||||
if attached form.fields_by_name (a_name) as lst then
|
||||
across
|
||||
lst as i
|
||||
loop
|
||||
i.item.set_is_invalid (b)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
apply_to_associated_form
|
||||
do
|
||||
if attached errors as errs then
|
||||
across
|
||||
errs as e
|
||||
loop
|
||||
if attached e.item as err then
|
||||
if attached err.field as e_field then
|
||||
set_fields_invalid (True, e_field.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
across
|
||||
items as c
|
||||
loop
|
||||
across
|
||||
form as i
|
||||
loop
|
||||
apply_to_associated_form_item (c.key, c.item, i.item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation: apply
|
||||
|
||||
apply_to_associated_form_item (a_name: READABLE_STRING_8; a_value: detachable WSF_VALUE; i: WSF_WIDGET)
|
||||
local
|
||||
do
|
||||
if attached {WSF_FORM_FIELD} i as l_field then
|
||||
if not attached {WSF_FORM_SUBMIT_INPUT} l_field then
|
||||
if l_field.name.same_string (a_name) then
|
||||
l_field.set_value (a_value)
|
||||
end
|
||||
end
|
||||
elseif attached {ITERABLE [WSF_WIDGET]} i as l_set then
|
||||
across
|
||||
l_set as c
|
||||
loop
|
||||
apply_to_associated_form_item (a_name, a_value, c.item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Change
|
||||
|
||||
report_error (a_msg: READABLE_STRING_8)
|
||||
do
|
||||
add_error (Void, a_msg)
|
||||
ensure
|
||||
is_invalid: not is_valid
|
||||
end
|
||||
|
||||
report_invalid_field (a_field_name: READABLE_STRING_8; a_msg: READABLE_STRING_8)
|
||||
require
|
||||
has_field: form.has_field (a_field_name)
|
||||
do
|
||||
if attached form.fields_by_name (a_field_name) as lst then
|
||||
across
|
||||
lst as c
|
||||
loop
|
||||
add_error (c.item, a_msg)
|
||||
end
|
||||
end
|
||||
ensure
|
||||
is_invalid: not is_valid
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
get_items (req: WSF_REQUEST)
|
||||
do
|
||||
get_form_items (req, form)
|
||||
end
|
||||
|
||||
get_form_items (req: WSF_REQUEST; lst: ITERABLE [WSF_WIDGET])
|
||||
do
|
||||
across
|
||||
lst as c
|
||||
loop
|
||||
if attached {WSF_FORM_FIELD} c.item as l_field then
|
||||
get_form_field_item (req, l_field, l_field.name)
|
||||
elseif attached {ITERABLE [WSF_WIDGET]} c.item as l_set then
|
||||
get_form_items (req, l_set)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
get_form_field_item (req: WSF_REQUEST; i: WSF_FORM_FIELD; n: READABLE_STRING_8)
|
||||
local
|
||||
v: detachable WSF_VALUE
|
||||
do
|
||||
if form.is_post_method then
|
||||
v := req.table_item (n, agent req.form_parameter)
|
||||
else
|
||||
v := req.table_item (n, agent req.query_parameter)
|
||||
end
|
||||
if v = Void then
|
||||
if n.ends_with_general ("[]") then
|
||||
if form.is_post_method then
|
||||
v := req.form_parameter (n.substring (1, n.count - 2))
|
||||
else
|
||||
v := req.query_parameter (n.substring (1, n.count - 2))
|
||||
end
|
||||
end
|
||||
end
|
||||
if i.is_required and (v = Void or else v.is_empty) then
|
||||
add_error (i, "Field %"<em>" + n + "</em>%" is required")
|
||||
else
|
||||
items.force (v, n)
|
||||
end
|
||||
end
|
||||
|
||||
add_error (a_field: detachable WSF_FORM_FIELD; a_msg: detachable READABLE_STRING_8)
|
||||
local
|
||||
err: like errors
|
||||
do
|
||||
err := errors
|
||||
if err = Void then
|
||||
create err.make (1)
|
||||
errors := err
|
||||
end
|
||||
err.force ([a_field, a_msg])
|
||||
end
|
||||
|
||||
items: HASH_TABLE [detachable WSF_VALUE, READABLE_STRING_8]
|
||||
|
||||
feature -- Cached values
|
||||
|
||||
cached_value (k: READABLE_STRING_8): detachable ANY
|
||||
do
|
||||
if attached cached_values as tb then
|
||||
Result := tb.item (k)
|
||||
end
|
||||
end
|
||||
|
||||
add_cached_value (k: READABLE_STRING_8; v: detachable ANY)
|
||||
local
|
||||
tb: like cached_values
|
||||
do
|
||||
tb := cached_values
|
||||
if tb = Void then
|
||||
create tb.make (1)
|
||||
cached_values := tb
|
||||
end
|
||||
tb.force (v, k)
|
||||
end
|
||||
|
||||
remove_cached_value (k: READABLE_STRING_8; v: detachable ANY)
|
||||
do
|
||||
if attached cached_values as tb then
|
||||
tb.remove (k)
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation: cached values
|
||||
|
||||
cached_values: detachable HASH_TABLE [detachable ANY, READABLE_STRING_8]
|
||||
|
||||
feature -- Reports
|
||||
|
||||
has_error: BOOLEAN
|
||||
do
|
||||
Result := attached errors as err and then not err.is_empty
|
||||
end
|
||||
|
||||
errors: detachable ARRAYED_LIST [TUPLE [field: detachable WSF_FORM_FIELD; message: detachable READABLE_STRING_8]]
|
||||
|
||||
invariant
|
||||
|
||||
end
|
||||
84
library/server/wsf_html/form/wsf_form_div.e
Normal file
84
library/server/wsf_html/form/wsf_form_div.e
Normal file
@@ -0,0 +1,84 @@
|
||||
note
|
||||
description : "Objects that ..."
|
||||
author : "$Author$"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_DIV
|
||||
|
||||
inherit
|
||||
WSF_FORM_ITEM
|
||||
|
||||
WSF_FORM_COMPOSITE
|
||||
|
||||
WSF_WITH_CSS_ID
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_item,
|
||||
make_with_items,
|
||||
make_with_text,
|
||||
make_with_text_and_css_id,
|
||||
make_with_item_and_css_id
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Initialize `Current'.
|
||||
do
|
||||
initialize_with_count (0)
|
||||
end
|
||||
|
||||
make_with_text (s: READABLE_STRING_8)
|
||||
do
|
||||
make_with_item (create {WSF_FORM_RAW_TEXT}.make (s))
|
||||
end
|
||||
|
||||
make_with_item (i: WSF_WIDGET)
|
||||
do
|
||||
initialize_with_count (1)
|
||||
extend (i)
|
||||
end
|
||||
|
||||
make_with_items (it: ITERABLE [WSF_WIDGET])
|
||||
do
|
||||
initialize_with_count (2)
|
||||
across
|
||||
it as c
|
||||
loop
|
||||
extend (c.item)
|
||||
end
|
||||
end
|
||||
|
||||
make_with_item_and_css_id (i: WSF_WIDGET; a_css_id: READABLE_STRING_8)
|
||||
do
|
||||
make_with_item (i)
|
||||
set_css_id (a_css_id)
|
||||
end
|
||||
|
||||
make_with_text_and_css_id (s: READABLE_STRING_8; a_css_id: READABLE_STRING_8)
|
||||
do
|
||||
make_with_text (s)
|
||||
set_css_id (a_css_id)
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
do
|
||||
a_html.append ("<div")
|
||||
append_css_class_to (a_html, Void)
|
||||
append_css_id_to (a_html)
|
||||
append_css_style_to (a_html)
|
||||
|
||||
a_html.append (">%N")
|
||||
across
|
||||
items as c
|
||||
loop
|
||||
c.item.append_to_html (a_theme, a_html)
|
||||
end
|
||||
a_html.append ("%N</div>%N")
|
||||
end
|
||||
|
||||
end
|
||||
146
library/server/wsf_html/form/wsf_form_field.e
Normal file
146
library/server/wsf_html/form/wsf_form_field.e
Normal file
@@ -0,0 +1,146 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_ITEM}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_FORM_FIELD
|
||||
|
||||
inherit
|
||||
WSF_FORM_ITEM
|
||||
|
||||
WSF_WITH_CSS_ID
|
||||
|
||||
DEBUG_OUTPUT
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: READABLE_STRING_8
|
||||
|
||||
label: detachable READABLE_STRING_8
|
||||
|
||||
description: detachable READABLE_STRING_8
|
||||
|
||||
is_required: BOOLEAN
|
||||
|
||||
is_invalid: BOOLEAN
|
||||
|
||||
is_readonly: BOOLEAN
|
||||
|
||||
is_description_collapsible: BOOLEAN
|
||||
|
||||
feature -- Status report
|
||||
|
||||
debug_output: STRING
|
||||
-- String that should be displayed in debugger to represent `Current'.
|
||||
do
|
||||
Result := name + " {" + generator + "}"
|
||||
end
|
||||
|
||||
feature -- Validation
|
||||
|
||||
validation_action: detachable PROCEDURE [ANY, TUPLE [WSF_FORM_DATA]]
|
||||
-- Function returning True if valid, otherwise False
|
||||
|
||||
validate (fd: WSF_FORM_DATA)
|
||||
do
|
||||
if attached validation_action as act then
|
||||
act.call ([fd])
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
update_name (a_name: like name)
|
||||
require
|
||||
name.is_empty
|
||||
do
|
||||
name := a_name
|
||||
end
|
||||
|
||||
set_is_required (b: BOOLEAN)
|
||||
do
|
||||
is_required := b
|
||||
end
|
||||
|
||||
set_is_readonly (b: BOOLEAN)
|
||||
do
|
||||
is_readonly := b
|
||||
end
|
||||
|
||||
set_label (lab: like label)
|
||||
do
|
||||
label := lab
|
||||
end
|
||||
|
||||
set_description (t: like description)
|
||||
do
|
||||
description := t
|
||||
end
|
||||
|
||||
set_validation_action (act: like validation_action)
|
||||
do
|
||||
validation_action := act
|
||||
end
|
||||
|
||||
set_is_invalid (b: BOOLEAN)
|
||||
do
|
||||
is_invalid := b
|
||||
end
|
||||
|
||||
set_value (v: detachable WSF_VALUE)
|
||||
-- Set value `v' if applicable to Current
|
||||
deferred
|
||||
end
|
||||
|
||||
set_description_collapsible (b: BOOLEAN)
|
||||
-- Set `is_description_collapsible' to `b'
|
||||
do
|
||||
is_description_collapsible := b
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
local
|
||||
l_class_items: detachable ARRAYED_LIST [READABLE_STRING_8]
|
||||
do
|
||||
create l_class_items.make (2)
|
||||
if is_required then
|
||||
l_class_items.extend ("required")
|
||||
end
|
||||
if is_invalid then
|
||||
l_class_items.extend ("error")
|
||||
end
|
||||
if l_class_items.is_empty then
|
||||
l_class_items := Void
|
||||
end
|
||||
|
||||
a_html.append ("<div")
|
||||
append_css_class_to (a_html, l_class_items)
|
||||
a_html.append_character ('>')
|
||||
if attached label as lab then
|
||||
a_html.append ("<strong><label for=%"" + name + "%">" + lab + "</label></strong>")
|
||||
if is_required then
|
||||
a_html.append (" (<em>required</em>)")
|
||||
end
|
||||
a_html.append ("<br/>%N")
|
||||
end
|
||||
append_item_to_html (a_theme, a_html)
|
||||
if attached description as desc then
|
||||
if is_description_collapsible then
|
||||
a_html.append ("<div class=%"description collapsible%"><div>Description ...</div><div>" + desc + "</div></div>")
|
||||
else
|
||||
a_html.append ("<div class=%"description%">" + desc + "</div>")
|
||||
end
|
||||
end
|
||||
a_html.append ("</div>")
|
||||
end
|
||||
|
||||
append_item_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
deferred
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
81
library/server/wsf_html/form/wsf_form_field_set.e
Normal file
81
library/server/wsf_html/form/wsf_form_field_set.e
Normal file
@@ -0,0 +1,81 @@
|
||||
note
|
||||
description : "Objects that ..."
|
||||
author : "$Author$"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_FIELD_SET
|
||||
|
||||
inherit
|
||||
WSF_FORM_ITEM
|
||||
|
||||
WSF_FORM_COMPOSITE
|
||||
|
||||
WSF_WITH_CSS_ID
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Initialize `Current'.
|
||||
do
|
||||
initialize_with_count (0)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
legend: detachable READABLE_STRING_8
|
||||
|
||||
is_collapsible: BOOLEAN
|
||||
|
||||
feature -- Change
|
||||
|
||||
set_legend (v: like legend)
|
||||
do
|
||||
legend := v
|
||||
end
|
||||
|
||||
set_collapsible (b: BOOLEAN)
|
||||
do
|
||||
is_collapsible := b
|
||||
if b then
|
||||
add_css_class ("collapsible")
|
||||
else
|
||||
remove_css_class ("collapsible")
|
||||
end
|
||||
end
|
||||
|
||||
set_collapsed (b: BOOLEAN)
|
||||
do
|
||||
if b then
|
||||
add_css_class ("collapsed")
|
||||
else
|
||||
remove_css_class ("collapsed")
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
do
|
||||
a_html.append ("<fieldset")
|
||||
append_css_class_to (a_html, Void)
|
||||
append_css_id_to (a_html)
|
||||
append_css_style_to (a_html)
|
||||
|
||||
a_html.append (">%N")
|
||||
if attached legend as leg then
|
||||
a_html.append ("<legend>" + leg + "</legend>%N")
|
||||
end
|
||||
across
|
||||
items as c
|
||||
loop
|
||||
c.item.append_to_html (a_theme, a_html)
|
||||
end
|
||||
a_html.append ("%N</fieldset>%N")
|
||||
end
|
||||
|
||||
end
|
||||
46
library/server/wsf_html/form/wsf_form_file_input.e
Normal file
46
library/server/wsf_html/form/wsf_form_file_input.e
Normal file
@@ -0,0 +1,46 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_FILE_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_FILE_INPUT
|
||||
|
||||
inherit
|
||||
WSF_FORM_INPUT
|
||||
redefine
|
||||
specific_input_attributes_string
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Access
|
||||
|
||||
input_type: STRING = "file"
|
||||
|
||||
accepted_types: detachable READABLE_STRING_8
|
||||
-- Types of files that the server accepts
|
||||
|
||||
feature -- Change
|
||||
|
||||
set_accepted_types (v: like accepted_types)
|
||||
do
|
||||
accepted_types := v
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
specific_input_attributes_string: detachable STRING_8
|
||||
-- Specific input attributes if any.
|
||||
-- To redefine if needed
|
||||
do
|
||||
if attached accepted_types as l_accepted_types then
|
||||
Result := " accept=%"" + l_accepted_types + "%""
|
||||
end
|
||||
end
|
||||
|
||||
invariant
|
||||
|
||||
end
|
||||
37
library/server/wsf_html/form/wsf_form_hidden_input.e
Normal file
37
library/server/wsf_html/form/wsf_form_hidden_input.e
Normal file
@@ -0,0 +1,37 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_HIDDEN_INPUT
|
||||
|
||||
inherit
|
||||
WSF_FORM_INPUT
|
||||
redefine
|
||||
input_type,
|
||||
append_item_to_html
|
||||
end
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_text
|
||||
|
||||
feature -- Access
|
||||
|
||||
input_type: STRING
|
||||
once
|
||||
Result := "hidden"
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_item_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
do
|
||||
a_html.append ("<div style=%"display:none%">")
|
||||
Precursor (a_theme, a_html)
|
||||
a_html.append ("</div>")
|
||||
end
|
||||
|
||||
end
|
||||
58
library/server/wsf_html/form/wsf_form_image_input.e
Normal file
58
library/server/wsf_html/form/wsf_form_image_input.e
Normal file
@@ -0,0 +1,58 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_IMAGE_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_IMAGE_INPUT
|
||||
|
||||
inherit
|
||||
WSF_FORM_INPUT
|
||||
redefine
|
||||
specific_input_attributes_string
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Access
|
||||
|
||||
input_type: STRING = "image"
|
||||
|
||||
src: detachable READABLE_STRING_8
|
||||
-- Specifies the URL of the image to use as a submit button
|
||||
|
||||
alt: detachable READABLE_STRING_8
|
||||
-- Alternate text for an image.
|
||||
|
||||
feature -- Change
|
||||
|
||||
set_src (v: like src)
|
||||
do
|
||||
src := v
|
||||
end
|
||||
|
||||
set_alt (v: like alt)
|
||||
do
|
||||
alt := v
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
specific_input_attributes_string: detachable STRING_8
|
||||
-- Specific input attributes if any.
|
||||
-- To redefine if needed
|
||||
do
|
||||
create Result.make_empty
|
||||
if attached src as l_src then
|
||||
Result.append (" src=%"" + l_src + "%"")
|
||||
end
|
||||
if attached alt as l_alt then
|
||||
Result.append (" alt=%"" + l_alt + "%"")
|
||||
end
|
||||
end
|
||||
|
||||
invariant
|
||||
|
||||
end
|
||||
136
library/server/wsf_html/form/wsf_form_input.e
Normal file
136
library/server/wsf_html/form/wsf_form_input.e
Normal file
@@ -0,0 +1,136 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_FORM_INPUT
|
||||
|
||||
inherit
|
||||
WSF_FORM_FIELD
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_name: like name)
|
||||
do
|
||||
name := a_name
|
||||
end
|
||||
|
||||
make_with_text (a_name: like name; a_text: READABLE_STRING_32)
|
||||
do
|
||||
make (a_name)
|
||||
set_text_value (a_text)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
default_value: detachable READABLE_STRING_32
|
||||
|
||||
size: INTEGER
|
||||
-- Width, in characters, of an <input> element.
|
||||
|
||||
maxlength: INTEGER
|
||||
-- Maximum number of characters allowed in an <input> element.
|
||||
|
||||
disabled: BOOLEAN
|
||||
-- Current <input> element should be disabled?
|
||||
|
||||
input_type: STRING
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_text_value (s: detachable READABLE_STRING_32)
|
||||
do
|
||||
set_default_value (s)
|
||||
end
|
||||
|
||||
set_size (i: like size)
|
||||
do
|
||||
size := i
|
||||
end
|
||||
|
||||
set_maxlength (i: like maxlength)
|
||||
do
|
||||
maxlength := i
|
||||
end
|
||||
|
||||
set_disabled (b: like disabled)
|
||||
do
|
||||
disabled := b
|
||||
end
|
||||
|
||||
set_value (v: detachable WSF_VALUE)
|
||||
do
|
||||
if attached {WSF_STRING} v as s then
|
||||
set_text_value (s.value)
|
||||
else
|
||||
set_text_value (Void)
|
||||
end
|
||||
end
|
||||
|
||||
set_default_value (v: like default_value)
|
||||
do
|
||||
default_value := v
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_item_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
local
|
||||
old_count: INTEGER
|
||||
do
|
||||
a_html.append ("<input type=%""+ input_type +"%" name=%""+ name +"%"")
|
||||
append_css_class_to (a_html, Void)
|
||||
append_css_id_to (a_html)
|
||||
append_css_style_to (a_html)
|
||||
|
||||
if is_readonly then
|
||||
a_html.append (" readonly=%"readonly%"")
|
||||
end
|
||||
if attached default_value as dft then
|
||||
a_html.append (" value=%"" + a_theme.html_encoded (dft) + "%"")
|
||||
end
|
||||
if disabled then
|
||||
a_html.append (" disabled=%"disabled%"")
|
||||
end
|
||||
if size > 0 then
|
||||
a_html.append (" size=%"" + size.out + "%"")
|
||||
end
|
||||
if maxlength > 0 then
|
||||
a_html.append (" maxlength=%"" + maxlength.out + "%"")
|
||||
end
|
||||
|
||||
if attached specific_input_attributes_string as s then
|
||||
a_html.append_character (' ')
|
||||
a_html.append (s)
|
||||
end
|
||||
a_html.append (">")
|
||||
old_count := a_html.count
|
||||
append_child_to_html (a_theme, a_html)
|
||||
if a_html.count > old_count then
|
||||
a_html.append ("</input>")
|
||||
else
|
||||
check a_html.item (a_html.count) = '>' end
|
||||
a_html.put ('/', a_html.count) -- replace previous '>'
|
||||
a_html.append (">")
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
append_child_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
-- Specific child element if any.
|
||||
--| To redefine if needed
|
||||
do
|
||||
end
|
||||
|
||||
specific_input_attributes_string: detachable STRING_8
|
||||
-- Specific input attributes if any.
|
||||
--| To redefine if needed
|
||||
do
|
||||
end
|
||||
|
||||
end
|
||||
17
library/server/wsf_html/form/wsf_form_item.e
Normal file
17
library/server/wsf_html/form/wsf_form_item.e
Normal file
@@ -0,0 +1,17 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_ITEM}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_FORM_ITEM
|
||||
|
||||
inherit
|
||||
WSF_WIDGET
|
||||
|
||||
WSF_WITH_CSS_CLASS
|
||||
|
||||
WSF_WITH_CSS_STYLE
|
||||
|
||||
end
|
||||
27
library/server/wsf_html/form/wsf_form_password_input.e
Normal file
27
library/server/wsf_html/form/wsf_form_password_input.e
Normal file
@@ -0,0 +1,27 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_PASSWORD_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_PASSWORD_INPUT
|
||||
|
||||
inherit
|
||||
WSF_FORM_INPUT
|
||||
redefine
|
||||
input_type
|
||||
end
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_text
|
||||
|
||||
feature -- Access
|
||||
|
||||
input_type: STRING
|
||||
once
|
||||
Result := "password"
|
||||
end
|
||||
|
||||
end
|
||||
23
library/server/wsf_html/form/wsf_form_radio_input.e
Normal file
23
library/server/wsf_html/form/wsf_form_radio_input.e
Normal file
@@ -0,0 +1,23 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_RADIO_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_RADIO_INPUT
|
||||
|
||||
inherit
|
||||
WSF_FORM_SELECTABLE_INPUT
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_value
|
||||
|
||||
feature -- Access
|
||||
|
||||
input_type: STRING = "radio"
|
||||
|
||||
invariant
|
||||
|
||||
end
|
||||
34
library/server/wsf_html/form/wsf_form_raw_text.e
Normal file
34
library/server/wsf_html/form/wsf_form_raw_text.e
Normal file
@@ -0,0 +1,34 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_RAW_TEXT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_RAW_TEXT
|
||||
|
||||
inherit
|
||||
WSF_WIDGET_TEXT
|
||||
rename
|
||||
set_text as set_value,
|
||||
make_with_text as make
|
||||
redefine
|
||||
append_to_html
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
do
|
||||
append_item_html_to (a_theme, a_html)
|
||||
end
|
||||
|
||||
append_item_html_to (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
do
|
||||
a_html.append (text)
|
||||
end
|
||||
|
||||
end
|
||||
20
library/server/wsf_html/form/wsf_form_reset_input.e
Normal file
20
library/server/wsf_html/form/wsf_form_reset_input.e
Normal file
@@ -0,0 +1,20 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_RESET_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_RESET_INPUT
|
||||
|
||||
inherit
|
||||
WSF_FORM_INPUT
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Access
|
||||
|
||||
input_type: STRING = "reset"
|
||||
|
||||
end
|
||||
151
library/server/wsf_html/form/wsf_form_select.e
Normal file
151
library/server/wsf_html/form/wsf_form_select.e
Normal file
@@ -0,0 +1,151 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_SELECT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_SELECT
|
||||
|
||||
inherit
|
||||
WSF_FORM_FIELD
|
||||
|
||||
WSF_FORM_UTILITY
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_name: like name)
|
||||
do
|
||||
name := a_name
|
||||
create options.make (0)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
options: ARRAYED_LIST [WSF_FORM_SELECT_OPTION]
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_text_by_value (a_text: detachable READABLE_STRING_GENERAL)
|
||||
local
|
||||
opt: WSF_FORM_SELECT_OPTION
|
||||
l_found: BOOLEAN
|
||||
v: READABLE_STRING_8
|
||||
do
|
||||
if a_text /= Void then
|
||||
v := html_encoded_string (a_text.to_string_32)
|
||||
across
|
||||
options as o
|
||||
loop
|
||||
if o.item.is_same_value (v) then
|
||||
l_found := True
|
||||
o.item.set_is_selected (True)
|
||||
else
|
||||
o.item.set_is_selected (False)
|
||||
end
|
||||
end
|
||||
if not l_found then
|
||||
create opt.make (v, Void)
|
||||
opt.set_is_selected (True)
|
||||
add_option (opt)
|
||||
end
|
||||
else
|
||||
across
|
||||
options as o
|
||||
loop
|
||||
o.item.set_is_selected (False)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
select_value_by_text (a_text: detachable READABLE_STRING_GENERAL)
|
||||
local
|
||||
l_found: BOOLEAN
|
||||
v: READABLE_STRING_8
|
||||
do
|
||||
if a_text /= Void then
|
||||
v := html_encoded_string (a_text.to_string_32)
|
||||
across
|
||||
options as o
|
||||
loop
|
||||
if o.item.is_same_text (v) then
|
||||
l_found := True
|
||||
o.item.set_is_selected (True)
|
||||
else
|
||||
o.item.set_is_selected (False)
|
||||
end
|
||||
end
|
||||
else
|
||||
across
|
||||
options as o
|
||||
loop
|
||||
o.item.set_is_selected (False)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
set_value (v: detachable WSF_VALUE)
|
||||
do
|
||||
if attached {WSF_STRING} v as s then
|
||||
set_text_by_value (s.value)
|
||||
else
|
||||
set_text_by_value (Void)
|
||||
end
|
||||
end
|
||||
|
||||
add_option (opt: WSF_FORM_SELECT_OPTION)
|
||||
do
|
||||
options.force (opt)
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_item_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
local
|
||||
l_is_already_selected: BOOLEAN
|
||||
h: detachable STRING_8
|
||||
do
|
||||
a_html.append ("<select name=%""+ name +"%" ")
|
||||
if css_id = Void then
|
||||
set_css_id (name + "-select")
|
||||
end
|
||||
append_css_class_to (a_html, Void)
|
||||
append_css_id_to (a_html)
|
||||
append_css_style_to (a_html)
|
||||
|
||||
if is_readonly then
|
||||
a_html.append (" readonly=%"readonly%" />")
|
||||
else
|
||||
a_html.append ("/>")
|
||||
end
|
||||
|
||||
across
|
||||
options as o
|
||||
loop
|
||||
a_html.append ("<option value=%"" + o.item.value + "%" ")
|
||||
-- if not l_is_already_selected then
|
||||
if
|
||||
o.item.is_selected
|
||||
then
|
||||
l_is_already_selected := True
|
||||
a_html.append (" selected=%"selected%"")
|
||||
end
|
||||
-- end
|
||||
a_html.append (">" + o.item.text + "</option>%N")
|
||||
if attached o.item.description as d then
|
||||
if h = Void then
|
||||
create h.make_empty
|
||||
end
|
||||
h.append ("<div id=%"" + name + "-" + o.item.value + "%" class=%"option%"><strong>"+ o.item.text +"</strong>:"+ d + "</div>")
|
||||
end
|
||||
end
|
||||
a_html.append ("</select>%N")
|
||||
if h /= Void then
|
||||
a_html.append ("<div class=%"select help collapsible%" id=%"" + name + "-help%">" + h + "</div>%N")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
63
library/server/wsf_html/form/wsf_form_select_option.e
Normal file
63
library/server/wsf_html/form/wsf_form_select_option.e
Normal file
@@ -0,0 +1,63 @@
|
||||
note
|
||||
description : "Objects that ..."
|
||||
author : "$Author$"
|
||||
date : "$Date$"
|
||||
revision : "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_SELECT_OPTION
|
||||
|
||||
inherit
|
||||
WSF_FORM_SELECTABLE_ITEM
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_value: like value; a_text: detachable like text)
|
||||
-- Initialize `Current'.
|
||||
do
|
||||
value := a_value
|
||||
if a_text = Void then
|
||||
text := a_value
|
||||
else
|
||||
text := a_text
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Status
|
||||
|
||||
is_selected: BOOLEAN
|
||||
|
||||
is_same_value (v: READABLE_STRING_32): BOOLEAN
|
||||
do
|
||||
Result := value.same_string (v)
|
||||
end
|
||||
|
||||
is_same_text (v: like text): BOOLEAN
|
||||
do
|
||||
Result := text.same_string (v)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
value: READABLE_STRING_32
|
||||
|
||||
text: READABLE_STRING_8
|
||||
|
||||
description: detachable READABLE_STRING_8
|
||||
|
||||
feature -- Change
|
||||
|
||||
set_is_selected (b: like is_selected)
|
||||
do
|
||||
is_selected := b
|
||||
end
|
||||
|
||||
set_description (d: like description)
|
||||
do
|
||||
description := d
|
||||
end
|
||||
|
||||
end
|
||||
112
library/server/wsf_html/form/wsf_form_selectable_input.e
Normal file
112
library/server/wsf_html/form/wsf_form_selectable_input.e
Normal file
@@ -0,0 +1,112 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_SELECTABLE_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_FORM_SELECTABLE_INPUT
|
||||
|
||||
inherit
|
||||
WSF_FORM_INPUT
|
||||
rename
|
||||
default_value as value,
|
||||
make_with_text as make_with_value
|
||||
redefine
|
||||
set_value,
|
||||
specific_input_attributes_string,
|
||||
append_child_to_html
|
||||
end
|
||||
|
||||
WSF_FORM_SELECTABLE_ITEM
|
||||
rename
|
||||
is_selected as checked,
|
||||
set_is_selected as set_checked
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
checked: BOOLEAN
|
||||
-- Current <input> element should be preselected when the page loads
|
||||
|
||||
title: detachable READABLE_STRING_32
|
||||
|
||||
raw_title: detachable READABLE_STRING_8
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_same_value (v: READABLE_STRING_32): BOOLEAN
|
||||
do
|
||||
Result := attached value as l_value and then v.same_string (l_value)
|
||||
end
|
||||
|
||||
feature -- Change
|
||||
|
||||
set_title (t: detachable READABLE_STRING_32)
|
||||
do
|
||||
title := t
|
||||
end
|
||||
|
||||
set_raw_title (t: detachable READABLE_STRING_8)
|
||||
do
|
||||
raw_title := t
|
||||
end
|
||||
|
||||
set_checked (b: like checked)
|
||||
do
|
||||
checked := b
|
||||
end
|
||||
|
||||
set_checked_by_value (v: detachable WSF_VALUE)
|
||||
do
|
||||
if attached {WSF_STRING} v as s then
|
||||
if value /= Void then
|
||||
set_checked (is_same_value (s.value))
|
||||
else
|
||||
set_checked (s.value.same_string ("on") or s.value.same_string ("true") or s.value.same_string ("yes") or s.value.same_string ("enabled"))
|
||||
end
|
||||
else
|
||||
set_checked (False)
|
||||
end
|
||||
end
|
||||
|
||||
set_value (v: detachable WSF_VALUE)
|
||||
-- Set value `v' if applicable to Current
|
||||
do
|
||||
if attached {ITERABLE [WSF_VALUE]} v as lst then
|
||||
across
|
||||
lst as c
|
||||
loop
|
||||
set_checked_by_value (c.item)
|
||||
end
|
||||
else
|
||||
set_checked_by_value (v)
|
||||
Precursor (v)
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
append_child_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
-- Specific child element if any.
|
||||
--| To redefine if needed
|
||||
do
|
||||
if attached raw_title as t then
|
||||
a_html.append (t)
|
||||
elseif attached title as t then
|
||||
a_html.append (a_theme.html_encoded (t))
|
||||
end
|
||||
end
|
||||
|
||||
specific_input_attributes_string: detachable STRING_8
|
||||
-- Specific input attributes if any.
|
||||
-- To redefine if needed
|
||||
do
|
||||
if checked then
|
||||
Result := "checked=%"checked%""
|
||||
end
|
||||
end
|
||||
|
||||
invariant
|
||||
|
||||
end
|
||||
25
library/server/wsf_html/form/wsf_form_selectable_item.e
Normal file
25
library/server/wsf_html/form/wsf_form_selectable_item.e
Normal file
@@ -0,0 +1,25 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_SELECTABLE_ITEM}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_FORM_SELECTABLE_ITEM
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_selected : BOOLEAN
|
||||
deferred
|
||||
end
|
||||
|
||||
is_same_value (v: READABLE_STRING_32): BOOLEAN
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Change
|
||||
|
||||
set_is_selected (b: like is_selected)
|
||||
deferred
|
||||
end
|
||||
|
||||
end
|
||||
21
library/server/wsf_html/form/wsf_form_submit_input.e
Normal file
21
library/server/wsf_html/form/wsf_form_submit_input.e
Normal file
@@ -0,0 +1,21 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_SUBMIT_INPUT
|
||||
|
||||
inherit
|
||||
WSF_FORM_INPUT
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_text
|
||||
|
||||
feature -- Access
|
||||
|
||||
input_type: STRING = "submit"
|
||||
|
||||
end
|
||||
21
library/server/wsf_html/form/wsf_form_text_input.e
Normal file
21
library/server/wsf_html/form/wsf_form_text_input.e
Normal file
@@ -0,0 +1,21 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_TEXT_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_TEXT_INPUT
|
||||
|
||||
inherit
|
||||
WSF_FORM_INPUT
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_text
|
||||
|
||||
feature -- Access
|
||||
|
||||
input_type: STRING = "text"
|
||||
|
||||
end
|
||||
89
library/server/wsf_html/form/wsf_form_textarea.e
Normal file
89
library/server/wsf_html/form/wsf_form_textarea.e
Normal file
@@ -0,0 +1,89 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_INPUT}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_TEXTAREA
|
||||
|
||||
inherit
|
||||
WSF_FORM_FIELD
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_name: like name)
|
||||
do
|
||||
name := a_name
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
default_value: detachable READABLE_STRING_GENERAL
|
||||
|
||||
rows: INTEGER
|
||||
|
||||
cols: INTEGER
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_rows (i: like rows)
|
||||
do
|
||||
rows := i
|
||||
end
|
||||
|
||||
set_cols (i: like cols)
|
||||
do
|
||||
cols := i
|
||||
end
|
||||
|
||||
set_text_value (s: like default_value)
|
||||
do
|
||||
set_default_value (s)
|
||||
end
|
||||
|
||||
set_value (v: detachable WSF_VALUE)
|
||||
do
|
||||
if attached {WSF_STRING} v as s then
|
||||
set_text_value (s.value)
|
||||
else
|
||||
set_text_value (Void)
|
||||
end
|
||||
end
|
||||
|
||||
set_default_value (v: like default_value)
|
||||
do
|
||||
default_value := v
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_item_to_html (a_theme: WSF_THEME; a_html: STRING_8)
|
||||
do
|
||||
a_html.append ("<textarea name=%""+ name +"%"")
|
||||
if rows > 0 then
|
||||
a_html.append (" rows=%"" + rows.out + "%"")
|
||||
end
|
||||
if cols > 0 then
|
||||
a_html.append (" cols=%"" + cols.out + "%"")
|
||||
end
|
||||
|
||||
append_css_class_to (a_html, Void)
|
||||
append_css_id_to (a_html)
|
||||
append_css_style_to (a_html)
|
||||
|
||||
if is_readonly then
|
||||
a_html.append (" readonly=%"readonly%">")
|
||||
else
|
||||
a_html.append (">")
|
||||
end
|
||||
if attached default_value as dft then
|
||||
a_html.append (a_theme.html_encoded (dft))
|
||||
end
|
||||
a_html.append ("</textarea>")
|
||||
end
|
||||
|
||||
end
|
||||
22
library/server/wsf_html/form/wsf_form_utility.e
Normal file
22
library/server/wsf_html/form/wsf_form_utility.e
Normal file
@@ -0,0 +1,22 @@
|
||||
note
|
||||
description: "Summary description for {WSF_FORM_UTILITY}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_FORM_UTILITY
|
||||
|
||||
feature -- Converter
|
||||
|
||||
html_encoded_string (s: READABLE_STRING_32): READABLE_STRING_8
|
||||
do
|
||||
Result := html_encoder.encoded_string (s)
|
||||
end
|
||||
|
||||
html_encoder: HTML_ENCODER
|
||||
once
|
||||
create Result
|
||||
end
|
||||
|
||||
end
|
||||
37
library/server/wsf_html/form/wsf_theme.e
Normal file
37
library/server/wsf_html/form/wsf_theme.e
Normal file
@@ -0,0 +1,37 @@
|
||||
note
|
||||
description: "Summary description for {WSF_THEME}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_THEME
|
||||
|
||||
feature -- Access
|
||||
|
||||
url_encoded (s: detachable READABLE_STRING_GENERAL): STRING_8
|
||||
local
|
||||
enc: URL_ENCODER
|
||||
do
|
||||
create enc
|
||||
if s /= Void then
|
||||
Result := enc.general_encoded_string (s)
|
||||
else
|
||||
create Result.make_empty
|
||||
end
|
||||
end
|
||||
|
||||
html_encoded (s: detachable READABLE_STRING_GENERAL): STRING_8
|
||||
local
|
||||
enc: HTML_ENCODER
|
||||
do
|
||||
create enc
|
||||
if s /= Void then
|
||||
Result := enc.general_encoded_string (s)
|
||||
else
|
||||
create Result.make_empty
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
109
library/server/wsf_html/form/wsf_with_css_class.e
Normal file
109
library/server/wsf_html/form/wsf_with_css_class.e
Normal file
@@ -0,0 +1,109 @@
|
||||
note
|
||||
description: "Summary description for {WSF_WITH_CSS_CLASS}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_WITH_CSS_CLASS
|
||||
|
||||
feature -- Status report
|
||||
|
||||
css_classes: detachable LIST [READABLE_STRING_8]
|
||||
|
||||
feature -- Change
|
||||
|
||||
reset_css_classes
|
||||
do
|
||||
css_classes := Void
|
||||
end
|
||||
|
||||
add_css_classes (a_classes: detachable ITERABLE [READABLE_STRING_8])
|
||||
do
|
||||
if a_classes /= Void then
|
||||
across
|
||||
a_classes as c
|
||||
loop
|
||||
add_css_class (c.item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
add_css_class (a_class: READABLE_STRING_8)
|
||||
require
|
||||
is_valid_css_class: is_valid_css_class (a_class)
|
||||
local
|
||||
lst: like css_classes
|
||||
do
|
||||
lst := css_classes
|
||||
if lst = Void then
|
||||
create {ARRAYED_LIST [READABLE_STRING_8]} lst.make (1)
|
||||
lst.compare_objects
|
||||
css_classes := lst
|
||||
end
|
||||
lst.force (a_class)
|
||||
end
|
||||
|
||||
remove_css_class (a_class: READABLE_STRING_8)
|
||||
require
|
||||
is_valid_css_class: is_valid_css_class (a_class)
|
||||
local
|
||||
lst: like css_classes
|
||||
do
|
||||
lst := css_classes
|
||||
if lst /= Void then
|
||||
lst.prune_all (a_class)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Query
|
||||
|
||||
is_valid_css_class (s: detachable READABLE_STRING_8): BOOLEAN
|
||||
do
|
||||
Result := s /= Void implies (not s.is_empty)
|
||||
-- To complete
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_css_class_to (a_target: STRING; a_additional_classes: detachable ITERABLE [READABLE_STRING_8])
|
||||
local
|
||||
f: BOOLEAN
|
||||
cl: READABLE_STRING_8
|
||||
do
|
||||
if css_classes /= Void or a_additional_classes /= Void then
|
||||
a_target.append (" class=%"")
|
||||
f := True -- is first
|
||||
|
||||
if attached css_classes as l_classes then
|
||||
across
|
||||
l_classes as c
|
||||
loop
|
||||
cl := c.item
|
||||
if not cl.is_empty then
|
||||
if f then
|
||||
f := False
|
||||
else
|
||||
a_target.append_character (' ')
|
||||
end
|
||||
a_target.append (cl)
|
||||
end
|
||||
end
|
||||
end
|
||||
if attached a_additional_classes as l_classes then
|
||||
across
|
||||
l_classes as c
|
||||
loop
|
||||
cl := c.item
|
||||
if not cl.is_empty then
|
||||
if not f then
|
||||
a_target.append_character (' ')
|
||||
end
|
||||
a_target.append (cl)
|
||||
end
|
||||
end
|
||||
end
|
||||
a_target.append_character ('%"')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
41
library/server/wsf_html/form/wsf_with_css_id.e
Normal file
41
library/server/wsf_html/form/wsf_with_css_id.e
Normal file
@@ -0,0 +1,41 @@
|
||||
note
|
||||
description: "Summary description for {WSF_WITH_CSS_ID}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_WITH_CSS_ID
|
||||
|
||||
feature -- Status report
|
||||
|
||||
css_id: detachable READABLE_STRING_8
|
||||
|
||||
feature -- Change
|
||||
|
||||
set_css_id (a_id: like css_id)
|
||||
require
|
||||
is_valid_css_id: is_valid_css_id (a_id)
|
||||
do
|
||||
css_id := a_id
|
||||
end
|
||||
|
||||
feature -- Query
|
||||
|
||||
is_valid_css_id (s: detachable READABLE_STRING_8): BOOLEAN
|
||||
do
|
||||
Result := s /= Void implies (not s.is_empty)
|
||||
-- To complete
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_css_id_to (a_target: STRING)
|
||||
do
|
||||
if attached css_id as l_id then
|
||||
a_target.append (" id=%"")
|
||||
a_target.append (l_id)
|
||||
a_target.append_character ('%"')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
43
library/server/wsf_html/form/wsf_with_css_style.e
Normal file
43
library/server/wsf_html/form/wsf_with_css_style.e
Normal file
@@ -0,0 +1,43 @@
|
||||
note
|
||||
description: "Summary description for {WSF_WITH_CSS_STYLE}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_WITH_CSS_STYLE
|
||||
|
||||
feature -- Status report
|
||||
|
||||
css_style: detachable CSS_STYLE
|
||||
|
||||
feature -- Change
|
||||
|
||||
reset_css_style
|
||||
do
|
||||
css_style := Void
|
||||
end
|
||||
|
||||
add_css_style (a_style: like css_style)
|
||||
local
|
||||
s: like css_style
|
||||
do
|
||||
s := css_style
|
||||
if s = Void then
|
||||
css_style := a_style
|
||||
elseif a_style /= Void then
|
||||
css_style := s + a_style
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_css_style_to (a_target: STRING)
|
||||
do
|
||||
if attached css_style as l_css_style then
|
||||
a_target.append (" style=%"")
|
||||
l_css_style.append_inline_to (a_target)
|
||||
a_target.append_character ('%"')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
81
library/server/wsf_html/form/wsf_with_html_attribute.e
Normal file
81
library/server/wsf_html/form/wsf_with_html_attribute.e
Normal file
@@ -0,0 +1,81 @@
|
||||
note
|
||||
description: "Summary description for {WSF_WITH_HTML_ATTRIBUTE}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_WITH_HTML_ATTRIBUTE
|
||||
|
||||
feature -- Status report
|
||||
|
||||
html_attributes: detachable HASH_TABLE [detachable READABLE_STRING_8, STRING_8]
|
||||
|
||||
feature -- Change
|
||||
|
||||
reset_html_attributes
|
||||
do
|
||||
html_attributes := Void
|
||||
end
|
||||
|
||||
add_html_attribute (a_name: READABLE_STRING_8; a_value: detachable READABLE_STRING_8)
|
||||
require
|
||||
is_valid_attribute_name: is_valid_attribute_name (a_name)
|
||||
is_valid_attribute_value: is_valid_attribute_value (a_value)
|
||||
local
|
||||
lst: like html_attributes
|
||||
do
|
||||
lst := html_attributes
|
||||
if lst = Void then
|
||||
create lst.make (1)
|
||||
lst.compare_objects
|
||||
html_attributes := lst
|
||||
end
|
||||
lst.force (a_value, a_name)
|
||||
end
|
||||
|
||||
remove_html_attribute (a_name: READABLE_STRING_8)
|
||||
require
|
||||
is_valid_attribute_name: is_valid_attribute_name (a_name)
|
||||
local
|
||||
lst: like html_attributes
|
||||
do
|
||||
lst := html_attributes
|
||||
if lst /= Void then
|
||||
lst.remove (a_name)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Query
|
||||
|
||||
is_valid_attribute_name (s: detachable READABLE_STRING_8): BOOLEAN
|
||||
do
|
||||
Result := s /= Void implies (not s.is_empty)
|
||||
-- To complete
|
||||
end
|
||||
|
||||
is_valid_attribute_value (s: detachable READABLE_STRING_8): BOOLEAN
|
||||
do
|
||||
Result := s /= Void implies (not s.has ('%"'))
|
||||
-- To complete
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
append_html_attributes_to (a_target: STRING)
|
||||
do
|
||||
if attached html_attributes as attribs then
|
||||
across
|
||||
attribs as c
|
||||
loop
|
||||
a_target.append (" " + c.key)
|
||||
if attached c.item as v then
|
||||
a_target.append_character ('=')
|
||||
a_target.append_character ('%"')
|
||||
a_target.append (v)
|
||||
a_target.append_character ('%"')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user