use of org.olat.core.commons.editor.htmleditor.HTMLEditorController in project OpenOLAT by OpenOLAT.
the class CmdCreateFile method formOK.
@Override
protected void formOK(UserRequest ureq) {
// create the file
fileName = textElement.getValue();
VFSContainer currentContainer = folderComponent.getCurrentContainer();
VFSItem item = currentContainer.createChildLeaf(fileName);
if (item == null) {
status = FolderCommandStatus.STATUS_FAILED;
notifyFinished(ureq);
} else {
if (item instanceof MetaTagged) {
MetaInfo meta = ((MetaTagged) item).getMetaInfo();
meta.setAuthor(ureq.getIdentity());
if (licenseModule.isEnabled(licenseHandler)) {
License license = licenseService.createDefaultLicense(licenseHandler, getIdentity());
meta.setLicenseTypeKey(String.valueOf(license.getLicenseType().getKey()));
meta.setLicenseTypeName(license.getLicenseType().getName());
meta.setLicensor(license.getLicensor());
meta.setLicenseText(LicenseUIFactory.getLicenseText(license));
}
meta.write();
}
// start HTML editor with the folders root folder as base and the file
// path as a relative path from the root directory. But first check if the
// root directory is wirtable at all (e.g. not the case in users personal
// briefcase), and seach for the next higher directory that is writable.
String relFilePath = "/" + fileName;
// add current container path if not at root level
if (!folderComponent.getCurrentContainerPath().equals("/")) {
relFilePath = folderComponent.getCurrentContainerPath() + relFilePath;
}
VFSContainer writableRootContainer = folderComponent.getRootContainer();
ContainerAndFile result = VFSManager.findWritableRootFolderFor(writableRootContainer, relFilePath);
if (result != null) {
writableRootContainer = result.getContainer();
relFilePath = result.getFileName();
} else {
// use fallback that always work: current directory and current file
relFilePath = fileName;
writableRootContainer = folderComponent.getCurrentContainer();
}
if (relFilePath.endsWith(".html") || relFilePath.endsWith(".htm")) {
editorCtr = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), writableRootContainer, relFilePath, true, true);
((HTMLEditorController) editorCtr).setNewFile(true);
} else {
editorCtr = new PlainTextEditorController(ureq, getWindowControl(), (VFSLeaf) writableRootContainer.resolve(relFilePath), "utf-8", true, true, null);
}
listenTo(editorCtr);
initialPanel.setContent(editorCtr.getInitialComponent());
}
}
use of org.olat.core.commons.editor.htmleditor.HTMLEditorController in project OpenOLAT by OpenOLAT.
the class EditHTMLTaskController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_course_gta_edit_task_form");
String title = task.getTitle() == null ? "" : task.getTitle();
titleEl = uifactory.addTextElement("title", "task.title", 128, title, formLayout);
titleEl.setElementCssClass("o_sel_course_gta_upload_task_title");
titleEl.setMandatory(true);
String description = task.getDescription() == null ? "" : task.getDescription();
descriptionEl = uifactory.addTextAreaElement("descr", "task.description", 2048, 10, -1, true, description, formLayout);
contentEditor = new HTMLEditorController(ureq, getWindowControl(), taskContainer, task.getFilename(), null, "media", true, false, false, mainForm);
contentEditor.getRichTextConfiguration().disableMedia();
contentEditor.getRichTextConfiguration().setAllowCustomMediaFactory(false);
listenTo(contentEditor);
FormItem editorItem = contentEditor.getInitialFormItem();
editorItem.setLabel("task.file", null);
formLayout.add(editorItem);
FormLayoutContainer buttonCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonCont.setRootForm(mainForm);
formLayout.add(buttonCont);
uifactory.addFormSubmitButton("save", buttonCont);
uifactory.addFormCancelButton("cancel", buttonCont, ureq, getWindowControl());
}
use of org.olat.core.commons.editor.htmleditor.HTMLEditorController in project openolat by klemens.
the class EditHTMLTaskController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_course_gta_edit_task_form");
String title = task.getTitle() == null ? "" : task.getTitle();
titleEl = uifactory.addTextElement("title", "task.title", 128, title, formLayout);
titleEl.setElementCssClass("o_sel_course_gta_upload_task_title");
titleEl.setMandatory(true);
String description = task.getDescription() == null ? "" : task.getDescription();
descriptionEl = uifactory.addTextAreaElement("descr", "task.description", 2048, 10, -1, true, description, formLayout);
contentEditor = new HTMLEditorController(ureq, getWindowControl(), taskContainer, task.getFilename(), null, "media", true, false, false, mainForm);
contentEditor.getRichTextConfiguration().disableMedia();
contentEditor.getRichTextConfiguration().setAllowCustomMediaFactory(false);
listenTo(contentEditor);
FormItem editorItem = contentEditor.getInitialFormItem();
editorItem.setLabel("task.file", null);
formLayout.add(editorItem);
FormLayoutContainer buttonCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonCont.setRootForm(mainForm);
formLayout.add(buttonCont);
uifactory.addFormSubmitButton("save", buttonCont);
uifactory.addFormCancelButton("cancel", buttonCont, ureq, getWindowControl());
}
use of org.olat.core.commons.editor.htmleditor.HTMLEditorController in project OpenOLAT by OpenOLAT.
the class CmdEditContent method execute.
/**
* @see org.olat.modules.bc.commands.FolderCommand#execute(org.olat.modules.bc.components.FolderComponent, org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl, org.olat.core.gui.translator.Translator)
*/
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
this.folderComponent = folderComponent;
String pos = ureq.getParameter(ListRenderer.PARAM_CONTENTEDITID);
if (!StringHelper.containsNonWhitespace(pos)) {
// somehow parameter did not make it to us
status = FolderCommandStatus.STATUS_FAILED;
getWindowControl().setError(translator.translate("failed"));
return null;
}
status = FolderCommandHelper.sanityCheck(wControl, folderComponent);
if (status == FolderCommandStatus.STATUS_SUCCESS) {
currentItem = folderComponent.getCurrentContainerChildren().get(Integer.parseInt(pos));
status = FolderCommandHelper.sanityCheck2(wControl, folderComponent, currentItem);
}
if (status == FolderCommandStatus.STATUS_FAILED) {
return null;
}
// do fileEditSanityCheck
// OO-57
status = FolderCommandHelper.fileEditSanityCheck(currentItem);
if (status == FolderCommandStatus.STATUS_FAILED) {
// this should no longer happen, since folderComponent -> ListRenderer does not display edit-link for folders
logWarn("Given VFSItem is not a file, can't edit it: " + folderComponent.getCurrentContainerPath() + "/" + currentItem.getName(), null);
getWindowControl().setError(translator.translate("FileEditFailed"));
return null;
}
if (vfsLockManager.isLockedForMe(currentItem, ureq.getIdentity(), ureq.getUserSession().getRoles())) {
List<String> lockedFiles = Collections.singletonList(currentItem.getName());
String msg = FolderCommandHelper.renderLockedMessageAsHtml(translator, lockedFiles);
List<String> buttonLabels = Collections.singletonList(translator.translate("ok"));
lockedFiledCtr = activateGenericDialog(ureq, translator.translate("lock.title"), msg, buttonLabels, lockedFiledCtr);
return null;
}
// start HTML editor with the folders root folder as base and the file
// path as a relative path from the root directory. But first check if the
// root directory is wirtable at all (e.g. not the case in users personal
// briefcase), and seach for the next higher directory that is writable.
String relFilePath = "/" + currentItem.getName();
// add current container path if not at root level
if (!folderComponent.getCurrentContainerPath().equals("/")) {
relFilePath = folderComponent.getCurrentContainerPath() + relFilePath;
}
VFSContainer writableRootContainer = folderComponent.getRootContainer();
ContainerAndFile result = VFSManager.findWritableRootFolderFor(writableRootContainer, relFilePath);
if (result != null) {
if (currentItem.getParentContainer() != null) {
writableRootContainer = currentItem.getParentContainer();
relFilePath = currentItem.getName();
} else {
writableRootContainer = result.getContainer();
}
} else {
// use fallback that always work: current directory and current file
relFilePath = currentItem.getName();
writableRootContainer = folderComponent.getCurrentContainer();
}
// launch plaintext or html editor depending on file type
if (relFilePath.endsWith(".html") || relFilePath.endsWith(".htm")) {
CustomLinkTreeModel customLinkTreeModel = folderComponent.getCustomLinkTreeModel();
if (customLinkTreeModel != null) {
editorc = WysiwygFactory.createWysiwygControllerWithInternalLink(ureq, getWindowControl(), writableRootContainer, relFilePath, true, customLinkTreeModel);
((HTMLEditorController) editorc).setNewFile(false);
} else {
editorc = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), writableRootContainer, relFilePath, true, true);
((HTMLEditorController) editorc).setNewFile(false);
}
} else {
editorc = new PlainTextEditorController(ureq, getWindowControl(), (VFSLeaf) currentItem, "utf-8", true, false, null);
}
listenTo(editorc);
putInitialPanel(editorc.getInitialComponent());
return this;
}
use of org.olat.core.commons.editor.htmleditor.HTMLEditorController in project OpenOLAT by OpenOLAT.
the class LinkFileCombiCalloutController method event.
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
if (combiWindowController == source) {
doOpenFileChanger(ureq, event.getCommand());
} else if (source instanceof FileChooserController) {
// catch the events from the file chooser controller here
if (event instanceof FileChoosenEvent) {
FileChoosenEvent fce = (FileChoosenEvent) event;
file = (VFSLeaf) FileChooserUIFactory.getSelectedItem(fce);
relFilPathIsProposal = false;
setRelFilePath(FileChooserUIFactory.getSelectedRelativeItemPath(fce, baseContainer, null));
fireEvent(ureq, Event.DONE_EVENT);
} else if (event == Event.FAILED_EVENT) {
// selection failed for unknown reason
} else if (event == Event.CANCELLED_EVENT) {
// nothing to do
}
cleanupModal(true);
} else if (source instanceof FileUploadController) {
if (event == Event.DONE_EVENT) {
FileUploadController uploadCtr = (FileUploadController) source;
VFSLeaf newFile = uploadCtr.getUploadedFile();
if (newFile.getName().toLowerCase().endsWith("zip")) {
// Cleanup modal first
cleanupModal(true);
// Unzip file and open file chooser in new modal
VFSContainer zipContainer = doUnzip(newFile, newFile.getParentContainer());
if (zipContainer != null) {
FileChooserController fileChooserCtr = FileChooserUIFactory.createFileChooserController(ureq, getWindowControl(), zipContainer, null, true);
fileChooserCtr.setShowTitle(true);
displayModal(fileChooserCtr);
return;
}
} else {
// All other files
file = uploadCtr.getUploadedFile();
relFilPathIsProposal = false;
setRelFilePath(VFSManager.getRelativeItemPath(file, baseContainer, null));
fireEvent(ureq, Event.DONE_EVENT);
}
} else if (event.getCommand().equals(FolderEvent.UPLOAD_EVENT)) {
// Do nothing, ignore this internal event. When finished, done is fired
return;
} else if (event == Event.CANCELLED_EVENT) {
// nothing to do
}
cleanupModal(true);
} else if (source instanceof HTMLEditorController) {
if (event == Event.DONE_EVENT) {
relFilPathIsProposal = false;
editLink.setCustomDisplayText(translate("command.edit"));
fireEvent(ureq, Event.DONE_EVENT);
} else if (event == Event.CANCELLED_EVENT) {
// nothing to do
}
cleanupModal(true);
updateLinks();
} else if (source instanceof FileCreatorController) {
if (event == Event.DONE_EVENT) {
FileCreatorController createCtr = (FileCreatorController) source;
file = createCtr.getCreatedFile();
relFilPathIsProposal = false;
setRelFilePath(VFSManager.getRelativeItemPath(file, baseContainer, null));
fireEvent(ureq, Event.DONE_EVENT);
cleanupModal(true);
// Now open html editor
doOpenWysiwygEditor(ureq);
} else if (event == Event.CANCELLED_EVENT) {
cleanupModal(true);
}
} else if (source == cmc && event == CloseableModalController.CLOSE_MODAL_EVENT) {
// User closed dialog, same as cancel in a sub-controller
cleanupModal(false);
} else if (source == previewLayoutCtr && event == Event.BACK_EVENT) {
removeAsListenerAndDispose(previewLayoutCtr);
}
super.event(ureq, source, event);
}
Aggregations