Search in sources :

Example 11 with RepositoryEntryAllowToLeaveOptions

use of org.olat.repository.RepositoryEntryAllowToLeaveOptions in project OpenOLAT by OpenOLAT.

the class PublishStep01AccessForm method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer headersLayout = FormLayoutContainer.createCustomFormLayout("access", getTranslator(), velocity_root + "/publish_courseaccess.html");
    formLayout.add(headersLayout);
    headersLayout.contextPut("catalogEnabled", repositoryModule.isCatalogEnabled());
    FormLayoutContainer publishLayout = FormLayoutContainer.createDefaultFormLayout("publish", getTranslator());
    formLayout.add(publishLayout);
    publishLayout.setFormTitle(translate("rentry.publish"));
    publishLayout.setFormContextHelp("Course Settings#_zugriff");
    publishLayout.setElementCssClass("o_sel_repositoryentry_access");
    if (loginModule.isGuestLoginLinksEnabled()) {
        publishedKeys = new String[] { OAU_KEY, OAUG_KEY, MEMBERSONLY_KEY };
    } else {
        publishedKeys = new String[] { OAU_KEY, MEMBERSONLY_KEY };
    }
    String resourceType = entry.getOlatResource().getResourceableTypeName();
    if (TestFileResource.TYPE_NAME.equals(resourceType) || SurveyFileResource.TYPE_NAME.equals(resourceType) || ScormCPFileResource.TYPE_NAME.equals(resourceType)) {
        String warning = translate("warn.resource.need.course");
        flc.contextPut("off_warn", warning);
    }
    if (CourseModule.ORES_TYPE_COURSE.equals(resourceType)) {
        publishLayout.setFormDescription(translate("rentry.publish.course.desc"));
    } else {
        publishLayout.setFormDescription(translate("rentry.publish.other.desc"));
    }
    if (resourceType != null) {
        handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(resourceType);
    }
    // make configuration read only when managed by external system
    final boolean managedSettings = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.settings);
    final boolean managedAccess = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.access);
    String[] yesNoValues = new String[] { translate("yes"), translate("no") };
    authorsSwitch = uifactory.addRadiosHorizontal("authorsSwitch", "rentry.publish.authors", publishLayout, yesNoKeys, yesNoValues);
    authorsSwitch.setEnabled(!managedAccess);
    authorsSwitch.addActionListener(FormEvent.ONCHANGE);
    authorConfigLayout = FormLayoutContainer.createBareBoneFormLayout("authorConfigLayout", getTranslator());
    publishLayout.add(authorConfigLayout);
    canReference = uifactory.addCheckboxesVertical("cif_canReference", null, authorConfigLayout, new String[] { YES_KEY }, new String[] { translate("cif.canReference") }, 1);
    canReference.setEnabled(!managedSettings);
    canCopy = uifactory.addCheckboxesVertical("cif_canCopy", null, authorConfigLayout, new String[] { YES_KEY }, new String[] { translate("cif.canCopy") }, 1);
    canCopy.setEnabled(!managedSettings);
    canDownload = uifactory.addCheckboxesVertical("cif_canDownload", null, authorConfigLayout, new String[] { YES_KEY }, new String[] { translate("cif.canDownload") }, 1);
    canDownload.setEnabled(!managedSettings);
    canDownload.setVisible(handler.supportsDownload());
    uifactory.addSpacerElement("authorSpacer", authorConfigLayout, true);
    String[] publishedValues;
    if (loginModule.isGuestLoginLinksEnabled()) {
        publishedValues = new String[] { translate("cif.access.users"), translate("cif.access.users_guests"), translate("cif.access.membersonly") };
    } else {
        publishedValues = new String[] { translate("cif.access.users"), translate("cif.access.membersonly") };
    }
    usersSwitch = uifactory.addRadiosHorizontal("usersSwitch", "rentry.publish.users", publishLayout, yesNoKeys, yesNoValues);
    usersSwitch.addActionListener(FormEvent.ONCHANGE);
    usersSwitch.setEnabled(!managedAccess);
    userConfigLayout = FormLayoutContainer.createBareBoneFormLayout("userConfigLayout", getTranslator());
    publishLayout.add(userConfigLayout);
    publishedForUsers = uifactory.addDropdownSingleselect("publishedForUsers", null, userConfigLayout, publishedKeys, publishedValues, null);
    publishedForUsers.setEnabled(!managedAccess);
    publishedForUsers.addActionListener(FormEvent.ONCHANGE);
    uifactory.addSpacerElement("userSpacer", userConfigLayout, true);
    // Part 2
    FormLayoutContainer membershipLayout = FormLayoutContainer.createDefaultFormLayout("membership", getTranslator());
    formLayout.add(membershipLayout);
    membershipLayout.setFormTitle(translate("rentry.leaving.title"));
    String[] leaveValues = new String[] { translate("rentry.leave.atanytime"), translate("rentry.leave.afterenddate"), translate("rentry.leave.never") };
    final boolean managedLeaving = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.membersmanagement);
    leaveEl = uifactory.addDropdownSingleselect("entry.leave", "rentry.leave.option", membershipLayout, leaveKeys, leaveValues, null);
    boolean found = false;
    for (String leaveKey : leaveKeys) {
        if (leaveKey.equals(entry.getAllowToLeaveOption().name())) {
            leaveEl.select(leaveKey, true);
            found = true;
        }
    }
    if (!found) {
        if (managedLeaving) {
            leaveEl.select(RepositoryEntryAllowToLeaveOptions.never.name(), true);
        } else {
            RepositoryEntryAllowToLeaveOptions defaultOption = repositoryModule.getAllowToLeaveDefaultOption();
            leaveEl.select(defaultOption.name(), true);
        }
    }
    leaveEl.setEnabled(!managedLeaving);
    // Part 3
    accessLayout = FormLayoutContainer.createCustomFormLayout("accessConfig", getTranslator(), velocity_root + "/access_configuration.html");
    formLayout.add(accessLayout);
    accessLayout.setVisible(entry.getAccess() == RepositoryEntry.ACC_USERS || loginModule.isGuestLoginLinksEnabled() && entry.getAccess() == RepositoryEntry.ACC_USERS_GUESTS || entry.isMembersOnly());
    accessLayout.setFormTitle(translate("accesscontrol.title"));
    HelpTooltip acMethodsLabelHelp = new HelpTooltip("acMethodsLabelHelp", "Legen Sie fest unter welchen Bedingungen Benutzer diese Ressource buchen können.", "Course Settings#_buchungsmethode", getLocale());
    accessLayout.put("acMethodsLabelHelp", acMethodsLabelHelp);
    if (editable) {
        List<AccessMethod> methods = acService.getAvailableMethods(getIdentity(), ureq.getUserSession().getRoles());
        for (AccessMethod method : methods) {
            AccessMethodHandler methodHandler = acModule.getAccessMethodHandler(method.getType());
            if (methodHandler.isPaymentMethod() && !allowPaymentMethod) {
                continue;
            }
            String title = methodHandler.getMethodName(getLocale());
            FormLink add = uifactory.addFormLink("create." + methodHandler.getType(), title, null, accessLayout, Link.LINK | Link.NONTRANSLATED);
            add.setUserObject(method);
            add.setIconLeftCSS(("o_icon " + method.getMethodCssClass() + "_icon o_icon-lg").intern());
            addMethods.add(add);
            accessLayout.add(add.getName(), add);
        }
        accessLayout.contextPut("methods", addMethods);
    }
    String[] onValues = new String[] { "" };
    confirmationEmailEl = uifactory.addCheckboxesHorizontal("confirmation.email", accessLayout, onKeys, onValues);
    confirmationEmailEl.addActionListener(FormEvent.ONCHANGE);
    confirmationEmailEl.setVisible(false);
    String confPage = velocity_root + "/configuration_list.html";
    confControllerContainer = FormLayoutContainer.createCustomFormLayout("conf-controllers", getTranslator(), confPage);
    accessLayout.add(confControllerContainer);
    loadConfigurations();
    boolean confirmationEmail = false;
    for (AccessInfo info : confControllers) {
        confirmationEmail |= info.getLink().getOffer().isConfirmationEmail();
    }
    if (confirmationEmail) {
        confirmationEmailEl.select(onKeys[0], true);
    }
    confControllerContainer.contextPut("confControllers", confControllers);
    confControllerContainer.contextPut("emptyConfigGrantsFullAccess", Boolean.valueOf(emptyConfigGrantsFullAccess));
    initFormData();
}
Also used : HelpTooltip(org.olat.core.gui.components.helpTooltip.HelpTooltip) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) RepositoryEntryAllowToLeaveOptions(org.olat.repository.RepositoryEntryAllowToLeaveOptions) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Example 12 with RepositoryEntryAllowToLeaveOptions

use of org.olat.repository.RepositoryEntryAllowToLeaveOptions in project openolat by klemens.

the class PublishStep01AccessForm method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer headersLayout = FormLayoutContainer.createCustomFormLayout("access", getTranslator(), velocity_root + "/publish_courseaccess.html");
    formLayout.add(headersLayout);
    headersLayout.contextPut("catalogEnabled", repositoryModule.isCatalogEnabled());
    FormLayoutContainer publishLayout = FormLayoutContainer.createDefaultFormLayout("publish", getTranslator());
    formLayout.add(publishLayout);
    publishLayout.setFormTitle(translate("rentry.publish"));
    publishLayout.setFormContextHelp("Course Settings#_zugriff");
    publishLayout.setElementCssClass("o_sel_repositoryentry_access");
    if (loginModule.isGuestLoginLinksEnabled()) {
        publishedKeys = new String[] { OAU_KEY, OAUG_KEY, MEMBERSONLY_KEY };
    } else {
        publishedKeys = new String[] { OAU_KEY, MEMBERSONLY_KEY };
    }
    String resourceType = entry.getOlatResource().getResourceableTypeName();
    if (TestFileResource.TYPE_NAME.equals(resourceType) || SurveyFileResource.TYPE_NAME.equals(resourceType) || ScormCPFileResource.TYPE_NAME.equals(resourceType)) {
        String warning = translate("warn.resource.need.course");
        flc.contextPut("off_warn", warning);
    }
    if (CourseModule.ORES_TYPE_COURSE.equals(resourceType)) {
        publishLayout.setFormDescription(translate("rentry.publish.course.desc"));
    } else {
        publishLayout.setFormDescription(translate("rentry.publish.other.desc"));
    }
    if (resourceType != null) {
        handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(resourceType);
    }
    // make configuration read only when managed by external system
    final boolean managedSettings = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.settings);
    final boolean managedAccess = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.access);
    String[] yesNoValues = new String[] { translate("yes"), translate("no") };
    authorsSwitch = uifactory.addRadiosHorizontal("authorsSwitch", "rentry.publish.authors", publishLayout, yesNoKeys, yesNoValues);
    authorsSwitch.setEnabled(!managedAccess);
    authorsSwitch.addActionListener(FormEvent.ONCHANGE);
    authorConfigLayout = FormLayoutContainer.createBareBoneFormLayout("authorConfigLayout", getTranslator());
    publishLayout.add(authorConfigLayout);
    canReference = uifactory.addCheckboxesVertical("cif_canReference", null, authorConfigLayout, new String[] { YES_KEY }, new String[] { translate("cif.canReference") }, 1);
    canReference.setEnabled(!managedSettings);
    canCopy = uifactory.addCheckboxesVertical("cif_canCopy", null, authorConfigLayout, new String[] { YES_KEY }, new String[] { translate("cif.canCopy") }, 1);
    canCopy.setEnabled(!managedSettings);
    canDownload = uifactory.addCheckboxesVertical("cif_canDownload", null, authorConfigLayout, new String[] { YES_KEY }, new String[] { translate("cif.canDownload") }, 1);
    canDownload.setEnabled(!managedSettings);
    canDownload.setVisible(handler.supportsDownload());
    uifactory.addSpacerElement("authorSpacer", authorConfigLayout, true);
    String[] publishedValues;
    if (loginModule.isGuestLoginLinksEnabled()) {
        publishedValues = new String[] { translate("cif.access.users"), translate("cif.access.users_guests"), translate("cif.access.membersonly") };
    } else {
        publishedValues = new String[] { translate("cif.access.users"), translate("cif.access.membersonly") };
    }
    usersSwitch = uifactory.addRadiosHorizontal("usersSwitch", "rentry.publish.users", publishLayout, yesNoKeys, yesNoValues);
    usersSwitch.addActionListener(FormEvent.ONCHANGE);
    usersSwitch.setEnabled(!managedAccess);
    userConfigLayout = FormLayoutContainer.createBareBoneFormLayout("userConfigLayout", getTranslator());
    publishLayout.add(userConfigLayout);
    publishedForUsers = uifactory.addDropdownSingleselect("publishedForUsers", null, userConfigLayout, publishedKeys, publishedValues, null);
    publishedForUsers.setEnabled(!managedAccess);
    publishedForUsers.addActionListener(FormEvent.ONCHANGE);
    uifactory.addSpacerElement("userSpacer", userConfigLayout, true);
    // Part 2
    FormLayoutContainer membershipLayout = FormLayoutContainer.createDefaultFormLayout("membership", getTranslator());
    formLayout.add(membershipLayout);
    membershipLayout.setFormTitle(translate("rentry.leaving.title"));
    String[] leaveValues = new String[] { translate("rentry.leave.atanytime"), translate("rentry.leave.afterenddate"), translate("rentry.leave.never") };
    final boolean managedLeaving = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.membersmanagement);
    leaveEl = uifactory.addDropdownSingleselect("entry.leave", "rentry.leave.option", membershipLayout, leaveKeys, leaveValues, null);
    boolean found = false;
    for (String leaveKey : leaveKeys) {
        if (leaveKey.equals(entry.getAllowToLeaveOption().name())) {
            leaveEl.select(leaveKey, true);
            found = true;
        }
    }
    if (!found) {
        if (managedLeaving) {
            leaveEl.select(RepositoryEntryAllowToLeaveOptions.never.name(), true);
        } else {
            RepositoryEntryAllowToLeaveOptions defaultOption = repositoryModule.getAllowToLeaveDefaultOption();
            leaveEl.select(defaultOption.name(), true);
        }
    }
    leaveEl.setEnabled(!managedLeaving);
    // Part 3
    accessLayout = FormLayoutContainer.createCustomFormLayout("accessConfig", getTranslator(), velocity_root + "/access_configuration.html");
    formLayout.add(accessLayout);
    accessLayout.setVisible(entry.getAccess() == RepositoryEntry.ACC_USERS || loginModule.isGuestLoginLinksEnabled() && entry.getAccess() == RepositoryEntry.ACC_USERS_GUESTS || entry.isMembersOnly());
    accessLayout.setFormTitle(translate("accesscontrol.title"));
    HelpTooltip acMethodsLabelHelp = new HelpTooltip("acMethodsLabelHelp", "Legen Sie fest unter welchen Bedingungen Benutzer diese Ressource buchen können.", "Course Settings#_buchungsmethode", getLocale());
    accessLayout.put("acMethodsLabelHelp", acMethodsLabelHelp);
    if (editable) {
        List<AccessMethod> methods = acService.getAvailableMethods(getIdentity(), ureq.getUserSession().getRoles());
        for (AccessMethod method : methods) {
            AccessMethodHandler methodHandler = acModule.getAccessMethodHandler(method.getType());
            if (methodHandler.isPaymentMethod() && !allowPaymentMethod) {
                continue;
            }
            String title = methodHandler.getMethodName(getLocale());
            FormLink add = uifactory.addFormLink("create." + methodHandler.getType(), title, null, accessLayout, Link.LINK | Link.NONTRANSLATED);
            add.setUserObject(method);
            add.setIconLeftCSS(("o_icon " + method.getMethodCssClass() + "_icon o_icon-lg").intern());
            addMethods.add(add);
            accessLayout.add(add.getName(), add);
        }
        accessLayout.contextPut("methods", addMethods);
    }
    String[] onValues = new String[] { "" };
    confirmationEmailEl = uifactory.addCheckboxesHorizontal("confirmation.email", accessLayout, onKeys, onValues);
    confirmationEmailEl.addActionListener(FormEvent.ONCHANGE);
    confirmationEmailEl.setVisible(false);
    String confPage = velocity_root + "/configuration_list.html";
    confControllerContainer = FormLayoutContainer.createCustomFormLayout("conf-controllers", getTranslator(), confPage);
    accessLayout.add(confControllerContainer);
    loadConfigurations();
    boolean confirmationEmail = false;
    for (AccessInfo info : confControllers) {
        confirmationEmail |= info.getLink().getOffer().isConfirmationEmail();
    }
    if (confirmationEmail) {
        confirmationEmailEl.select(onKeys[0], true);
    }
    confControllerContainer.contextPut("confControllers", confControllers);
    confControllerContainer.contextPut("emptyConfigGrantsFullAccess", Boolean.valueOf(emptyConfigGrantsFullAccess));
    initFormData();
}
Also used : HelpTooltip(org.olat.core.gui.components.helpTooltip.HelpTooltip) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) RepositoryEntryAllowToLeaveOptions(org.olat.repository.RepositoryEntryAllowToLeaveOptions) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Aggregations

RepositoryEntryAllowToLeaveOptions (org.olat.repository.RepositoryEntryAllowToLeaveOptions)12 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 Calendar (java.util.Calendar)2 Date (java.util.Date)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 HelpTooltip (org.olat.core.gui.components.helpTooltip.HelpTooltip)2 MultiUserEvent (org.olat.core.util.event.MultiUserEvent)2 EntryChangedEvent (org.olat.repository.controllers.EntryChangedEvent)2 RepositoryEntryLifecycle (org.olat.repository.model.RepositoryEntryLifecycle)2 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)2 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)2