Search in sources :

Example 6 with CustomLinkTreeModel

use of org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel 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;
}
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 7 with CustomLinkTreeModel

use of org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel 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 CustomLinkTreeModel

use of org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel in project openolat by klemens.

the class STCourseNode method createNodeRunConstructionResult.

/**
 * @see org.olat.course.nodes.CourseNode#createNodeRunConstructionResult(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.WindowControl,
 *      org.olat.course.run.userview.UserCourseEnvironment,
 *      org.olat.course.run.userview.NodeEvaluation)
 */
@Override
public NodeRunConstructionResult createNodeRunConstructionResult(UserRequest ureq, WindowControl wControl, final UserCourseEnvironment userCourseEnv, NodeEvaluation ne, String nodecmd) {
    updateModuleConfigDefaults(false);
    Controller cont;
    String displayType = getModuleConfiguration().getStringValue(STCourseNodeEditController.CONFIG_KEY_DISPLAY_TYPE);
    String relPath = STCourseNodeEditController.getFileName(getModuleConfiguration());
    if (relPath != null && displayType.equals(STCourseNodeEditController.CONFIG_VALUE_DISPLAY_FILE)) {
        // we want a user chosen overview, so display the chosen file from the
        // material folder, otherwise display the normal overview
        // reuse the Run controller from the "Single Page" building block, since
        // we need to do exactly the same task
        Boolean allowRelativeLinks = getModuleConfiguration().getBooleanEntry(STCourseNodeEditController.CONFIG_KEY_ALLOW_RELATIVE_LINKS);
        if (allowRelativeLinks == null) {
            allowRelativeLinks = Boolean.FALSE;
        }
        DeliveryOptions deliveryOptions = (DeliveryOptions) getModuleConfiguration().get(SPEditController.CONFIG_KEY_DELIVERYOPTIONS);
        OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseModule.class, userCourseEnv.getCourseEnvironment().getCourseResourceableId());
        SinglePageController spCtr = new SinglePageController(ureq, wControl, userCourseEnv.getCourseEnvironment().getCourseFolderContainer(), relPath, allowRelativeLinks.booleanValue(), null, ores, deliveryOptions, userCourseEnv.getCourseEnvironment().isPreview());
        // check if user is allowed to edit the page in the run view
        CourseGroupManager cgm = userCourseEnv.getCourseEnvironment().getCourseGroupManager();
        boolean hasEditRights = (cgm.isIdentityCourseAdministrator(ureq.getIdentity()) || cgm.hasRight(ureq.getIdentity(), CourseRights.RIGHT_COURSEEDITOR)) || (getModuleConfiguration().getBooleanSafe(SPEditController.CONFIG_KEY_ALLOW_COACH_EDIT, false) && cgm.isIdentityCourseCoach(ureq.getIdentity()));
        if (hasEditRights) {
            spCtr.allowPageEditing();
            // set the link tree model to internal for the HTML editor
            CustomLinkTreeModel linkTreeModel = new CourseInternalLinkTreeModel(userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode());
            spCtr.setInternalLinkTreeModel(linkTreeModel);
        }
        spCtr.addLoggingResourceable(LoggingResourceable.wrap(this));
        // create clone wrapper layout, allow popping into second window
        CloneLayoutControllerCreatorCallback clccc = new CloneLayoutControllerCreatorCallback() {

            @Override
            public ControllerCreator createLayoutControllerCreator(final UserRequest uureq, final ControllerCreator contentControllerCreator) {
                return BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(uureq, new ControllerCreator() {

                    @Override
                    public Controller createController(UserRequest lureq, WindowControl lwControl) {
                        // wrap in column layout, popup window needs a layout controller
                        Controller ctr = contentControllerCreator.createController(lureq, lwControl);
                        LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(lureq, lwControl, ctr);
                        layoutCtr.setCustomCSS(CourseFactory.getCustomCourseCss(lureq.getUserSession(), userCourseEnv.getCourseEnvironment()));
                        Controller wrappedCtrl = TitledWrapperHelper.getWrapper(lureq, lwControl, ctr, STCourseNode.this, ICON_CSS_CLASS);
                        layoutCtr.addDisposableChildController(wrappedCtrl);
                        return layoutCtr;
                    }
                });
            }
        };
        Controller wrappedCtrl = TitledWrapperHelper.getWrapper(ureq, wControl, spCtr, this, ICON_CSS_CLASS);
        if (wrappedCtrl instanceof CloneableController) {
            cont = new CloneController(ureq, wControl, (CloneableController) wrappedCtrl, clccc);
        } else {
            throw new AssertException("Need to be a cloneable");
        }
    } else {
        // evaluate the score accounting for this node. this uses the score accountings local
        // cache hash map to reduce unnecessary calculations
        ScoreEvaluation se = userCourseEnv.getScoreAccounting().evalCourseNode(this);
        cont = TitledWrapperHelper.getWrapper(ureq, wControl, new STCourseNodeRunController(ureq, wControl, userCourseEnv, this, se, ne), this, ICON_CSS_CLASS);
    }
    // displayed in the ST-Runcontroller
    return new NodeRunConstructionResult(cont);
}
Also used : STCourseNodeRunController(org.olat.course.nodes.st.STCourseNodeRunController) CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) CloneableController(org.olat.core.gui.control.generic.clone.CloneableController) SinglePageController(org.olat.core.commons.modules.singlepage.SinglePageController) SPPeekviewController(org.olat.course.nodes.sp.SPPeekviewController) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) NodeEditController(org.olat.course.editor.NodeEditController) STCourseNodeRunController(org.olat.course.nodes.st.STCourseNodeRunController) TabbableController(org.olat.core.gui.control.generic.tabbable.TabbableController) CloneableController(org.olat.core.gui.control.generic.clone.CloneableController) AssessmentCourseNodeController(org.olat.course.assessment.ui.tool.AssessmentCourseNodeController) SPEditController(org.olat.course.nodes.sp.SPEditController) CloneController(org.olat.core.gui.control.generic.clone.CloneController) STCourseNodeEditController(org.olat.course.nodes.st.STCourseNodeEditController) Controller(org.olat.core.gui.control.Controller) STPeekViewController(org.olat.course.nodes.st.STPeekViewController) STIdentityListCourseNodeController(org.olat.course.nodes.st.STIdentityListCourseNodeController) SinglePageController(org.olat.core.commons.modules.singlepage.SinglePageController) WindowControl(org.olat.core.gui.control.WindowControl) NodeRunConstructionResult(org.olat.course.run.navigation.NodeRunConstructionResult) ControllerCreator(org.olat.core.gui.control.creator.ControllerCreator) CustomLinkTreeModel(org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel) CloneController(org.olat.core.gui.control.generic.clone.CloneController) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) CloneLayoutControllerCreatorCallback(org.olat.core.gui.control.generic.clone.CloneLayoutControllerCreatorCallback) DeliveryOptions(org.olat.core.gui.control.generic.iframe.DeliveryOptions) UserRequest(org.olat.core.gui.UserRequest) CourseInternalLinkTreeModel(org.olat.course.tree.CourseInternalLinkTreeModel)

Aggregations

CustomLinkTreeModel (org.olat.core.commons.controllers.linkchooser.CustomLinkTreeModel)8 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)4 UserRequest (org.olat.core.gui.UserRequest)4 WindowControl (org.olat.core.gui.control.WindowControl)4 ControllerCreator (org.olat.core.gui.control.creator.ControllerCreator)4 CourseInternalLinkTreeModel (org.olat.course.tree.CourseInternalLinkTreeModel)4 LinkChooserController (org.olat.core.commons.controllers.linkchooser.LinkChooserController)2 HTMLEditorController (org.olat.core.commons.editor.htmleditor.HTMLEditorController)2 PlainTextEditorController (org.olat.core.commons.editor.plaintexteditor.PlainTextEditorController)2 FolderRunController (org.olat.core.commons.modules.bc.FolderRunController)2 SinglePageController (org.olat.core.commons.modules.singlepage.SinglePageController)2 Controller (org.olat.core.gui.control.Controller)2 CloneController (org.olat.core.gui.control.generic.clone.CloneController)2 CloneLayoutControllerCreatorCallback (org.olat.core.gui.control.generic.clone.CloneLayoutControllerCreatorCallback)2 CloneableController (org.olat.core.gui.control.generic.clone.CloneableController)2 DeliveryOptions (org.olat.core.gui.control.generic.iframe.DeliveryOptions)2 PopupBrowserWindow (org.olat.core.gui.control.generic.popup.PopupBrowserWindow)2 TabbableController (org.olat.core.gui.control.generic.tabbable.TabbableController)2 OLATResourceable (org.olat.core.id.OLATResourceable)2