Implemented save/publish/unpublish control on nodes.

Display on published blogs (except for admin, or author of the related blog).
This commit is contained in:
Jocelyn Fiat
2017-03-30 17:16:02 +02:00
parent 230ef8ed18
commit e547279016
4 changed files with 102 additions and 27 deletions

View File

@@ -156,6 +156,7 @@ feature -- HTML Output
local
n: CMS_NODE
lnk: CMS_LOCAL_LINK
l_hide: BOOLEAN
do
-- Output the title. If more than one page, also output the current page number
append_page_title_html_to (page, a_output)
@@ -169,25 +170,42 @@ feature -- HTML Output
posts as ic
loop
n := ic.item
lnk := blog_api.node_api.node_link (n)
a_output.append ("<li class=%"cms_type_"+ n.content_type +"%">")
l_hide := not n.is_published
if l_hide then
if
attached api.user as u
then
if api.user_api.is_admin_user (u) then
l_hide := False
else
l_hide := not u.same_as (n.author)
end
end
end
if not l_hide then
lnk := blog_api.node_api.node_link (n)
a_output.append ("<li class=%"cms_type_"+ n.content_type +"%">")
-- Output the creation date
append_creation_date_html_to (n, a_output)
if not n.is_published then
a_output.append ("<div class=%"warning%">This entry is not yet published!</div>")
end
-- Output the creation date
append_creation_date_html_to (n, a_output)
-- Output the author of the post
append_author_html_to (n, page, a_output)
-- Output the author of the post
append_author_html_to (n, page, a_output)
-- Output the title of the post as a link (to the detail page)
append_title_html_to (n, page, a_output)
-- Output the title of the post as a link (to the detail page)
append_title_html_to (n, page, a_output)
-- Output associated tags.
append_taxonomy_html_to (n, page, a_output)
-- Output associated tags.
append_taxonomy_html_to (n, page, a_output)
-- Output the summary of the post and a more link to the detail page
append_summary_html_to (n, page, a_output)
-- Output the summary of the post and a more link to the detail page
append_summary_html_to (n, page, a_output)
a_output.append ("</li>%N")
a_output.append ("</li>%N")
end
end
-- End of post list

View File

@@ -88,6 +88,11 @@ feature -- Output
a_response.set_value (a_node, "node")
a_response.set_value (a_node.content_type, "optional_content_type")
create s.make_empty
if a_node.is_not_published then
a_response.add_warning_message ("This node is NOT published!")
elseif a_node.is_trashed then
a_response.add_warning_message ("This node is in the TRASH!")
end
append_content_as_html_to (a_node, False, s, a_response)
a_response.set_main_content (s)
end

View File

@@ -254,15 +254,25 @@ feature -- Form
edit_form_submit (fd: WSF_FORM_DATA; a_node: detachable CMS_NODE; a_type: CMS_NODE_TYPE [CMS_NODE]; b: STRING)
local
l_preview: BOOLEAN
l_preview, l_op_save, l_op_publish, l_op_unpublish: BOOLEAN
l_node: detachable CMS_NODE
s: STRING
l_node_path: READABLE_STRING_8
l_path_alias, l_existing_path_alias, l_auto_path_alias: detachable READABLE_STRING_8
do
fixme ("Refactor code per operacion: Preview, Save")
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string ("Preview")
fixme ("Refactor code per operation: Preview, Save/Publish/UnPublish")
l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string (preview_submit_label)
if not l_preview then
l_op_save := True
if attached {WSF_STRING} fd.item ("op") as l_op then
if l_op.same_string (publish_submit_label) then
l_op_publish := True
elseif l_op.same_string (unpublish_submit_label) then
l_op_unpublish := True
else
check l_op.same_string (save_submit_label) end
end
end
debug ("cms")
across
fd as c
@@ -289,8 +299,13 @@ feature -- Form
end
fixme ("for now, publishing is not implemented, so let's assume any node saved is published.") -- FIXME
l_node.mark_published
if l_op_publish then
l_node.mark_published
elseif l_op_unpublish then
l_node.mark_not_published
else
-- Default status
end
node_api.save_node (l_node)
if attached user as u then
api.log ("node",
@@ -362,6 +377,7 @@ feature -- Form
f: CMS_FORM
ts: WSF_FORM_SUBMIT_INPUT
th: WSF_FORM_HIDDEN_INPUT
div: WSF_WIDGET_DIV
do
create f.make (a_url, a_name)
create th.make ("node-id")
@@ -375,18 +391,50 @@ feature -- Form
populate_form (a_node_type, f, a_node)
f.extend_html_text ("<br/>")
create ts.make ("op")
ts.set_default_value ("Save")
f.extend (ts)
create div.make
div.add_css_class ("css-editing-buttons")
f.extend (div)
create ts.make ("op")
ts.set_default_value ("Preview")
f.extend (ts)
ts.set_default_value (preview_submit_label)
ts.set_description ("Preview without saving.")
div.extend (ts)
if a_node = Void then
create ts.make ("op")
ts.set_default_value (save_submit_label)
div.extend (ts)
create ts.make ("op")
ts.set_default_value (publish_submit_label)
ts.set_description ("Save and mark published.")
div.extend (ts)
else
if a_node.is_published then
create ts.make ("op")
ts.set_default_value (save_submit_label)
ts.set_description ("Save and keep published.")
div.extend (ts)
create ts.make ("op")
ts.set_default_value (unpublish_submit_label)
ts.set_description ("Save and mark unpublished.")
div.extend (ts)
else
create ts.make ("op")
ts.set_default_value (save_submit_label)
div.extend (ts)
create ts.make ("op")
ts.set_default_value (publish_submit_label)
ts.set_description ("Save and mark published.")
div.extend (ts)
end
end
Result := f
end
new_delete_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_node_type: CMS_NODE_TYPE [CMS_NODE]): CMS_FORM
-- Create a web form named `a_name' for node `a_node' (if set), using form action url `a_url', and for type of node `a_node_type'.
require
@@ -487,4 +535,11 @@ feature -- Form
end
end
feature -- Labels
save_submit_label: STRING = "Save"
publish_submit_label: STRING = "Publish"
unpublish_submit_label: STRING = "Unpublish"
preview_submit_label: STRING = "Preview"
end

View File

@@ -248,11 +248,8 @@ feature {CMS_API_ACCESS} -- CMS Formats management
-- Save `formats`.
local
f: CMS_FORMAT
jp: JSON_PARSER
cfg: JSON_CONFIG
j,ji: JSON_OBJECT
s: STRING_32
l_name, l_title: READABLE_STRING_8
ct: CMS_CONTENT_TYPE
do
-- { "plain_text": { "title": "Plain text", "filters": "plain_text+foobar+toto"}, ...}