Moved taxonomy integration for web form inside CMS_TAXONOMY_API.
Moved a few helpers routine from CMS_RESPONSE to CMS_API. Added CMS_CONTENT.identifier: detachable READABLE_STRING_32 .
This commit is contained in:
@@ -92,246 +92,15 @@ feature -- Forms ...
|
||||
|
||||
f.extend (fset)
|
||||
|
||||
-- Path alias
|
||||
-- Path alias
|
||||
populate_form_with_taxonomy (response, f, a_node)
|
||||
populate_form_with_path_alias (response, f, a_node)
|
||||
end
|
||||
|
||||
populate_form_with_taxonomy (response: NODE_RESPONSE; f: CMS_FORM; a_node: detachable CMS_NODE)
|
||||
local
|
||||
ti: detachable WSF_FORM_TEXT_INPUT
|
||||
th: WSF_FORM_HIDDEN_INPUT
|
||||
w_set: WSF_FORM_FIELD_SET
|
||||
w_select: WSF_FORM_SELECT
|
||||
w_opt: WSF_FORM_SELECT_OPTION
|
||||
w_cb: WSF_FORM_CHECKBOX_INPUT
|
||||
w_voc_set: WSF_FORM_FIELD_SET
|
||||
s: STRING_32
|
||||
voc: CMS_VOCABULARY
|
||||
t: detachable CMS_TERM
|
||||
l_terms: detachable CMS_TERM_COLLECTION
|
||||
l_has_edit_permission: BOOLEAN
|
||||
populate_form_with_taxonomy (response: CMS_RESPONSE; f: CMS_FORM; a_content: detachable CMS_CONTENT)
|
||||
do
|
||||
if
|
||||
attached {CMS_TAXONOMY_API} response.api.module_api ({CMS_TAXONOMY_MODULE}) as l_taxonomy_api and then
|
||||
attached l_taxonomy_api.vocabularies_for_type (content_type.name) as l_vocs and then not l_vocs.is_empty
|
||||
then
|
||||
|
||||
l_has_edit_permission := response.has_permissions (<<"update any taxonomy", "update " + content_type.name + " taxonomy">>)
|
||||
|
||||
-- Handle Taxonomy fields, if any associated with `content_type'.
|
||||
create w_set.make
|
||||
w_set.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)
|
||||
|
||||
l_terms := Void
|
||||
if a_node /= Void and then a_node.has_id then
|
||||
l_terms := l_taxonomy_api.terms_of_entity (a_node.content_type, a_node.id.out, voc)
|
||||
if l_terms /= Void then
|
||||
l_terms.sort
|
||||
end
|
||||
end
|
||||
create w_voc_set.make
|
||||
w_set.extend (w_voc_set)
|
||||
|
||||
if voc.is_tags then
|
||||
w_voc_set.set_legend (response.translation (voc.name, Void))
|
||||
|
||||
create ti.make ({STRING_32} "taxonomy_" + voc.id.out)
|
||||
w_voc_set.extend (ti)
|
||||
if voc.is_term_required then
|
||||
ti.enable_required
|
||||
end
|
||||
if attached voc.description as l_desc then
|
||||
ti.set_description (response.html_encoded (response.translation (l_desc, Void)))
|
||||
else
|
||||
ti.set_description (response.html_encoded (response.translation (voc.name, Void)))
|
||||
end
|
||||
ti.set_size (70)
|
||||
if l_terms /= Void then
|
||||
create s.make_empty
|
||||
across
|
||||
l_terms as ic
|
||||
loop
|
||||
t := ic.item
|
||||
if not s.is_empty then
|
||||
s.append_character (',')
|
||||
s.append_character (' ')
|
||||
end
|
||||
if ic.item.text.has (' ') then
|
||||
s.append_character ('"')
|
||||
s.append (t.text)
|
||||
s.append_character ('"')
|
||||
else
|
||||
s.append (t.text)
|
||||
end
|
||||
end
|
||||
ti.set_text_value (s)
|
||||
end
|
||||
if not l_has_edit_permission then
|
||||
ti.set_is_readonly (True)
|
||||
end
|
||||
else
|
||||
l_taxonomy_api.fill_vocabularies_with_terms (voc)
|
||||
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 (response.html_encoded (l_desc))
|
||||
else
|
||||
w_voc_set.set_legend (response.html_encoded (voc.name))
|
||||
end
|
||||
across
|
||||
voc as voc_terms_ic
|
||||
loop
|
||||
t := voc_terms_ic.item
|
||||
create w_cb.make_with_value ({STRING_32} "taxonomy_" + voc.id.out + "[]", t.text)
|
||||
w_cb.set_title (t.text)
|
||||
w_voc_set.extend (w_cb)
|
||||
if l_terms /= Void and then across l_terms as ic some ic.item.text.same_string (t.text) end then
|
||||
w_cb.set_checked (True)
|
||||
end
|
||||
if not l_has_edit_permission then
|
||||
w_cb.set_is_readonly (True)
|
||||
end
|
||||
end
|
||||
else
|
||||
create w_select.make ({STRING_32} "taxonomy_" + voc.id.out)
|
||||
w_voc_set.extend (w_select)
|
||||
|
||||
if attached voc.description as l_desc then
|
||||
w_select.set_description (response.html_encoded (l_desc))
|
||||
else
|
||||
w_select.set_description (response.html_encoded (voc.name))
|
||||
end
|
||||
w_voc_set.set_legend (response.html_encoded (voc.name))
|
||||
|
||||
across
|
||||
voc as voc_terms_ic
|
||||
loop
|
||||
t := voc_terms_ic.item
|
||||
create w_opt.make (response.html_encoded (t.text), response.html_encoded (t.text))
|
||||
w_select.add_option (w_opt)
|
||||
|
||||
if l_terms /= Void and then across l_terms as ic some ic.item.text.same_string (t.text) end then
|
||||
w_opt.set_is_selected (True)
|
||||
end
|
||||
end
|
||||
if not l_has_edit_permission then
|
||||
w_select.set_is_readonly (True)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
f.submit_actions.extend (agent taxonomy_submit_action (response, l_taxonomy_api, l_vocs, a_node, ?))
|
||||
|
||||
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 (w_set, l_title_field)
|
||||
else
|
||||
f.extend (w_set)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
taxonomy_submit_action (a_response: CMS_RESPONSE; a_taxonomy_api: CMS_TAXONOMY_API; a_vocs: CMS_VOCABULARY_COLLECTION; a_node: detachable CMS_NODE fd: WSF_FORM_DATA)
|
||||
require
|
||||
vocs_not_empty: not a_vocs.is_empty
|
||||
local
|
||||
l_voc_name: READABLE_STRING_32
|
||||
l_terms_to_remove: ARRAYED_LIST [CMS_TERM]
|
||||
l_new_terms: LIST [READABLE_STRING_32]
|
||||
l_text: READABLE_STRING_GENERAL
|
||||
l_found: BOOLEAN
|
||||
t: detachable CMS_TERM
|
||||
vid: INTEGER_64
|
||||
do
|
||||
if
|
||||
a_node /= Void and then a_node.has_id and then
|
||||
attached fd.table_item ("taxonomy_vocabularies") as fd_vocs
|
||||
then
|
||||
if a_response.has_permissions (<<{STRING_32} "update any taxonomy", {STRING_32} "update " + content_type.name + " taxonomy">>) then
|
||||
across
|
||||
fd_vocs.values as ic
|
||||
loop
|
||||
vid := ic.key.to_integer_64
|
||||
l_voc_name := ic.item.string_representation
|
||||
|
||||
if attached a_vocs.item_by_id (vid) as voc then
|
||||
if attached fd.string_item ("taxonomy_" + vid.out) as l_string then
|
||||
l_new_terms := a_taxonomy_api.splitted_string (l_string, ',')
|
||||
elseif attached fd.table_item ("taxonomy_" + vid.out) as fd_terms then
|
||||
create {ARRAYED_LIST [READABLE_STRING_32]} l_new_terms.make (fd_terms.count)
|
||||
across
|
||||
fd_terms as t_ic
|
||||
loop
|
||||
l_new_terms.force (t_ic.item.string_representation)
|
||||
end
|
||||
else
|
||||
create {ARRAYED_LIST [READABLE_STRING_32]} l_new_terms.make (0)
|
||||
end
|
||||
|
||||
create l_terms_to_remove.make (0)
|
||||
if attached a_taxonomy_api.terms_of_entity (content_type.name, a_node.id.out, voc) as l_existing_terms then
|
||||
across
|
||||
l_existing_terms as t_ic
|
||||
loop
|
||||
l_text := t_ic.item.text
|
||||
from
|
||||
l_found := False
|
||||
l_new_terms.start
|
||||
until
|
||||
l_new_terms.after
|
||||
loop
|
||||
if l_new_terms.item.same_string_general (l_text) then
|
||||
-- Already associated with term `t_ic.text'.
|
||||
l_found := True
|
||||
l_new_terms.remove
|
||||
else
|
||||
l_new_terms.forth
|
||||
end
|
||||
end
|
||||
if not l_found then
|
||||
-- Remove term
|
||||
l_terms_to_remove.force (t_ic.item)
|
||||
end
|
||||
end
|
||||
across
|
||||
l_terms_to_remove as t_ic
|
||||
loop
|
||||
a_taxonomy_api.unassociate_term_from_entity (t_ic.item, content_type.name, a_node.id.out)
|
||||
end
|
||||
end
|
||||
across
|
||||
l_new_terms as t_ic
|
||||
loop
|
||||
t := a_taxonomy_api.term_by_text (t_ic.item, voc)
|
||||
if
|
||||
t = Void and voc.is_tags
|
||||
then
|
||||
-- Create new term!
|
||||
create t.make (t_ic.item)
|
||||
a_taxonomy_api.save_term (t, voc)
|
||||
if a_taxonomy_api.has_error then
|
||||
t := Void
|
||||
end
|
||||
end
|
||||
if t /= Void then
|
||||
a_taxonomy_api.associate_term_with_entity (t, content_type.name, a_node.id.out)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if attached {CMS_TAXONOMY_API} response.api.module_api ({CMS_TAXONOMY_MODULE}) as l_taxonomy_api then
|
||||
l_taxonomy_api.populate_edit_form (response, f, content_type.name, a_content)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -573,7 +342,7 @@ feature -- Output
|
||||
vocs as ic
|
||||
loop
|
||||
if
|
||||
attached l_taxonomy_api.terms_of_entity (content_type.name, a_node.id.out, ic.item) as l_terms and then
|
||||
attached l_taxonomy_api.terms_of_content (a_node, ic.item) as l_terms and then
|
||||
not l_terms.is_empty
|
||||
then
|
||||
a_output.append ("<ul class=%"taxonomy term-" + ic.item.id.out + "%">")
|
||||
|
||||
Reference in New Issue
Block a user