Search in sources :

Example 6 with HTMLEditorController

use of org.olat.core.commons.editor.htmleditor.HTMLEditorController in project openolat by klemens.

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);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HTMLEditorController(org.olat.core.commons.editor.htmleditor.HTMLEditorController) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileUploadController(org.olat.core.commons.modules.bc.FileUploadController)

Example 7 with HTMLEditorController

use of org.olat.core.commons.editor.htmleditor.HTMLEditorController in project openolat by klemens.

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;
}
Also used : CustomLinkTreeModel(org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HTMLEditorController(org.olat.core.commons.editor.htmleditor.HTMLEditorController) VFSContainer(org.olat.core.util.vfs.VFSContainer) PlainTextEditorController(org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController) ContainerAndFile(org.olat.core.util.vfs.util.ContainerAndFile)

Example 8 with HTMLEditorController

use of org.olat.core.commons.editor.htmleditor.HTMLEditorController in project openolat by klemens.

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());
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HTMLEditorController(org.olat.core.commons.editor.htmleditor.HTMLEditorController) VFSContainer(org.olat.core.util.vfs.VFSContainer) PlainTextEditorController(org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) License(org.olat.core.commons.services.license.License) VFSItem(org.olat.core.util.vfs.VFSItem) ContainerAndFile(org.olat.core.util.vfs.util.ContainerAndFile)

Aggregations

HTMLEditorController (org.olat.core.commons.editor.htmleditor.HTMLEditorController)8 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)6 PlainTextEditorController (org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController)4 ContainerAndFile (org.olat.core.util.vfs.util.ContainerAndFile)4 CustomLinkTreeModel (org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel)2 FileUploadController (org.olat.core.commons.modules.bc.FileUploadController)2 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)2 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)2 License (org.olat.core.commons.services.license.License)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2