Better control on path alias.
If user has permission to edit, provide a text input, otherwise just a label if path are required. Reviewed html generated for taxonomy field in node edit form. Improved the blog entries list by providing (if permitted) link to blog entry creation, and link to the user entries or all entries.
This commit is contained in:
@@ -8,6 +8,9 @@ class
|
||||
|
||||
inherit
|
||||
CMS_NODE_TYPE [CMS_BLOG]
|
||||
redefine
|
||||
is_path_alias_required
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
@@ -20,6 +23,11 @@ feature -- Access
|
||||
description: STRING_32 = "Content published as a blog post."
|
||||
-- Optional description
|
||||
|
||||
feature -- Setting
|
||||
|
||||
is_path_alias_required: BOOLEAN = True
|
||||
-- <Precursor>.
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_node_with_title (a_title: READABLE_STRING_32; a_partial_node: detachable CMS_NODE): like new_node
|
||||
|
||||
@@ -160,6 +160,8 @@ feature -- HTML Output
|
||||
-- Output the title. If more than one page, also output the current page number
|
||||
append_page_title_html_to (page, a_output)
|
||||
|
||||
append_user_related_html_to (page, a_output)
|
||||
|
||||
-- Get the posts from the current page (given by page number and entries per page)
|
||||
-- Start list of posts
|
||||
a_output.append ("<ul class=%"cms_blog_nodes%">%N")
|
||||
@@ -198,12 +200,23 @@ feature -- HTML Output
|
||||
append_page_title_html_to (a_page: CMS_RESPONSE; a_output: STRING)
|
||||
-- Append the title of the page as a html string to `a_output'.
|
||||
-- It shows the current page number.
|
||||
local
|
||||
l_title: STRING
|
||||
do
|
||||
a_output.append ("<h2>Blog")
|
||||
create l_title.make_from_string ("Blog entries")
|
||||
if multiple_pages_needed then
|
||||
a_output.append (" (Page " + page_number.out + " of " + pages_count.out + ")")
|
||||
l_title.append (" (Page " + page_number.out + " of " + pages_count.out + ")")
|
||||
end
|
||||
a_page.set_title (l_title)
|
||||
-- a_output.append ("<h2>" + l_title + "</h2>")
|
||||
end
|
||||
|
||||
append_user_related_html_to (a_page: CMS_RESPONSE; a_output: STRING)
|
||||
do
|
||||
if attached api.user as u and api.has_permission ("create blog") then
|
||||
a_page.add_to_primary_tabs (a_page.local_link ("Create a new blog entry", "node/add/blog"))
|
||||
a_page.add_to_primary_tabs (a_page.local_link ("View your blog entries", "blog/" + u.id.out))
|
||||
end
|
||||
a_output.append ("</h2>")
|
||||
end
|
||||
|
||||
append_creation_date_html_to (n: CMS_NODE; a_output: STRING)
|
||||
|
||||
@@ -22,6 +22,7 @@ inherit
|
||||
posts,
|
||||
total_entries,
|
||||
append_page_title_html_to,
|
||||
append_user_related_html_to,
|
||||
base_path
|
||||
end
|
||||
|
||||
@@ -116,18 +117,29 @@ feature -- HTML Output
|
||||
|
||||
append_page_title_html_to (a_page: CMS_RESPONSE; a_output: STRING)
|
||||
-- Returns the title of the page as a html string. It shows the current page number and the name of the current user
|
||||
local
|
||||
l_title: STRING
|
||||
do
|
||||
a_output.append ("<h2>Posts from ")
|
||||
create l_title.make_from_string ("Blog entries from ")
|
||||
if attached user as l_user then
|
||||
a_output.append (html_encoded (a_page.user_profile_name (l_user)))
|
||||
l_title.append (html_encoded (a_page.user_profile_name (l_user)))
|
||||
else
|
||||
a_output.append ("unknown user")
|
||||
l_title.append ("unknown user")
|
||||
end
|
||||
if multiple_pages_needed then
|
||||
a_output.append (" (Page " + page_number.out + " of " + pages_count.out + ")")
|
||||
l_title.append (" (Page " + page_number.out + " of " + pages_count.out + ")")
|
||||
-- Get the posts from the current page (limited by entries per page)
|
||||
end
|
||||
a_output.append ("</h2>")
|
||||
a_page.set_title (l_title)
|
||||
-- a_output.append ("<h2>" + l_title + "</h2>")
|
||||
end
|
||||
|
||||
append_user_related_html_to (a_page: CMS_RESPONSE; a_output: STRING)
|
||||
do
|
||||
if attached api.user as u and api.has_permission ("create blog") then
|
||||
a_page.add_to_primary_tabs (a_page.local_link ("Create a new blog entry", "node/add/blog"))
|
||||
end
|
||||
a_page.add_to_primary_tabs (a_page.local_link ("View all blog entries", "blogs/"))
|
||||
end
|
||||
|
||||
base_path : STRING
|
||||
|
||||
@@ -28,6 +28,15 @@ feature -- Access
|
||||
available_formats: ARRAYED_LIST [CONTENT_FORMAT]
|
||||
-- Available formats for Current type.
|
||||
|
||||
feature -- Setting
|
||||
|
||||
is_path_alias_required: BOOLEAN
|
||||
-- Is path alias required for Current node type?
|
||||
-- By default: False.
|
||||
-- (i.e always set a path alias, instead of default /node/{id})
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_node_with_title (a_title: READABLE_STRING_32; a_partial_node: detachable CMS_NODE): like new_node
|
||||
|
||||
@@ -106,6 +106,8 @@ feature -- Forms ...
|
||||
|
||||
populate_form_with_path_alias (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable CMS_NODE)
|
||||
local
|
||||
w: detachable WSF_WIDGET
|
||||
div: WSF_FORM_DIV
|
||||
ti: WSF_FORM_TEXT_INPUT
|
||||
thi: WSF_FORM_HIDDEN_INPUT
|
||||
l_uri: detachable READABLE_STRING_8
|
||||
@@ -115,11 +117,6 @@ feature -- Forms ...
|
||||
-- Path alias
|
||||
l_auto_path_alias := node_api.path_alias_uri_suggestion (a_node, content_type)
|
||||
|
||||
create ti.make ("path_alias")
|
||||
ti.set_label ("Path")
|
||||
ti.set_pattern ("^([A-Za-z0-9-_+ ]).+")
|
||||
ti.set_description ("Path alias pattern: ^([A-Za-z0-9-_+ ]).+ For example resource/page1 ")
|
||||
ti.set_size (70)
|
||||
if a_node /= Void and then a_node.has_id then
|
||||
if attached a_node.link as lnk then
|
||||
l_uri := lnk.location
|
||||
@@ -130,10 +127,21 @@ feature -- Forms ...
|
||||
l_iri := percent_encoder.percent_decoded_string (response.api.location_alias (response.node_api.node_path (a_node)))
|
||||
l_uri := l_iri.to_string_8
|
||||
end
|
||||
ti.set_description ("Optionally specify an alternative URL path by which this content can be accessed.<br/>%NFor example, type 'about' when writing an about page. Use a relative path or the URL alias won't work.")
|
||||
else
|
||||
l_uri := ""
|
||||
end
|
||||
|
||||
if cms_api.has_permission ("edit path_alias") then
|
||||
create ti.make ("path_alias")
|
||||
ti.set_label ("Path")
|
||||
ti.set_pattern ("^([A-Za-z0-9-_+ ]).+")
|
||||
ti.set_description ("Path alias pattern: ^([A-Za-z0-9-_+ ]).+ For example resource/page1 ")
|
||||
ti.set_size (70)
|
||||
|
||||
if a_node /= Void and then a_node.has_id then
|
||||
ti.set_description ("Optionally specify an alternative URL path by which this content can be accessed.<br/>%NFor example, type 'about' when writing an about page. Use a relative path or the URL alias won't work.")
|
||||
end
|
||||
|
||||
ti.set_text_value (l_uri)
|
||||
ti.set_placeholder (l_auto_path_alias)
|
||||
ti.set_validation_action (agent (fd: WSF_FORM_DATA; ia_response: NODE_RESPONSE; ia_node: detachable CMS_NODE)
|
||||
@@ -161,23 +169,45 @@ feature -- Forms ...
|
||||
end
|
||||
end(?, response, a_node)
|
||||
)
|
||||
if not cms_api.has_permission ("edit path_alias") then
|
||||
w := ti
|
||||
elseif a_node /= Void and then a_node.has_id and then l_uri /= Void and then not l_uri.is_whitespace then
|
||||
-- FIXME: should we have an input field or just a raw text?
|
||||
ti.set_is_readonly (True)
|
||||
-- ti.set_is_readonly (True)
|
||||
create div.make
|
||||
div.add_css_class ("path-alias")
|
||||
div.extend_html_text ("<strong><label>Path</label></strong> = ")
|
||||
div.extend_html_text ("<a href=%""+ cms_api.site_url + l_uri +"%">" + l_uri + "</a>")
|
||||
w := div
|
||||
elseif content_type.is_path_alias_required and then l_auto_path_alias /= Void and then not l_auto_path_alias.is_whitespace then
|
||||
create div.make
|
||||
div.extend_html_text ("<strong><label>Path</label></strong> = ")
|
||||
if a_node /= Void and then a_node.has_id then
|
||||
div.extend_html_text ("<a href=%""+ cms_api.site_url + l_auto_path_alias +"%">" + l_auto_path_alias + "</a>")
|
||||
else
|
||||
div.extend_html_text ("<span>"+ cms_api.site_url + "</span>")
|
||||
-- if a_node /= Void and then a_node.has_id then
|
||||
-- div.extend_html_text ("<span>" + l_auto_path_alias + "</span>")
|
||||
-- else
|
||||
div.extend_html_text ("<span>" + l_auto_path_alias + " ...</span>")
|
||||
-- end
|
||||
end
|
||||
w := div
|
||||
end
|
||||
if w /= Void then
|
||||
if
|
||||
attached f.fields_by_name ("title") as l_title_fields and then
|
||||
attached l_title_fields.first as l_title_field
|
||||
then
|
||||
f.insert_after (ti, l_title_field)
|
||||
f.insert_after (w, l_title_field)
|
||||
else
|
||||
f.extend (ti)
|
||||
f.extend (w)
|
||||
end
|
||||
-- Auto path alias / suggestion
|
||||
create thi.make ("auto_path_alias")
|
||||
thi.set_text_value (l_auto_path_alias)
|
||||
thi.set_is_readonly (True)
|
||||
f.insert_after (thi, ti)
|
||||
f.insert_before (thi, w)
|
||||
end
|
||||
end
|
||||
|
||||
update_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||
|
||||
@@ -111,12 +111,16 @@ feature {NONE} -- Create a new node
|
||||
end
|
||||
|
||||
if l_node.has_id then
|
||||
set_title ("Edit " + html_encoded (a_type.title) + " #" + l_node.id.out)
|
||||
set_title ("Edit " + html_encoded (a_type.title) + " item #" + l_node.id.out)
|
||||
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)
|
||||
else
|
||||
set_title ("New " + html_encoded (a_type.title))
|
||||
set_title ("Create a new " + html_encoded (a_type.title) + " item")
|
||||
end
|
||||
if attached a_type.description as desc then
|
||||
f.prepend (create {WSF_WIDGET_TEXT}.make_with_text ("<span class=%"description%">" + api.html_encoded (desc) + "</span>"))
|
||||
end
|
||||
|
||||
f.append_to_html (wsf_theme, b)
|
||||
else
|
||||
b.append ("<h1>")
|
||||
@@ -305,7 +309,6 @@ feature -- Form
|
||||
-- Path aliase
|
||||
l_node_path := node_api.node_path (l_node)
|
||||
l_existing_path_alias := api.location_alias (l_node_path)
|
||||
|
||||
l_auto_path_alias := node_api.path_alias_uri_suggestion (l_node, a_type)
|
||||
if attached fd.string_item ("path_alias") as f_path_alias then
|
||||
l_path_alias := percent_encoder.partial_encoded_string (f_path_alias, <<'/'>>)
|
||||
@@ -321,7 +324,9 @@ feature -- Form
|
||||
api.set_path_alias (l_node_path, l_auto_path_alias, True)
|
||||
elseif l_existing_path_alias.same_string (l_node_path) then
|
||||
-- not aliased! Use default.
|
||||
if a_type.is_path_alias_required then
|
||||
api.set_path_alias (l_node_path, l_auto_path_alias, True)
|
||||
end
|
||||
else
|
||||
add_error_message ("Permission denied to reset path alias on node #" + l_node.id.out + "!")
|
||||
end
|
||||
@@ -336,9 +341,9 @@ feature -- Form
|
||||
l_node.set_link (node_api.node_link (l_node))
|
||||
end
|
||||
end
|
||||
elseif l_existing_path_alias /= Void then
|
||||
elseif l_existing_path_alias /= Void and then not l_existing_path_alias.same_string (l_node_path) then
|
||||
l_node.set_link (create {CMS_LOCAL_LINK}.make (l_node.title, l_existing_path_alias))
|
||||
elseif l_auto_path_alias /= Void then
|
||||
elseif a_type.is_path_alias_required and l_auto_path_alias /= Void then
|
||||
-- Use auto path alias
|
||||
api.set_path_alias (l_node_path, l_auto_path_alias, True)
|
||||
l_node.set_link (create {CMS_LOCAL_LINK}.make (l_node.title, l_auto_path_alias))
|
||||
|
||||
@@ -257,11 +257,11 @@ feature -- Web forms
|
||||
local
|
||||
ti: detachable WSF_FORM_TEXT_INPUT
|
||||
th: WSF_FORM_HIDDEN_INPUT
|
||||
w_set: WSF_FORM_FIELD_SET
|
||||
w_div: WSF_FORM_DIV
|
||||
w_select: WSF_FORM_SELECT
|
||||
w_opt: WSF_FORM_SELECT_OPTION
|
||||
w_cb: WSF_FORM_CHECKBOX_INPUT
|
||||
w_voc_set: WSF_FORM_FIELD_SET
|
||||
w_voc_set: WSF_FORM_DIV
|
||||
s: STRING_32
|
||||
voc: CMS_VOCABULARY
|
||||
t: detachable CMS_TERM
|
||||
@@ -274,15 +274,15 @@ feature -- Web forms
|
||||
l_has_edit_permission := a_response.has_permissions (<<"update any taxonomy", "update " + a_content_type_name + " taxonomy">>)
|
||||
|
||||
-- Handle Taxonomy fields, if any associated with `content_type'.
|
||||
create w_set.make
|
||||
w_set.add_css_class ("taxonomy")
|
||||
create w_div.make
|
||||
w_div.add_css_class ("taxonomy")
|
||||
l_vocs.sort
|
||||
across
|
||||
l_vocs as vocs_ic
|
||||
loop
|
||||
voc := vocs_ic.item
|
||||
create th.make_with_text ({STRING_32} "taxonomy_vocabularies[" + voc.id.out + "]", voc.name)
|
||||
w_set.extend (th)
|
||||
w_div.extend (th)
|
||||
|
||||
l_terms := Void
|
||||
if a_content /= Void then
|
||||
@@ -292,10 +292,11 @@ feature -- Web forms
|
||||
end
|
||||
end
|
||||
create w_voc_set.make
|
||||
w_set.extend (w_voc_set)
|
||||
w_div.extend (w_voc_set)
|
||||
|
||||
if voc.is_tags then
|
||||
w_voc_set.set_legend (cms_api.translation (voc.name, Void))
|
||||
w_voc_set.extend_text ("<strong><label>" + cms_api.html_encoded (cms_api.translation (voc.name, Void)) + "</label></strong>")
|
||||
-- set_legend (cms_api.translation (voc.name, Void))
|
||||
|
||||
create ti.make ({STRING_32} "taxonomy_" + voc.id.out)
|
||||
w_voc_set.extend (ti)
|
||||
@@ -336,9 +337,11 @@ feature -- Web forms
|
||||
if not voc.terms.is_empty then
|
||||
if voc.multiple_terms_allowed then
|
||||
if attached voc.description as l_desc then
|
||||
w_voc_set.set_legend (cms_api.html_encoded (l_desc))
|
||||
w_voc_set.extend_text ("<strong><label>" + cms_api.html_encoded (l_desc) + "</label></strong>")
|
||||
-- w_voc_set.set_legend (cms_api.html_encoded (l_desc))
|
||||
else
|
||||
w_voc_set.set_legend (cms_api.html_encoded (voc.name))
|
||||
w_voc_set.extend_text ("<strong><label>" + cms_api.html_encoded (voc.name) + "</label></strong>")
|
||||
-- w_voc_set.set_legend (cms_api.html_encoded (voc.name))
|
||||
end
|
||||
across
|
||||
voc as voc_terms_ic
|
||||
@@ -363,7 +366,8 @@ feature -- Web forms
|
||||
else
|
||||
w_select.set_description (cms_api.html_encoded (voc.name))
|
||||
end
|
||||
w_voc_set.set_legend (cms_api.html_encoded (voc.name))
|
||||
w_voc_set.extend_text ("<strong><label>" + cms_api.html_encoded (voc.name) + "</label></strong>")
|
||||
-- w_voc_set.set_legend (cms_api.html_encoded (voc.name))
|
||||
|
||||
across
|
||||
voc as voc_terms_ic
|
||||
@@ -390,9 +394,9 @@ feature -- Web forms
|
||||
attached a_form.fields_by_name ("title") as l_title_fields and then
|
||||
attached l_title_fields.first as l_title_field
|
||||
then
|
||||
a_form.insert_after (w_set, l_title_field)
|
||||
a_form.insert_after (w_div, l_title_field)
|
||||
else
|
||||
a_form.extend (w_set)
|
||||
a_form.extend (w_div)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user