Implemented view node by content type (no more hardcoded cases).

Added CMS_NODE_TYPE as descendant of CMS_CONTENT_TYPE,
  in case we have content which is not a node in the future.
  (probably useless, but for now, this extra abstraction is harmful)
Moved all node related code under node module cluster.
Applied comments from Javier Velilla.
Code cleaning.
This commit is contained in:
2015-04-29 17:28:33 +02:00
parent e8bb3790ba
commit c982f0ea9c
34 changed files with 756 additions and 521 deletions

View File

@@ -24,7 +24,7 @@ feature {NONE} -- Initialization
Precursor Precursor
end end
feature {CMS_CONTENT_TYPE} -- Conversion feature -- Conversion
import_node (a_node: CMS_NODE) import_node (a_node: CMS_NODE)
-- <Precursor> -- <Precursor>
@@ -39,7 +39,7 @@ feature -- Access
content_type: READABLE_STRING_8 content_type: READABLE_STRING_8
once once
Result := {CMS_BLOG_CONTENT_TYPE}.name Result := {CMS_BLOG_NODE_TYPE}.name
end end
feature -- Access: content feature -- Access: content

View File

@@ -1,75 +0,0 @@
note
description: "Summary description for {CMS_BLOG_CONTENT_TYPE_WEBFORM_MANAGER}."
date: "$Date$"
revision: "$Revision$"
class
CMS_BLOG_CONTENT_TYPE_WEBFORM_MANAGER
inherit
CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER [CMS_BLOG]
redefine
content_type,
fill_edit_form,
change_node,
new_node
end
create
make
feature -- Access
content_type: CMS_BLOG_CONTENT_TYPE
-- Associated content type.
feature -- form
fill_edit_form (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable like new_node)
local
ti: WSF_FORM_TEXT_INPUT
fset: WSF_FORM_FIELD_SET
ta: WSF_FORM_TEXTAREA
tselect: WSF_FORM_SELECT
opt: WSF_FORM_SELECT_OPTION
s: STRING_32
do
Precursor (response, f, a_node)
create ti.make ("tags")
ti.set_label ("Tags")
ti.set_size (70)
if a_node /= Void and then attached a_node.tags as l_tags then
create s.make_empty
across
l_tags as ic
loop
if not s.is_empty then
s.append_character (',')
end
s.append (ic.item)
end
ti.set_text_value (s)
end
ti.set_is_required (False)
f.extend (ti)
end
change_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: like new_node)
do
Precursor (response, fd, a_node)
if attached fd.string_item ("tags") as l_tags then
a_node.set_tags_from_string (l_tags)
end
end
new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable like new_node): like content_type.new_node
-- <Precursor>
do
Result := Precursor (response, fd, a_node)
if attached fd.string_item ("tags") as l_tags then
Result.set_tags_from_string (l_tags)
end
end
end

View File

@@ -35,14 +35,14 @@ feature {CMS_API} -- Module Initialization
initialize (api: CMS_API) initialize (api: CMS_API)
-- <Precursor> -- <Precursor>
local local
ct: CMS_BLOG_CONTENT_TYPE ct: CMS_BLOG_NODE_TYPE
do do
Precursor (api) Precursor (api)
if attached {CMS_NODE_API} api.module_api ({NODE_MODULE}) as l_node_api then if attached {CMS_NODE_API} api.module_api ({NODE_MODULE}) as l_node_api then
create ct create ct
l_node_api.add_content_type (ct) l_node_api.add_content_type (ct)
l_node_api.add_content_type_webform_manager (create {CMS_BLOG_CONTENT_TYPE_WEBFORM_MANAGER}.make (ct)) l_node_api.add_content_type_webform_manager (create {CMS_BLOG_NODE_TYPE_WEBFORM_MANAGER}.make (ct))
-- Add support for CMS_BLOG, which requires a storage extension to store the optional "tags" value -- Add support for CMS_BLOG, which requires a storage extension to store the optional "tags" value
-- For now, we only have extension based on SQL statement. -- For now, we only have extension based on SQL statement.
if attached {CMS_NODE_STORAGE_SQL} l_node_api.node_storage as l_sql_node_storage then if attached {CMS_NODE_STORAGE_SQL} l_node_api.node_storage as l_sql_node_storage then

View File

@@ -1,13 +1,13 @@
note note
description: "Summary description for {CMS_BLOG_CONTENT_TYPE}." description: "Summary description for {CMS_BLOG_NODE_TYPE}."
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class class
CMS_BLOG_CONTENT_TYPE CMS_BLOG_NODE_TYPE
inherit inherit
CMS_CONTENT_TYPE CMS_NODE_TYPE
redefine redefine
default_create default_create
end end
@@ -60,5 +60,4 @@ feature -- Factory
end end
end end
end end

View File

@@ -0,0 +1,109 @@
note
description: "Summary description for {CMS_BLOG_NODE_TYPE_WEBFORM_MANAGER}."
date: "$Date$"
revision: "$Revision$"
class
CMS_BLOG_NODE_TYPE_WEBFORM_MANAGER
inherit
CMS_NODE_TYPE_WEBFORM_MANAGER [CMS_BLOG]
redefine
content_type,
populate_form,
update_node,
new_node,
append_html_output_to
end
create
make
feature -- Access
content_type: CMS_BLOG_NODE_TYPE
-- Associated content type.
feature -- form
populate_form (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable CMS_NODE)
local
ti: WSF_FORM_TEXT_INPUT
s: STRING_32
do
Precursor (response, f, a_node)
create ti.make ("tags")
ti.set_label ("Tags")
ti.set_size (70)
if
a_node /= Void and then
attached {CMS_BLOG} a_node as a_blog and then
attached a_blog.tags as l_tags
then
create s.make_empty
across
l_tags as ic
loop
if not s.is_empty then
s.append_character (',')
end
s.append (ic.item)
end
ti.set_text_value (s)
end
ti.set_is_required (False)
f.extend (ti)
end
update_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: CMS_NODE)
do
Precursor (response, fd, a_node)
if attached fd.string_item ("tags") as l_tags then
if attached {CMS_BLOG} a_node as l_blog then
l_blog.set_tags_from_string (l_tags)
end
end
end
new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable like new_node): like content_type.new_node
-- <Precursor>
do
Result := Precursor (response, fd, a_node)
if attached fd.string_item ("tags") as l_tags then
Result.set_tags_from_string (l_tags)
end
end
feature -- Output
append_html_output_to (a_node: CMS_NODE; a_response: NODE_RESPONSE)
-- <Precursor>
local
s: STRING
do
Precursor (a_node, a_response)
if attached a_response.main_content as l_main_content then
s := l_main_content
else
create s.make_empty
end
if attached {CMS_BLOG} a_node as l_blog_post then
if attached l_blog_post.tags as l_tags then
s.append ("<div><strong>Tags:</strong> ")
across
l_tags as ic
loop
s.append ("<span class=%"tag%">")
s.append (a_response.html_encoded (ic.item))
s.append ("</span> ")
end
s.append ("</div>")
end
end
a_response.set_main_content (s)
end
end

View File

@@ -28,7 +28,7 @@ feature -- Access
content_type: STRING content_type: STRING
once once
Result := {CMS_BLOG_CONTENT_TYPE}.name Result := {CMS_BLOG_NODE_TYPE}.name
end end
feature -- Persistence feature -- Persistence

View File

@@ -29,21 +29,11 @@ feature -- Access
Result := link (u.name, "/user/" + u.id.out, Void) Result := link (u.name, "/user/" + u.id.out, Void)
end end
node_link (n: CMS_NODE): like link
do
Result := link (n.title, "/node/" + n.id.out, Void)
end
user_url (u: CMS_USER): like url user_url (u: CMS_USER): like url
do do
Result := url ("/user/" + u.id.out, Void) Result := url ("/user/" + u.id.out, Void)
end end
node_url (n: CMS_NODE): like url
do
Result := url ("/node/" + n.id.out, Void)
end
feature -- Helper feature -- Helper
is_empty (s: detachable READABLE_STRING_GENERAL): BOOLEAN is_empty (s: detachable READABLE_STRING_GENERAL): BOOLEAN

View File

@@ -9,6 +9,9 @@ note
deferred class deferred class
CMS_CONTENT_TYPE CMS_CONTENT_TYPE
inherit
CMS_API_ACCESS
feature -- Access feature -- Access
name: READABLE_STRING_8 name: READABLE_STRING_8
@@ -33,18 +36,6 @@ feature -- Access
deferred deferred
end end
feature -- Factory
new_node_with_title (a_title: READABLE_STRING_32; a_partial_node: detachable CMS_NODE): like new_node
-- New node with `a_title' and fill from partial `a_partial_node' if set.
deferred
end
new_node (a_partial_node: detachable CMS_NODE): CMS_NODE
-- New node based on partial `a_partial_node' if set.
deferred
end
note note
copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -30,19 +30,19 @@ feature {NONE} -- Implementation
else else
create {CMS_NODE_STORAGE_NULL} node_storage.make create {CMS_NODE_STORAGE_NULL} node_storage.make
end end
initialize_content_types initialize_node_types
end end
initialize_content_types initialize_node_types
-- Initialize content type system. -- Initialize content type system.
local local
ct: CMS_PAGE_CONTENT_TYPE ct: CMS_PAGE_NODE_TYPE
do do
create content_types.make (1) create content_types.make (1)
create content_type_webform_managers.make (1) create content_type_webform_managers.make (1)
create ct create ct
add_content_type (ct) add_content_type (ct)
add_content_type_webform_manager (create {CMS_PAGE_CONTENT_TYPE_WEBFORM_MANAGER}.make (ct)) add_content_type_webform_manager (create {CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER}.make (ct))
end end
feature {CMS_MODULE} -- Access nodes storage. feature {CMS_MODULE} -- Access nodes storage.
@@ -54,12 +54,27 @@ feature -- Content type
content_types: ARRAYED_LIST [CMS_CONTENT_TYPE] content_types: ARRAYED_LIST [CMS_CONTENT_TYPE]
-- Available content types -- Available content types
node_types: ARRAYED_LIST [CMS_NODE_TYPE]
-- Node content types.
do
create Result.make (content_types.count)
across
content_types as ic
loop
if attached {CMS_NODE_TYPE} ic.item as l_node_type then
Result.extend (l_node_type)
end
end
end
add_content_type (a_type: CMS_CONTENT_TYPE) add_content_type (a_type: CMS_CONTENT_TYPE)
-- Register content type `a_type'.
do do
content_types.force (a_type) content_types.force (a_type)
end end
content_type (a_name: READABLE_STRING_GENERAL): detachable CMS_CONTENT_TYPE content_type (a_name: READABLE_STRING_GENERAL): detachable CMS_CONTENT_TYPE
-- Content type named `a_named' if any.
do do
across across
content_types as ic content_types as ic
@@ -73,33 +88,84 @@ feature -- Content type
end end
end end
node_type (a_name: READABLE_STRING_GENERAL): detachable CMS_NODE_TYPE
-- Content type named `a_named' if any.
do
across
content_types as ic
until
Result /= Void
loop
if
attached {like node_type} ic.item as l_node_type and then
a_name.is_case_insensitive_equal (l_node_type.name)
then
Result := l_node_type
end
end
end
node_type_for (a_node: CMS_NODE): detachable CMS_NODE_TYPE
-- Content type for node `a_node' if any.
local
l_type_name: READABLE_STRING_8
do
l_type_name := a_node.content_type
Result := node_type (l_type_name)
end
feature -- Content type webform feature -- Content type webform
content_type_webform_managers: ARRAYED_LIST [CMS_CONTENT_TYPE_WEBFORM_MANAGER] content_type_webform_managers: ARRAYED_LIST [CMS_CONTENT_TYPE_WEBFORM_MANAGER]
-- Available content types -- Available content types
add_content_type_webform_manager (a_type: CMS_CONTENT_TYPE_WEBFORM_MANAGER) add_content_type_webform_manager (a_manager: CMS_CONTENT_TYPE_WEBFORM_MANAGER)
-- Register webform manager `a_manager'.
do do
content_type_webform_managers.force (a_type) content_type_webform_managers.force (a_manager)
end end
content_type_webform_manager (a_name: READABLE_STRING_GENERAL): detachable CMS_CONTENT_TYPE_WEBFORM_MANAGER content_type_webform_manager (a_content_type: CMS_CONTENT_TYPE): detachable CMS_CONTENT_TYPE_WEBFORM_MANAGER
-- Web form manager for content type `a_content_type' if any.
local
l_type_name: READABLE_STRING_GENERAL
do do
l_type_name := a_content_type.name
across across
content_type_webform_managers as ic content_type_webform_managers as ic
until until
Result /= Void Result /= Void
loop loop
Result := ic.item Result := ic.item
if not a_name.is_case_insensitive_equal (Result.name) then if not l_type_name.is_case_insensitive_equal (Result.name) then
Result := Void Result := Void
end end
end end
end end
node_type_webform_manager (a_node_type: CMS_NODE_TYPE): detachable CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER
-- Web form manager for node type `a_node_type' if any.
local
l_type_name: READABLE_STRING_GENERAL
do
l_type_name := a_node_type.name
across
content_type_webform_managers as ic
until
Result /= Void
loop
if
attached {CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER} ic.item as l_manager and then
l_type_name.is_case_insensitive_equal (l_manager.name)
then
Result := l_manager
end
end
end
feature -- URL feature -- URL
new_content_path (ct: detachable CMS_CONTENT_TYPE): STRING new_content_path (ct: detachable CMS_NODE_TYPE): STRING
-- URI path for new content of type `ct' -- URI path for new content of type `ct'
-- or URI of path for selection of new content possibilities if ct is Void. -- or URI of path for selection of new content possibilities if ct is Void.
do do
@@ -158,7 +224,7 @@ feature -- Access: Node
-- otherwise return directly `a_node'. -- otherwise return directly `a_node'.
do do
if attached {CMS_PARTIAL_NODE} a_node as l_partial_node then if attached {CMS_PARTIAL_NODE} a_node as l_partial_node then
if attached content_type (l_partial_node.content_type) as ct then if attached node_type_for (l_partial_node) as ct then
Result := ct.new_node (l_partial_node) Result := ct.new_node (l_partial_node)
node_storage.fill_node (Result) node_storage.fill_node (Result)
else else

View File

@@ -0,0 +1,30 @@
note
description: "[
Interface defining a CMS content type.
]"
status: "draft"
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_NODE_TYPE
inherit
CMS_CONTENT_TYPE
feature -- Factory
new_node_with_title (a_title: READABLE_STRING_32; a_partial_node: detachable CMS_NODE): like new_node
-- New node with `a_title' and fill from partial `a_partial_node' if set.
deferred
end
new_node (a_partial_node: detachable CMS_NODE): CMS_NODE
-- New node based on partial `a_partial_node' if set.
deferred
end
note
copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -43,7 +43,7 @@ feature{NONE} -- Initialization
title_set: title = a_title title_set: title = a_title
end end
feature {CMS_CONTENT_TYPE} -- Conversion feature -- Conversion
import_node (a_node: CMS_NODE) import_node (a_node: CMS_NODE)
-- Import `a_node' into current node. -- Import `a_node' into current node.

View File

@@ -24,7 +24,7 @@ feature {NONE} -- Initialization
Precursor Precursor
end end
feature {CMS_CONTENT_TYPE} -- Conversion feature -- Conversion
import_node (a_node: CMS_NODE) import_node (a_node: CMS_NODE)
-- <Precursor> -- <Precursor>
@@ -39,7 +39,7 @@ feature -- Access
content_type: READABLE_STRING_8 content_type: READABLE_STRING_8
once once
Result := {CMS_PAGE_CONTENT_TYPE}.name Result := {CMS_PAGE_NODE_TYPE}.name
end end
feature -- Access: content feature -- Access: content

View File

@@ -1,13 +1,13 @@
note note
description: "Summary description for {CMS_PAGE_CONTENT_TYPE}." description: "Summary description for {CMS_PAGE_NODE_TYPE}."
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class class
CMS_PAGE_CONTENT_TYPE CMS_PAGE_NODE_TYPE
inherit inherit
CMS_CONTENT_TYPE CMS_NODE_TYPE
redefine redefine
default_create default_create
end end

View File

@@ -1,12 +1,17 @@
note note
description: "Summary description for {CMS_CONTENT_TYPE_WEBFORM_MANAGER}." description: "[
author: "" Html builder for content type `content_type'.
This is used to build webform and html output for a specific node, or node content type.
]"
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
deferred class deferred class
CMS_CONTENT_TYPE_WEBFORM_MANAGER CMS_CONTENT_TYPE_WEBFORM_MANAGER
inherit
CMS_API_ACCESS
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_type: like content_type) make (a_type: like content_type)
@@ -20,25 +25,9 @@ feature -- Access
-- Associated content type. -- Associated content type.
name: READABLE_STRING_8 name: READABLE_STRING_8
-- Associated content type name.
do do
Result := content_type.name Result := content_type.name
end end
feature -- Forms ...
fill_edit_form (response: NODE_RESPONSE; a_form: WSF_FORM; a_node: detachable CMS_NODE)
deferred
end
new_node (response: NODE_RESPONSE; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): CMS_NODE
deferred
-- Result := content_type.new_node (a_node)
end
change_node (response: NODE_RESPONSE; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE)
-- require
-- a_node.has_id
deferred
end
end end

View File

@@ -1,10 +1,13 @@
note note
description: "Summary description for {CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER}." description: "[
Html builder for content type `content_type'.
This is used to build webform and html output for a specific node, or node content type.
]"
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class deferred class
CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER [G -> CMS_NODE] CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER
inherit inherit
CMS_CONTENT_TYPE_WEBFORM_MANAGER CMS_CONTENT_TYPE_WEBFORM_MANAGER
@@ -12,148 +15,53 @@ inherit
content_type content_type
end end
create
make
feature -- Access feature -- Access
content_type: CMS_CONTENT_TYPE content_type: CMS_NODE_TYPE
-- Associated content type. -- Associated content type.
feature -- Query
has_valid_node_type (a_node: CMS_NODE): BOOLEAN
-- Accept `a_node' for Current operations.
do
Result := attached {like new_node} a_node
end
feature -- Forms ... feature -- Forms ...
fill_edit_form (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable like new_node) populate_form (response: NODE_RESPONSE; a_form: WSF_FORM; a_node: detachable CMS_NODE)
local -- Fill the web form `a_form' with data from `a_node' if set.
ti: WSF_FORM_TEXT_INPUT require
fset: WSF_FORM_FIELD_SET a_node = Void or else has_valid_node_type (a_node)
ta: WSF_FORM_TEXTAREA deferred
tselect: WSF_FORM_SELECT
opt: WSF_FORM_SELECT_OPTION
do
create ti.make ("title")
ti.set_label ("Title")
ti.set_size (70)
if a_node /= Void then
ti.set_text_value (a_node.title)
end
ti.set_is_required (True)
f.extend (ti)
f.extend_html_text ("<br/>")
create ta.make ("body")
ta.set_rows (10)
ta.set_cols (70)
if a_node /= Void then
ta.set_text_value (a_node.content)
end
-- ta.set_label ("Body")
ta.set_description ("This is the main content")
ta.set_is_required (False)
create fset.make
fset.set_legend ("Body")
fset.extend (ta)
fset.extend_html_text ("<br/>")
create tselect.make ("format")
tselect.set_label ("Body's format")
tselect.set_is_required (True)
across
content_type.available_formats as c
loop
create opt.make (c.item.name, c.item.title)
if attached c.item.html_help as f_help then
opt.set_description ("<ul>" + f_help + "</ul>")
end
tselect.add_option (opt)
end
if a_node /= Void and then attached a_node.format as l_format then
tselect.set_text_by_value (l_format)
end end
fset.extend (tselect) feature -- Node ...
f.extend (fset)
new_node (response: NODE_RESPONSE; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): like content_type.new_node
-- New typed node with data from `a_form_data', and eventually data from `a_node' if set.
require
a_node = Void or else has_valid_node_type (a_node)
deferred
--| Possible implementation:
--| Result := content_type.new_node (a_node)
end end
change_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: like new_node) update_node (response: NODE_RESPONSE; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE)
local -- Update node `a_node' with data from `a_form_data'.
b: detachable READABLE_STRING_8 require
f: detachable CONTENT_FORMAT has_valid_node_type (a_node)
do deferred
if attached fd.integer_item ("id") as l_id and then l_id > 0 then
check a_node.id = l_id end
end
if attached fd.string_item ("title") as l_title then
a_node.set_title (l_title)
end end
if attached fd.string_item ("body") as l_body then feature -- Output
b := l_body
end
if attached fd.string_item ("format") as s_format and then attached response.api.format (s_format) as f_format then
f := f_format
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then
f := f_format
else
f := response.api.formats.default_format
end
if b /= Void then
a_node.set_content (b, Void, f.name) -- FIXME: summary
end
end
new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable like new_node): like content_type.new_node append_html_output_to (a_node: CMS_NODE; a_response: NODE_RESPONSE)
-- <Precursor> -- Append an html representation of `a_node' to response `a_response'.
local require
b: detachable READABLE_STRING_8 has_valid_node_type (a_node)
f: detachable CONTENT_FORMAT deferred
l_node: detachable like new_node
do
l_node := a_node
if attached fd.integer_item ("id") as l_id and then l_id > 0 then
if l_node /= Void then
check l_node.id = l_id end
else
if attached {like new_node} response.node_api.node (l_id) as n then
l_node := n
else
-- FIXME: Error
end
end
end
if attached fd.string_item ("title") as l_title then
if l_node = Void then
l_node := content_type.new_node (Void)
l_node.set_title (l_title)
else
l_node.set_title (l_title)
end
else
if l_node = Void then
l_node := content_type.new_node_with_title ("...", Void)
end
end
l_node.set_author (response.user)
if attached fd.string_item ("body") as l_body then
b := l_body
end
if attached fd.string_item ("format") as s_format and then attached response.api.format (s_format) as f_format then
f := f_format
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then
f := f_format
else
f := response.api.formats.default_format
end
if b /= Void then
l_node.set_content (b, Void, f.name)
end
Result := l_node
end end
end end

View File

@@ -0,0 +1,203 @@
note
description: "Summary description for {CMS_NODE_TYPE_WEBFORM_MANAGER}."
date: "$Date$"
revision: "$Revision$"
class
CMS_NODE_TYPE_WEBFORM_MANAGER [G -> CMS_NODE]
inherit
CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER
create
make
feature -- Forms ...
populate_form (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable CMS_NODE)
local
ti: WSF_FORM_TEXT_INPUT
fset: WSF_FORM_FIELD_SET
ta: WSF_FORM_TEXTAREA
tselect: WSF_FORM_SELECT
opt: WSF_FORM_SELECT_OPTION
do
create ti.make ("title")
ti.set_label ("Title")
ti.set_size (70)
if a_node /= Void then
ti.set_text_value (a_node.title)
end
ti.set_is_required (True)
f.extend (ti)
f.extend_html_text ("<br/>")
create ta.make ("body")
ta.set_rows (10)
ta.set_cols (70)
if a_node /= Void then
ta.set_text_value (a_node.content)
end
-- ta.set_label ("Body")
ta.set_description ("This is the main content")
ta.set_is_required (False)
create fset.make
fset.set_legend ("Body")
fset.extend (ta)
fset.extend_html_text ("<br/>")
create tselect.make ("format")
tselect.set_label ("Body's format")
tselect.set_is_required (True)
across
content_type.available_formats as c
loop
create opt.make (c.item.name, c.item.title)
if attached c.item.html_help as f_help then
opt.set_description ("<ul>" + f_help + "</ul>")
end
tselect.add_option (opt)
end
if a_node /= Void and then attached a_node.format as l_format then
tselect.set_text_by_value (l_format)
end
fset.extend (tselect)
f.extend (fset)
end
update_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: CMS_NODE)
local
b: detachable READABLE_STRING_8
f: detachable CONTENT_FORMAT
do
if attached fd.integer_item ("id") as l_id and then l_id > 0 then
check a_node.id = l_id end
end
if attached fd.string_item ("title") as l_title then
a_node.set_title (l_title)
end
if attached fd.string_item ("body") as l_body then
b := l_body
end
if attached fd.string_item ("format") as s_format and then attached response.api.format (s_format) as f_format then
f := f_format
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then
f := f_format
else
f := response.api.formats.default_format
end
if b /= Void then
a_node.set_content (b, Void, f.name) -- FIXME: summary
end
end
new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable CMS_NODE): like content_type.new_node
-- <Precursor>
local
b: detachable READABLE_STRING_8
f: detachable CONTENT_FORMAT
l_node: detachable like new_node
do
if attached {like new_node} a_node as l_arg_node then
l_node := l_arg_node
else
l_node := content_type.new_node (a_node)
end
if attached fd.integer_item ("id") as l_id and then l_id > 0 then
if l_node /= Void then
check l_node.id = l_id end
else
if attached {like new_node} response.node_api.node (l_id) as n then
l_node := n
else
-- FIXME: Error
end
end
end
if attached fd.string_item ("title") as l_title then
if l_node = Void then
l_node := content_type.new_node (Void)
l_node.set_title (l_title)
else
l_node.set_title (l_title)
end
else
if l_node = Void then
l_node := content_type.new_node_with_title ("...", Void)
end
end
l_node.set_author (response.user)
if attached fd.string_item ("body") as l_body then
b := l_body
end
if attached fd.string_item ("format") as s_format and then attached response.api.format (s_format) as f_format then
f := f_format
elseif a_node /= Void and then attached a_node.format as s_format and then attached response.api.format (s_format) as f_format then
f := f_format
else
f := response.api.formats.default_format
end
if b /= Void then
l_node.set_content (b, Void, f.name)
end
Result := l_node
end
feature -- Output
append_html_output_to (a_node: CMS_NODE; a_response: NODE_RESPONSE)
-- <Precursor>
local
lnk: CMS_LOCAL_LINK
hdate: HTTP_DATE
s: STRING
node_api: CMS_NODE_API
do
node_api := a_response.node_api
a_response.add_variable (a_node, "node")
create lnk.make ("View", node_api.node_path (a_node))
lnk.set_weight (1)
a_response.add_to_primary_tabs (lnk)
create lnk.make ("Edit", node_api.node_path (a_node) + "/edit")
lnk.set_weight (2)
a_response.add_to_primary_tabs (lnk)
create s.make_empty
s.append ("<div class=%"info%"> ")
if attached a_node.author as l_author then
s.append (" by ")
s.append (l_author.name)
end
if attached a_node.modification_date as l_modified then
s.append (" (modified: ")
create hdate.make_from_date_time (l_modified)
s.append (hdate.yyyy_mmm_dd_string)
s.append (")")
end
s.append ("</div>")
if attached a_node.content as l_content then
s.append ("<p class=%"content%">")
if attached node_api.cms_api.format (a_node.format) as f then
s.append (f.formatted_output (l_content))
else
s.append (node_api.cms_api.formats.default_format.formatted_output (l_content))
end
s.append ("</p>")
end
a_response.set_title (a_node.title)
a_response.set_main_content (s)
end
end

View File

@@ -1,16 +1,17 @@
note note
description: "Summary description for {CMS_PAGE_CONTENT_TYPE_WEBFORM_MANAGER}." description: "Summary description for {CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER}."
author: "" author: ""
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class class
CMS_PAGE_CONTENT_TYPE_WEBFORM_MANAGER CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER
inherit inherit
CMS_NODE_CONTENT_TYPE_WEBFORM_MANAGER [CMS_PAGE] CMS_NODE_TYPE_WEBFORM_MANAGER [CMS_PAGE]
redefine redefine
content_type content_type,
append_html_output_to
end end
create create
@@ -18,7 +19,7 @@ create
feature -- Access feature -- Access
content_type: CMS_PAGE_CONTENT_TYPE content_type: CMS_PAGE_NODE_TYPE
-- Associated content type. -- Associated content type.
feature -- Forms ... feature -- Forms ...
@@ -156,5 +157,29 @@ feature -- Forms ...
-- Result := l_node -- Result := l_node
-- end -- end
feature -- Output
append_html_output_to (a_node: CMS_NODE; a_response: NODE_RESPONSE)
-- <Precursor>
local
s: STRING
do
Precursor (a_node, a_response)
if attached a_response.main_content as l_main_content then
s := l_main_content
else
create s.make_empty
end
if attached {CMS_PAGE} a_node as l_node_page then
if attached l_node_page.parent as l_parent_node then
s.append ("<div>Parent page is ")
s.append (a_response.link (l_parent_node.title + " (#" + l_parent_node.id.out + ")", a_response.node_api.node_path (l_parent_node), Void))
s.append ("</div>")
end
end
a_response.set_main_content (s)
end
end end

View File

@@ -1,7 +1,5 @@
note note
description: "Summary description for {NODE_FORM_RESPONSE}." description: "CMS Response handling node editing workflow using Web forms."
author: ""
date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class class
@@ -42,6 +40,7 @@ feature -- Execution
f: like edit_form f: like edit_form
fd: detachable WSF_FORM_DATA fd: detachable WSF_FORM_DATA
nid: INTEGER_64 nid: INTEGER_64
l_node_type: CMS_NODE_TYPE
do do
create b.make_empty create b.make_empty
nid := node_id_path_parameter (request) nid := node_id_path_parameter (request)
@@ -49,7 +48,7 @@ feature -- Execution
nid > 0 and then nid > 0 and then
attached node_api.node (nid) as l_node attached node_api.node (nid) as l_node
then then
if attached node_api.content_type (l_node.content_type) as l_type then if attached node_api.node_type_for (l_node) as l_type then
if has_permission ("edit " + l_type.name) then if has_permission ("edit " + l_type.name) then
f := edit_form (l_node, url (request.path_info, Void), "edit-" + l_type.name, l_type) f := edit_form (l_node, url (request.path_info, Void), "edit-" + l_type.name, l_type)
if request.is_post_request_method then if request.is_post_request_method then
@@ -65,9 +64,9 @@ feature -- Execution
add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs) add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs)
add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs) add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs)
b.append ("saved") b.append (html_encoded (l_type.title) + " saved")
else else
set_title ("Edit #" + l_node.id.out) set_title ("Edit " + html_encoded (l_type.title) + " #" + l_node.id.out)
add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs) add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs)
add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs) add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs)
@@ -82,7 +81,7 @@ feature -- Execution
end end
elseif elseif
attached {WSF_STRING} request.path_parameter ("type") as p_type and then attached {WSF_STRING} request.path_parameter ("type") as p_type and then
attached node_api.content_type (p_type.value) as l_type attached node_api.node_type (p_type.value) as l_type
then then
if has_permission ("create " + l_type.name) then if has_permission ("create " + l_type.name) then
if attached l_type.new_node (Void) as l_node then if attached l_type.new_node (Void) as l_node then
@@ -94,7 +93,7 @@ feature -- Execution
fd := f.last_data fd := f.last_data
end end
set_title ("Edit #" + l_node.id.out) set_title ("Edit " + html_encoded (l_type.title) + " #" + l_node.id.out)
add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs) add_to_menu (create {CMS_LOCAL_LINK}.make ("View", node_url (l_node)), primary_tabs)
add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs) add_to_menu (create {CMS_LOCAL_LINK}.make ("Edit", "/node/" + l_node.id.out + "/edit"), primary_tabs)
@@ -106,16 +105,19 @@ feature -- Execution
else else
b.append ("<h1>Access denied</h1>") b.append ("<h1>Access denied</h1>")
end end
else else
set_title ("Create new content ...") set_title ("Create new content ...")
b.append ("<ul id=%"content-types%">") b.append ("<ul id=%"content-types%">")
across across
node_api.content_types as c node_api.node_types as ic
loop loop
if has_permission ("create " + c.item.name) then l_node_type := ic.item
b.append ("<li>" + link (c.item.name, "/node/add/" + c.item.name, Void)) if
if attached c.item.description as d then has_permission ("create any")
or has_permission ("create " + l_node_type.name)
then
b.append ("<li>" + link (l_node_type.name, "/node/add/" + l_node_type.name, Void))
if attached l_node_type.description as d then
b.append ("<div class=%"description%">" + d + "</div>") b.append ("<div class=%"description%">" + d + "</div>")
end end
b.append ("</li>") b.append ("</li>")
@@ -155,7 +157,7 @@ feature -- Form
end end
end end
edit_form_submit (fd: WSF_FORM_DATA; a_node: detachable CMS_NODE; a_type: CMS_CONTENT_TYPE; b: STRING) edit_form_submit (fd: WSF_FORM_DATA; a_node: detachable CMS_NODE; a_type: CMS_NODE_TYPE; b: STRING)
local local
l_preview: BOOLEAN l_preview: BOOLEAN
l_node: detachable CMS_NODE l_node: detachable CMS_NODE
@@ -200,7 +202,7 @@ feature -- Form
end end
end end
edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_CONTENT_TYPE): CMS_FORM edit_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_type: CMS_NODE_TYPE): CMS_FORM
local local
f: CMS_FORM f: CMS_FORM
ts: WSF_FORM_SUBMIT_INPUT ts: WSF_FORM_SUBMIT_INPUT
@@ -231,26 +233,28 @@ feature -- Form
Result := f Result := f
end end
new_node (a_content_type: CMS_CONTENT_TYPE; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): CMS_NODE new_node (a_content_type: CMS_NODE_TYPE; a_form_data: WSF_FORM_DATA; a_node: detachable CMS_NODE): CMS_NODE
--
do do
if attached node_api.content_type_webform_manager (a_content_type.name) as wf then if attached node_api.node_type_webform_manager (a_content_type) as wf then
Result := wf.new_node (Current, a_form_data, a_node) Result := wf.new_node (Current, a_form_data, a_node)
else else
Result := a_content_type.new_node (a_node) Result := a_content_type.new_node (a_node)
end end
end end
change_node (a_content_type: CMS_CONTENT_TYPE; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE) change_node (a_content_type: CMS_NODE_TYPE; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE)
-- Update node `a_node' with form_data `a_form_data' for the given content type `a_content_type'.
do do
if attached node_api.content_type_webform_manager (a_content_type.name) as wf then if attached node_api.node_type_webform_manager (a_content_type) as wf then
wf.change_node (Current, a_form_data, a_node) wf.update_node (Current, a_form_data, a_node)
end end
end end
fill_edit_form (a_content_type: CMS_CONTENT_TYPE; a_form: WSF_FORM; a_node: detachable CMS_NODE) fill_edit_form (a_content_type: CMS_NODE_TYPE; a_form: WSF_FORM; a_node: detachable CMS_NODE)
do do
if attached node_api.content_type_webform_manager (a_content_type.name) as wf then if attached node_api.node_type_webform_manager (a_content_type) as wf then
wf.fill_edit_form (Current, a_form, a_node) wf.populate_form (Current, a_form, a_node)
end end
end end

View File

@@ -1,5 +1,9 @@
note note
description: "handler for CMS node in the CMS interface." description: "[
handler for CMS node in the CMS interface.
TODO: implement REST API.
]"
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $" date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
revision: "$Revision: 96616 $" revision: "$Revision: 96616 $"
@@ -61,13 +65,10 @@ feature -- HTTP Methods
do_get (req: WSF_REQUEST; res: WSF_RESPONSE) do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor> -- <Precursor>
local local
l_page: CMS_RESPONSE
s: STRING
hdate: HTTP_DATE
lnk: CMS_LOCAL_LINK
l_node: detachable CMS_NODE l_node: detachable CMS_NODE
l_nid: INTEGER_64 l_nid: INTEGER_64
edit_response: NODE_FORM_RESPONSE edit_response: NODE_FORM_RESPONSE
view_response: NODE_VIEW_RESPONSE
do do
if req.path_info.ends_with_general ("/edit") then if req.path_info.ends_with_general ("/edit") then
create edit_response.make (req, res, api, node_api) create edit_response.make (req, res, api, node_api)
@@ -83,49 +84,9 @@ feature -- HTTP Methods
l_node := node_api.node (l_nid) l_node := node_api.node (l_nid)
end end
if l_node /= Void then if l_node /= Void then
-- FIXME: allow a per content type display here! create view_response.make (req, res, api, node_api)
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api) view_response.set_node (l_node)
l_page.add_variable (l_node, "node") view_response.execute
create lnk.make ("View", node_api.node_path (l_node))
lnk.set_weight (1)
l_page.add_to_primary_tabs (lnk)
create lnk.make ("Edit", node_api.node_path (l_node) + "/edit")
lnk.set_weight (2)
l_page.add_to_primary_tabs (lnk)
create s.make_empty
s.append ("<div class=%"info%"> ")
if attached l_node.author as l_author then
s.append (" by ")
s.append (l_author.name)
end
if attached l_node.modification_date as l_modified then
s.append (" (modified: ")
create hdate.make_from_date_time (l_modified)
s.append (hdate.yyyy_mmm_dd_string)
s.append (")")
end
s.append ("</div>")
if attached l_node.content as l_content then
s.append ("<p class=%"content%">")
if attached api.format (l_node.format) as f then
s.append (f.formatted_output (l_content))
else
s.append (api.formats.default_format.formatted_output (l_content))
end
s.append ("</p>")
end
if attached {CMS_PAGE} l_node as l_node_page then
if attached l_node_page.parent as l_parent_node then
s.append ("<div>Parent page is ")
s.append (l_page.link (l_parent_node.title + " (#" + l_parent_node.id.out + ")", node_api.node_path (l_parent_node), Void))
s.append ("</div>")
end
end
l_page.set_title (l_node.title)
l_page.set_main_content (s)
l_page.execute
elseif l_nid > 0 then --| i.e: l_node = Void elseif l_nid > 0 then --| i.e: l_node = Void
send_not_found (req, res) send_not_found (req, res)
else else
@@ -149,55 +110,57 @@ feature -- HTTP Methods
create edit_response.make (req, res, api, node_api) create edit_response.make (req, res, api, node_api)
edit_response.execute edit_response.execute
else else
to_implement ("Check user permissions!!!") handle_not_implemented ("REST API not yet implemented", req, res)
if attached current_user (req) as l_user then -- to_implement ("Check user permissions!!!")
if attached {WSF_STRING} req.path_parameter ("id") as l_id then -- if attached current_user (req) as l_user then
if -- if attached {WSF_STRING} req.path_parameter ("id") as l_id then
l_id.is_integer and then -- if
attached node_api.node (l_id.value.to_integer_64) as l_node -- l_id.is_integer and then
then -- attached node_api.node (l_id.value.to_integer_64) as l_node
if attached {WSF_STRING} req.form_parameter ("method") as l_method then -- then
if l_method.is_case_insensitive_equal ("DELETE") then -- if attached {WSF_STRING} req.form_parameter ("method") as l_method then
do_delete (req, res) -- if l_method.is_case_insensitive_equal ("DELETE") then
elseif l_method.is_case_insensitive_equal ("PUT") then -- do_delete (req, res)
do_put (req, res) -- elseif l_method.is_case_insensitive_equal ("PUT") then
else -- do_put (req, res)
process_node_update (req, res, l_user, l_node) -- else
-- Accept this, even if this is not proper usage of POST -- process_node_update (req, res, l_user, l_node)
-- (create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute -- -- Accept this, even if this is not proper usage of POST
end -- -- (create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end -- end
else -- end
do_error (req, res, l_id) -- else
end -- do_error (req, res, l_id)
else -- end
process_node_creation (req, res, l_user) -- else
end -- process_node_creation (req, res, l_user)
else -- end
send_access_denied (req, res) -- else
end -- send_access_denied (req, res)
-- end
end end
end end
do_put (req: WSF_REQUEST; res: WSF_RESPONSE) do_put (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor> -- <Precursor>
do do
if attached current_user (req) as l_user then handle_not_implemented ("REST API not yet implemented", req, res)
if attached {WSF_STRING} req.path_parameter ("id") as l_id then -- if attached current_user (req) as l_user then
if -- if attached {WSF_STRING} req.path_parameter ("id") as l_id then
l_id.is_integer and then -- if
attached node_api.node (l_id.value.to_integer_64) as l_node -- l_id.is_integer and then
then -- attached node_api.node (l_id.value.to_integer_64) as l_node
process_node_update (req, res, l_user, l_node) -- then
else -- process_node_update (req, res, l_user, l_node)
do_error (req, res, l_id) -- else
end -- do_error (req, res, l_id)
else -- end
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute -- else
end -- (create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
else -- end
send_access_denied (req, res) -- else
end -- send_access_denied (req, res)
-- end
end end
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE) do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
@@ -228,48 +191,49 @@ feature -- HTTP Methods
process_node_creation (req: WSF_REQUEST; res: WSF_RESPONSE; a_user: CMS_USER) process_node_creation (req: WSF_REQUEST; res: WSF_RESPONSE; a_user: CMS_USER)
local local
u_node: CMS_NODE -- u_node: CMS_NODE
do do
-- New node -- New node
-- FIXME !!! -- FIXME !!!
if handle_not_implemented ("REST API not yet implemented", req, res)
attached {WSF_STRING} req.form_parameter ("type") as p_type and then -- if
attached node_api.content_type (p_type.value) as ct -- should be string 8 value. -- attached {WSF_STRING} req.form_parameter ("type") as p_type and then
then -- attached node_api.node_type (p_type.value) as ct -- should be string 8 value.
if api.user_has_permission (a_user, "create " + ct.name) then -- then
u_node := ct.new_node (Void) -- if api.user_has_permission (a_user, "create " + ct.name) then
-- create {CMS_PARTIAL_NODE} u_node.make_empty (p_type.url_encoded_value) -- u_node := ct.new_node (Void)
update_node_from_data_form (req, u_node) -- -- create {CMS_PARTIAL_NODE} u_node.make_empty (p_type.url_encoded_value)
u_node.set_author (a_user) -- update_node_from_data_form (req, u_node)
node_api.new_node (u_node) -- u_node.set_author (a_user)
if attached {WSF_STRING} req.item ("destination") as p_destination then -- node_api.new_node (u_node)
redirect_to (req.absolute_script_url (p_destination.url_encoded_value), res) -- if attached {WSF_STRING} req.item ("destination") as p_destination then
else -- redirect_to (req.absolute_script_url (p_destination.url_encoded_value), res)
redirect_to (req.absolute_script_url (""), res) -- else
end -- redirect_to (req.absolute_script_url (""), res)
else -- end
send_access_denied (req, res) -- else
end -- send_access_denied (req, res)
else -- end
do_error (req, res, Void) -- else
end -- do_error (req, res, Void)
-- end
end end
process_node_update (req: WSF_REQUEST; res: WSF_RESPONSE; a_user: CMS_USER; a_node: CMS_NODE) -- process_node_update (req: WSF_REQUEST; res: WSF_RESPONSE; a_user: CMS_USER; a_node: CMS_NODE)
do -- do
if api.user_has_permission (a_user, "modify " + a_node.content_type) then -- if api.user_has_permission (a_user, "modify " + a_node.content_type) then
update_node_from_data_form (req, a_node) -- update_node_from_data_form (req, a_node)
a_node.set_author (a_user) -- a_node.set_author (a_user)
node_api.update_node (a_node) -- node_api.update_node (a_node)
if attached {WSF_STRING} req.item ("destination") as p_destination then -- if attached {WSF_STRING} req.item ("destination") as p_destination then
redirect_to (req.absolute_script_url (p_destination.url_encoded_value), res) -- redirect_to (req.absolute_script_url (p_destination.url_encoded_value), res)
else -- else
redirect_to (req.absolute_script_url (""), res) -- redirect_to (req.absolute_script_url (""), res)
end -- end
else -- else
send_access_denied (req, res) -- send_access_denied (req, res)
end -- end
end -- end
feature -- Error feature -- Error
@@ -296,81 +260,47 @@ feature {NONE} -- Node
create_new_node (req: WSF_REQUEST; res: WSF_RESPONSE) create_new_node (req: WSF_REQUEST; res: WSF_RESPONSE)
local local
l_page: NOT_IMPLEMENTED_ERROR_CMS_RESPONSE
l_node: detachable CMS_NODE
l_gen_page: GENERIC_VIEW_CMS_RESPONSE l_gen_page: GENERIC_VIEW_CMS_RESPONSE
edit_response: NODE_FORM_RESPONSE edit_response: NODE_FORM_RESPONSE
s: STRING s: STRING
do do
if if req.path_info.starts_with_general ("/node/add/") then
attached {WSF_STRING} req.path_parameter ("type") as p_type and then
attached node_api.content_type (p_type.value) as ct
then
create edit_response.make (req, res, api, node_api) create edit_response.make (req, res, api, node_api)
edit_response.execute edit_response.execute
-- create l_page.make (req, res, api) elseif req.is_get_request_method then
-- l_node := ct.new_node (Void) redirect_to (req.absolute_script_url ("/node/add/"), res)
-- l_page.set_main_content (l_node.out)
-- l_page.execute
else else
create l_gen_page.make (req, res, api) send_bad_request (req, res)
create s.make_empty
s.append ("<ul>")
across
node_api.content_types as ic
loop
if api.user_has_permission (current_user (req), "create " + ic.item.name) then
s.append ("<li>")
s.append (l_gen_page.link (ic.item.title, node_api.new_content_path (ic.item), Void))
if attached ic.item.description as l_description then
s.append ("<p class=%"description%">")
s.append (l_gen_page.html_encoded (l_description))
s.append ("</p>")
end end
s.append ("</li>")
end
end
s.append ("</ul>")
l_gen_page.set_title ("Create new content ...")
l_gen_page.set_main_content (s)
l_gen_page.execute
end
-- if api.user_has_permission (current_user (req), "create node") then
-- create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
-- l_page.execute
-- else
-- send_access_denied (req, res)
-- end
end end
feature -- {NONE} Form data feature -- {NONE} Form data
update_node_from_data_form (req: WSF_REQUEST; a_node: CMS_NODE) -- update_node_from_data_form (req: WSF_REQUEST; a_node: CMS_NODE)
-- Extract request form data and build a object -- -- Extract request form data and build a object
-- Node -- -- Node
local -- local
l_title: detachable READABLE_STRING_32 -- l_title: detachable READABLE_STRING_32
l_summary, l_content, l_format: detachable READABLE_STRING_8 -- l_summary, l_content, l_format: detachable READABLE_STRING_8
do -- do
if attached {WSF_STRING} req.form_parameter ("title") as p_title then -- if attached {WSF_STRING} req.form_parameter ("title") as p_title then
l_title := p_title.value -- l_title := p_title.value
a_node.set_title (l_title) -- a_node.set_title (l_title)
end -- end
if attached {WSF_STRING} req.form_parameter ("summary") as p_summary then -- if attached {WSF_STRING} req.form_parameter ("summary") as p_summary then
l_summary := html_encoded (p_summary.value) -- l_summary := html_encoded (p_summary.value)
end -- end
if attached {WSF_STRING} req.form_parameter ("content") as p_content then -- if attached {WSF_STRING} req.form_parameter ("content") as p_content then
l_content := html_encoded (p_content.value) -- l_content := html_encoded (p_content.value)
end -- end
if attached {WSF_STRING} req.form_parameter ("format") as p_format then -- if attached {WSF_STRING} req.form_parameter ("format") as p_format then
l_format := p_format.url_encoded_value -- l_format := p_format.url_encoded_value
end -- end
if l_format = Void then -- if l_format = Void then
l_format := a_node.format -- l_format := a_node.format
end -- end
a_node.set_content (l_content, l_summary, l_format) -- a_node.set_content (l_content, l_summary, l_format)
end -- end
end end

View File

@@ -1,6 +1,5 @@
note note
description: "Summary description for {NODE_RESPONSE}." description: "Generic CMS Response for a CMS NODE."
author: ""
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
@@ -26,6 +25,7 @@ feature {NONE} -- Initialization
feature -- Access feature -- Access
node_api: CMS_NODE_API node_api: CMS_NODE_API
-- Associated node API.
feature -- Generation feature -- Generation

View File

@@ -0,0 +1,75 @@
note
description: "Summary description for {NODE_VIEW_RESPONSE}."
date: "$Date$"
revision: "$Revision$"
class
NODE_VIEW_RESPONSE
inherit
NODE_RESPONSE
redefine
make,
initialize
end
create
make
feature {NONE} -- Initialization
make (req: WSF_REQUEST; res: WSF_RESPONSE; a_api: like api; a_node_api: like node_api)
do
create {WSF_NULL_THEME} wsf_theme.make
Precursor (req, res, a_api, a_node_api)
end
initialize
do
Precursor
create {WSF_CMS_THEME} wsf_theme.make (Current, theme)
end
wsf_theme: WSF_THEME
feature -- Access
node: detachable CMS_NODE
feature -- Element change
set_node (a_node: like node)
do
node := a_node
end
feature -- Execution
process
-- Computed response message.
local
b: STRING_8
nid: INTEGER_64
l_node: like node
do
l_node := node
if l_node = Void then
create b.make_empty
nid := node_id_path_parameter (request)
if nid > 0 then
l_node := node_api.node (nid)
end
end
if l_node /= Void then
if
attached node_api.node_type_for (l_node) as l_content_type and then
attached node_api.node_type_webform_manager (l_content_type) as l_manager
then
l_manager.append_html_output_to (l_node, Current)
end
else
set_main_content ("Missing node")
end
end
end

View File

@@ -47,7 +47,7 @@ feature {CMS_API} -- Module Initialization
-- <Precursor> -- <Precursor>
local local
p1,p2: CMS_PAGE p1,p2: CMS_PAGE
ct: CMS_PAGE_CONTENT_TYPE ct: CMS_PAGE_NODE_TYPE
l_node_api: like node_api l_node_api: like node_api
do do
Precursor (api) Precursor (api)

View File

@@ -6,9 +6,6 @@ note
deferred class deferred class
CMS_NODE_STORAGE_I CMS_NODE_STORAGE_I
inherit
SHARED_LOGGER
feature -- Error Handling feature -- Error Handling
error_handler: ERROR_HANDLER error_handler: ERROR_HANDLER

View File

@@ -17,8 +17,6 @@ inherit
REFACTORING_HELPER REFACTORING_HELPER
SHARED_LOGGER
create create
make make

View File

@@ -16,8 +16,6 @@ inherit
node_storage node_storage
end end
SHARED_LOGGER
create create
make make
@@ -30,7 +28,7 @@ feature -- Access
content_type: STRING content_type: STRING
once once
Result := {CMS_PAGE_CONTENT_TYPE}.name Result := {CMS_PAGE_NODE_TYPE}.name
end end
feature -- Persistence feature -- Persistence
@@ -73,7 +71,7 @@ feature -- Persistence
local local
l_parameters: STRING_TABLE [ANY] l_parameters: STRING_TABLE [ANY]
n: INTEGER n: INTEGER
ct: CMS_PAGE_CONTENT_TYPE ct: CMS_PAGE_NODE_TYPE
do do
error_handler.reset error_handler.reset
write_information_log (generator + ".fill_page") write_information_log (generator + ".fill_page")

View File

@@ -68,20 +68,6 @@ feature -- Access: user
do do
end end
feature -- User Nodes
user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST [CMS_NODE]
-- Possible list of nodes where the user identified by `a_id', is a collaborator.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
end
user_author_nodes (a_id: like {CMS_USER}.id): LIST [CMS_NODE]
-- Possible list of nodes where the user identified by `a_id', is the author.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
end
feature -- Change: user feature -- Change: user
new_user (a_user: CMS_USER) new_user (a_user: CMS_USER)

View File

@@ -6,6 +6,9 @@ note
deferred class deferred class
CMS_STORAGE_SQL_I CMS_STORAGE_SQL_I
inherit
SHARED_LOGGER
feature -- Access feature -- Access
api: detachable CMS_API api: detachable CMS_API

View File

@@ -0,0 +1,9 @@
note
description: "Interface having access to restricted features relate to CMS APIs."
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_API_ACCESS
end

View File

@@ -20,7 +20,7 @@ feature {NONE} -- Implementation
do do
end end
feature {CMS_MODULE, CMS_API} -- Restricted access feature {CMS_API_ACCESS, CMS_MODULE, CMS_API} -- Restricted access
cms_api: CMS_API cms_api: CMS_API