Search in sources :

Example 6 with Form

use of org.olat.core.gui.components.form.flexible.impl.Form in project OpenOLAT by OpenOLAT.

the class AbstractFlexiTableRenderer method renderSortDropdown.

protected void renderSortDropdown(StringOutput sb, FlexiTableElementImpl ftE, List<FlexiTableSort> sorts) {
    Form theForm = ftE.getRootForm();
    String dispatchId = ftE.getFormDispatchId();
    sb.append("<div class='btn-group'>").append("<button id='table-button-sorters-").append(dispatchId).append("' type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown'>").append("<i class='o_icon o_icon_sort_menu o_icon-lg'> </i> <b class='caret'></b></button>").append("<div id='table-sorters-").append(dispatchId).append("' class='hide'><ul class='o_dropdown list-unstyled' role='menu'>");
    for (FlexiTableSort sort : sorts) {
        if (FlexiTableSort.SPACER.equals(sort)) {
            sb.append("<li class='divider'></li>");
        } else {
            sb.append("<li><a href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(theForm, dispatchId, 1, true, true, true, new NameValuePair("sort", sort.getSortKey().getKey()), new NameValuePair("asc", sort.getSortKey().isAsc() ? "desc" : "asc"))).append("\">");
            if (sort.isSelected()) {
                if (sort.getSortKey().isAsc()) {
                    sb.append("<i class='o_icon o_icon_sort_desc o_icon-fw'> </i> ");
                } else {
                    sb.append("<i class='o_icon o_icon_sort_asc o_icon-fw'> </i> ");
                }
            }
            sb.append(sort.getLabel()).append("</a></li>");
        }
    }
    sb.append("</ul></div></div> ").append("<script type='text/javascript'>\n").append("/* <![CDATA[ */\n").append("jQuery(function() { o_popover('table-button-sorters-").append(dispatchId).append("','table-sorters-").append(dispatchId).append("'); });\n").append("/* ]]> */\n").append("</script>");
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) Form(org.olat.core.gui.components.form.flexible.impl.Form) FlexiTableSort(org.olat.core.gui.components.form.flexible.elements.FlexiTableSort)

Example 7 with Form

use of org.olat.core.gui.components.form.flexible.impl.Form in project OpenOLAT by OpenOLAT.

the class FileElementImpl method evalFormRequest.

@Override
public void evalFormRequest(UserRequest ureq) {
    Form form = getRootForm();
    String dispatchuri = form.getRequestParameter("dispatchuri");
    if (dispatchuri != null && dispatchuri.equals(component.getFormDispatchId())) {
        if ("delete".equals(form.getRequestParameter("delete"))) {
            if (isConfirmDelete()) {
                doConfirmDelete(ureq);
            } else {
                getRootForm().fireFormEvent(ureq, new FileElementEvent(FileElementEvent.DELETE, this, FormEvent.ONCLICK));
            }
        }
    }
    Set<String> keys = form.getRequestMultipartFilesSet();
    if (keys.size() > 0 && keys.contains(component.getFormDispatchId())) {
        // Remove old files first
        if (tempUploadFile != null && tempUploadFile.exists()) {
            tempUploadFile.delete();
        }
        // Move file from a temporary request scope location to a location
        // with a
        // temporary form item scope. The file must be moved later using the
        // moveUploadFileTo() method to the final destination.
        tempUploadFile = new File(WebappHelper.getTmpDir(), CodeHelper.getUniqueID());
        File tmpRequestFile = form.getRequestMultipartFile(component.getFormDispatchId());
        // Move file to internal temp location
        boolean success = tmpRequestFile.renameTo(tempUploadFile);
        if (!success) {
            // try to move file by copying it, command above might fail
            // when source and target are on different volumes
            FileUtils.copyFileToFile(tmpRequestFile, tempUploadFile, true);
        }
        uploadFilename = form.getRequestMultipartFileName(component.getFormDispatchId());
        // prevent an issue with Firefox
        uploadFilename = FileUtils.normalizeFilenameWithSuffix(uploadFilename);
        // use mime-type from file name to have deterministic mime types
        uploadMimeType = WebappHelper.getMimeType(uploadFilename);
        if (uploadMimeType == null) {
            // use browser mime type as fallback if unknown
            uploadMimeType = form.getRequestMultipartFileMimeType(component.getFormDispatchId());
        }
        if (uploadMimeType == null) {
            // use application fallback for worst case
            uploadMimeType = "application/octet-stream";
        }
        if (previewEl != null && uploadMimeType != null && (uploadMimeType.startsWith("image/") || uploadMimeType.startsWith("video/"))) {
            VFSLeaf media = new LocalFileImpl(tempUploadFile);
            previewEl.setMedia(media, uploadMimeType);
            previewEl.setCropSelectionEnabled(cropSelectionEnabled);
            previewEl.setMaxWithAndHeightToFitWithin(300, 200);
            previewEl.setVisible(true);
        } else if (previewEl != null) {
            previewEl.setVisible(false);
        }
        // Mark associated component dirty, that it gets rerendered
        component.setDirty(true);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Form(org.olat.core.gui.components.form.flexible.impl.Form) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File)

Example 8 with Form

use of org.olat.core.gui.components.form.flexible.impl.Form in project OpenOLAT by OpenOLAT.

the class RichTextElementRenderer method render.

@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    RichTextElementComponent teC = (RichTextElementComponent) source;
    RichTextElementImpl te = teC.getRichTextElementImpl();
    // DOM ID used to identify the rich text element in the browser DOM
    String domID = teC.getFormDispatchId();
    if (!source.isEnabled()) {
        renderDisabled(sb, domID, teC);
    } else {
        sb.append("<div id='").append(domID).append("_diw' class='o_richtext_mce");
        if (!te.getEditorConfiguration().isPathInStatusBar()) {
            sb.append(" o_richtext_mce_without_path");
        }
        sb.append("'>");
        // switches
        TextMode currentTextMode;
        if (te.getEditorConfiguration().getTextModes().size() > 1) {
            TextModeState textModeState = te.getAvailableTextModes();
            currentTextMode = textModeState.getCurrentMode();
            List<TextMode> modes = textModeState.getAvailableTextModes();
            if (modes.size() > 0) {
                Form form = te.getRootForm();
                sb.append("<div class='o_richtext_mce_modes'><div class='btn-group'>");
                for (TextMode mode : modes) {
                    sb.append("<a href='javascript:;' class='btn btn-default btn-xs").append(" active", currentTextMode == mode).append("'").append(" onclick=\"").append(FormJSHelper.getXHRFnCallFor(form, teC.getFormDispatchId(), 1, false, false, true, new NameValuePair("cmd", mode.name()))).append("\">").append(source.getTranslator().translate(mode.name())).append("</a>");
                }
                sb.append("</div></div>");
            }
        } else {
            currentTextMode = TextMode.formatted;
        }
        switch(currentTextMode) {
            case formatted:
                renderTinyMCE_4(sb, domID, teC, ubu, source.getTranslator());
                break;
            case multiLine:
                renderMultiLine(sb, domID, teC);
                break;
            case oneLine:
                renderOneLine(sb, domID, teC);
                break;
        }
        sb.append("</div>");
    }
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) Form(org.olat.core.gui.components.form.flexible.impl.Form) TextModeState(org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextElementImpl.TextModeState)

Example 9 with Form

use of org.olat.core.gui.components.form.flexible.impl.Form in project OpenOLAT by OpenOLAT.

the class RichTextElementRenderer method renderTinyMCE_4.

private void renderTinyMCE_4(StringOutput sb, String domID, RichTextElementComponent teC, URLBuilder ubu, Translator translator) {
    RichTextElementImpl te = teC.getRichTextElementImpl();
    te.setRenderingMode(TextMode.formatted);
    RichTextConfiguration config = te.getEditorConfiguration();
    List<String> onInit = config.getOnInit();
    StringOutput configurations = new StringOutput();
    config.appendConfigToTinyJSArray_4(configurations, translator);
    if (config.getAdditionalConfiguration() != null) {
        config.getAdditionalConfiguration().appendConfigToTinyJSArray_4(configurations, translator);
    }
    StringOutput baseUrl = new StringOutput();
    StaticMediaDispatcher.renderStaticURI(baseUrl, "js/tinymce4/tinymce/tinymce.min.js", true);
    // Read write view
    renderTinyMCETextarea(sb, domID, teC);
    Form form = te.getRootForm();
    configurations.append("ffxhrevent: { formNam:\"").append(form.getFormName()).append("\", dispIdField:\"").append(form.getDispatchFieldId()).append("\",").append(" dispId:\"").append(teC.getFormDispatchId()).append("\", eventIdField:\"").append(form.getEventFieldId()).append("\"},\n");
    if (te.getMaxLength() > 0) {
        configurations.append("maxSize:").append(te.getMaxLength()).append("\n");
    }
    sb.append("<script type='text/javascript'>/* <![CDATA[ */\n");
    // file browser url
    sb.append("  BTinyHelper.editorMediaUris.put('").append(domID).append("','");
    ubu.buildURI(sb, null, null);
    sb.append("');\n");
    sb.append("  jQuery('#").append(domID).append("').tinymce({\n").append("    selector: '#").append(domID).append("',\n").append("    script_url: '").append(baseUrl.toString()).append("',\n").append("    setup: function(ed){\n").append("      ed.on('init', function(e) {\n").append("        ").append(onInit.get(0).replace(".curry(", "(")).append(";\n").append("      });\n").append("      ed.on('change', function(e) {\n").append("        BTinyHelper.triggerOnChange('").append(domID).append("');\n").append("      });\n");
    if (config.isSendOnBlur()) {
        sb.append("      ed.on('blur', function(e) {\n").append("        o_ffXHREvent('").append(form.getFormName()).append("','").append(form.getDispatchFieldId()).append("','").append(teC.getFormDispatchId()).append("','").append(form.getEventFieldId()).append("', 2, false, false, false, 'cmd','saveinlinedtiny','").append(domID).append("',ed.getContent());\n").append("      });\n");
    }
    sb.append("    },\n").append(configurations).append("  });\n").append("/* ]]> */</script>\n");
}
Also used : Form(org.olat.core.gui.components.form.flexible.impl.Form) StringOutput(org.olat.core.gui.render.StringOutput)

Example 10 with Form

use of org.olat.core.gui.components.form.flexible.impl.Form in project OpenOLAT by OpenOLAT.

the class StaticFlexiCellRenderer method render.

@Override
public void render(Renderer renderer, StringOutput target, Object cellValue, int row, FlexiTableComponent source, URLBuilder ubu, Translator translator) {
    String cellAction = getAction();
    if (StringHelper.containsNonWhitespace(cellAction)) {
        FlexiTableElementImpl ftE = source.getFlexiTableElement();
        String id = source.getFormDispatchId();
        Form rootForm = ftE.getRootForm();
        NameValuePair pair = new NameValuePair(cellAction, Integer.toString(row));
        String jsCode = FormJSHelper.getXHRFnCallFor(rootForm, id, 1, true, true, pair);
        target.append("<a href=\"javascript:").append(jsCode).append(";\"");
        if (StringHelper.containsNonWhitespace(linkTitle)) {
            target.append(" title=\"").append(StringEscapeUtils.escapeHtml(linkTitle)).append("\"");
        }
        if (StringHelper.containsNonWhitespace(linkCSS)) {
            target.append(" class=\"").append(linkCSS).append("\"");
        }
        target.append(">");
        if (StringHelper.containsNonWhitespace(iconLeftCSS)) {
            target.append("<i class=\"o_icon ").append(iconLeftCSS).append("\">&nbsp;</i>");
        }
        if (labelDelegate == null) {
            target.append(getLabel());
        } else {
            labelDelegate.render(renderer, target, cellValue, row, source, ubu, translator);
        }
        if (StringHelper.containsNonWhitespace(iconRightCSS)) {
            target.append(" <i class=\"o_icon ").append(iconRightCSS).append("\">&nbsp;</i>");
        }
        target.append("</a>");
    } else if (labelDelegate == null) {
        target.append(getLabel());
    } else {
        labelDelegate.render(renderer, target, cellValue, row, source, ubu, translator);
    }
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) Form(org.olat.core.gui.components.form.flexible.impl.Form)

Aggregations

Form (org.olat.core.gui.components.form.flexible.impl.Form)64 NameValuePair (org.olat.core.gui.components.form.flexible.impl.NameValuePair)42 AssessmentRenderFunctions.contentAsString (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)10 Component (org.olat.core.gui.components.Component)4 FlexiTableFilter (org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter)4 FlexiTableSort (org.olat.core.gui.components.form.flexible.elements.FlexiTableSort)4 StringOutput (org.olat.core.gui.render.StringOutput)4 TestSessionController (uk.ac.ed.ph.jqtiplus.running.TestSessionController)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 HashSet (java.util.HashSet)2 Matcher (java.util.regex.Matcher)2 SortKey (org.olat.core.commons.persistence.SortKey)2 TextBoxListElementComponent (org.olat.core.gui.components.form.flexible.impl.elements.TextBoxListElementComponent)2 TextBoxListElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.TextBoxListElementImpl)2 TextModeState (org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextElementImpl.TextModeState)2 FlexiTableElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableElementImpl)2 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)2 AJAXFlags (org.olat.core.gui.control.winmgr.AJAXFlags)2