From 8ea20ffc6213f15da5d7f53b37a5f0e5e4915569 Mon Sep 17 00:00:00 2001 From: gnaegi <none@none> Date: Wed, 16 May 2012 13:57:46 +0200 Subject: [PATCH] OO-264 fixed redscreen when file edit limit reached, show error to user instead of RS --- .../htmleditor/HTMLEditorController.java | 56 ++++++++++--------- .../htmleditor/_content/htmleditor.html | 9 +++ .../bc/_spring/folderModuleCorecontext.xml | 2 +- .../resources/serviceconfig/olat.properties | 2 + 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/olat/core/commons/editor/htmleditor/HTMLEditorController.java b/src/main/java/org/olat/core/commons/editor/htmleditor/HTMLEditorController.java index 403dc4ff070..6828ad6c7f1 100644 --- a/src/main/java/org/olat/core/commons/editor/htmleditor/HTMLEditorController.java +++ b/src/main/java/org/olat/core/commons/editor/htmleditor/HTMLEditorController.java @@ -108,6 +108,7 @@ public class HTMLEditorController extends FormBasicController { private boolean editable = true; private boolean newFile = true; private boolean editorCheckEnabled = true; // default + private String fileToLargeError = null; /** * Factory method to create a file based HTML editor instance that uses @@ -146,10 +147,10 @@ public class HTMLEditorController extends FormBasicController { if ( size > FolderConfig.getMaxEditSizeLimit()) { // limit to reasonable size, see OO-57 setTranslator(Util.createPackageTranslator(PlainTextEditorController.class, getLocale(),getTranslator())); - getWindowControl().setError(translate("plaintext.error.tolarge", new String[]{(size / 1000) + "", (FolderConfig.getMaxEditSizeLimit()/1000)+""})); + fileToLargeError = translate("plaintext.error.tolarge", new String[]{(size / 1000) + "", (FolderConfig.getMaxEditSizeLimit()/1000)+""}); this.body = ""; this.editable = false; - //initForm(ureq); + initForm(ureq); return; } @@ -222,29 +223,34 @@ public class HTMLEditorController extends FormBasicController { */ @Override protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { - htmlElement = uifactory.addRichTextElementForFileData("rtfElement", null, body, -1, -1, false, baseContainer, fileName, customLinkTreeModel, formLayout, ureq.getUserSession(), getWindowControl()); - // - // Add resize handler - RichTextConfiguration editorConfiguration = htmlElement.getEditorConfiguration(); - editorConfiguration.addOnInitCallbackFunction("b_resizetofit_htmleditor"); - editorConfiguration.setNonQuotedConfigValue(RichTextConfiguration.HEIGHT, "b_initialEditorHeight()"); - // - // The buttons - save = uifactory.addFormLink("savebuttontext", formLayout, Link.BUTTON); - save.addActionListener(this, FormEvent.ONCLICK); - cancel = uifactory.addFormLink("cancel", formLayout, Link.BUTTON); - cancel.addActionListener(this, FormEvent.ONCLICK); - saveClose = uifactory.addFormLink("saveandclosebuttontext", formLayout, Link.BUTTON); - saveClose.addActionListener(this, FormEvent.ONCLICK); - // - // Add some file metadata - VelocityContainer vc = (VelocityContainer) formLayout.getComponent(); - metadataVC = createVelocityContainer("metadata"); - vc.put("metadata", metadataVC); - long lm = fileLeaf.getLastModified(); - metadataVC.contextPut("lastModified", Formatter.getInstance(ureq.getLocale()).formatDateAndTime(new Date(lm))); - metadataVC.contextPut("charSet", charSet); - metadataVC.contextPut("fileName", fileName); + if (fileToLargeError != null) { + VelocityContainer vc = (VelocityContainer) formLayout.getComponent(); + vc.contextPut("fileToLargeError", fileToLargeError); + } else { + htmlElement = uifactory.addRichTextElementForFileData("rtfElement", null, body, -1, -1, false, baseContainer, fileName, customLinkTreeModel, formLayout, ureq.getUserSession(), getWindowControl()); + // + // Add resize handler + RichTextConfiguration editorConfiguration = htmlElement.getEditorConfiguration(); + editorConfiguration.addOnInitCallbackFunction("b_resizetofit_htmleditor"); + editorConfiguration.setNonQuotedConfigValue(RichTextConfiguration.HEIGHT, "b_initialEditorHeight()"); + // + // The buttons + save = uifactory.addFormLink("savebuttontext", formLayout, Link.BUTTON); + save.addActionListener(this, FormEvent.ONCLICK); + cancel = uifactory.addFormLink("cancel", formLayout, Link.BUTTON); + cancel.addActionListener(this, FormEvent.ONCLICK); + saveClose = uifactory.addFormLink("saveandclosebuttontext", formLayout, Link.BUTTON); + saveClose.addActionListener(this, FormEvent.ONCLICK); + // + // Add some file metadata + VelocityContainer vc = (VelocityContainer) formLayout.getComponent(); + metadataVC = createVelocityContainer("metadata"); + vc.put("metadata", metadataVC); + long lm = fileLeaf.getLastModified(); + metadataVC.contextPut("lastModified", Formatter.getInstance(ureq.getLocale()).formatDateAndTime(new Date(lm))); + metadataVC.contextPut("charSet", charSet); + metadataVC.contextPut("fileName", fileName); + } } public boolean isEditable() { diff --git a/src/main/java/org/olat/core/commons/editor/htmleditor/_content/htmleditor.html b/src/main/java/org/olat/core/commons/editor/htmleditor/_content/htmleditor.html index 74d2bb969e6..71363da7774 100644 --- a/src/main/java/org/olat/core/commons/editor/htmleditor/_content/htmleditor.html +++ b/src/main/java/org/olat/core/commons/editor/htmleditor/_content/htmleditor.html @@ -1,4 +1,13 @@ <div class="b_htmleditor_wrapper b_clearfix"> + +#if($fileToLargeError) + <div class="o_cpeditor_message"> + <div class="b_error"> + $fileToLargeError + </div> + </div> +#end + #if($locked) <p class="b_warning"> $r.translate("error.pageeditedby", $lockOwner) diff --git a/src/main/java/org/olat/core/commons/modules/bc/_spring/folderModuleCorecontext.xml b/src/main/java/org/olat/core/commons/modules/bc/_spring/folderModuleCorecontext.xml index 8cdd9d3e983..88b7fdac0a0 100644 --- a/src/main/java/org/olat/core/commons/modules/bc/_spring/folderModuleCorecontext.xml +++ b/src/main/java/org/olat/core/commons/modules/bc/_spring/folderModuleCorecontext.xml @@ -32,7 +32,7 @@ <!-- Restrict sending document to links to enforce authentication --> SendDocLinkOnly=${folder.sendDocumentLinkOnly} <!-- max edit filesize for online-editing in Bytes --> - EditFileSizeLimit=524288 + EditFileSizeLimit=${folder.editFileSizeLimitBytes} </value> </property> </bean> diff --git a/src/main/resources/serviceconfig/olat.properties b/src/main/resources/serviceconfig/olat.properties index 1e4ef67183b..2be079fbb16 100644 --- a/src/main/resources/serviceconfig/olat.properties +++ b/src/main/resources/serviceconfig/olat.properties @@ -41,6 +41,8 @@ folder.maxulmb=50 folder.quotamb=100 folder.sendDocumentToExtern=true folder.sendDocumentLinkOnly=true +# file size limit for HTML and text editor is 1MB +folder.editFileSizeLimitBytes=1048576 ######################################################################## # Application settings -- GitLab