Search in sources :

Example 1 with RichTextConfiguration

use of org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration in project OpenOLAT by OpenOLAT.

the class FeedFormController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // title might be longer from external source
    String saveTitle = PersistenceHelper.truncateStringDbSave(feed.getTitle(), 256, true);
    title = uifactory.addTextElement("title", "feed.title.label", 256, saveTitle, formLayout);
    title.setElementCssClass("o_sel_feed_title");
    title.setMandatory(true);
    title.setNotEmptyCheck("feed.form.field.is_mandatory");
    description = uifactory.addRichTextElementForStringDataMinimalistic("description", "feed.form.description", feed.getDescription(), 5, -1, formLayout, getWindowControl());
    description.setMaxLength(4000);
    RichTextConfiguration richTextConfig = description.getEditorConfiguration();
    // set upload dir to the media dir
    richTextConfig.setFileBrowserUploadRelPath("media");
    // Add a delete link and an image component to the image container.
    deleteImage = uifactory.addFormLink("feed.image.delete", formLayout, Link.BUTTON);
    deleteImage.setVisible(false);
    file = uifactory.addFileElement(getWindowControl(), "feed.file.label", formLayout);
    file.addActionListener(FormEvent.ONCHANGE);
    file.setPreview(ureq.getUserSession(), true);
    if (feed.getImageName() != null) {
        VFSLeaf imageResource = FeedManager.getInstance().createFeedMediaFile(feed, feed.getImageName(), null);
        if (imageResource instanceof LocalFileImpl) {
            file.setPreview(ureq.getUserSession(), true);
            file.setInitialFile(((LocalFileImpl) imageResource).getBasefile());
            deleteImage.setVisible(true);
        }
    }
    Set<String> mimeTypes = new HashSet<String>();
    mimeTypes.add("image/jpeg");
    mimeTypes.add("image/jpg");
    mimeTypes.add("image/png");
    mimeTypes.add("image/gif");
    file.limitToMimeType(mimeTypes, "feed.form.file.type.error.images", null);
    int maxFileSizeKB = feedQuota.getUlLimitKB().intValue();
    String supportAddr = WebappHelper.getMailConfig("mailQuota");
    file.setMaxUploadSizeKB(maxFileSizeKB, "ULLimitExceeded", new String[] { new Long(maxFileSizeKB / 1024).toString(), supportAddr });
    // if external feed, display feed-url text-element:
    if (feed.isExternal()) {
        feedUrl = uifactory.addTextElement("feedUrl", "feed.form.feedurl", 5000, feed.getExternalFeedUrl(), flc);
        feedUrl.setElementCssClass("o_sel_feed_url");
        feedUrl.setDisplaySize(70);
        String type = feed.getResourceableTypeName();
        if (type != null && type.indexOf("BLOG") >= 0) {
            feedUrl.setExampleKey("feed.form.feedurl.example", null);
        } else {
            feedUrl.setExampleKey("feed.form.feedurl.example_podcast", null);
        }
    }
    // Submit and cancelButton buttons
    final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("submit", buttonLayout);
    cancelButton = uifactory.addFormLink("cancel", buttonLayout, Link.BUTTON);
}
Also used : RichTextConfiguration(org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) HashSet(java.util.HashSet)

Example 2 with RichTextConfiguration

use of org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration in project OpenOLAT by OpenOLAT.

the class FIBEditorController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    titleEl = uifactory.addTextElement("title", "form.imd.title", -1, itemBuilder.getTitle(), formLayout);
    titleEl.setElementCssClass("o_sel_assessment_item_title");
    titleEl.setMandatory(true);
    titleEl.setEnabled(!readOnly);
    String relativePath = rootDirectory.toPath().relativize(itemFile.toPath().getParent()).toString();
    VFSContainer itemContainer = (VFSContainer) rootContainer.resolve(relativePath);
    String question = itemBuilder.getQuestion();
    textEl = uifactory.addRichTextElementForQTI21("desc", "form.imd.descr", question, 16, -1, itemContainer, formLayout, ureq.getUserSession(), getWindowControl());
    textEl.addActionListener(FormEvent.ONCLICK);
    textEl.setElementCssClass("o_sel_assessment_item_fib_text");
    RichTextConfiguration richTextConfig = textEl.getEditorConfiguration();
    richTextConfig.setReadOnly(restrictedEdit || readOnly);
    boolean hasNumericals = itemBuilder.hasNumericalInputs();
    boolean hasTexts = itemBuilder.hasTextEntry();
    if (!hasNumericals && !hasTexts) {
        if (preferredType == QTI21QuestionType.numerical) {
            hasNumericals = true;
            hasTexts = false;
        } else if (preferredType == QTI21QuestionType.fib) {
            hasNumericals = false;
            hasTexts = true;
        } else {
            hasNumericals = true;
            hasTexts = true;
        }
    }
    if (hasNumericals) {
        setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_ni");
    } else {
        setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_fib");
    }
    richTextConfig.enableQTITools(hasTexts, hasNumericals, false);
    // Submit Button
    FormLayoutContainer buttonsContainer = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonsContainer.setElementCssClass("o_sel_fib_save");
    buttonsContainer.setRootForm(mainForm);
    buttonsContainer.setVisible(!readOnly);
    formLayout.add(buttonsContainer);
    uifactory.addFormSubmitButton("submit", buttonsContainer);
}
Also used : RichTextConfiguration(org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration) VFSContainer(org.olat.core.util.vfs.VFSContainer) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 3 with RichTextConfiguration

use of org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration in project OpenOLAT by OpenOLAT.

the class SectionController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("fieldset.legend.sectionsettings");
    setFormContextHelp("Test and Questionnaire Editor in Detail#details_testeditor_test_konf");
    String title = section.getTitle();
    titleEl = uifactory.addTextElement("title", "form.metadata.title", 255, title, formLayout);
    String objectives = section.getObjectives();
    objectivesEl = uifactory.addRichTextElementForStringData("objectives", "form.metadata.objectives", objectives, 6, 12, false, qtiPackage.getBaseDir(), null, formLayout, ureq.getUserSession(), getWindowControl());
    objectivesEl.getEditorConfiguration().setFigCaption(false);
    RichTextConfiguration richTextConfig = objectivesEl.getEditorConfiguration();
    // disable <p> element for enabling vertical layouts
    richTextConfig.disableRootParagraphElement();
    // set upload dir to the media dir
    richTextConfig.setFileBrowserUploadRelPath("media");
    // manually enable the source edit button
    richTextConfig.enableCode();
    // allow script tags...
    richTextConfig.setInvalidElements(RichTextConfiguration.INVALID_ELEMENTS_FORM_FULL_VALUE_UNSAVE_WITH_SCRIPT);
    richTextConfig.setExtendedValidElements("script[src,type,defer]");
    // form.section.durationswitch
    String[] yesnoValues = new String[] { translate("yes"), translate("no") };
    limitTimeEl = uifactory.addRadiosHorizontal("form.section.durationswitch", formLayout, yesnoKeys, yesnoValues);
    limitTimeEl.addActionListener(FormEvent.ONCHANGE);
    limitTimeEl.setEnabled(!restrictedEdit);
    timeMinEl = uifactory.addIntegerElement("form.imd.time.min", 0, formLayout);
    timeMinEl.setDisplaySize(3);
    timeMinEl.setEnabled(!restrictedEdit);
    timeSecEl = uifactory.addIntegerElement("form.imd.time.sek", 0, formLayout);
    timeSecEl.setDisplaySize(3);
    timeSecEl.setEnabled(!restrictedEdit);
    if (section.getDuration() != null && section.getDuration().isSet()) {
        limitTimeEl.select(yesnoKeys[0], true);
        timeMinEl.setIntValue(section.getDuration().getMin());
        timeSecEl.setIntValue(section.getDuration().getSec());
    } else {
        limitTimeEl.select(yesnoKeys[1], true);
        timeMinEl.setVisible(false);
        timeSecEl.setVisible(false);
    }
    // ordering
    boolean random = SelectionOrdering.RANDOM.equals(section.getSelection_ordering().getOrderType());
    shuffleEl = uifactory.addRadiosHorizontal("shuffle", "form.section.shuffle", formLayout, yesnoKeys, yesnoValues);
    shuffleEl.addActionListener(FormEvent.ONCHANGE);
    shuffleEl.setEnabled(!restrictedEdit);
    if (random) {
        shuffleEl.select(yesnoKeys[0], true);
    } else {
        shuffleEl.select(yesnoKeys[1], true);
    }
    int numOfItems = section.getItems().size();
    String[] theKeys = new String[numOfItems + 1];
    String[] theValues = new String[numOfItems + 1];
    theKeys[0] = "0";
    theValues[0] = translate("form.section.selection_all");
    for (int i = 0; i < numOfItems; i++) {
        theKeys[i + 1] = Integer.toString(i + 1);
        theValues[i + 1] = Integer.toString(i + 1);
    }
    selectionNumEl = uifactory.addDropdownSingleselect("selection.num", "form.section.selection_pre", formLayout, theKeys, theValues, null);
    selectionNumEl.setHelpText(translate("form.section.selection_pre.hover"));
    selectionNumEl.setEnabled(!restrictedEdit);
    int selectionNum = section.getSelection_ordering().getSelectionNumber();
    if (selectionNum <= 0) {
        selectionNumEl.select(theKeys[0], true);
    } else if (selectionNum > 0 && selectionNum < theKeys.length) {
        selectionNumEl.select(theKeys[selectionNum], true);
    } else {
        selectionNumEl.select(theKeys[theKeys.length - 1], true);
    }
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    formLayout.add(buttonsCont);
    uifactory.addFormSubmitButton("submit", buttonsCont);
}
Also used : RichTextConfiguration(org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 4 with RichTextConfiguration

use of org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration in project OpenOLAT by OpenOLAT.

the class ItemMetadataFormController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("fieldset.legend.metadata");
    int t = item.getQuestion().getType();
    if (!isSurvey && t == Question.TYPE_ESSAY) {
        setFormWarning("warning.essay.test");
    }
    if (isSurvey) {
        setFormContextHelp("Test and Questionnaire Editor in Detail#details_testeditor_test_konf_frage");
    } else {
        setFormContextHelp("Test and Questionnaire Editor in Detail#details_testeditor_test_konf_frage");
    }
    // Title
    title = uifactory.addTextElement("title", "form.imd.title", -1, item.getTitle(), formLayout);
    title.setMandatory(true);
    title.setNotEmptyCheck("form.imd.error.empty.title");
    // Question Type
    String typeName = getType();
    uifactory.addStaticTextElement("type", "form.imd.type", typeName, formLayout);
    // Description
    desc = uifactory.addRichTextElementForStringData("desc", "form.imd.descr", item.getObjectives(), 8, -1, true, null, null, formLayout, ureq.getUserSession(), getWindowControl());
    desc.getEditorConfiguration().setFigCaption(false);
    RichTextConfiguration richTextConfig = desc.getEditorConfiguration();
    // set upload dir to the media dir
    richTextConfig.setFileBrowserUploadRelPath("media");
    // Layout/Alignment
    Question q = item.getQuestion();
    // alignment of KPRIM is only horizontal
    if (q instanceof ChoiceQuestion && item.getQuestion().getType() != Question.TYPE_KPRIM) {
        String[] layoutKeys = new String[] { "h", "v" };
        String[] layoutValues = new String[] { translate("form.imd.layout.horizontal"), translate("form.imd.layout.vertical") };
        // layout = uifactory.addDropdownSingleselect("form.imd.layout", formLayout, layoutKeys, layoutValues, null);
        layout = uifactory.addRadiosHorizontal("layout", "form.imd.layout", formLayout, layoutKeys, layoutValues);
        layout.select(((ChoiceQuestion) q).getFlowLabelClass().equals(ChoiceQuestion.BLOCK) ? "h" : "v", true);
    }
    if (!isSurvey) {
        String[] yesnoKeys = new String[] { "y", "n" };
        String[] yesnoValues = new String[] { translate("yes"), translate("no") };
        // Attempts
        limitAttempts = uifactory.addRadiosHorizontal("form.imd.limittries", formLayout, yesnoKeys, yesnoValues);
        limitAttempts.setEnabled(!isRestrictedEditMode);
        // Radios/Checkboxes need onclick because of IE bug OLAT-5753
        limitAttempts.addActionListener(FormEvent.ONCLICK);
        attempts = uifactory.addIntegerElement("form.imd.tries", 0, formLayout);
        attempts.setEnabled(!isRestrictedEditMode);
        attempts.setDisplaySize(3);
        if (item.getMaxattempts() > 0) {
            limitAttempts.select("y", true);
            attempts.setIntValue(item.getMaxattempts());
        } else {
            limitAttempts.select("n", true);
            attempts.setVisible(false);
        }
        // Time Limit
        limitTime = uifactory.addRadiosHorizontal("form.imd.limittime", formLayout, yesnoKeys, yesnoValues);
        // Radios/Checkboxes need onclick because of IE bug OLAT-5753
        limitTime.addActionListener(FormEvent.ONCLICK);
        limitTime.setEnabled(!isRestrictedEditMode);
        timeMin = uifactory.addIntegerElement("form.imd.time.min", 0, formLayout);
        timeMin.setEnabled(!isRestrictedEditMode);
        timeMin.setDisplaySize(3);
        timeSec = uifactory.addIntegerElement("form.imd.time.sek", 0, formLayout);
        timeSec.setEnabled(!isRestrictedEditMode);
        timeSec.setDisplaySize(3);
        if (item.getDuration() != null && item.getDuration().isSet()) {
            limitTime.select("y", true);
            timeMin.setIntValue(item.getDuration().getMin());
            timeSec.setIntValue(item.getDuration().getSec());
        } else {
            limitTime.select("n", true);
            timeMin.setVisible(false);
            timeSec.setVisible(false);
        }
        // Shuffle Answers
        shuffle = uifactory.addRadiosHorizontal("shuffle", "form.imd.shuffle", formLayout, yesnoKeys, yesnoValues);
        shuffle.setEnabled(!isRestrictedEditMode);
        shuffle.setVisible(t != Question.TYPE_ESSAY && t != Question.TYPE_FIB);
        if (item.getQuestion().isShuffle()) {
            shuffle.select("y", true);
        } else {
            shuffle.select("n", true);
        }
        // Hints
        Control itemControl = item.getItemcontrols().get(0);
        showHints = uifactory.addRadiosHorizontal("showHints", "form.imd.solutionhints.show", formLayout, yesnoKeys, yesnoValues);
        showHints.setEnabled(!isRestrictedEditMode);
        // Radios/Checkboxes need onclick because of IE bug OLAT-5753
        showHints.addActionListener(FormEvent.ONCLICK);
        showHints.setVisible(t != Question.TYPE_ESSAY);
        hint = uifactory.addRichTextElementForStringData("hint", "form.imd.solutionhints", item.getQuestion().getHintText(), 8, -1, true, qti.getBaseDir(), null, formLayout, ureq.getUserSession(), getWindowControl());
        hint.setEnabled(!isRestrictedEditMode);
        hint.getEditorConfiguration().setFigCaption(false);
        // set upload dir to the media dir
        hint.getEditorConfiguration().setFileBrowserUploadRelPath("media");
        if (itemControl.isHint()) {
            showHints.select("y", true);
        } else {
            showHints.select("n", true);
            hint.setVisible(false);
        }
        // Solution
        showSolution = uifactory.addRadiosHorizontal("showSolution", "form.imd.correctsolution.show", formLayout, yesnoKeys, yesnoValues);
        showSolution.setEnabled(!isRestrictedEditMode);
        // Radios/Checkboxes need onclick because of IE bug OLAT-5753
        showSolution.addActionListener(FormEvent.ONCLICK);
        boolean essay = (q.getType() == Question.TYPE_ESSAY);
        String solLabel = essay ? "form.imd.correctsolution.word" : "form.imd.correctsolution";
        solution = uifactory.addRichTextElementForStringData("solution", solLabel, item.getQuestion().getSolutionText(), 8, -1, true, qti.getBaseDir(), null, formLayout, ureq.getUserSession(), getWindowControl());
        solution.setEnabled(!isRestrictedEditMode);
        solution.getEditorConfiguration().setFigCaption(false);
        // set upload dir to the media dir
        solution.getEditorConfiguration().setFileBrowserUploadRelPath("media");
        if (itemControl.isSolution()) {
            showSolution.select("y", true);
        } else {
            showSolution.select("n", true);
            showSolution.setVisible(!essay);
            // solution always visible for essay
            solution.setVisible(essay);
        }
    }
    // Submit Button
    uifactory.addFormSubmitButton("submit", formLayout);
}
Also used : RichTextConfiguration(org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration) WindowControl(org.olat.core.gui.control.WindowControl) Control(org.olat.ims.qti.editor.beecom.objects.Control) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)

Example 5 with RichTextConfiguration

use of org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration in project OpenOLAT by OpenOLAT.

the class InfoMsgForm method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    msg = uifactory.addRichTextElementForStringData("msg", "infomsg", infomsg, 20, 70, true, staticFolderMgr.getRootContainer(), null, formLayout, ureq.getUserSession(), getWindowControl());
    msg.setMaxLength(1024);
    RichTextConfiguration richTextConfig = msg.getEditorConfiguration();
    // manually enable the source edit button
    richTextConfig.enableCode();
    // allow script tags...
    richTextConfig.setInvalidElements(RichTextConfiguration.INVALID_ELEMENTS_FORM_FULL_VALUE_UNSAVE_WITH_SCRIPT);
    richTextConfig.setExtendedValidElements("script[src,type,defer]");
    // add style buttons to make alert style available
    richTextConfig.setContentCSSFromTheme(getWindowControl().getWindowBackOffice().getWindow().getGuiTheme());
    String path = Settings.getServerContextPath() + "/raw/static/";
    richTextConfig.setLinkBrowserAbsolutFilePath(path);
    FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
    formLayout.add(buttonGroupLayout);
    uifactory.addFormSubmitButton("submit", "submit", buttonGroupLayout);
    uifactory.addFormCancelButton("cancel", buttonGroupLayout, ureq, getWindowControl());
}
Also used : RichTextConfiguration(org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Aggregations

RichTextConfiguration (org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration)20 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)12 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 File (java.io.File)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)2 WindowControl (org.olat.core.gui.control.WindowControl)2 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)2 Control (org.olat.ims.qti.editor.beecom.objects.Control)2 Question (org.olat.ims.qti.editor.beecom.objects.Question)2