Updated CMS experimental component
Fixed various issues with fieldset or similar not traversed
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
site.name=EWF Web CMS
|
||||
#site.base_url=/demo
|
||||
site.email=your@email.com
|
||||
root-dir=../www
|
||||
root-dir=www
|
||||
var-dir=var
|
||||
files-dir=../www/files
|
||||
themes-dir=../www/themes
|
||||
files-dir=www/files
|
||||
themes-dir=www/themes
|
||||
theme=test
|
||||
|
||||
@@ -111,7 +111,7 @@ feature -- Access
|
||||
themes_location := s
|
||||
else
|
||||
create dn.make_from_string (root_location)
|
||||
dn.extend ("theme")
|
||||
dn.extend ("themes")
|
||||
themes_location := dn.string
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,7 +53,11 @@ feature {CMS_SESSION_CONTROLER} -- Access: restricted
|
||||
|
||||
base_url: detachable READABLE_STRING_8
|
||||
do
|
||||
Result := service.server_base_url
|
||||
if attached service.base_url as l_url then
|
||||
Result := request.script_url (l_url)
|
||||
else
|
||||
Result := request.script_url ("")
|
||||
end
|
||||
end
|
||||
|
||||
pending_messages_session_item_name: STRING = "cms.pending_messages"
|
||||
|
||||
@@ -7,6 +7,9 @@ note
|
||||
class
|
||||
CMS_API_OPTIONS
|
||||
|
||||
inherit
|
||||
TABLE_ITERABLE [detachable ANY, STRING]
|
||||
|
||||
create
|
||||
make,
|
||||
make_from_manifest
|
||||
@@ -70,6 +73,25 @@ feature -- Access
|
||||
|
||||
table: HASH_TABLE [detachable ANY, STRING]
|
||||
|
||||
feature -- Change
|
||||
|
||||
import (a_opts: CMS_API_OPTIONS)
|
||||
do
|
||||
across
|
||||
a_opts as c
|
||||
loop
|
||||
force (c.item, c.key)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
new_cursor: TABLE_ITERATION_CURSOR [detachable ANY, STRING]
|
||||
-- Fresh cursor associated with current structure
|
||||
do
|
||||
Result := table.new_cursor
|
||||
end
|
||||
|
||||
invariant
|
||||
|
||||
end
|
||||
|
||||
@@ -156,6 +156,7 @@ feature -- Access
|
||||
Result.append ("#" + f)
|
||||
end
|
||||
if l_abs then
|
||||
Result := based_path (Result)
|
||||
if Result.substring_index ("://", 1) = 0 then
|
||||
Result.prepend (service.site_url)
|
||||
end
|
||||
|
||||
@@ -11,6 +11,9 @@ create
|
||||
make,
|
||||
make_from_string
|
||||
|
||||
convert
|
||||
make_from_string ({READABLE_STRING_8, STRING_8})
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
|
||||
@@ -38,6 +38,16 @@ feature -- Access
|
||||
Result := items.count
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
@@ -12,6 +12,7 @@ inherit
|
||||
rename
|
||||
default_value as value
|
||||
redefine
|
||||
set_value,
|
||||
specific_input_attributes_string,
|
||||
child_to_html
|
||||
end
|
||||
@@ -35,6 +36,8 @@ feature -- Access
|
||||
|
||||
text: detachable READABLE_STRING_32
|
||||
|
||||
raw_text: detachable READABLE_STRING_8
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_same_value (v: READABLE_STRING_32): BOOLEAN
|
||||
@@ -49,18 +52,44 @@ feature -- Change
|
||||
text := t
|
||||
end
|
||||
|
||||
set_raw_text (t: detachable READABLE_STRING_8)
|
||||
do
|
||||
raw_text := t
|
||||
end
|
||||
|
||||
set_checked (b: like checked)
|
||||
do
|
||||
checked := b
|
||||
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
|
||||
if
|
||||
attached {WSF_STRING} c.item as s and then
|
||||
is_same_value (s.value)
|
||||
then
|
||||
set_checked (True)
|
||||
end
|
||||
end
|
||||
else
|
||||
Precursor (v)
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
child_to_html (a_theme: CMS_THEME): detachable READABLE_STRING_8
|
||||
-- Specific child element if any.
|
||||
--| To redefine if needed
|
||||
do
|
||||
if attached text as t then
|
||||
if attached raw_text as t then
|
||||
Result := t
|
||||
elseif attached text as t then
|
||||
Result := a_theme.html_encoded (t)
|
||||
elseif attached value as v then
|
||||
Result := a_theme.html_encoded (v)
|
||||
|
||||
@@ -49,6 +49,12 @@ feature -- Access
|
||||
end
|
||||
end
|
||||
|
||||
-- table_item (a_name: READABLE_STRING_GENERAL): detachable WSF_VALUE
|
||||
-- do
|
||||
-- FIXME
|
||||
-- Result := items.item (a_name.as_string_8 + "[]")
|
||||
-- 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
|
||||
@@ -108,14 +114,28 @@ feature -- Basic operation
|
||||
across
|
||||
form as i
|
||||
loop
|
||||
if attached {CMS_FORM_FIELD} i.item as l_field then
|
||||
if not attached {CMS_FORM_SUBMIT_INPUT} l_field then
|
||||
if l_field.name.same_string (c.key) then
|
||||
l_field.set_value (c.item)
|
||||
end
|
||||
end
|
||||
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: CMS_FORM_ITEM)
|
||||
local
|
||||
do
|
||||
if attached {CMS_FORM_FIELD} i as l_field then
|
||||
if not attached {CMS_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 [CMS_FORM_ITEM]} 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
|
||||
|
||||
@@ -151,27 +171,68 @@ feature {NONE} -- Implementation
|
||||
end
|
||||
|
||||
get_form_items (req: WSF_REQUEST; lst: ITERABLE [CMS_FORM_ITEM])
|
||||
local
|
||||
n: READABLE_STRING_8
|
||||
v: detachable WSF_VALUE
|
||||
do
|
||||
across
|
||||
lst as c
|
||||
loop
|
||||
if attached {CMS_FORM_FIELD} c.item as l_field then
|
||||
n := l_field.name
|
||||
v := req.form_parameter (n)
|
||||
if l_field.is_required and (v = Void or else v.is_empty) then
|
||||
add_error (l_field, "Field %"<em>" + l_field.name + "</em>%" is required")
|
||||
else
|
||||
items.force (v, n)
|
||||
end
|
||||
elseif attached {CMS_FORM_FIELD_SET} c.item as l_fieldset then
|
||||
get_form_items (req, l_fieldset)
|
||||
get_form_field_item (req, l_field, l_field.name)
|
||||
elseif attached {ITERABLE [CMS_FORM_ITEM]} c.item as l_set then
|
||||
get_form_items (req, l_set)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
get_form_field_item (req: WSF_REQUEST; i: CMS_FORM_FIELD; n: READABLE_STRING_8)
|
||||
local
|
||||
v: detachable WSF_VALUE
|
||||
-- tb: detachable WSF_TABLE
|
||||
do
|
||||
if form.is_post_method then
|
||||
v := req.form_parameter (n)
|
||||
else
|
||||
v := req.query_parameter (n)
|
||||
end
|
||||
if v = Void and then 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
|
||||
if i.is_required and (v = Void or else v.is_empty) then
|
||||
add_error (i, "Field %"<em>" + n + "</em>%" is required")
|
||||
else
|
||||
-- if attached {WSF_TABLE} v then
|
||||
-- -- `v' overwrite any previous values if any
|
||||
-- -- since it is already a WSF_TABLE
|
||||
-- else
|
||||
-- attached items.item (n) as ov then
|
||||
-- if attached {WSF_TABLE} ov as vtb then
|
||||
-- tb := vtb
|
||||
-- elseif attached {WSF_MULTIPLE_STRING} ov as vm then
|
||||
-- if tb = Void then
|
||||
-- create tb.make (n)
|
||||
-- end
|
||||
-- across
|
||||
-- vm as c
|
||||
-- loop
|
||||
-- tb.add_value (c.item, (tb.count + 1).out)
|
||||
-- end
|
||||
-- else
|
||||
-- create tb.make (n)
|
||||
---- create v_multi.make_with_value (ov)
|
||||
-- end
|
||||
-- if v /= Void then
|
||||
-- tb.add_value (v, (tb.count + 1).out)
|
||||
---- v_multi.add_value (v)
|
||||
-- end
|
||||
-- v := tb
|
||||
-- end
|
||||
items.force (v, n)
|
||||
end
|
||||
end
|
||||
|
||||
add_error (a_field: detachable CMS_FORM_FIELD; a_msg: detachable READABLE_STRING_8)
|
||||
local
|
||||
err: like errors
|
||||
|
||||
@@ -15,7 +15,9 @@ inherit
|
||||
WITH_CSS_ID
|
||||
|
||||
create
|
||||
make
|
||||
make,
|
||||
make_with_item,
|
||||
make_with_text
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
@@ -25,6 +27,17 @@ feature {NONE} -- Initialization
|
||||
create items.make (0)
|
||||
end
|
||||
|
||||
make_with_text (s: READABLE_STRING_8)
|
||||
do
|
||||
make_with_item (create {CMS_FORM_RAW_TEXT}.make (s))
|
||||
end
|
||||
|
||||
make_with_item (i: CMS_FORM_ITEM)
|
||||
do
|
||||
create items.make (1)
|
||||
extend (i)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
new_cursor: ITERATION_CURSOR [CMS_FORM_ITEM]
|
||||
|
||||
@@ -29,6 +29,8 @@ feature -- Access
|
||||
|
||||
legend: detachable READABLE_STRING_8
|
||||
|
||||
is_collapsible: BOOLEAN
|
||||
|
||||
feature -- Access
|
||||
|
||||
new_cursor: ITERATION_CURSOR [CMS_FORM_ITEM]
|
||||
@@ -49,6 +51,30 @@ feature -- Change
|
||||
items.force (i)
|
||||
end
|
||||
|
||||
extend_text (t: READABLE_STRING_8)
|
||||
do
|
||||
items.force (create {CMS_FORM_RAW_TEXT}.make (t))
|
||||
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
|
||||
|
||||
to_html (a_theme: CMS_THEME): STRING_8
|
||||
|
||||
@@ -26,11 +26,24 @@ feature -- Change
|
||||
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
|
||||
@@ -56,7 +69,9 @@ feature -- Conversion
|
||||
loop
|
||||
cl := c.item
|
||||
if not cl.is_empty then
|
||||
if not f then
|
||||
if f then
|
||||
f := False
|
||||
else
|
||||
a_target.append_character (' ')
|
||||
end
|
||||
a_target.append (cl)
|
||||
|
||||
@@ -56,7 +56,7 @@ feature -- Factory
|
||||
ti.set_is_required (True)
|
||||
f.extend (ti)
|
||||
|
||||
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create ta.make ("body")
|
||||
ta.set_rows (10)
|
||||
@@ -72,8 +72,7 @@ feature -- Factory
|
||||
fset.set_legend ("Body")
|
||||
fset.extend (ta)
|
||||
|
||||
|
||||
fset.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
|
||||
fset.extend_text ("<br/>")
|
||||
|
||||
create tselect.make ("format")
|
||||
tselect.set_label ("Body's format")
|
||||
|
||||
@@ -127,7 +127,7 @@ feature -- Execution
|
||||
|
||||
a_type.fill_edit_form (f, a_node)
|
||||
|
||||
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create ts.make ("op")
|
||||
ts.set_default_value ("Save")
|
||||
|
||||
@@ -132,7 +132,7 @@ feature -- Execution
|
||||
|
||||
a_type.fill_edit_form (f, a_node)
|
||||
|
||||
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create ts.make ("op")
|
||||
ts.set_default_value ("Save")
|
||||
|
||||
@@ -128,14 +128,14 @@ feature -- Execution
|
||||
ti.set_is_readonly (True)
|
||||
f.extend (ti)
|
||||
|
||||
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create tp.make ("password")
|
||||
tp.set_label ("Password")
|
||||
tp.set_is_required (False)
|
||||
f.extend (tp)
|
||||
|
||||
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create ti.make ("email")
|
||||
ti.set_label ("Valid email address")
|
||||
@@ -145,7 +145,7 @@ feature -- Execution
|
||||
ti.set_is_required (True)
|
||||
f.extend (ti)
|
||||
|
||||
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create ta.make ("note")
|
||||
ta.set_label ("Additional note about you")
|
||||
@@ -156,7 +156,7 @@ feature -- Execution
|
||||
ta.set_is_required (False)
|
||||
f.extend (ta)
|
||||
|
||||
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create ts.make ("op")
|
||||
ts.set_default_value ("Save")
|
||||
|
||||
@@ -114,7 +114,7 @@ feature -- Execution
|
||||
th.set_is_required (True)
|
||||
f.extend (th)
|
||||
else
|
||||
f.extend (create {CMS_FORM_RAW_TEXT}.make ("The associated account has no e-mail address."))
|
||||
f.extend_text ("The associated account has no e-mail address.")
|
||||
err := True
|
||||
end
|
||||
|
||||
|
||||
@@ -131,21 +131,21 @@ feature -- Execution
|
||||
end)
|
||||
f.extend (ti)
|
||||
|
||||
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create tp.make ("password")
|
||||
tp.set_label ("Password")
|
||||
tp.set_is_required (True)
|
||||
f.extend (tp)
|
||||
|
||||
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create ti.make ("email")
|
||||
ti.set_label ("Valid email address")
|
||||
ti.set_is_required (True)
|
||||
f.extend (ti)
|
||||
|
||||
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create ta.make ("note")
|
||||
ta.set_label ("Additional note about you")
|
||||
@@ -153,7 +153,7 @@ feature -- Execution
|
||||
ta.set_is_required (False)
|
||||
f.extend (ta)
|
||||
|
||||
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
|
||||
f.extend_text ("<br/>")
|
||||
|
||||
create ts.make ("Register")
|
||||
ts.set_default_value ("Register")
|
||||
|
||||
Reference in New Issue
Block a user