Search in sources :

Example 6 with FileUploadController

use of org.olat.core.commons.modules.bc.FileUploadController in project OpenOLAT by OpenOLAT.

the class LinkFileCombiCalloutController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (combiWindowController == source) {
        doOpenFileChanger(ureq, event.getCommand());
    } else if (source instanceof FileChooserController) {
        // catch the events from the file chooser controller here
        if (event instanceof FileChoosenEvent) {
            FileChoosenEvent fce = (FileChoosenEvent) event;
            file = (VFSLeaf) FileChooserUIFactory.getSelectedItem(fce);
            relFilPathIsProposal = false;
            setRelFilePath(FileChooserUIFactory.getSelectedRelativeItemPath(fce, baseContainer, null));
            fireEvent(ureq, Event.DONE_EVENT);
        } else if (event == Event.FAILED_EVENT) {
        // selection failed for unknown reason
        } else if (event == Event.CANCELLED_EVENT) {
        // nothing to do
        }
        cleanupModal(true);
    } else if (source instanceof FileUploadController) {
        if (event == Event.DONE_EVENT) {
            FileUploadController uploadCtr = (FileUploadController) source;
            VFSLeaf newFile = uploadCtr.getUploadedFile();
            if (newFile.getName().toLowerCase().endsWith("zip")) {
                // Cleanup modal first
                cleanupModal(true);
                // Unzip file and open file chooser in new modal
                VFSContainer zipContainer = doUnzip(newFile, newFile.getParentContainer());
                if (zipContainer != null) {
                    FileChooserController fileChooserCtr = FileChooserUIFactory.createFileChooserController(ureq, getWindowControl(), zipContainer, null, true);
                    fileChooserCtr.setShowTitle(true);
                    displayModal(fileChooserCtr);
                    return;
                }
            } else {
                // All other files
                file = uploadCtr.getUploadedFile();
                relFilPathIsProposal = false;
                setRelFilePath(VFSManager.getRelativeItemPath(file, baseContainer, null));
                fireEvent(ureq, Event.DONE_EVENT);
            }
        } else if (event.getCommand().equals(FolderEvent.UPLOAD_EVENT)) {
            // Do nothing, ignore this internal event. When finished, done is fired
            return;
        } else if (event == Event.CANCELLED_EVENT) {
        // nothing to do
        }
        cleanupModal(true);
    } else if (source instanceof HTMLEditorController) {
        if (event == Event.DONE_EVENT) {
            relFilPathIsProposal = false;
            editLink.setCustomDisplayText(translate("command.edit"));
            fireEvent(ureq, Event.DONE_EVENT);
        } else if (event == Event.CANCELLED_EVENT) {
        // nothing to do
        }
        cleanupModal(true);
        updateLinks();
    } else if (source instanceof FileCreatorController) {
        if (event == Event.DONE_EVENT) {
            FileCreatorController createCtr = (FileCreatorController) source;
            file = createCtr.getCreatedFile();
            relFilPathIsProposal = false;
            setRelFilePath(VFSManager.getRelativeItemPath(file, baseContainer, null));
            fireEvent(ureq, Event.DONE_EVENT);
            cleanupModal(true);
            // Now open html editor
            doOpenWysiwygEditor(ureq);
        } else if (event == Event.CANCELLED_EVENT) {
            cleanupModal(true);
        }
    } else if (source == cmc && event == CloseableModalController.CLOSE_MODAL_EVENT) {
        // User closed dialog, same as cancel in a sub-controller
        cleanupModal(false);
    } else if (source == previewLayoutCtr && event == Event.BACK_EVENT) {
        removeAsListenerAndDispose(previewLayoutCtr);
    }
    super.event(ureq, source, event);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HTMLEditorController(org.olat.core.commons.editor.htmleditor.HTMLEditorController) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileUploadController(org.olat.core.commons.modules.bc.FileUploadController)

Example 7 with FileUploadController

use of org.olat.core.commons.modules.bc.FileUploadController in project openolat by klemens.

the class LinkFileCombiCalloutController method doOpenFileChanger.

public void doOpenFileChanger(UserRequest ureq, String tool) {
    // close callout and open appropriate file changer controller
    calloutCtr.deactivate();
    Controller toolCtr = null;
    if (tool.equals("chooseLink")) {
        VFSItemFilter filter = new SystemItemFilter();
        FileChooserController fileChooserCtr = FileChooserUIFactory.createFileChooserController(ureq, getWindowControl(), baseContainer, filter, true);
        fileChooserCtr.setShowTitle(true);
        fileChooserCtr.selectPath(relFilePath);
        toolCtr = fileChooserCtr;
    }
    if (tool.equals("createLink")) {
        String folderPath = null;
        if (StringHelper.containsNonWhitespace(relFilePath)) {
            // remove file name from relFilePath to represent directory path
            folderPath = relFilePath.substring(0, relFilePath.lastIndexOf("/"));
        }
        toolCtr = new FileCreatorController(ureq, getWindowControl(), baseContainer, folderPath);
    }
    if (tool.equals("uploadLink")) {
        long quotaLeftKB = VFSManager.getQuotaLeftKB(baseContainer);
        String folderPath = null;
        if (StringHelper.containsNonWhitespace(relFilePath)) {
            // remove file name from relFilePath to represent directory path
            folderPath = relFilePath.substring(0, relFilePath.lastIndexOf("/"));
        }
        toolCtr = new FileUploadController(getWindowControl(), baseContainer, ureq, quotaLeftKB, quotaLeftKB, null, false, true, false, false, true, true, folderPath);
    }
    displayModal(toolCtr);
}
Also used : VFSItemFilter(org.olat.core.util.vfs.filters.VFSItemFilter) FileUploadController(org.olat.core.commons.modules.bc.FileUploadController) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) LayoutMain3ColsPreviewController(org.olat.core.commons.fullWebApp.LayoutMain3ColsPreviewController) HTMLEditorController(org.olat.core.commons.editor.htmleditor.HTMLEditorController) Controller(org.olat.core.gui.control.Controller) BasicController(org.olat.core.gui.control.controller.BasicController) SinglePageController(org.olat.core.commons.modules.singlepage.SinglePageController) CloseableCalloutWindowController(org.olat.core.gui.control.generic.closablewrapper.CloseableCalloutWindowController) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) FileUploadController(org.olat.core.commons.modules.bc.FileUploadController)

Example 8 with FileUploadController

use of org.olat.core.commons.modules.bc.FileUploadController in project openolat by klemens.

the class LinkFileCombiCalloutController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (combiWindowController == source) {
        doOpenFileChanger(ureq, event.getCommand());
    } else if (source instanceof FileChooserController) {
        // catch the events from the file chooser controller here
        if (event instanceof FileChoosenEvent) {
            FileChoosenEvent fce = (FileChoosenEvent) event;
            file = (VFSLeaf) FileChooserUIFactory.getSelectedItem(fce);
            relFilPathIsProposal = false;
            setRelFilePath(FileChooserUIFactory.getSelectedRelativeItemPath(fce, baseContainer, null));
            fireEvent(ureq, Event.DONE_EVENT);
        } else if (event == Event.FAILED_EVENT) {
        // selection failed for unknown reason
        } else if (event == Event.CANCELLED_EVENT) {
        // nothing to do
        }
        cleanupModal(true);
    } else if (source instanceof FileUploadController) {
        if (event == Event.DONE_EVENT) {
            FileUploadController uploadCtr = (FileUploadController) source;
            VFSLeaf newFile = uploadCtr.getUploadedFile();
            if (newFile.getName().toLowerCase().endsWith("zip")) {
                // Cleanup modal first
                cleanupModal(true);
                // Unzip file and open file chooser in new modal
                VFSContainer zipContainer = doUnzip(newFile, newFile.getParentContainer());
                if (zipContainer != null) {
                    FileChooserController fileChooserCtr = FileChooserUIFactory.createFileChooserController(ureq, getWindowControl(), zipContainer, null, true);
                    fileChooserCtr.setShowTitle(true);
                    displayModal(fileChooserCtr);
                    return;
                }
            } else {
                // All other files
                file = uploadCtr.getUploadedFile();
                relFilPathIsProposal = false;
                setRelFilePath(VFSManager.getRelativeItemPath(file, baseContainer, null));
                fireEvent(ureq, Event.DONE_EVENT);
            }
        } else if (event.getCommand().equals(FolderEvent.UPLOAD_EVENT)) {
            // Do nothing, ignore this internal event. When finished, done is fired
            return;
        } else if (event == Event.CANCELLED_EVENT) {
        // nothing to do
        }
        cleanupModal(true);
    } else if (source instanceof HTMLEditorController) {
        if (event == Event.DONE_EVENT) {
            relFilPathIsProposal = false;
            editLink.setCustomDisplayText(translate("command.edit"));
            fireEvent(ureq, Event.DONE_EVENT);
        } else if (event == Event.CANCELLED_EVENT) {
        // nothing to do
        }
        cleanupModal(true);
        updateLinks();
    } else if (source instanceof FileCreatorController) {
        if (event == Event.DONE_EVENT) {
            FileCreatorController createCtr = (FileCreatorController) source;
            file = createCtr.getCreatedFile();
            relFilPathIsProposal = false;
            setRelFilePath(VFSManager.getRelativeItemPath(file, baseContainer, null));
            fireEvent(ureq, Event.DONE_EVENT);
            cleanupModal(true);
            // Now open html editor
            doOpenWysiwygEditor(ureq);
        } else if (event == Event.CANCELLED_EVENT) {
            cleanupModal(true);
        }
    } else if (source == cmc && event == CloseableModalController.CLOSE_MODAL_EVENT) {
        // User closed dialog, same as cancel in a sub-controller
        cleanupModal(false);
    } else if (source == previewLayoutCtr && event == Event.BACK_EVENT) {
        removeAsListenerAndDispose(previewLayoutCtr);
    }
    super.event(ureq, source, event);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HTMLEditorController(org.olat.core.commons.editor.htmleditor.HTMLEditorController) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileUploadController(org.olat.core.commons.modules.bc.FileUploadController)

Example 9 with FileUploadController

use of org.olat.core.commons.modules.bc.FileUploadController in project openolat by klemens.

the class CmdUpload method execute.

public Controller execute(FolderComponent folderComponent, UserRequest ureq, Translator trans, boolean cancelResetsButton) {
    this.cancelResetsForm = cancelResetsButton;
    setTranslator(trans);
    currentContainer = folderComponent.getCurrentContainer();
    if (currentContainer.canWrite() != VFSConstants.YES)
        throw new AssertException("Cannot write to selected folder.");
    // mainVC is the main view
    mainVC = createVelocityContainer("upload");
    // Add progress bar
    ubar = new ProgressBar("ubar");
    ubar.setWidth(200);
    ubar.setUnitLabel("MB");
    ubar.setRenderLabelRights(true);
    mainVC.put(ubar.getComponentName(), ubar);
    // Calculate quota and limits
    long actualUsage = 0;
    quotaKB = Quota.UNLIMITED;
    uploadLimitKB = Quota.UNLIMITED;
    inheritingContainer = VFSManager.findInheritingSecurityCallbackContainer(currentContainer);
    if (inheritingContainer != null) {
        secCallback = inheritingContainer.getLocalSecurityCallback();
        actualUsage = VFSManager.getUsageKB(inheritingContainer);
        ubar.setActual(actualUsage / 1024);
        if (inheritingContainer.getLocalSecurityCallback().getQuota() != null) {
            quotaKB = secCallback.getQuota().getQuotaKB().longValue();
            uploadLimitKB = (int) secCallback.getQuota().getUlLimitKB().longValue();
        }
    }
    // set wether we have a quota on this folder
    if (quotaKB == Quota.UNLIMITED) {
        ubar.setIsNoMax(true);
    } else if (quotaKB == 0) {
        ubar.setMax(quotaKB);
    } else {
        ubar.setMax(quotaKB / 1024f);
    }
    // set default ulLimit if none is defined...
    if (uploadLimitKB == Quota.UNLIMITED) {
        uploadLimitKB = QuotaManager.getInstance().getDefaultQuotaDependingOnRole(ureq.getIdentity()).getUlLimitKB().longValue();
    }
    // Add file upload form
    long remainingQuotaKB;
    if (quotaKB == Quota.UNLIMITED)
        remainingQuotaKB = quotaKB;
    else if (quotaKB - actualUsage < 0)
        remainingQuotaKB = 0;
    else
        remainingQuotaKB = quotaKB - actualUsage;
    removeAsListenerAndDispose(fileUploadCtr);
    fileUploadCtr = new FileUploadController(getWindowControl(), currentContainer, ureq, uploadLimitKB, remainingQuotaKB, null, false, true, showMetadata, true, showCancel, false);
    listenTo(fileUploadCtr);
    mainVC.put("fileUploadCtr", fileUploadCtr.getInitialComponent());
    mainVC.contextPut("showFieldset", Boolean.TRUE);
    // if folder full show error msg
    if (remainingQuotaKB == 0) {
        String supportAddr = WebappHelper.getMailConfig("mailQuota");
        String msg = translate("QuotaExceededSupport", new String[] { supportAddr });
        getWindowControl().setError(msg);
        return null;
    }
    putInitialPanel(mainVC);
    return this;
}
Also used : AssertException(org.olat.core.logging.AssertException) ProgressBar(org.olat.core.gui.components.progressbar.ProgressBar) FileUploadController(org.olat.core.commons.modules.bc.FileUploadController)

Example 10 with FileUploadController

use of org.olat.core.commons.modules.bc.FileUploadController in project openolat by klemens.

the class DialogElementsEditController method doUpload.

private void doUpload(UserRequest ureq) {
    removeAsListenerAndDispose(fileUplCtr);
    VFSContainer tmpContainer = new LocalFolderImpl(new File(WebappHelper.getTmpDir(), "poster_" + UUID.randomUUID()));
    fileUplCtr = new FileUploadController(getWindowControl(), tmpContainer, ureq, FolderConfig.getLimitULKB(), Quota.UNLIMITED, null, false, false, false, false, true, false);
    listenTo(fileUplCtr);
    cmc = new CloseableModalController(getWindowControl(), "close", fileUplCtr.getInitialComponent(), true, translate("dialog.upload.file"));
    listenTo(cmc);
    cmc.activate();
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) VFSContainer(org.olat.core.util.vfs.VFSContainer) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) FileUploadController(org.olat.core.commons.modules.bc.FileUploadController)

Aggregations

FileUploadController (org.olat.core.commons.modules.bc.FileUploadController)10 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 File (java.io.File)4 HTMLEditorController (org.olat.core.commons.editor.htmleditor.HTMLEditorController)4 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)4 LayoutMain3ColsPreviewController (org.olat.core.commons.fullWebApp.LayoutMain3ColsPreviewController)2 SinglePageController (org.olat.core.commons.modules.singlepage.SinglePageController)2 ProgressBar (org.olat.core.gui.components.progressbar.ProgressBar)2 Controller (org.olat.core.gui.control.Controller)2 BasicController (org.olat.core.gui.control.controller.BasicController)2 CloseableCalloutWindowController (org.olat.core.gui.control.generic.closablewrapper.CloseableCalloutWindowController)2 AssertException (org.olat.core.logging.AssertException)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)2 VFSItemFilter (org.olat.core.util.vfs.filters.VFSItemFilter)2