TextBody Step basiclly works now
parent
62d98af857
commit
4a6478c78b
|
|
@ -152,7 +152,7 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep {
|
|||
}
|
||||
|
||||
public List<CmsEditorLocaleVariantRow> getVariants() {
|
||||
return variants;
|
||||
return Collections.unmodifiableList(variants);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -178,7 +178,6 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep {
|
|||
* @return A redirect to this authoring step.
|
||||
*/
|
||||
@POST
|
||||
// @Path("/@add")
|
||||
@Path("/add")
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String addTextValue(
|
||||
|
|
@ -212,11 +211,7 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep {
|
|||
getArticle().getText().addValue(locale, value);
|
||||
itemRepo.save(getArticle());
|
||||
|
||||
return String.format(
|
||||
"%s/%s/@edit",
|
||||
buildRedirectPathForStep(),
|
||||
locale.toString()
|
||||
);
|
||||
return buildRedirectPathForStep();
|
||||
} else {
|
||||
return documentUi.showAccessDenied(
|
||||
getContentSection(),
|
||||
|
|
@ -261,7 +256,6 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep {
|
|||
|
||||
|
||||
@GET
|
||||
// @Path("/{locale}/@edit")
|
||||
@Path("/edit/{locale}")
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String editTextValue(
|
||||
|
|
@ -303,7 +297,6 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep {
|
|||
* @return A redirect to this authoring step.
|
||||
*/
|
||||
@POST
|
||||
// @Path("/{locale}/@edit")
|
||||
@Path("/edit/{locale}")
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String editTextValue(
|
||||
|
|
@ -428,7 +421,6 @@ public class MvcArticleTextBodyStep extends AbstractMvcAuthoringStep {
|
|||
final CmsEditorLocaleVariantRow variant = new CmsEditorLocaleVariantRow();
|
||||
variant.setLocale(entry.getKey().toString());
|
||||
final Document document = Jsoup.parseBodyFragment(entry.getValue());
|
||||
document.body().text();
|
||||
variant.setWordCount(
|
||||
new StringTokenizer(document.body().text()).countTokens()
|
||||
);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.librecms.ui.contenttypes;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentItemRepository;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
|
|
@ -27,6 +29,7 @@ import org.librecms.ui.contentsections.ItemPermissionChecker;
|
|||
import org.librecms.ui.contentsections.documents.MvcAuthoringSteps;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -36,6 +39,8 @@ import javax.ws.rs.GET;
|
|||
import javax.ws.rs.NotFoundException;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -58,8 +63,47 @@ public class MvcArticleTextBodyStepResources {
|
|||
private ItemPermissionChecker itemPermissionChecker;
|
||||
|
||||
@GET
|
||||
// @Path("/{locale}/@view")
|
||||
@Path("/variants/{locale}/wordcount")
|
||||
@Produces(MediaType.TEXT_HTML)
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public long getWordCount(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
final String sectionIdentifier,
|
||||
@PathParam(MvcAuthoringSteps.DOCUMENT_PATH_PATH_PARAM_NAME)
|
||||
final String documentPathParam,
|
||||
@PathParam("locale") final String localeParam
|
||||
) {
|
||||
final ContentSection contentSection = sectionsUi
|
||||
.findContentSection(sectionIdentifier)
|
||||
.orElseThrow(
|
||||
() -> new NotFoundException()
|
||||
);
|
||||
|
||||
final ContentItem document = itemRepo
|
||||
.findByPath(contentSection, documentPathParam)
|
||||
.orElseThrow(
|
||||
() -> new NotFoundException()
|
||||
);
|
||||
|
||||
if (!(document instanceof Article)) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
final Article article = (Article) document;
|
||||
if (itemPermissionChecker.canEditItem(article)) {
|
||||
final String text = article
|
||||
.getText()
|
||||
.getValue(new Locale(localeParam));
|
||||
final Document jsoupDoc = Jsoup.parseBodyFragment(text);
|
||||
return new StringTokenizer(jsoupDoc.body().text()).countTokens();
|
||||
} else {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/variants/{locale}")
|
||||
@Produces(MediaType.TEXT_HTML)
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String viewTextValue(
|
||||
@PathParam(MvcAuthoringSteps.SECTION_IDENTIFIER_PATH_PARAM)
|
||||
|
|
@ -68,14 +112,6 @@ public class MvcArticleTextBodyStepResources {
|
|||
final String documentPathParam,
|
||||
@PathParam("locale") final String localeParam
|
||||
) {
|
||||
// try {
|
||||
// init();
|
||||
// } catch (ContentSectionNotFoundException ex) {
|
||||
// return ex.showErrorMessage();
|
||||
// } catch (DocumentNotFoundException ex) {
|
||||
// return ex.showErrorMessage();
|
||||
// }
|
||||
|
||||
final ContentSection contentSection = sectionsUi
|
||||
.findContentSection(sectionIdentifier)
|
||||
.orElseThrow(
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
shortDescription="Label for the add button"
|
||||
type="String" />
|
||||
<cc:attribute name="addDialogCancelLabel"
|
||||
default="Cancel"
|
||||
default="#{CmsAdminMessages['cancel_button.label']}"
|
||||
required="false"
|
||||
shortDescription="Label for the cancel and close buttons."
|
||||
type="String" />
|
||||
|
|
@ -24,17 +24,17 @@
|
|||
shortDescription="Help text for the locale select field"
|
||||
type="String" />
|
||||
<cc:attribute name="addDialogLocaleSelectLabel"
|
||||
default="Locale"
|
||||
default="#{CmsAdminMessages['locale_select.label']}"
|
||||
required="false"
|
||||
shortDescription="Label for the locale select field"
|
||||
type="String" />
|
||||
<cc:attribute name="addDialogSubmitLabel"
|
||||
default="Add"
|
||||
default="#{CmsAdminMessages['locale_add.label']}"
|
||||
required="false"
|
||||
shortDescription="Label for the submit button"
|
||||
type="String" />
|
||||
<cc:attribute name="addDialogTitle"
|
||||
default="Add localization"
|
||||
default="#{CmsAdminMessages['locale_add.dialog.title']}"
|
||||
required="false"
|
||||
shortDescription="Title for the dialog."
|
||||
type="String" />
|
||||
|
|
@ -44,17 +44,17 @@
|
|||
shortDescription="Can the current user edit the text?"
|
||||
type="boolean" />
|
||||
<cc:attribute name="editButtonLabel"
|
||||
default="Edit"
|
||||
default="#{CmsAdminMessages['edit_button.label']}"
|
||||
required="false"
|
||||
shortDescription="Label for the edit button"
|
||||
type="String" />
|
||||
<cc:attribute name="editDialogCancelLabel"
|
||||
default="Cancel"
|
||||
default="#{CmsAdminMessages['cancel_button.label']}"
|
||||
required="false"
|
||||
shortDescription="Label for the cancel and close button of the edit dialog"
|
||||
type="String" />
|
||||
<cc:attribute name="editDialogSubmitLabel"
|
||||
default="save"
|
||||
default="#{CmsAdminMessages['save_button.label']}"
|
||||
required="false"
|
||||
shortDescription="Label for the submit button of the edit dialog"
|
||||
type="String" />
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
shortDescription="Label for the value field"
|
||||
type="String" />
|
||||
<cc:attribute name="editDialogTitle"
|
||||
default="Edit localized value"
|
||||
default="#{CmsAdminMessages['text.edit.dialog.title']}"
|
||||
required="false"
|
||||
shortDescription="Title for the edit dialog"
|
||||
type="String" />
|
||||
|
|
@ -91,7 +91,7 @@
|
|||
shortDescription="ID for the editor. Also used as prefix to generate IDs for some subcomponents"
|
||||
type="String" />
|
||||
<cc:attribute name="emptyText"
|
||||
default="No localized values"
|
||||
default="#{text.editor.no_localized_values}"
|
||||
required="false"
|
||||
shortDescription="Text shown if the localized has no values yet."
|
||||
type="String" />
|
||||
|
|
@ -337,9 +337,11 @@
|
|||
<tbody>
|
||||
<c:forEach items="#{cc.attrs.variants}"
|
||||
var="variant">
|
||||
<tr>
|
||||
<tr id="variant-#{variant.locale}">
|
||||
<td>#{variant.locale}</td>
|
||||
<td>#{CmsAdminMessages.getMessage('cms_editor.variants.wordcount', [variant.wordCount])}</td>
|
||||
<td>
|
||||
<span class="wordcount">#{variant.wordCount}</span> #{CmsAdminMessages['cms_editor.variants.wordcount']}
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-primary cms-editor-view-button"
|
||||
data-view-dialog="#{cc.attrs.editorId}-view-dialog"
|
||||
|
|
@ -353,6 +355,7 @@
|
|||
<c:if test="#{cc.attrs.canEdit}">
|
||||
<button class="btn btn-primary cms-editor-edit-button"
|
||||
data-edit-dialog="#{cc.attrs.editorId}-edit-dialog"
|
||||
data-locale="#{variant.locale}"
|
||||
data-variant-url="#{cc.attrs.variantUrl}/#{variant.locale}"
|
||||
data-save-url="#{cc.attrs.editMethod}/#{variant.locale}"
|
||||
type="button">
|
||||
|
|
@ -445,7 +448,7 @@
|
|||
data-backdrop="static"
|
||||
id="#{cc.attrs.editorId}-view-dialog"
|
||||
tabindex="-1">
|
||||
<div class="modal-dialog modal-xl">
|
||||
<div class="modal-dialog modal-xl modal-dialog-scrollable">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<c:choose>
|
||||
|
|
@ -493,7 +496,7 @@
|
|||
data-backdrop="static"
|
||||
id="#{cc.attrs.editorId}-edit-dialog"
|
||||
tabindex="-1">
|
||||
<div class="modal-dialog modal-xl">
|
||||
<div class="modal-dialog modal-xl modal-dialog-scrollable">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<c:choose>
|
||||
|
|
|
|||
|
|
@ -10,23 +10,11 @@
|
|||
<ui:define name="authoringStep">
|
||||
<h2>#{CmsArticleMessageBundle['textstep.header']}</h2>
|
||||
|
||||
<!-- <libreccm:localizedStringEditor
|
||||
addMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@article-text/add"
|
||||
editMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@article-text/edit"
|
||||
editorId="article-text-editor"
|
||||
hasUnusedLocales="#{!CmsArticleTextBodyStep.unusedLocales.isEmpty()}"
|
||||
headingLevel="3"
|
||||
objectIdentifier="#{CmsSelectedDocumentModel.itemPath}"
|
||||
removeMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@article-text/remove"
|
||||
title="#{CmsArticleMessageBundle['text.editor.header']}"
|
||||
unusedLocales="#{CmsArticleTextBodyStep.unusedLocales}"
|
||||
useTextarea="true"
|
||||
values="#{CmsArticleTextBodyStep.textValues}"
|
||||
/>
|
||||
|
||||
<div id="cms-editor"></div>-->
|
||||
|
||||
<librecms:cmsEditor addMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@article-text/add"
|
||||
<librecms:cmsEditor addButtonLabel="#{CmsArticleMessageBundle['text.editor.add_variant']}"
|
||||
addDialogLocaleSelectHelp="#{CmsAdminMessages['text.editor.add.locale.help']}"
|
||||
addMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@article-text/add"
|
||||
editDialogValueHelp="#{CmsAdminMessages['text.editor.edit.value.help']}"
|
||||
editDialogValueLabel="#{CmsAdminMessages['text.editor.edit.value.label']}"
|
||||
editMethod="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@article-text/edit"
|
||||
editorId="article-text-editor"
|
||||
hasUnusedLocales="#{!CmsArticleTextBodyStep.unusedLocales.isEmpty()}"
|
||||
|
|
|
|||
|
|
@ -768,4 +768,12 @@ contentsection.configuration.workflow.task_details.assignments.dialog.roles.help
|
|||
contentsection.configuration.workflows.task_details.assigned_to.dialog.title=Edit assigned roles
|
||||
cms_editor.buttons.emph=Emphasized
|
||||
cms_editor.buttons.strong_emph=Strong emphasized
|
||||
cms_editor.variants.wordcount={0} words
|
||||
cms_editor.variants.wordcount=words
|
||||
cancel_button.label=Cancel
|
||||
locale_select.label=Language
|
||||
locale_add.label=Add language
|
||||
locale_add.dialog.title=Add language variant
|
||||
edit_button.label=Edit
|
||||
save_button.label=Save
|
||||
text.edit.dialog.title=Edit localized variant
|
||||
text.editor.no_localized_values=No localized variants available yet.
|
||||
|
|
|
|||
|
|
@ -769,4 +769,12 @@ contentsection.configuration.workflow.task_details.assignments.dialog.roles.help
|
|||
contentsection.configuration.workflows.task_details.assigned_to.dialog.title=Zugewiesene Rollen bearbeiten
|
||||
cms_editor.buttons.emph=Betont
|
||||
cms_editor.buttons.strong_emph=Stark betont
|
||||
cms_editor.variants.wordcount={0} W\u00f6rter
|
||||
cms_editor.variants.wordcount=W\u00f6rter
|
||||
cancel_button.label=Abbrechen
|
||||
locale_select.label=Sprache
|
||||
locale_add.label=Sprache hinzuf\u00fcgen
|
||||
locale_add.dialog.title=Sprachvariante hinzuf\u00fcgen
|
||||
edit_button.label=Bearbeiten
|
||||
save_button.label=Speichern
|
||||
text.edit.dialog.title=Lokalisierte Variante bearbeiten
|
||||
text.editor.no_localized_values=Es wurden noch keine lokalisierten Varianten angelegt
|
||||
|
|
|
|||
|
|
@ -92,3 +92,7 @@ textstep.languages.none=No texts available
|
|||
textstep.header.edit=Edit text for locale {0}
|
||||
textstep.header.view=Text for locale {0}
|
||||
textstep.back=Back to available languages
|
||||
text.editor.add_variant=Add language
|
||||
text.editor.add.locale.help=The language of the new variant.
|
||||
text.editor.edit.value.help=The text of the article.
|
||||
text.editor.edit.value.label=Text
|
||||
|
|
|
|||
|
|
@ -92,3 +92,7 @@ textstep.languages.none=Keine Texte vorhandenen
|
|||
textstep.header.edit=Text f\u00fcr Sprache {0} bearbeiten
|
||||
textstep.header.view=Text f\u00fcr Sprache {0}
|
||||
textstep.back=Zur\u00fcck zur Liste der verf\u00fcgbaren Sprachen
|
||||
text.editor.add_variant=Sprache hinzuf\u00fcgen
|
||||
text.editor.add.locale.help=Die Sprache der neuen Variante.
|
||||
text.editor.edit.value.help=Der Text des Artikels.
|
||||
text.editor.edit.value.label=Text
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
|
|||
event.preventDefault();
|
||||
|
||||
const target = event.currentTarget as Element;
|
||||
const locale = target.getAttribute("data-locale");
|
||||
const variantUrl = target.getAttribute("data-variant-url");
|
||||
const editDialogId = target.getAttribute("data-edit-dialog");
|
||||
const saveUrl = target.getAttribute("data-save-url");
|
||||
|
|
@ -154,21 +155,22 @@ document.addEventListener("DOMContentLoaded", function (event) {
|
|||
|
||||
saveButton.addEventListener("click", event => {
|
||||
const html = editor.getHTML();
|
||||
const formData = new FormData();
|
||||
formData.append("value", html);
|
||||
const params = new URLSearchParams();
|
||||
params.append("value", html);
|
||||
fetch(saveUrl, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
body: formData
|
||||
body: params
|
||||
})
|
||||
.then(saveResponse => {
|
||||
if (saveResponse.ok) {
|
||||
showMessage(
|
||||
"#cms-editor-msg-save-successful"
|
||||
);
|
||||
window.location.reload();
|
||||
} else {
|
||||
showMessage(
|
||||
"#cms-editor-msg-save-failed"
|
||||
|
|
|
|||
Loading…
Reference in New Issue