Search in sources :

Example 1 with FileElement

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

the class ItemsController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    // reload feed for this event and make sure the updated feed object is
    // in the view
    feedResource = feedManager.loadFeed(feedResource);
    accessibleItems = feedManager.loadFilteredAndSortedItems(feedResource, callback, ureq.getIdentity());
    if (source == cmc) {
        if (event.equals(CloseableModalController.CLOSE_MODAL_EVENT)) {
            removeAsListenerAndDispose(cmc);
            cmc = null;
            removeAsListenerAndDispose(itemFormCtr);
            itemFormCtr = null;
            // Check if this item has ever been added to the feed. If not,
            // remove the temp dir
            cleanupTmpItemMediaDir(currentItem);
            // internally or subscribe to an external feed.
            if (!feedManager.hasItems(feedResource)) {
                feedResource = feedManager.updateFeedMode(null, feedResource);
                makeInternalAndExternalButtons();
            }
            // release lock
            feedManager.releaseLock(lock);
        }
    } else if (source == confirmDialogCtr && DialogBoxUIFactory.isYesEvent(event)) {
        // The user confirmed that the item shall be deleted
        Item item = (Item) ((DialogBoxController) source).getUserObject();
        lock = feedManager.acquireLock(feedResource, item, getIdentity());
        if (lock.isSuccess()) {
            // remove the item from the naviCtr
            naviCtr.remove(item);
            // permanently remove item
            feedResource = feedManager.deleteItem(item);
            // remove delete and edit buttons of this item
            for (Link deleteButton : deleteButtons) {
                if (item.equals(deleteButton.getUserObject())) {
                    deleteButtons.remove(deleteButton);
                    break;
                }
            }
            for (Link editButton : editButtons) {
                if (item.equals(editButton.getUserObject())) {
                    editButtons.remove(editButton);
                    break;
                }
            }
            // items manually or from an external source/feed.
            if (!feedManager.hasItems(feedResource)) {
                makeInternalAndExternalButtons();
                // The subscription/feed url from the feed info is obsolete
                fireEvent(ureq, ItemsController.FEED_INFO_IS_DIRTY_EVENT);
            } else {
                if (callback.mayEditItems() || callback.mayCreateItems()) {
                    createEditButtons(ureq, feedResource);
                }
                createCommentsAndRatingsLinks(ureq, feedResource);
            }
            vcItems.setDirty(true);
            // in case we were in single item view, show all items
            mainPanel.setContent(vcItems);
            feedManager.releaseLock(lock);
            lock = null;
            // do logging
            ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_ITEM_DELETE, getClass(), LoggingResourceable.wrap(item));
        } else {
            String fullName = userManager.getUserDisplayName(lock.getOwner());
            showInfo("feed.item.is.being.edited.by", fullName);
        }
    } else if (source == itemFormCtr) {
        if (event.equals(Event.CHANGED_EVENT) || event.equals(Event.CANCELLED_EVENT)) {
            if (event.equals(Event.CHANGED_EVENT)) {
                FileElement mediaFile = currentItem.getMediaFile();
                if (feedManager.getItemContainer(currentItem) == null) {
                    // Ups, deleted in the meantime by someone else
                    // remove the item from the naviCtr
                    naviCtr.remove(currentItem);
                } else {
                    if (!accessibleItems.contains(currentItem)) {
                        // Add the modified item if it is not part of the
                        // feed
                        feedResource = feedManager.createItem(feedResource, currentItem, mediaFile);
                        if (feedResource != null) {
                            createButtonsForItem(ureq, feedResource, currentItem);
                            createItemLink(currentItem);
                            // Add date component
                            String guid = currentItem.getGuid();
                            if (currentItem.getDate() != null) {
                                DateComponentFactory.createDateComponentWithYear("date." + guid, currentItem.getDate(), vcItems);
                            }
                            // Add comments and rating
                            createCommentsAndRatingsLink(ureq, feedResource, currentItem);
                            // add it to the navigation controller
                            naviCtr.add(currentItem);
                            accessibleItems = feedManager.loadFilteredAndSortedItems(feedResource, callback, ureq.getIdentity());
                            if (accessibleItems != null && accessibleItems.size() == 1) {
                                // First item added, show feed url (for
                                // subscription)
                                fireEvent(ureq, ItemsController.FEED_INFO_IS_DIRTY_EVENT);
                                // Set the base URI of the feed for the
                                // current user. All users
                                // have unique URIs.
                                helper.setURIs(currentItem.getFeed());
                            }
                        }
                    } else {
                        // Write item file
                        currentItem = feedManager.updateItem(currentItem, mediaFile);
                        if (itemCtr != null) {
                            displayItemController(ureq, currentItem);
                        }
                        ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_ITEM_EDIT, getClass(), LoggingResourceable.wrap(currentItem));
                    }
                }
                vcItems.setDirty(true);
                // if the current item is displayed, update the view
                if (itemCtr != null) {
                    itemCtr.getInitialComponent().setDirty(true);
                }
            } else if (event.equals(Event.CANCELLED_EVENT)) {
                // Check if this item has ever been added to the feed. If
                // not, remove the temp dir
                cleanupTmpItemMediaDir(currentItem);
                // internally or subscribe to an external feed.
                if (!feedManager.hasItems(feedResource)) {
                    feedResource = feedManager.updateFeedMode(null, feedResource);
                    makeInternalAndExternalButtons();
                }
            }
            // release the lock
            feedManager.releaseLock(lock);
            // Dispose the cmc and the podcastFormCtr.
            cmc.deactivate();
            removeAsListenerAndDispose(cmc);
            cmc = null;
            removeAsListenerAndDispose(itemFormCtr);
            itemFormCtr = null;
        }
    } else if (source == externalUrlCtr) {
        if (event.equals(Event.CHANGED_EVENT)) {
            String externalUrl = externalUrlCtr.getExternalFeedUrlEl();
            feedManager.updateExternalFeedUrl(feedResource, externalUrl);
        } else if (event.equals(Event.CHANGED_EVENT)) {
        // nothing to do
        }
        cmc.deactivate();
        removeAsListenerAndDispose(cmc);
        cmc = null;
        removeAsListenerAndDispose(externalUrlCtr);
        externalUrlCtr = null;
    } else if (source == naviCtr && event instanceof NavigationEvent) {
        List<? extends Dated> selItems = ((NavigationEvent) event).getSelectedItems();
        List<Item> items = new ArrayList<>();
        for (Dated item : selItems) {
            if (item instanceof Item) {
                items.add((Item) item);
            }
        }
        if (callback.mayEditItems() || callback.mayCreateItems()) {
            createEditButtons(ureq, feedResource);
        }
        createCommentsAndRatingsLinks(ureq, feedResource);
        vcItems.setDirty(true);
        mainPanel.setContent(vcItems);
    } else if (source == itemCtr) {
        if (event == Event.BACK_EVENT) {
            mainPanel.setContent(vcItems);
            removeAsListenerAndDispose(itemCtr);
            itemCtr = null;
        }
    } else if (source instanceof UserCommentsAndRatingsController) {
        UserCommentsAndRatingsController commentsRatingsCtr = (UserCommentsAndRatingsController) source;
        if (event == UserCommentsAndRatingsController.EVENT_COMMENT_LINK_CLICKED) {
            // go to details page
            Item item = (Item) commentsRatingsCtr.getUserObject();
            if (item != null) {
                ItemController myItemCtr = displayItemController(ureq, item);
                List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromResourceType(ItemController.ACTIVATION_KEY_COMMENTS);
                myItemCtr.activate(ureq, entries, null);
            }
        }
    }
    // reload everything
    if (feedResource != null) {
        resetItems(ureq, feedResource);
    }
}
Also used : NavigationEvent(org.olat.core.commons.controllers.navigation.NavigationEvent) ArrayList(java.util.ArrayList) ContextEntry(org.olat.core.id.context.ContextEntry) DialogBoxController(org.olat.core.gui.control.generic.modal.DialogBoxController) Item(org.olat.modules.webFeed.Item) UserCommentsAndRatingsController(org.olat.core.commons.services.commentAndRating.ui.UserCommentsAndRatingsController) FileElement(org.olat.core.gui.components.form.flexible.elements.FileElement) Dated(org.olat.core.commons.controllers.navigation.Dated) Link(org.olat.core.gui.components.link.Link)

Example 2 with FileElement

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

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)

Example 3 with FileElement

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

the class ItemsController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    // reload feed for this event and make sure the updated feed object is
    // in the view
    feedResource = feedManager.loadFeed(feedResource);
    accessibleItems = feedManager.loadFilteredAndSortedItems(feedResource, callback, ureq.getIdentity());
    if (source == cmc) {
        if (event.equals(CloseableModalController.CLOSE_MODAL_EVENT)) {
            removeAsListenerAndDispose(cmc);
            cmc = null;
            removeAsListenerAndDispose(itemFormCtr);
            itemFormCtr = null;
            // Check if this item has ever been added to the feed. If not,
            // remove the temp dir
            cleanupTmpItemMediaDir(currentItem);
            // internally or subscribe to an external feed.
            if (!feedManager.hasItems(feedResource)) {
                feedResource = feedManager.updateFeedMode(null, feedResource);
                makeInternalAndExternalButtons();
            }
            // release lock
            feedManager.releaseLock(lock);
        }
    } else if (source == confirmDialogCtr && DialogBoxUIFactory.isYesEvent(event)) {
        // The user confirmed that the item shall be deleted
        Item item = (Item) ((DialogBoxController) source).getUserObject();
        lock = feedManager.acquireLock(feedResource, item, getIdentity());
        if (lock.isSuccess()) {
            // remove the item from the naviCtr
            naviCtr.remove(item);
            // permanently remove item
            feedResource = feedManager.deleteItem(item);
            // remove delete and edit buttons of this item
            for (Link deleteButton : deleteButtons) {
                if (item.equals(deleteButton.getUserObject())) {
                    deleteButtons.remove(deleteButton);
                    break;
                }
            }
            for (Link editButton : editButtons) {
                if (item.equals(editButton.getUserObject())) {
                    editButtons.remove(editButton);
                    break;
                }
            }
            // items manually or from an external source/feed.
            if (!feedManager.hasItems(feedResource)) {
                makeInternalAndExternalButtons();
                // The subscription/feed url from the feed info is obsolete
                fireEvent(ureq, ItemsController.FEED_INFO_IS_DIRTY_EVENT);
            } else {
                if (callback.mayEditItems() || callback.mayCreateItems()) {
                    createEditButtons(ureq, feedResource);
                }
                createCommentsAndRatingsLinks(ureq, feedResource);
            }
            vcItems.setDirty(true);
            // in case we were in single item view, show all items
            mainPanel.setContent(vcItems);
            feedManager.releaseLock(lock);
            lock = null;
            // do logging
            ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_ITEM_DELETE, getClass(), LoggingResourceable.wrap(item));
        } else {
            String fullName = userManager.getUserDisplayName(lock.getOwner());
            showInfo("feed.item.is.being.edited.by", fullName);
        }
    } else if (source == itemFormCtr) {
        if (event.equals(Event.CHANGED_EVENT) || event.equals(Event.CANCELLED_EVENT)) {
            if (event.equals(Event.CHANGED_EVENT)) {
                FileElement mediaFile = currentItem.getMediaFile();
                if (feedManager.getItemContainer(currentItem) == null) {
                    // Ups, deleted in the meantime by someone else
                    // remove the item from the naviCtr
                    naviCtr.remove(currentItem);
                } else {
                    if (!accessibleItems.contains(currentItem)) {
                        // Add the modified item if it is not part of the
                        // feed
                        feedResource = feedManager.createItem(feedResource, currentItem, mediaFile);
                        if (feedResource != null) {
                            createButtonsForItem(ureq, feedResource, currentItem);
                            createItemLink(currentItem);
                            // Add date component
                            String guid = currentItem.getGuid();
                            if (currentItem.getDate() != null) {
                                DateComponentFactory.createDateComponentWithYear("date." + guid, currentItem.getDate(), vcItems);
                            }
                            // Add comments and rating
                            createCommentsAndRatingsLink(ureq, feedResource, currentItem);
                            // add it to the navigation controller
                            naviCtr.add(currentItem);
                            accessibleItems = feedManager.loadFilteredAndSortedItems(feedResource, callback, ureq.getIdentity());
                            if (accessibleItems != null && accessibleItems.size() == 1) {
                                // First item added, show feed url (for
                                // subscription)
                                fireEvent(ureq, ItemsController.FEED_INFO_IS_DIRTY_EVENT);
                                // Set the base URI of the feed for the
                                // current user. All users
                                // have unique URIs.
                                helper.setURIs(currentItem.getFeed());
                            }
                        }
                    } else {
                        // Write item file
                        currentItem = feedManager.updateItem(currentItem, mediaFile);
                        if (itemCtr != null) {
                            displayItemController(ureq, currentItem);
                        }
                        ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_ITEM_EDIT, getClass(), LoggingResourceable.wrap(currentItem));
                    }
                }
                vcItems.setDirty(true);
                // if the current item is displayed, update the view
                if (itemCtr != null) {
                    itemCtr.getInitialComponent().setDirty(true);
                }
            } else if (event.equals(Event.CANCELLED_EVENT)) {
                // Check if this item has ever been added to the feed. If
                // not, remove the temp dir
                cleanupTmpItemMediaDir(currentItem);
                // internally or subscribe to an external feed.
                if (!feedManager.hasItems(feedResource)) {
                    feedResource = feedManager.updateFeedMode(null, feedResource);
                    makeInternalAndExternalButtons();
                }
            }
            // release the lock
            feedManager.releaseLock(lock);
            // Dispose the cmc and the podcastFormCtr.
            cmc.deactivate();
            removeAsListenerAndDispose(cmc);
            cmc = null;
            removeAsListenerAndDispose(itemFormCtr);
            itemFormCtr = null;
        }
    } else if (source == externalUrlCtr) {
        if (event.equals(Event.CHANGED_EVENT)) {
            String externalUrl = externalUrlCtr.getExternalFeedUrlEl();
            feedManager.updateExternalFeedUrl(feedResource, externalUrl);
        } else if (event.equals(Event.CHANGED_EVENT)) {
        // nothing to do
        }
        cmc.deactivate();
        removeAsListenerAndDispose(cmc);
        cmc = null;
        removeAsListenerAndDispose(externalUrlCtr);
        externalUrlCtr = null;
    } else if (source == naviCtr && event instanceof NavigationEvent) {
        List<? extends Dated> selItems = ((NavigationEvent) event).getSelectedItems();
        List<Item> items = new ArrayList<>();
        for (Dated item : selItems) {
            if (item instanceof Item) {
                items.add((Item) item);
            }
        }
        if (callback.mayEditItems() || callback.mayCreateItems()) {
            createEditButtons(ureq, feedResource);
        }
        createCommentsAndRatingsLinks(ureq, feedResource);
        vcItems.setDirty(true);
        mainPanel.setContent(vcItems);
    } else if (source == itemCtr) {
        if (event == Event.BACK_EVENT) {
            mainPanel.setContent(vcItems);
            removeAsListenerAndDispose(itemCtr);
            itemCtr = null;
        }
    } else if (source instanceof UserCommentsAndRatingsController) {
        UserCommentsAndRatingsController commentsRatingsCtr = (UserCommentsAndRatingsController) source;
        if (event == UserCommentsAndRatingsController.EVENT_COMMENT_LINK_CLICKED) {
            // go to details page
            Item item = (Item) commentsRatingsCtr.getUserObject();
            if (item != null) {
                ItemController myItemCtr = displayItemController(ureq, item);
                List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromResourceType(ItemController.ACTIVATION_KEY_COMMENTS);
                myItemCtr.activate(ureq, entries, null);
            }
        }
    }
    // reload everything
    if (feedResource != null) {
        resetItems(ureq, feedResource);
    }
}
Also used : NavigationEvent(org.olat.core.commons.controllers.navigation.NavigationEvent) ArrayList(java.util.ArrayList) ContextEntry(org.olat.core.id.context.ContextEntry) DialogBoxController(org.olat.core.gui.control.generic.modal.DialogBoxController) Item(org.olat.modules.webFeed.Item) UserCommentsAndRatingsController(org.olat.core.commons.services.commentAndRating.ui.UserCommentsAndRatingsController) FileElement(org.olat.core.gui.components.form.flexible.elements.FileElement) Dated(org.olat.core.commons.controllers.navigation.Dated) Link(org.olat.core.gui.components.link.Link)

Example 4 with FileElement

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

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 5 with FileElement

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

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)

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