Skip to content
Snippets Groups Projects
Commit 8345e3ce authored by srosse's avatar srosse
Browse files

OO-2191: add the delete button in the upload of tiny to remove a file

parent eded4d64
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,7 @@ import org.olat.core.gui.components.form.flexible.impl.Form;
import org.olat.core.gui.components.form.flexible.impl.FormBasicController;
import org.olat.core.gui.components.form.flexible.impl.FormEvent;
import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer;
import org.olat.core.gui.components.form.flexible.impl.elements.FileElementEvent;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
......@@ -303,7 +304,11 @@ public class FileUploadController extends FormBasicController {
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if(fileEl == source) {
if(metaDataCtr != null) {
if(FileElementEvent.DELETE.equals(event.getCommand())) {
fileEl.reset();
fileEl.setDeleteEnabled(false);
fileEl.clearError();
} else if(metaDataCtr != null) {
String filename = fileEl.getUploadFileName();
if(!FileUtils.validateFilename(filename)) {
String suffix = FileUtils.getFileSuffix(filename);
......@@ -879,9 +884,10 @@ public class FileUploadController extends FormBasicController {
String filename = fileEl.getUploadFileName();
boolean allOk = validateFilename(filename, fileEl);
List<ValidationStatus> status = new ArrayList<>();
fileEl.validate(status);//revalidate because we clear the errors
return allOk && status.isEmpty();
List<ValidationStatus> fileStatus = new ArrayList<>();
fileEl.validate(fileStatus);//revalidate because we clear the error
fileEl.setDeleteEnabled(fileStatus.size() > 0);
return allOk && fileStatus.isEmpty();
}
private boolean validateFilename(String filename, FormItem itemEl) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment