use of org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration in project openolat by klemens.
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);
}
use of org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration in project openolat by klemens.
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);
}
use of org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration in project openolat by klemens.
the class HottextEditorController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_hot");
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.setElementCssClass("o_sel_assessment_item_hottext_text");
textEl.addActionListener(FormEvent.ONCLICK);
RichTextConfiguration richTextConfig = textEl.getEditorConfiguration();
richTextConfig.enableQTITools(false, false, true);
richTextConfig.setAdditionalConfiguration(new CorrectAnswersConfiguration());
richTextConfig.setReadOnly(restrictedEdit || readOnly);
// Submit Button
FormLayoutContainer buttonsContainer = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonsContainer.setElementCssClass("o_sel_hottext_save");
buttonsContainer.setRootForm(mainForm);
buttonsContainer.setVisible(!readOnly);
formLayout.add(buttonsContainer);
uifactory.addFormSubmitButton("submit", buttonsContainer);
}
use of org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration in project OpenOLAT by OpenOLAT.
the class ItemFormController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_feed_form");
title = uifactory.addTextElement("title", "feed.title.label", 256, item.getTitle(), this.flc);
title.setElementCssClass("o_sel_feed_title");
title.setMandatory(true);
title.setNotEmptyCheck("feed.form.field.is_mandatory");
description = uifactory.addRichTextElementForStringData("description", "feed.form.description", item.getDescription(), 12, -1, false, baseDir, null, formLayout, ureq.getUserSession(), getWindowControl());
RichTextConfiguration descRichTextConfig = description.getEditorConfiguration();
// set upload dir to the media dir
descRichTextConfig.setFileBrowserUploadRelPath("media");
// disable XSS unsave buttons for movie (no media in standard profile)
descRichTextConfig.disableMedia();
content = uifactory.addRichTextElementForStringData("content", "feed.form.content", item.getContent(), 18, -1, false, baseDir, null, formLayout, ureq.getUserSession(), getWindowControl());
RichTextConfiguration richTextConfig = content.getEditorConfiguration();
// set upload dir to the media dir
richTextConfig.setFileBrowserUploadRelPath("media");
// disable XSS unsave buttons for movie (no media in standard profile)
richTextConfig.disableMedia();
content.setVisible(hasContent());
file = uifactory.addFileElement(getWindowControl(), "file", flc);
file.setLabel("feed.item.file.label", null);
if (hasMandatoryMedia()) {
file.setMandatory(true, "feed.item.file.mandatory");
} else {
file.setDeleteEnabled(true);
}
File mediaFile = FeedManager.getInstance().loadItemEnclosureFile(item);
file.setInitialFile(mediaFile);
file.addActionListener(FormEvent.ONCHANGE);
if (baseDir.getLocalSecurityCallback() != null && baseDir.getLocalSecurityCallback().getQuota() != null) {
Long uploadLimitKB = baseDir.getLocalSecurityCallback().getQuota().getUlLimitKB();
String supportAddr = WebappHelper.getMailConfig("mailQuota");
file.setMaxUploadSizeKB(uploadLimitKB.intValue(), "ULLimitExceeded", new String[] { Formatter.roundToString((uploadLimitKB.floatValue() / 1000f), 1), supportAddr });
}
String width = item.getWidth() != null && item.getWidth() > 0 ? Integer.toString(item.getWidth()) : "";
widthEl = uifactory.addTextElement("video-width", "feed.item.file.width", 12, width, flc);
String height = item.getHeight() != null && item.getHeight() > 0 ? Integer.toString(item.getHeight()) : "";
heightEl = uifactory.addTextElement("video-height", "feed.item.file.height", 12, height, flc);
Calendar cal = Calendar.getInstance(ureq.getLocale());
if (item.getPublishDate() != null) {
cal.setTime(item.getPublishDate());
}
publishDateChooser = uifactory.addDateChooser("publishDateChooser", "feed.publish.date", cal.getTime(), formLayout);
publishDateChooser.setNotEmptyCheck("feed.publish.date.is.required");
publishDateChooser.setValidDateCheck("feed.publish.date.invalid");
publishDateChooser.setDateChooserTimeEnabled(true);
publishDateChooser.setVisible(hasDraftMode());
final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
this.flc.add(buttonLayout);
uifactory.addFormSubmitButton("feed.publish", buttonLayout);
if (hasDraftMode()) {
draftButton = uifactory.addFormLink("feed.save.as.draft", buttonLayout, Link.BUTTON);
draftButton.addActionListener(FormEvent.ONCLICK);
}
cancelButton = uifactory.addFormLink("cancel", buttonLayout, Link.BUTTON);
}
use of org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration in project OpenOLAT by OpenOLAT.
the class HTMLEditorController 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) {
if (fileToLargeError != null) {
VelocityContainer vc = (VelocityContainer) formLayout.getComponent();
vc.contextPut("fileToLargeError", fileToLargeError);
} else {
htmlElement = uifactory.addRichTextElementForFileData("rtfElement", null, body, -1, -1, baseContainer, fileName, customLinkTreeModel, formLayout, ureq.getUserSession(), getWindowControl());
//
// Add resize handler
RichTextConfiguration editorConfiguration = htmlElement.getEditorConfiguration();
editorConfiguration.addOnInitCallbackFunction("b_resizetofit_htmleditor");
editorConfiguration.enableEditorHeight();
if (StringHelper.containsNonWhitespace(mediaPath)) {
editorConfiguration.setFileBrowserUploadRelPath(mediaPath);
}
// The buttons
if (buttonsEnabled) {
save = uifactory.addFormLink("savebuttontext", formLayout, Link.BUTTON);
cancel = uifactory.addFormCancelButton("cancel", formLayout, ureq, getWindowControl());
saveClose = uifactory.addFormLink("saveandclosebuttontext", formLayout, Link.BUTTON);
}
// Add some file metadata
VelocityContainer vc = (VelocityContainer) formLayout.getComponent();
metadataVC = createVelocityContainer("metadata");
vc.put("metadata", metadataVC);
long lm = fileLeaf.getLastModified();
metadataVC.contextPut("lastModified", Formatter.getInstance(ureq.getLocale()).formatDateAndTime(new Date(lm)));
metadataVC.contextPut("charSet", charSet);
metadataVC.contextPut("fileName", fileName);
}
}
Aggregations