Search in sources :

Example 6 with FileElement

use of org.olat.core.gui.components.form.flexible.elements.FileElement in project OpenOLAT by OpenOLAT.

the class EvaluationFormController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (saveAsDoneButton == source) {
        doConfirmDone(ureq);
    } else if (source instanceof SingleSelection) {
        SingleSelection radioEl = (SingleSelection) source;
        Object uobject = radioEl.getUserObject();
        if (uobject instanceof SliderWrapper) {
            String selectedKey = radioEl.getSelectedKey();
            SliderWrapper sliderWrapper = (SliderWrapper) uobject;
            saveNumericalResponse(new BigDecimal(selectedKey), selectedKey, sliderWrapper.getId());
        }
    } else if (source instanceof SliderElement) {
        SliderElement slider = (SliderElement) source;
        Object uobject = slider.getUserObject();
        if (uobject instanceof SliderWrapper) {
            double value = slider.getValue();
            SliderWrapper sliderWrapper = (SliderWrapper) uobject;
            saveNumericalResponse(BigDecimal.valueOf(value), Double.toString(value), sliderWrapper.getId());
        }
    } else if (source instanceof FormLink) {
        FormLink link = (FormLink) source;
        Object uobject = link.getUserObject();
        if (uobject instanceof TextInputWrapper) {
            TextInputWrapper wrapper = (TextInputWrapper) uobject;
            String value = wrapper.getTextEl().getValue();
            saveNumericalResponse(null, value, wrapper.getId());
        }
    } else if (source instanceof FileElement) {
        FileElement fileElement = (FileElement) source;
        Object uobject = fileElement.getUserObject();
        if (uobject instanceof FileUploadWrapper) {
            FileUploadWrapper wrapper = (FileUploadWrapper) uobject;
            if (event instanceof FileElementEvent) {
                if (FileElementEvent.DELETE.equals(event.getCommand())) {
                    saveFileResponse(null, null, wrapper.getId());
                    fileElement.setInitialFile(null);
                    if (fileElement.getUploadFile() != null) {
                        fileElement.reset();
                    }
                    flc.setDirty(true);
                }
            } else if (fileElement.isUploadSuccess()) {
                File file = fileElement.getUploadFile();
                String filename = fileElement.getUploadFileName();
                saveFileResponse(file, filename, wrapper.getId());
            }
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : TextInputWrapper(org.olat.modules.forms.ui.model.TextInputWrapper) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) FileUploadWrapper(org.olat.modules.forms.ui.model.FileUploadWrapper) FileElementEvent(org.olat.core.gui.components.form.flexible.impl.elements.FileElementEvent) BigDecimal(java.math.BigDecimal) SliderWrapper(org.olat.modules.forms.ui.model.SliderWrapper) SliderElement(org.olat.core.gui.components.form.flexible.elements.SliderElement) FileElement(org.olat.core.gui.components.form.flexible.elements.FileElement) File(java.io.File)

Example 7 with FileElement

use of org.olat.core.gui.components.form.flexible.elements.FileElement in project openolat by klemens.

the class EvaluationFormController method forgeFileUpload.

private EvaluationFormElementWrapper forgeFileUpload(UserRequest ureq, FileUpload element) {
    FileElement fileEl = uifactory.addFileElement(getWindowControl(), "file_upload_" + CodeHelper.getRAMUniqueID(), "", flc);
    fileEl.setPreview(ureq.getUserSession(), true);
    fileEl.addActionListener(FormEvent.ONCHANGE);
    fileEl.setDeleteEnabled(true);
    fileEl.setMaxUploadSizeKB(element.getMaxUploadSizeKB(), "file.upload.error.limit.exeeded", null);
    Set<String> mimeTypes = MimeTypeSetFactory.getMimeTypes(element.getMimeTypeSetKey());
    fileEl.limitToMimeType(mimeTypes, "file.upload.error.mime.type.wrong", null);
    EvaluationFormResponse response = identifierToResponses.get(element.getId());
    File responseFile = evaluationFormManager.loadResponseFile(response);
    if (responseFile != null) {
        fileEl.setInitialFile(responseFile);
    }
    fileEl.setEnabled(!readOnly);
    FileUploadWrapper fileUploadWrapper = new FileUploadWrapper(fileEl, element);
    fileEl.setUserObject(fileUploadWrapper);
    EvaluationFormElementWrapper wrapper = new EvaluationFormElementWrapper(element);
    wrapper.setFileUploadWrapper(fileUploadWrapper);
    return wrapper;
}
Also used : EvaluationFormElementWrapper(org.olat.modules.forms.ui.model.EvaluationFormElementWrapper) FileElement(org.olat.core.gui.components.form.flexible.elements.FileElement) EvaluationFormResponse(org.olat.modules.forms.EvaluationFormResponse) FileUploadWrapper(org.olat.modules.forms.ui.model.FileUploadWrapper) File(java.io.File)

Example 8 with FileElement

use of org.olat.core.gui.components.form.flexible.elements.FileElement in project openolat by klemens.

the class FormUIFactory method addFileElement.

/**
 * Add a file upload element
 * @param name
 * @param i18nKey
 * @param formLayout
 * @return
 */
public FileElement addFileElement(WindowControl wControl, String name, String i18nLabel, FormItemContainer formLayout) {
    FileElement fileElement = new FileElementImpl(wControl, name);
    setLabelIfNotNull(i18nLabel, fileElement);
    formLayout.add(fileElement);
    return fileElement;
}
Also used : FileElementImpl(org.olat.core.gui.components.form.flexible.impl.elements.FileElementImpl) FileElement(org.olat.core.gui.components.form.flexible.elements.FileElement)

Aggregations

FileElement (org.olat.core.gui.components.form.flexible.elements.FileElement)8 File (java.io.File)4 FileUploadWrapper (org.olat.modules.forms.ui.model.FileUploadWrapper)4 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Dated (org.olat.core.commons.controllers.navigation.Dated)2 NavigationEvent (org.olat.core.commons.controllers.navigation.NavigationEvent)2 UserCommentsAndRatingsController (org.olat.core.commons.services.commentAndRating.ui.UserCommentsAndRatingsController)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 SliderElement (org.olat.core.gui.components.form.flexible.elements.SliderElement)2 FileElementEvent (org.olat.core.gui.components.form.flexible.impl.elements.FileElementEvent)2 FileElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.FileElementImpl)2 Link (org.olat.core.gui.components.link.Link)2 DialogBoxController (org.olat.core.gui.control.generic.modal.DialogBoxController)2 ContextEntry (org.olat.core.id.context.ContextEntry)2 EvaluationFormResponse (org.olat.modules.forms.EvaluationFormResponse)2 EvaluationFormElementWrapper (org.olat.modules.forms.ui.model.EvaluationFormElementWrapper)2 SliderWrapper (org.olat.modules.forms.ui.model.SliderWrapper)2 TextInputWrapper (org.olat.modules.forms.ui.model.TextInputWrapper)2