Updated CMS experimental component

Fixed various issues with fieldset or similar not traversed
This commit is contained in:
Jocelyn Fiat
2013-02-04 15:35:23 +01:00
parent dc6255d410
commit 7db054a36d
18 changed files with 223 additions and 40 deletions

View File

@@ -1,8 +1,8 @@
site.name=EWF Web CMS site.name=EWF Web CMS
#site.base_url=/demo #site.base_url=/demo
site.email=your@email.com site.email=your@email.com
root-dir=../www root-dir=www
var-dir=var var-dir=var
files-dir=../www/files files-dir=www/files
themes-dir=../www/themes themes-dir=www/themes
theme=test theme=test

View File

@@ -111,7 +111,7 @@ feature -- Access
themes_location := s themes_location := s
else else
create dn.make_from_string (root_location) create dn.make_from_string (root_location)
dn.extend ("theme") dn.extend ("themes")
themes_location := dn.string themes_location := dn.string
end end
end end

View File

@@ -53,7 +53,11 @@ feature {CMS_SESSION_CONTROLER} -- Access: restricted
base_url: detachable READABLE_STRING_8 base_url: detachable READABLE_STRING_8
do 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 end
pending_messages_session_item_name: STRING = "cms.pending_messages" pending_messages_session_item_name: STRING = "cms.pending_messages"

View File

@@ -7,6 +7,9 @@ note
class class
CMS_API_OPTIONS CMS_API_OPTIONS
inherit
TABLE_ITERABLE [detachable ANY, STRING]
create create
make, make,
make_from_manifest make_from_manifest
@@ -70,6 +73,25 @@ feature -- Access
table: HASH_TABLE [detachable ANY, STRING] 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 invariant
end end

View File

@@ -156,6 +156,7 @@ feature -- Access
Result.append ("#" + f) Result.append ("#" + f)
end end
if l_abs then if l_abs then
Result := based_path (Result)
if Result.substring_index ("://", 1) = 0 then if Result.substring_index ("://", 1) = 0 then
Result.prepend (service.site_url) Result.prepend (service.site_url)
end end

View File

@@ -11,6 +11,9 @@ create
make, make,
make_from_string make_from_string
convert
make_from_string ({READABLE_STRING_8, STRING_8})
feature {NONE} -- Initialization feature {NONE} -- Initialization
make make

View File

@@ -38,6 +38,16 @@ feature -- Access
Result := items.count Result := items.count
end 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 method: READABLE_STRING_8
-- Form's method -- Form's method
--| GET or POST --| GET or POST

View File

@@ -12,6 +12,7 @@ inherit
rename rename
default_value as value default_value as value
redefine redefine
set_value,
specific_input_attributes_string, specific_input_attributes_string,
child_to_html child_to_html
end end
@@ -35,6 +36,8 @@ feature -- Access
text: detachable READABLE_STRING_32 text: detachable READABLE_STRING_32
raw_text: detachable READABLE_STRING_8
feature -- Status report feature -- Status report
is_same_value (v: READABLE_STRING_32): BOOLEAN is_same_value (v: READABLE_STRING_32): BOOLEAN
@@ -49,18 +52,44 @@ feature -- Change
text := t text := t
end end
set_raw_text (t: detachable READABLE_STRING_8)
do
raw_text := t
end
set_checked (b: like checked) set_checked (b: like checked)
do do
checked := b checked := b
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
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 feature {NONE} -- Implementation
child_to_html (a_theme: CMS_THEME): detachable READABLE_STRING_8 child_to_html (a_theme: CMS_THEME): detachable READABLE_STRING_8
-- Specific child element if any. -- Specific child element if any.
--| To redefine if needed --| To redefine if needed
do 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) Result := a_theme.html_encoded (t)
elseif attached value as v then elseif attached value as v then
Result := a_theme.html_encoded (v) Result := a_theme.html_encoded (v)

View File

@@ -49,6 +49,12 @@ feature -- Access
end end
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 integer_item (a_name: READABLE_STRING_GENERAL): INTEGER
do do
if attached {WSF_STRING} item (a_name) as s and then s.is_integer then if attached {WSF_STRING} item (a_name) as s and then s.is_integer then
@@ -108,13 +114,27 @@ feature -- Basic operation
across across
form as i form as i
loop loop
if attached {CMS_FORM_FIELD} i.item as l_field then 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 not attached {CMS_FORM_SUBMIT_INPUT} l_field then
if l_field.name.same_string (c.key) then if l_field.name.same_string (a_name) then
l_field.set_value (c.item) l_field.set_value (a_value)
end
end end
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 end
end end
@@ -151,25 +171,66 @@ feature {NONE} -- Implementation
end end
get_form_items (req: WSF_REQUEST; lst: ITERABLE [CMS_FORM_ITEM]) get_form_items (req: WSF_REQUEST; lst: ITERABLE [CMS_FORM_ITEM])
local
n: READABLE_STRING_8
v: detachable WSF_VALUE
do do
across across
lst as c lst as c
loop loop
if attached {CMS_FORM_FIELD} c.item as l_field then if attached {CMS_FORM_FIELD} c.item as l_field then
n := l_field.name 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) 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 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) items.force (v, n)
end end
elseif attached {CMS_FORM_FIELD_SET} c.item as l_fieldset then
get_form_items (req, l_fieldset)
end
end
end end
add_error (a_field: detachable CMS_FORM_FIELD; a_msg: detachable READABLE_STRING_8) add_error (a_field: detachable CMS_FORM_FIELD; a_msg: detachable READABLE_STRING_8)

View File

@@ -15,7 +15,9 @@ inherit
WITH_CSS_ID WITH_CSS_ID
create create
make make,
make_with_item,
make_with_text
feature {NONE} -- Initialization feature {NONE} -- Initialization
@@ -25,6 +27,17 @@ feature {NONE} -- Initialization
create items.make (0) create items.make (0)
end 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 feature -- Access
new_cursor: ITERATION_CURSOR [CMS_FORM_ITEM] new_cursor: ITERATION_CURSOR [CMS_FORM_ITEM]

View File

@@ -29,6 +29,8 @@ feature -- Access
legend: detachable READABLE_STRING_8 legend: detachable READABLE_STRING_8
is_collapsible: BOOLEAN
feature -- Access feature -- Access
new_cursor: ITERATION_CURSOR [CMS_FORM_ITEM] new_cursor: ITERATION_CURSOR [CMS_FORM_ITEM]
@@ -49,6 +51,30 @@ feature -- Change
items.force (i) items.force (i)
end 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 feature -- Conversion
to_html (a_theme: CMS_THEME): STRING_8 to_html (a_theme: CMS_THEME): STRING_8

View File

@@ -26,11 +26,24 @@ feature -- Change
lst := css_classes lst := css_classes
if lst = Void then if lst = Void then
create {ARRAYED_LIST [READABLE_STRING_8]} lst.make (1) create {ARRAYED_LIST [READABLE_STRING_8]} lst.make (1)
lst.compare_objects
css_classes := lst css_classes := lst
end end
lst.force (a_class) lst.force (a_class)
end 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 feature -- Query
is_valid_css_class (s: detachable READABLE_STRING_8): BOOLEAN is_valid_css_class (s: detachable READABLE_STRING_8): BOOLEAN
@@ -56,7 +69,9 @@ feature -- Conversion
loop loop
cl := c.item cl := c.item
if not cl.is_empty then if not cl.is_empty then
if not f then if f then
f := False
else
a_target.append_character (' ') a_target.append_character (' ')
end end
a_target.append (cl) a_target.append (cl)

View File

@@ -56,7 +56,7 @@ feature -- Factory
ti.set_is_required (True) ti.set_is_required (True)
f.extend (ti) f.extend (ti)
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>")) f.extend_text ("<br/>")
create ta.make ("body") create ta.make ("body")
ta.set_rows (10) ta.set_rows (10)
@@ -72,8 +72,7 @@ feature -- Factory
fset.set_legend ("Body") fset.set_legend ("Body")
fset.extend (ta) fset.extend (ta)
fset.extend_text ("<br/>")
fset.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>"))
create tselect.make ("format") create tselect.make ("format")
tselect.set_label ("Body's format") tselect.set_label ("Body's format")

View File

@@ -127,7 +127,7 @@ feature -- Execution
a_type.fill_edit_form (f, a_node) 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") create ts.make ("op")
ts.set_default_value ("Save") ts.set_default_value ("Save")

View File

@@ -132,7 +132,7 @@ feature -- Execution
a_type.fill_edit_form (f, a_node) 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") create ts.make ("op")
ts.set_default_value ("Save") ts.set_default_value ("Save")

View File

@@ -128,14 +128,14 @@ feature -- Execution
ti.set_is_readonly (True) ti.set_is_readonly (True)
f.extend (ti) f.extend (ti)
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>")) f.extend_text ("<br/>")
create tp.make ("password") create tp.make ("password")
tp.set_label ("Password") tp.set_label ("Password")
tp.set_is_required (False) tp.set_is_required (False)
f.extend (tp) f.extend (tp)
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>")) f.extend_text ("<br/>")
create ti.make ("email") create ti.make ("email")
ti.set_label ("Valid email address") ti.set_label ("Valid email address")
@@ -145,7 +145,7 @@ feature -- Execution
ti.set_is_required (True) ti.set_is_required (True)
f.extend (ti) f.extend (ti)
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>")) f.extend_text ("<br/>")
create ta.make ("note") create ta.make ("note")
ta.set_label ("Additional note about you") ta.set_label ("Additional note about you")
@@ -156,7 +156,7 @@ feature -- Execution
ta.set_is_required (False) ta.set_is_required (False)
f.extend (ta) f.extend (ta)
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>")) f.extend_text ("<br/>")
create ts.make ("op") create ts.make ("op")
ts.set_default_value ("Save") ts.set_default_value ("Save")

View File

@@ -114,7 +114,7 @@ feature -- Execution
th.set_is_required (True) th.set_is_required (True)
f.extend (th) f.extend (th)
else 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 err := True
end end

View File

@@ -131,21 +131,21 @@ feature -- Execution
end) end)
f.extend (ti) f.extend (ti)
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>")) f.extend_text ("<br/>")
create tp.make ("password") create tp.make ("password")
tp.set_label ("Password") tp.set_label ("Password")
tp.set_is_required (True) tp.set_is_required (True)
f.extend (tp) f.extend (tp)
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>")) f.extend_text ("<br/>")
create ti.make ("email") create ti.make ("email")
ti.set_label ("Valid email address") ti.set_label ("Valid email address")
ti.set_is_required (True) ti.set_is_required (True)
f.extend (ti) f.extend (ti)
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>")) f.extend_text ("<br/>")
create ta.make ("note") create ta.make ("note")
ta.set_label ("Additional note about you") ta.set_label ("Additional note about you")
@@ -153,7 +153,7 @@ feature -- Execution
ta.set_is_required (False) ta.set_is_required (False)
f.extend (ta) f.extend (ta)
f.extend (create {CMS_FORM_RAW_TEXT}.make ("<br/>")) f.extend_text ("<br/>")
create ts.make ("Register") create ts.make ("Register")
ts.set_default_value ("Register") ts.set_default_value ("Register")