diff --git a/src/main/java/org/olat/course/condition/ConditionEditController.java b/src/main/java/org/olat/course/condition/ConditionEditController.java index 63dad781e823bf4852c2b0871743cb1a1460de3d..2ce5b4f245b49be9a08cc39cdc8d675b150a12c1 100644 --- a/src/main/java/org/olat/course/condition/ConditionEditController.java +++ b/src/main/java/org/olat/course/condition/ConditionEditController.java @@ -32,18 +32,10 @@ import org.olat.core.gui.components.Component; import org.olat.core.gui.components.link.Link; import org.olat.core.gui.components.link.LinkFactory; import org.olat.core.gui.components.velocity.VelocityContainer; -import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.controller.BasicController; -import org.olat.core.gui.translator.Translator; import org.olat.core.logging.OLATRuntimeException; -import org.olat.core.util.Util; -import org.olat.course.condition.additionalconditions.AdditionalCondition; -import org.olat.course.condition.additionalconditions.PasswordCondition; -import org.olat.course.editor.CourseEditorEnv; -import org.olat.course.editor.EditorMainController; -import org.olat.course.nodes.AbstractAccessableCourseNode; import org.olat.course.nodes.CourseNode; import org.olat.course.run.userview.UserCourseEnvironment; /** @@ -56,9 +48,6 @@ import org.olat.course.run.userview.UserCourseEnvironment; */ public class ConditionEditController extends BasicController { - //private static final String PACKAGE_EDITOR = Util.getPackageName(EditorMainController.class); - private static final String VELOCITY_ROOT = Util.getPackageVelocityRoot(ConditionEditController.class); - private VelocityContainer myContent; private ConditionConfigExpertForm conditionExpertForm; @@ -69,10 +58,6 @@ public class ConditionEditController extends BasicController { private Link easyModeButton; private Link expertModeButton; private ConditionConfigEasyController conditionEasyCtrllr; - // <OLATCE-91> - private PasswordCondition passwordCondition; - private Controller passwordConditionEditController; - // </OLATCE-91> /** @@ -81,28 +66,10 @@ public class ConditionEditController extends BasicController { * @param wControl Owning window control * @param euce * @param cond The condition which should be used to initialize the forms - * can then be used to embedd the condition form in your velocity container with $r.render("mainComponentName") * @param nodeIdentList */ public ConditionEditController(UserRequest ureq, WindowControl wControl, UserCourseEnvironment euce, Condition cond, List<CourseNode> nodeIdentList) { - this(ureq, wControl, cond, nodeIdentList, euce, false); - } - - /** - * Create a controller which can edit a condition in easy and expert mode - * @param ureq User Request data - * @param wControl The window control - * @param groupMgr The course group manager - * @param cond The condition which should be used to initialize the forms - * @param formName Name of the condition form - must be unique within a HTML page - * @param nodeIdentList - * @param euce - * @param showPasswordAccess If you want to show the password condition - */ - public ConditionEditController(UserRequest ureq, WindowControl wControl, - Condition cond, List<CourseNode> nodeIdentList, UserCourseEnvironment euce, - boolean showPasswordAccess) { super(ureq, wControl); this.condition = cond; this.validatedCondition = cloneCondition(condition); @@ -122,45 +89,14 @@ public class ConditionEditController extends BasicController { } else { doEasyMode(ureq); } - - // <OLATCE-91> - CourseEditorEnv courseEnv = euce.getCourseEditorEnv(); - CourseNode courseNode = courseEnv.getNode(courseEnv.getCurrentCourseNodeId()); - boolean isRootNode = courseEnv.getRootNodeId().equals(courseNode.getIdent()); - if(showPasswordAccess && courseNode instanceof AbstractAccessableCourseNode){ - AbstractAccessableCourseNode accessableCourseNode = (AbstractAccessableCourseNode)courseNode; - for(AdditionalCondition addCond : accessableCourseNode.getAdditionalConditions()){ - if(addCond instanceof PasswordCondition){ - passwordCondition = (PasswordCondition) addCond; - } - } - if ((passwordCondition == null) && (!isRootNode)) { - passwordCondition = new PasswordCondition(); - accessableCourseNode.getAdditionalConditions().add(passwordCondition); - } - if ((passwordCondition != null) && (isRootNode)) { - String pass = passwordCondition.getPassword(); - if ((pass == null) || (pass.length() == 0)) { - accessableCourseNode.getAdditionalConditions().remove(passwordCondition); - passwordCondition = null; - } - } - if (passwordCondition != null) { - passwordConditionEditController = passwordCondition.getEditorComponent(ureq, wControl); - listenTo(passwordConditionEditController); - } - } - // </OLATCE-91> putInitialPanel(myContent); } - private Condition cloneCondition(Condition orig) { return orig.clone(); } - @Override protected void event(UserRequest ureq, org.olat.core.gui.control.Controller source, Event event) { if(source == conditionEasyCtrllr){ @@ -188,17 +124,10 @@ public class ConditionEditController extends BasicController { // Inform all listeners about the changed condition fireEvent(ureq, Event.CHANGED_EVENT); } - // <OLATCE-91> - } else if (source == passwordConditionEditController ){ - fireEvent(ureq, event); - // </OLATCE-91> } } - - /** - * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.components.Component, org.olat.core.gui.control.Event) - */ + @Override public void event(UserRequest ureq, Component source, Event event) { if (source == easyModeButton){ doEasyMode(ureq); @@ -252,28 +181,7 @@ public class ConditionEditController extends BasicController { public Condition getCondition() { return condition; } - - /** - * Get the condition editor wrapped as a generic accessability condition editor - * @param title The title of this access condition, displayed as header in the surrounding fieldset - * @return The wrapped condition editor component - */ - public VelocityContainer getWrappedDefaultAccessConditionVC(String title){ - Translator accessTranslator = Util.createPackageTranslator(EditorMainController.class, getLocale()); - VelocityContainer defaultAccessConditionView = new VelocityContainer("defaultAccessConditionView", VELOCITY_ROOT + "/defaultaccessedit.html", accessTranslator, null); - defaultAccessConditionView.put("defaultAccessConditionView", myContent); - if(passwordConditionEditController != null) { - defaultAccessConditionView.put("pwcond", passwordConditionEditController.getInitialComponent()); - defaultAccessConditionView.contextPut("renderPW", true); - } - defaultAccessConditionView.contextPut("title", title); - return defaultAccessConditionView; - } - /** - * - * @see org.olat.core.gui.control.DefaultController#doDispose(boolean) - */ @Override protected void doDispose() { // child controller disposed by basic controller diff --git a/src/main/java/org/olat/course/condition/TabbableConditionNodeConfigController.java b/src/main/java/org/olat/course/condition/TabbableConditionNodeConfigController.java index 92253f4cadf17a4828e98b2b858513588cea042a..31b0090331817e3ce23bfc9b758d5061b19264e7 100644 --- a/src/main/java/org/olat/course/condition/TabbableConditionNodeConfigController.java +++ b/src/main/java/org/olat/course/condition/TabbableConditionNodeConfigController.java @@ -27,7 +27,7 @@ import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.generic.tabbable.ActivateableTabbableDefaultController; import org.olat.core.util.Util; -import org.olat.course.assessment.AssessmentHelper; +import org.olat.course.editor.AccessEditController; import org.olat.course.editor.ConditionAccessEditConfig; import org.olat.course.editor.NodeEditController; import org.olat.course.editor.VisibilityEditController; @@ -48,26 +48,23 @@ public class TabbableConditionNodeConfigController extends ActivateableTabbableD private static final String PANE_TAB_ACCESSIBILITY = "pane.tab.accessibility"; private final static String[] paneKeys = { PANE_TAB_VISIBILITY, PANE_TAB_ACCESSIBILITY }; - private final CourseNode courseNode; private final VisibilityEditController visibilityCtrl; - private ConditionEditController accessCtrl; + private AccessEditController accessCtrl; private TabbedPane tabPane; public TabbableConditionNodeConfigController(UserRequest ureq, WindowControl wControl, CourseNode courseNode, - UserCourseEnvironment userCourseEnvironment, CourseEditorTreeModel editorModel, ConditionAccessEditConfig accessEditConfig) { + UserCourseEnvironment userCourseEnvironment, CourseEditorTreeModel editorModel, + ConditionAccessEditConfig accessEditConfig) { super(ureq, wControl); - this.courseNode = courseNode; setTranslator(Util.createPackageTranslator(NodeEditController.class, getLocale(), getTranslator())); visibilityCtrl = new VisibilityEditController(ureq, getWindowControl(), courseNode, userCourseEnvironment, editorModel); listenTo(visibilityCtrl); - - if (courseNode instanceof AbstractAccessableCourseNode) { - Condition accessCondition = courseNode.getPreConditionAccess(); - accessCtrl = new ConditionEditController(ureq, wControl, accessCondition, - AssessmentHelper.getAssessableNodes(editorModel, courseNode), userCourseEnvironment, - accessEditConfig.isShowPassword()); + + if (courseNode instanceof AbstractAccessableCourseNode && !accessEditConfig.isCustomAccessConditionController()) { + accessCtrl = new AccessEditController(ureq, getWindowControl(), (AbstractAccessableCourseNode) courseNode, + userCourseEnvironment, editorModel, accessEditConfig); listenTo(accessCtrl); } } @@ -77,9 +74,7 @@ public class TabbableConditionNodeConfigController extends ActivateableTabbableD tabPane = tabbedPane; tabbedPane.addTab(translate(PANE_TAB_VISIBILITY), visibilityCtrl.getInitialComponent()); if (accessCtrl != null) { - tabbedPane.addTab(translate(PANE_TAB_ACCESSIBILITY), - accessCtrl.getWrappedDefaultAccessConditionVC(translate("condition.accessibility.title"))); - + tabbedPane.addTab(translate(PANE_TAB_ACCESSIBILITY), accessCtrl.getInitialComponent()); } } @@ -99,11 +94,11 @@ public class TabbableConditionNodeConfigController extends ActivateableTabbableD if (event == NodeEditController.NODECONFIG_CHANGED_EVENT) { fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT); } - } else if (source == accessCtrl && event.equals(Event.CHANGED_EVENT)) { - Condition cond = accessCtrl.getCondition(); - ((AbstractAccessableCourseNode)courseNode).setPreConditionAccess(cond); - fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT); - } + } else if (source == accessCtrl) { + if (event == NodeEditController.NODECONFIG_CHANGED_EVENT) { + fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT); + } + } } @Override diff --git a/src/main/java/org/olat/course/editor/AccessEditController.java b/src/main/java/org/olat/course/editor/AccessEditController.java new file mode 100644 index 0000000000000000000000000000000000000000..f5780bc2bcac644a32a1500c67c5c595598b2dd5 --- /dev/null +++ b/src/main/java/org/olat/course/editor/AccessEditController.java @@ -0,0 +1,122 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.course.editor; + +import org.olat.core.gui.UserRequest; +import org.olat.core.gui.components.Component; +import org.olat.core.gui.components.velocity.VelocityContainer; +import org.olat.core.gui.control.Controller; +import org.olat.core.gui.control.Event; +import org.olat.core.gui.control.WindowControl; +import org.olat.core.gui.control.controller.BasicController; +import org.olat.course.assessment.AssessmentHelper; +import org.olat.course.condition.Condition; +import org.olat.course.condition.ConditionEditController; +import org.olat.course.condition.additionalconditions.AdditionalCondition; +import org.olat.course.condition.additionalconditions.PasswordCondition; +import org.olat.course.nodes.AbstractAccessableCourseNode; +import org.olat.course.run.userview.UserCourseEnvironment; +import org.olat.course.tree.CourseEditorTreeModel; + +/** + * + * Initial date: 10 Sep 2019<br> + * @author uhensler, urs.hensler@frentix.com, http://www.frentix.com + * + */ +public class AccessEditController extends BasicController { + + private final VelocityContainer mainVc; + private ConditionEditController accessConditionCtrl; + private Controller passwordConditionEditController; + + private final AbstractAccessableCourseNode courseNode; + + public AccessEditController(UserRequest ureq, WindowControl wControl, AbstractAccessableCourseNode courseNode, + UserCourseEnvironment userCourseEnvironment, CourseEditorTreeModel editorModel, + ConditionAccessEditConfig accessEditConfig) { + super(ureq, wControl); + this.courseNode = courseNode; + mainVc = createVelocityContainer("accessedit"); + + // access + Condition accessCondition = courseNode.getPreConditionAccess(); + accessConditionCtrl = new ConditionEditController(ureq, wControl, userCourseEnvironment, accessCondition, + AssessmentHelper.getAssessableNodes(editorModel, courseNode)); + listenTo(accessConditionCtrl); + mainVc.put("accessCondition", accessConditionCtrl.getInitialComponent()); + + // password + CourseEditorEnv courseEnv = userCourseEnvironment.getCourseEditorEnv(); + boolean isRootNode = courseEnv.getRootNodeId().equals(courseNode.getIdent()); + if(accessEditConfig.isShowPassword()){ + PasswordCondition passwordCondition = null; + for(AdditionalCondition addCond : courseNode.getAdditionalConditions()){ + if(addCond instanceof PasswordCondition){ + passwordCondition = (PasswordCondition) addCond; + } + } + if ((passwordCondition == null) && (!isRootNode)) { + passwordCondition = new PasswordCondition(); + courseNode.getAdditionalConditions().add(passwordCondition); + } + if ((passwordCondition != null) && (isRootNode)) { + String pass = passwordCondition.getPassword(); + if ((pass == null) || (pass.length() == 0)) { + courseNode.getAdditionalConditions().remove(passwordCondition); + passwordCondition = null; + } + } + if (passwordCondition != null) { + passwordConditionEditController = passwordCondition.getEditorComponent(ureq, wControl); + listenTo(passwordConditionEditController); + } + if(passwordConditionEditController != null) { + mainVc.put("passwordCondition", passwordConditionEditController.getInitialComponent()); + mainVc.contextPut("renderPW", true); + } + } + + putInitialPanel(mainVc); + } + + @Override + protected void event(UserRequest ureq, Controller source, Event event) { + if (source == accessConditionCtrl && event == Event.CHANGED_EVENT) { + Condition cond = accessConditionCtrl.getCondition(); + courseNode.setPreConditionAccess(cond); + fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT); + } else if (source == passwordConditionEditController && event == Event.CHANGED_EVENT){ + fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT); + } + super.event(ureq, source, event); + } + + @Override + protected void event(UserRequest ureq, Component source, Event event) { + // + } + + @Override + protected void doDispose() { + // + } + +} diff --git a/src/main/java/org/olat/course/condition/_content/defaultaccessedit.html b/src/main/java/org/olat/course/editor/_content/accessedit.html similarity index 55% rename from src/main/java/org/olat/course/condition/_content/defaultaccessedit.html rename to src/main/java/org/olat/course/editor/_content/accessedit.html index f26dc68ac16f56399b9cee485f99fdc877c55d5b..598c0bf16a51efdaab62b517a668917fa54632e6 100644 --- a/src/main/java/org/olat/course/condition/_content/defaultaccessedit.html +++ b/src/main/java/org/olat/course/editor/_content/accessedit.html @@ -1,12 +1,12 @@ -<fieldset> +<fieldset class="o_form form-horizontal o_sel_course_access_condition_form"> <legend>$r.contextHelpWithWrapper("General Configuration of Course Elements#_zugang") - $title</legend> - $r.render("defaultAccessConditionView") + $r.translate("pane.tab.accessibility")</legend> + $r.render("accessCondition") </fieldset> #if($renderPW) <fieldset class="o_sel_course_node_password_config"> <legend> $r.translate("password.field")</legend> - $r.render("pwcond") + $r.render("passwordCondition") </fieldset> #end \ No newline at end of file