Refactored add child feature, to have all the page specific code in CMS_PAGE_NODE_TYPE_WEBFORM_MANAGER (and not in the general node code).
Note that ideally PAGE could be a separated page node module (as it is for blog). Added listing of children for each "page".
This commit is contained in:
@@ -281,14 +281,17 @@ feature -- Access: Node
|
|||||||
else
|
else
|
||||||
Result := l_partial_node
|
Result := l_partial_node
|
||||||
end
|
end
|
||||||
|
-- Update link with aliasing.
|
||||||
|
if Result /= Void and then Result.has_id then
|
||||||
|
Result.set_link (node_link (Result))
|
||||||
|
end
|
||||||
else
|
else
|
||||||
Result := a_node
|
Result := a_node
|
||||||
|
if Result.has_id and Result.link = Void then
|
||||||
|
Result.set_link (node_link (Result))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
check has_link: Result.has_id implies attached Result.link as lnk and then lnk.location.same_string (node_link (Result).location) end
|
||||||
-- Update link with aliasing.
|
|
||||||
if a_node /= Void and then a_node.has_id then
|
|
||||||
a_node.set_link (node_link (a_node))
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Update partial user if needed.
|
-- Update partial user if needed.
|
||||||
if
|
if
|
||||||
@@ -327,60 +330,47 @@ feature -- Access: Node
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Access: page/book outline
|
||||||
|
|
||||||
|
children (a_node: CMS_NODE): detachable LIST [CMS_NODE]
|
||||||
|
-- Children of node `a_node'.
|
||||||
|
-- note: this is the partial version of the nodes.
|
||||||
|
do
|
||||||
|
Result := node_storage.children (a_node)
|
||||||
|
end
|
||||||
|
|
||||||
available_parents_for_node (a_node: CMS_NODE): LIST [CMS_NODE]
|
available_parents_for_node (a_node: CMS_NODE): LIST [CMS_NODE]
|
||||||
-- List of possible parents nodes for node `a_node'.
|
-- Potential parent nodes for node `a_node'.
|
||||||
-- Ensure the list of possible parent nodes does not allow a potential cycle.
|
-- Ensure no cycle exists.
|
||||||
do
|
do
|
||||||
create {ARRAYED_LIST[CMS_NODE]}Result.make (0)
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
across node_storage.available_parents_for_node(a_node) as ic loop
|
across node_storage.available_parents_for_node (a_node) as ic loop
|
||||||
if not has_cycle (a_node, ic.item) then
|
check distinct: not a_node.same_node (ic.item) end
|
||||||
|
if not is_node_a_parent_of (a_node, ic.item) then
|
||||||
Result.force (ic.item)
|
Result.force (ic.item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
not_cycle: Result.for_all (agent not_cycle (a_node, ?))
|
no_cycle: across Result as c all not is_node_a_parent_of (a_node, c.item) end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
not_cycle (a_node: CMS_NODE; a_parent: CMS_NODE): BOOLEAN
|
is_node_a_parent_of (a_node: CMS_NODE; a_child: CMS_NODE): BOOLEAN
|
||||||
|
-- Is `a_node' a direct or indirect parent of node `a_child'?
|
||||||
|
require
|
||||||
|
distinct_nodes: not a_node.same_node (a_child)
|
||||||
do
|
do
|
||||||
Result := not has_cycle (a_node, a_parent)
|
|
||||||
end
|
|
||||||
|
|
||||||
has_cycle (a_node: CMS_NODE; a_parent: CMS_NODE): BOOLEAN
|
|
||||||
-- Check if adding the node `a_parent' as parent of node `a_node' form a cycle.
|
|
||||||
local
|
|
||||||
l_flag: BOOLEAN
|
|
||||||
l_item: detachable CMS_PAGE
|
|
||||||
do
|
|
||||||
Result := False
|
|
||||||
if
|
if
|
||||||
attached {CMS_PAGE} a_node as l_page and then
|
attached {CMS_PAGE} full_node (a_child) as l_child_page and then
|
||||||
attached {CMS_PAGE} full_node (a_parent) as l_page_parent
|
attached l_child_page.parent as l_parent
|
||||||
then
|
then
|
||||||
l_page.set_parent (l_page_parent)
|
if l_parent.same_node (l_child_page) then
|
||||||
from
|
Result := True
|
||||||
l_item := l_page_parent
|
else
|
||||||
until
|
Result := is_node_a_parent_of (a_node, l_parent)
|
||||||
l_flag or else Result
|
end
|
||||||
loop
|
|
||||||
if attached l_item and then attached {CMS_PAGE} node (l_item.id) as l_parent then
|
|
||||||
if l_parent.id = l_page.id then
|
|
||||||
Result := True
|
|
||||||
else
|
|
||||||
l_item := l_parent.parent
|
|
||||||
end
|
|
||||||
else
|
|
||||||
l_flag := True
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- Set parent to void.
|
|
||||||
l_page.set_parent (Void)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Permission Scope: Node
|
feature -- Permission Scope: Node
|
||||||
|
|||||||
@@ -170,6 +170,8 @@ feature -- Access
|
|||||||
Result.force ("trash own " + l_type_name)
|
Result.force ("trash own " + l_type_name)
|
||||||
Result.force ("restore own " + l_type_name)
|
Result.force ("restore own " + l_type_name)
|
||||||
|
|
||||||
|
Result.force ("view unpublished " + l_type_name)
|
||||||
|
|
||||||
Result.force ("view revisions own " + l_type_name)
|
Result.force ("view revisions own " + l_type_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ deferred class
|
|||||||
CMS_NODE
|
CMS_NODE
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
DEBUG_OUTPUT
|
||||||
REFACTORING_HELPER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
feature{NONE} -- Initialization
|
feature{NONE} -- Initialization
|
||||||
@@ -166,6 +166,23 @@ feature -- Access: menu
|
|||||||
link: detachable CMS_LOCAL_LINK
|
link: detachable CMS_LOCAL_LINK
|
||||||
-- Associated menu link.
|
-- Associated menu link.
|
||||||
|
|
||||||
|
feature -- Status report
|
||||||
|
|
||||||
|
debug_output: STRING_32
|
||||||
|
-- <Precursor>
|
||||||
|
do
|
||||||
|
create Result.make_from_string_general ("#")
|
||||||
|
Result.append_integer_64 (id)
|
||||||
|
Result.append_character (' ')
|
||||||
|
Result.append_character ('<')
|
||||||
|
Result.append_string_general (content_type)
|
||||||
|
Result.append_character ('>')
|
||||||
|
Result.append_character (' ')
|
||||||
|
Result.append_character ('%"')
|
||||||
|
Result.append (title)
|
||||||
|
Result.append_character ('%"')
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Element change
|
feature -- Element change
|
||||||
|
|
||||||
set_content (a_content: like content; a_summary: like summary; a_format: like format)
|
set_content (a_content: like content; a_summary: like summary; a_format: like format)
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ feature -- Output
|
|||||||
create lnk.make ("Trash", node_api.node_path (a_node) + "/trash")
|
create lnk.make ("Trash", node_api.node_path (a_node) + "/trash")
|
||||||
lnk.set_weight (2)
|
lnk.set_weight (2)
|
||||||
a_response.add_to_primary_tabs (lnk)
|
a_response.add_to_primary_tabs (lnk)
|
||||||
elseif a_node /= Void and then a_node.has_id then
|
elseif a_node.has_id then
|
||||||
-- Node in {{CMS_NODE_API}.published} or {CMS_NODE_API}.not_published} status.
|
-- Node in {{CMS_NODE_API}.published} or {CMS_NODE_API}.not_published} status.
|
||||||
create lnk.make ("Edit", node_api.node_path (a_node) + "/edit")
|
create lnk.make ("Edit", node_api.node_path (a_node) + "/edit")
|
||||||
lnk.set_weight (2)
|
lnk.set_weight (2)
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ inherit
|
|||||||
redefine
|
redefine
|
||||||
content_type,
|
content_type,
|
||||||
append_html_output_to,
|
append_html_output_to,
|
||||||
|
populate_form,
|
||||||
|
new_node,
|
||||||
update_node
|
update_node
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -24,159 +26,112 @@ feature -- Access
|
|||||||
|
|
||||||
feature -- Forms ...
|
feature -- Forms ...
|
||||||
|
|
||||||
|
populate_form (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable CMS_NODE)
|
||||||
|
local
|
||||||
|
ti: WSF_FORM_NUMBER_INPUT
|
||||||
|
l_parent_id, nid: INTEGER_64
|
||||||
|
do
|
||||||
|
Precursor (response, f, a_node)
|
||||||
|
|
||||||
|
if attached {CMS_PAGE} a_node as l_page then
|
||||||
|
create ti.make ("select_parent_node")
|
||||||
|
|
||||||
|
if attached l_page.parent as l_parent_node then
|
||||||
|
l_parent_id := l_parent_node.id
|
||||||
|
f.extend_html_text ("<div><strong>Currently, the parent page is </strong> ")
|
||||||
|
f.extend_html_text (response.node_html_link (l_parent_node, l_parent_node.title))
|
||||||
|
f.extend_html_text ("</div>")
|
||||||
|
ti.set_label ("Change parent")
|
||||||
|
ti.set_description ("Select a new parent ...")
|
||||||
|
else
|
||||||
|
ti.set_label ("Select parent")
|
||||||
|
ti.set_description ("Select a parent ...")
|
||||||
|
end
|
||||||
|
ti.set_validation_action (agent parent_validation (response, ?))
|
||||||
|
f.extend (ti)
|
||||||
|
|
||||||
|
if response.location.ends_with_general ("/add_child/page") then
|
||||||
|
nid := response.node_id_path_parameter (response.request)
|
||||||
|
l_parent_id := nid
|
||||||
|
end
|
||||||
|
if l_parent_id > 0 then
|
||||||
|
ti.set_default_value (l_parent_id.out)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
update_node (a_response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: CMS_NODE)
|
update_node (a_response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
|
local
|
||||||
|
l_parent_id: INTEGER_64
|
||||||
do
|
do
|
||||||
Precursor (a_response, fd, a_node)
|
Precursor (a_response, fd, a_node)
|
||||||
if
|
if attached {CMS_PAGE} a_node as l_page then
|
||||||
attached {CMS_PAGE} a_node as l_node_page and then
|
if attached fd.integer_item ("select_parent_node") as i_parent_node then
|
||||||
attached fd.integer_item ("select_parent_node") as i_parent_node and then
|
l_parent_id := i_parent_node.to_integer_64
|
||||||
i_parent_node > 0 and then
|
end
|
||||||
attached {CMS_PAGE} a_response.node_api.node (i_parent_node) as l_parent_page
|
if
|
||||||
then
|
l_parent_id > 0 and then
|
||||||
l_node_page.set_parent (l_parent_page)
|
attached {CMS_PAGE} a_response.node_api.node (l_parent_id) as l_parent_page
|
||||||
elseif attached {CMS_PAGE} a_node as l_node_page and then
|
then
|
||||||
attached fd.integer_item ("select_parent_node") as i_parent_node and then
|
l_page.set_parent (l_parent_page)
|
||||||
i_parent_node = -1
|
elseif l_parent_id = -1 then
|
||||||
then
|
-- Set parent to Void
|
||||||
-- Set parent to Void
|
l_page.set_parent (Void)
|
||||||
l_node_page.set_parent (Void)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
-- fill_edit_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/>")
|
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.integer_item ("select_parent_node") as l_parent_id then
|
||||||
|
if l_parent_id = -1 then
|
||||||
|
Result.set_parent (Void)
|
||||||
|
elseif attached {CMS_PAGE} response.node_api.node (l_parent_id) as l_parent then
|
||||||
|
Result.set_parent (l_parent)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- create ta.make ("body")
|
parent_validation (a_response: NODE_RESPONSE; fd: WSF_FORM_DATA)
|
||||||
-- ta.set_rows (10)
|
local
|
||||||
-- ta.set_cols (70)
|
l_selected: BOOLEAN
|
||||||
-- if a_node /= Void then
|
node_api: CMS_NODE_API
|
||||||
-- ta.set_text_value (a_node.content)
|
l_parent_id: INTEGER_64
|
||||||
-- end
|
do
|
||||||
---- ta.set_label ("Body")
|
node_api := a_response.node_api
|
||||||
-- ta.set_description ("This is the main content")
|
if attached fd.integer_item ("select_parent_node") as s_parent_node then
|
||||||
-- ta.set_is_required (False)
|
l_parent_id := s_parent_node.to_integer_64
|
||||||
|
else
|
||||||
-- create fset.make
|
l_parent_id := 0
|
||||||
-- fset.set_legend ("Body")
|
end
|
||||||
-- fset.extend (ta)
|
if
|
||||||
|
l_parent_id > 0 and then
|
||||||
-- fset.extend_html_text ("<br/>")
|
attached node_api.node (a_response.node_id_path_parameter (a_response.request)) as l_node
|
||||||
|
then
|
||||||
-- create tselect.make ("format")
|
if not a_response.location.ends_with_general ("/add_child/page") then
|
||||||
-- tselect.set_label ("Body's format")
|
across
|
||||||
-- tselect.set_is_required (True)
|
node_api.available_parents_for_node (l_node) as ic
|
||||||
-- across
|
until
|
||||||
-- content_type.available_formats as c
|
l_selected
|
||||||
-- loop
|
loop
|
||||||
-- create opt.make (c.item.name, c.item.title)
|
if ic.item.id = l_parent_id then
|
||||||
-- if attached c.item.html_help as f_help then
|
l_selected := True
|
||||||
-- opt.set_description ("<ul>" + f_help + "</ul>")
|
end
|
||||||
-- end
|
end
|
||||||
-- tselect.add_option (opt)
|
if not l_selected then
|
||||||
-- end
|
fd.report_invalid_field ("select_parent_node", "Invalid node id " + l_parent_id.out)
|
||||||
-- if a_node /= Void and then attached a_node.format as l_format then
|
end
|
||||||
-- tselect.set_text_by_value (l_format)
|
end
|
||||||
-- end
|
elseif l_parent_id = -1 or else l_parent_id = 0 then
|
||||||
|
-- -1 is Used to unassign a parent node
|
||||||
-- fset.extend (tselect)
|
-- 0 is not taken into account, any other input value is considered invalid.
|
||||||
|
else
|
||||||
-- f.extend (fset)
|
fd.report_invalid_field ("select_parent_node", "Invalid node id")
|
||||||
|
end
|
||||||
-- end
|
end
|
||||||
|
|
||||||
-- change_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: like new_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 like new_node): CMS_PAGE
|
|
||||||
-- -- <Precursor>
|
|
||||||
-- local
|
|
||||||
-- b: detachable READABLE_STRING_8
|
|
||||||
-- f: detachable CONTENT_FORMAT
|
|
||||||
-- 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
|
|
||||||
|
|
||||||
feature -- Output
|
feature -- Output
|
||||||
|
|
||||||
@@ -184,8 +139,20 @@ feature -- Output
|
|||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
local
|
local
|
||||||
s: STRING
|
s: STRING
|
||||||
|
node_api: CMS_NODE_API
|
||||||
|
lnk: CMS_LOCAL_LINK
|
||||||
do
|
do
|
||||||
|
node_api := a_response.node_api
|
||||||
Precursor (a_node, a_response)
|
Precursor (a_node, a_response)
|
||||||
|
|
||||||
|
if a_node.has_id and then not a_node.is_trashed then
|
||||||
|
if node_api.has_permission_for_action_on_node ("create", a_node, a_response.user) then
|
||||||
|
create lnk.make ("Add Child", node_api.node_path (a_node) + "/add_child/page")
|
||||||
|
lnk.set_weight (3)
|
||||||
|
a_response.add_to_primary_tabs (lnk)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if attached a_response.main_content as l_main_content then
|
if attached a_response.main_content as l_main_content then
|
||||||
s := l_main_content
|
s := l_main_content
|
||||||
else
|
else
|
||||||
@@ -193,11 +160,22 @@ feature -- Output
|
|||||||
end
|
end
|
||||||
|
|
||||||
if attached {CMS_PAGE} a_node as l_node_page then
|
if attached {CMS_PAGE} a_node as l_node_page then
|
||||||
|
s.append ("<ul class=%"page-navigation%">")
|
||||||
if attached l_node_page.parent as l_parent_node then
|
if attached l_node_page.parent as l_parent_node then
|
||||||
s.append ("<div>Parent page is ")
|
s.append ("<li class=%"page-parent%">Go to parent page ")
|
||||||
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 (a_response.link (l_parent_node.title, a_response.node_api.node_path (l_parent_node), Void))
|
||||||
s.append ("</div>")
|
s.append ("</li>")
|
||||||
end
|
end
|
||||||
|
if attached node_api.children (a_node) as l_children then
|
||||||
|
across
|
||||||
|
l_children as ic
|
||||||
|
loop
|
||||||
|
s.append ("<li>")
|
||||||
|
s.append (a_response.link (ic.item.title, a_response.node_api.node_path (ic.item), Void))
|
||||||
|
s.append ("</li>")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
s.append ("</ul>")
|
||||||
end
|
end
|
||||||
|
|
||||||
a_response.set_main_content (s)
|
a_response.set_main_content (s)
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ feature -- Execution
|
|||||||
-- Computed response message.
|
-- Computed response message.
|
||||||
local
|
local
|
||||||
b: STRING_8
|
b: STRING_8
|
||||||
f: like new_edit_form
|
|
||||||
fd: detachable WSF_FORM_DATA
|
|
||||||
nid: INTEGER_64
|
nid: INTEGER_64
|
||||||
do
|
do
|
||||||
create b.make_empty
|
create b.make_empty
|
||||||
@@ -67,6 +65,7 @@ feature -- Execution
|
|||||||
location.ends_with_general ("/add_child/page") and then
|
location.ends_with_general ("/add_child/page") and then
|
||||||
has_permissions (<<"create any", "create " + l_type.name>>)
|
has_permissions (<<"create any", "create " + l_type.name>>)
|
||||||
then
|
then
|
||||||
|
-- FIXME: remove page dep from node module.
|
||||||
create_new_node (l_type, b)
|
create_new_node (l_type, b)
|
||||||
else
|
else
|
||||||
b.append ("<h1>")
|
b.append ("<h1>")
|
||||||
@@ -128,10 +127,13 @@ feature {NONE} -- Create a new node
|
|||||||
f.process (Current)
|
f.process (Current)
|
||||||
fd := f.last_data
|
fd := f.last_data
|
||||||
end
|
end
|
||||||
set_title ("Edit " + html_encoded (a_type.title) + " #" + l_node.id.out)
|
|
||||||
if l_node.has_id then
|
if l_node.has_id then
|
||||||
|
set_title ("Edit " + html_encoded (a_type.title) + " #" + l_node.id.out)
|
||||||
add_to_menu (node_local_link (l_node, translation ("View", Void)), primary_tabs)
|
add_to_menu (node_local_link (l_node, translation ("View", Void)), primary_tabs)
|
||||||
add_to_menu (create {CMS_LOCAL_LINK}.make (translation ("Edit", Void), node_api.node_path (l_node) + "/edit"), primary_tabs)
|
add_to_menu (create {CMS_LOCAL_LINK}.make (translation ("Edit", Void), node_api.node_path (l_node) + "/edit"), primary_tabs)
|
||||||
|
else
|
||||||
|
set_title ("New " + html_encoded (a_type.title))
|
||||||
end
|
end
|
||||||
f.append_to_html (wsf_theme, b)
|
f.append_to_html (wsf_theme, b)
|
||||||
else
|
else
|
||||||
@@ -233,7 +235,6 @@ feature -- Form
|
|||||||
local
|
local
|
||||||
l_preview: BOOLEAN
|
l_preview: BOOLEAN
|
||||||
l_format: detachable CONTENT_FORMAT
|
l_format: detachable CONTENT_FORMAT
|
||||||
l_selected: BOOLEAN
|
|
||||||
do
|
do
|
||||||
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
|
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
|
||||||
if l_preview then
|
if l_preview then
|
||||||
@@ -255,32 +256,6 @@ feature -- Form
|
|||||||
end
|
end
|
||||||
b.append ("</div>")
|
b.append ("</div>")
|
||||||
end
|
end
|
||||||
|
|
||||||
if
|
|
||||||
attached fd.integer_item ("select_parent_node") as s_parent_node and then
|
|
||||||
s_parent_node.to_integer_64 > 0 and then
|
|
||||||
attached node_api.node (s_parent_node) as l_parent_node and then
|
|
||||||
attached node_api.node (node_id_path_parameter (request)) as l_node
|
|
||||||
then
|
|
||||||
across node_api.available_parents_for_node (l_node) as ic until l_selected loop
|
|
||||||
if l_parent_node.same_node (ic.item) then
|
|
||||||
l_selected := True
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not l_selected then
|
|
||||||
fd.report_invalid_field ("select_parent_node", "Invalid node id " + s_parent_node.out)
|
|
||||||
end
|
|
||||||
elseif
|
|
||||||
attached fd.integer_item ("select_parent_node") as s_parent_node and then
|
|
||||||
(s_parent_node = -1 or else s_parent_node = 0)
|
|
||||||
then
|
|
||||||
-- -1 is Used to unassing a parent node
|
|
||||||
-- 0 is not taken into account, any other input value is considered invalid.
|
|
||||||
else
|
|
||||||
fd.report_invalid_field ("select_parent_node", "Invalid node id")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
edit_form_submit (fd: WSF_FORM_DATA; a_node: detachable CMS_NODE; a_type: CMS_NODE_TYPE [CMS_NODE]; b: STRING)
|
edit_form_submit (fd: WSF_FORM_DATA; a_node: detachable CMS_NODE; a_type: CMS_NODE_TYPE [CMS_NODE]; b: STRING)
|
||||||
@@ -322,15 +297,6 @@ feature -- Form
|
|||||||
fixme ("for now, publishing is not implemented, so let's assume any node saved is published.") -- FIXME
|
fixme ("for now, publishing is not implemented, so let's assume any node saved is published.") -- FIXME
|
||||||
l_node.mark_published
|
l_node.mark_published
|
||||||
|
|
||||||
-- Save parent id in current node.
|
|
||||||
nid := node_id_path_parameter (request)
|
|
||||||
if location.ends_with_general ("/add_child/page") and then
|
|
||||||
nid > 0 and then attached {CMS_PAGE} l_node as l_new_page and then
|
|
||||||
attached {CMS_PAGE} node_api.node (nid) as l_page
|
|
||||||
then
|
|
||||||
l_new_page.set_parent (l_page)
|
|
||||||
end
|
|
||||||
|
|
||||||
node_api.save_node (l_node)
|
node_api.save_node (l_node)
|
||||||
if attached user as u then
|
if attached user as u then
|
||||||
api.log ("node",
|
api.log ("node",
|
||||||
@@ -369,8 +335,6 @@ feature -- Form
|
|||||||
f: CMS_FORM
|
f: CMS_FORM
|
||||||
ts: WSF_FORM_SUBMIT_INPUT
|
ts: WSF_FORM_SUBMIT_INPUT
|
||||||
th: WSF_FORM_HIDDEN_INPUT
|
th: WSF_FORM_HIDDEN_INPUT
|
||||||
ti: WSF_FORM_NUMBER_INPUT
|
|
||||||
l_item: CMS_NODE
|
|
||||||
do
|
do
|
||||||
create f.make (a_url, a_name)
|
create f.make (a_url, a_name)
|
||||||
create th.make ("node-id")
|
create th.make ("node-id")
|
||||||
@@ -382,29 +346,6 @@ feature -- Form
|
|||||||
f.extend (th)
|
f.extend (th)
|
||||||
|
|
||||||
populate_form (a_node_type, f, a_node)
|
populate_form (a_node_type, f, a_node)
|
||||||
f.extend_html_text ("<br/>")
|
|
||||||
|
|
||||||
if attached {CMS_PAGE} a_node as l_node_page then
|
|
||||||
if attached l_node_page.parent as l_parent_node then
|
|
||||||
f.extend_html_text ("<div><strong>Parent page is </strong> ")
|
|
||||||
f.extend_html_text (node_html_link (l_parent_node, l_parent_node.title + "(#" + l_parent_node.id.out + ")"))
|
|
||||||
f.extend_html_text ("<br/>")
|
|
||||||
f.extend_html_text ("Change parent to?")
|
|
||||||
create ti.make ("select_parent_node")
|
|
||||||
ti.set_label ("Parent Node")
|
|
||||||
f.extend (ti)
|
|
||||||
f.extend_html_text ("</div>")
|
|
||||||
else
|
|
||||||
f.extend_html_text ("<div><strong>Not has parent page</strong> ")
|
|
||||||
f.extend_html_text ("<br/>")
|
|
||||||
f.extend_html_text ("Add parent to?")
|
|
||||||
create ti.make ("select_parent_node")
|
|
||||||
ti.set_label ("Parent Node")
|
|
||||||
f.extend (ti)
|
|
||||||
f.extend_html_text ("</div>")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
f.extend_html_text ("<br/>")
|
f.extend_html_text ("<br/>")
|
||||||
create ts.make ("op")
|
create ts.make ("op")
|
||||||
|
|||||||
@@ -126,24 +126,29 @@ feature -- HTTP Methods
|
|||||||
then
|
then
|
||||||
l_node := node_api.revision_node (l_nid, l_rev)
|
l_node := node_api.revision_node (l_nid, l_rev)
|
||||||
end
|
end
|
||||||
if
|
if l_node = Void then
|
||||||
l_node /= Void and then (l_rev > 0 or else l_node.is_published)
|
|
||||||
then
|
|
||||||
create view_response.make (req, res, api, node_api)
|
|
||||||
view_response.set_node (l_node)
|
|
||||||
view_response.set_revision (l_rev)
|
|
||||||
view_response.execute
|
|
||||||
elseif
|
|
||||||
attached current_user (req) as l_user and then
|
|
||||||
l_node /= Void and then ( node_api.is_author_of_node (l_user, l_node) or else api.user_api.is_admin_user (l_user))
|
|
||||||
then
|
|
||||||
create view_response.make (req, res, api, node_api)
|
|
||||||
view_response.set_node (l_node)
|
|
||||||
view_response.set_revision (l_rev)
|
|
||||||
view_response.execute
|
|
||||||
else
|
|
||||||
|
|
||||||
send_not_found (req, res)
|
send_not_found (req, res)
|
||||||
|
else
|
||||||
|
if
|
||||||
|
l_rev > 0 or else l_node.is_published
|
||||||
|
then
|
||||||
|
create view_response.make (req, res, api, node_api)
|
||||||
|
view_response.set_node (l_node)
|
||||||
|
view_response.set_revision (l_rev)
|
||||||
|
view_response.execute
|
||||||
|
elseif
|
||||||
|
attached current_user (req) as l_user and then
|
||||||
|
( node_api.is_author_of_node (l_user, l_node)
|
||||||
|
or else api.user_api.user_has_permission (l_user, "view unpublished " + l_node.content_type)
|
||||||
|
)
|
||||||
|
then
|
||||||
|
create view_response.make (req, res, api, node_api)
|
||||||
|
view_response.set_node (l_node)
|
||||||
|
view_response.set_revision (l_rev)
|
||||||
|
view_response.execute
|
||||||
|
else
|
||||||
|
send_access_denied (req, res)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- redirect_to (req.absolute_script_url ("/node/"), res) -- New node.
|
-- redirect_to (req.absolute_script_url ("/node/"), res) -- New node.
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ feature -- Execution
|
|||||||
attached node_api.node_type_webform_manager (l_content_type) as l_manager
|
attached node_api.node_type_webform_manager (l_content_type) as l_manager
|
||||||
then
|
then
|
||||||
l_manager.append_html_output_to (l_node, Current)
|
l_manager.append_html_output_to (l_node, Current)
|
||||||
add_to_primary_tabs (create {CMS_LOCAL_LINK}.make ("Add Child", node_api.node_path (l_node) + "/add_child/page"))
|
|
||||||
end
|
end
|
||||||
elseif revision > 0 then
|
elseif revision > 0 then
|
||||||
set_main_content ("Missing revision node!")
|
set_main_content ("Missing revision node!")
|
||||||
|
|||||||
@@ -117,9 +117,19 @@ feature -- Access
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Access: outline
|
||||||
|
|
||||||
|
children (a_node: CMS_NODE): detachable LIST [CMS_NODE]
|
||||||
|
-- Children of node `a_node'.
|
||||||
|
-- note: this is the partial version of the nodes.
|
||||||
|
deferred
|
||||||
|
end
|
||||||
|
|
||||||
available_parents_for_node (a_node: CMS_NODE): LIST [CMS_NODE]
|
available_parents_for_node (a_node: CMS_NODE): LIST [CMS_NODE]
|
||||||
-- Given the node `a_node', return the list of possible parent nodes id
|
-- Given the node `a_node', return the list of possible parent nodes id
|
||||||
deferred
|
deferred
|
||||||
|
ensure
|
||||||
|
a_node_excluded: across Result as ic all not a_node.same_node (ic.item) end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Change: Node
|
feature -- Change: Node
|
||||||
|
|||||||
@@ -86,6 +86,13 @@ feature -- Access: node
|
|||||||
create {ARRAYED_LIST [CMS_USER]} Result.make (0)
|
create {ARRAYED_LIST [CMS_USER]} Result.make (0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Access: outline
|
||||||
|
|
||||||
|
children (a_node: CMS_NODE): detachable LIST [CMS_NODE]
|
||||||
|
-- <Precursor>
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
available_parents_for_node (a_node: CMS_NODE): LIST [CMS_NODE]
|
available_parents_for_node (a_node: CMS_NODE): LIST [CMS_NODE]
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -255,6 +255,32 @@ feature -- Access
|
|||||||
-- end
|
-- end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Access: outline
|
||||||
|
|
||||||
|
children (a_node: CMS_NODE): detachable LIST [CMS_NODE]
|
||||||
|
-- <Precursor>
|
||||||
|
local
|
||||||
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
|
do
|
||||||
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
|
|
||||||
|
error_handler.reset
|
||||||
|
write_information_log (generator + ".children")
|
||||||
|
|
||||||
|
from
|
||||||
|
create l_parameters.make (1)
|
||||||
|
l_parameters.put (a_node.id, "nid")
|
||||||
|
sql_query (sql_select_children_of_node, l_parameters)
|
||||||
|
sql_start
|
||||||
|
until
|
||||||
|
sql_after
|
||||||
|
loop
|
||||||
|
if attached fetch_node as l_node then
|
||||||
|
Result.force (l_node)
|
||||||
|
end
|
||||||
|
sql_forth
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
available_parents_for_node (a_node: CMS_NODE): LIST [CMS_NODE]
|
available_parents_for_node (a_node: CMS_NODE): LIST [CMS_NODE]
|
||||||
-- <Precursor>
|
-- <Precursor>
|
||||||
@@ -482,7 +508,17 @@ feature {NONE} -- Queries
|
|||||||
Sql_last_insert_node_revision: STRING = "SELECT MAX(revision) FROM node_revisions;"
|
Sql_last_insert_node_revision: STRING = "SELECT MAX(revision) FROM node_revisions;"
|
||||||
Sql_last_insert_node_revision_for_nid: STRING = "SELECT MAX(revision) FROM node_revisions WHERE nid=:nid;"
|
Sql_last_insert_node_revision_for_nid: STRING = "SELECT MAX(revision) FROM node_revisions WHERE nid=:nid;"
|
||||||
|
|
||||||
sql_select_available_parents_for_node : STRING = "SELECT pn_1.nid, pn_1.revision, pn_1.type, title, summary, content, format, author, publish, created, changed, status FROM nodes pn_1 LEFT JOIN page_nodes pn_2 ON pn_1.nid = pn_2.nid AND pn_1.nid != :nid WHERE pn_2.parent != :nid AND pn_1.status != -1 GROUP BY pn_1.nid, pn_1.revision;"
|
sql_select_available_parents_for_node : STRING = "[
|
||||||
|
SELECT node.nid, node.revision, node.type, title, summary, content, format, author, publish, created, changed, status
|
||||||
|
FROM nodes node LEFT JOIN page_nodes pn ON node.nid = pn.nid AND node.nid != :nid
|
||||||
|
WHERE node.nid != :nid AND pn.parent != :nid AND node.status != -1 GROUP BY node.nid, node.revision;
|
||||||
|
]"
|
||||||
|
|
||||||
|
sql_select_children_of_node: STRING = "[
|
||||||
|
SELECT node.nid, node.revision, node.type, title, summary, content, format, author, publish, created, changed, status
|
||||||
|
FROM nodes node LEFT JOIN page_nodes pn ON node.nid = pn.nid
|
||||||
|
WHERE pn.parent = :nid AND node.status != -1 GROUP BY node.nid, node.revision;
|
||||||
|
]"
|
||||||
|
|
||||||
feature {NONE} -- Sql Queries: USER_ROLES collaborators, author
|
feature {NONE} -- Sql Queries: USER_ROLES collaborators, author
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user