Search in sources :

Example 46 with FormLink

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

the class MessageEditController method createOrUpdateAttachmentListLayout.

// adds or updates the list of already existing attachments with a delete
// button for each
private void createOrUpdateAttachmentListLayout(FormItemContainer formLayout) {
    FormItem attachLayout = formLayout.getFormComponent("attachLayout");
    List<VFSItem> attachments = new ArrayList<VFSItem>();
    // add already existing attachments:
    if (message.getKey() != null) {
        VFSContainer msgContainer = fm.getMessageContainer(message.getForum().getKey(), message.getKey());
        attachments.addAll(msgContainer.getItems(exclFilter));
    }
    // add files from TempFolder
    attachments.addAll(getTempFolderFileList());
    Collections.sort(attachments, new Comparator<VFSItem>() {

        final Collator c = Collator.getInstance(getLocale());

        public int compare(final VFSItem o1, final VFSItem o2) {
            return c.compare((o1).getName(), (o2).getName());
        }
    });
    FormLayoutContainer tmpLayout;
    if (attachLayout == null) {
        String editPage = Util.getPackageVelocityRoot(this.getClass()) + "/attachments-editview.html";
        tmpLayout = FormLayoutContainer.createCustomFormLayout("attachLayout", getTranslator(), editPage);
        formLayout.add(tmpLayout);
    } else {
        tmpLayout = (FormLayoutContainer) attachLayout;
    }
    tmpLayout.contextPut("attachments", attachments);
    // add delete links for each attachment if user is allowed to see them
    int attNr = 1;
    for (VFSItem tmpFile : attachments) {
        FormLink tmpLink = uifactory.addFormLink(CMD_DELETE_ATTACHMENT + attNr, tmpLayout, Link.BUTTON_XSMALL);
        if (!(foCallback.mayEditMessageAsModerator() || ((userIsMsgCreator) && (msgHasChildren == false)))) {
            tmpLink.setEnabled(false);
            tmpLink.setVisible(false);
        }
        tmpLink.setUserObject(tmpFile);
        tmpLink.setI18nKey("attachments.remove.string");
        attNr++;
    }
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Collator(java.text.Collator)

Example 47 with FormLink

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

the class MediaCenterController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source == tableEl) {
        if (event instanceof SelectionEvent) {
            SelectionEvent se = (SelectionEvent) event;
            String cmd = se.getCommand();
            MediaRow row = model.getObject(se.getIndex());
            if ("select".equals(cmd)) {
                if (select) {
                    doSelect(ureq, row.getKey());
                } else {
                    Activateable2 activateable = doOpenMedia(ureq, row.getKey());
                    if (activateable != null) {
                        activateable.activate(ureq, null, null);
                    }
                }
            }
        } else if (event instanceof FlexiTableSearchEvent) {
            loadModel();
        }
    } else if (newMediaCallout == source) {
        doOpenNewMediaCallout(ureq, newMediaCallout);
    } else if (source instanceof FormLink) {
        FormLink link = (FormLink) source;
        String cmd = link.getCmd();
        if ("select".equals(cmd)) {
            MediaRow row = (MediaRow) link.getUserObject();
            if (select) {
                doSelect(ureq, row.getKey());
            } else {
                Activateable2 activateable = doOpenMedia(ureq, row.getKey());
                if (activateable != null) {
                    activateable.activate(ureq, null, null);
                }
            }
        } else if ("tag".equals(cmd)) {
            doToggleCategory(link);
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : Activateable2(org.olat.core.gui.control.generic.dtabs.Activateable2) SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) MediaSelectionEvent(org.olat.modules.portfolio.ui.event.MediaSelectionEvent) FlexiTableSearchEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) MediaRow(org.olat.modules.portfolio.ui.model.MediaRow)

Example 48 with FormLink

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

the class MediaDetailsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        layoutCont.contextPut("title", StringHelper.escapeHtml(media.getTitle()));
        layoutCont.contextPut("description", StringHelper.xssScan(media.getDescription()));
        layoutCont.contextPut("iconCssClass", handler.getIconCssClass(media));
        mediaCtrl = handler.getMediaController(ureq, getWindowControl(), media, new StandardMediaRenderingHints());
        if (mediaCtrl != null) {
            listenTo(mediaCtrl);
            layoutCont.put("media", mediaCtrl.getInitialComponent());
        }
        String metaPage = velocity_root + "/media_details_metadata.html";
        FormLayoutContainer metaCont = FormLayoutContainer.createCustomFormLayout("meta", getTranslator(), metaPage);
        layoutCont.add("meta", metaCont);
        metaCont.setRootForm(mainForm);
        metaCont.contextPut("media", media);
        String author = userManager.getUserDisplayName(media.getAuthor());
        metaCont.contextPut("author", author);
        if (media.getCollectionDate() != null) {
            String collectionDate = Formatter.getInstance(getLocale()).formatDate(media.getCollectionDate());
            metaCont.contextPut("collectionDate", collectionDate);
        }
        if (media.getBusinessPath() != null) {
            gotoOriginalLink = LinkFactory.createLink("goto.original", metaCont.getFormItemComponent(), this);
        }
        if (StringHelper.containsNonWhitespace(media.getMetadataXml())) {
            Object metadata = MetadataXStream.get().fromXML(media.getMetadataXml());
            metaCont.contextPut("metadata", metadata);
        }
        List<Category> categories = portfolioService.getCategories(media);
        if (categories != null && categories.size() > 0) {
            Map<String, String> categoriesMap = categories.stream().collect(Collectors.toMap(c -> c.getName(), c -> c.getName()));
            TextBoxListElement categoriesEl = uifactory.addTextBoxListElement("categories", "categories", "categories.hint", categoriesMap, metaCont, getTranslator());
            categoriesEl.setHelpText(translate("categories.hint"));
            categoriesEl.setElementCssClass("o_sel_ep_tagsinput");
            categoriesEl.setEnabled(false);
        }
        List<FormLink> binderLinks = new ArrayList<>(usedInList.size());
        Set<Long> binderUniqueKeys = new HashSet<>();
        for (BinderPageUsage binder : usedInList) {
            if (binderUniqueKeys.contains(binder.getBinderKey()))
                continue;
            FormLink link;
            if (binder.getBinderKey() == null) {
                link = uifactory.addFormLink("binder_" + (++counter), "page", binder.getPageTitle(), null, metaCont, Link.LINK | Link.NONTRANSLATED);
                binderUniqueKeys.add(binder.getPageKey());
            } else {
                link = uifactory.addFormLink("binder_" + (++counter), "binder", binder.getBinderTitle(), null, metaCont, Link.LINK | Link.NONTRANSLATED);
                binderUniqueKeys.add(binder.getBinderKey());
            }
            link.setUserObject(binder);
            binderLinks.add(link);
        }
        metaCont.contextPut("binderLinks", binderLinks);
    }
}
Also used : BinderPageUsage(org.olat.modules.portfolio.model.BinderPageUsage) TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) Activateable2(org.olat.core.gui.control.generic.dtabs.Activateable2) FormEvent(org.olat.core.gui.components.form.flexible.impl.FormEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) FormItem(org.olat.core.gui.components.form.flexible.FormItem) TextBoxListElement(org.olat.core.gui.components.form.flexible.elements.TextBoxListElement) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Event(org.olat.core.gui.control.Event) FormBasicController(org.olat.core.gui.components.form.flexible.impl.FormBasicController) FormItemContainer(org.olat.core.gui.components.form.flexible.FormItemContainer) Category(org.olat.modules.portfolio.Category) ContextEntry(org.olat.core.id.context.ContextEntry) Media(org.olat.modules.portfolio.Media) Map(java.util.Map) MediaHandler(org.olat.modules.portfolio.MediaHandler) StringHelper(org.olat.core.util.StringHelper) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) StateEntry(org.olat.core.id.context.StateEntry) Formatter(org.olat.core.util.Formatter) PortfolioService(org.olat.modules.portfolio.PortfolioService) DialogBoxController(org.olat.core.gui.control.generic.modal.DialogBoxController) Link(org.olat.core.gui.components.link.Link) WindowControl(org.olat.core.gui.control.WindowControl) Set(java.util.Set) MediaEvent(org.olat.modules.portfolio.ui.event.MediaEvent) Component(org.olat.core.gui.components.Component) LinkFactory(org.olat.core.gui.components.link.LinkFactory) Collectors(java.util.stream.Collectors) Controller(org.olat.core.gui.control.Controller) UserManager(org.olat.user.UserManager) List(java.util.List) MetadataXStream(org.olat.modules.portfolio.manager.MetadataXStream) NewControllerFactory(org.olat.NewControllerFactory) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Align(org.olat.core.gui.components.stack.TooledStackedPanel.Align) TooledController(org.olat.core.gui.components.stack.TooledController) DialogBoxUIFactory(org.olat.core.gui.control.generic.modal.DialogBoxUIFactory) UserRequest(org.olat.core.gui.UserRequest) PageStatus(org.olat.modules.portfolio.PageStatus) StandardMediaRenderingHints(org.olat.modules.portfolio.model.StandardMediaRenderingHints) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Category(org.olat.modules.portfolio.Category) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) StandardMediaRenderingHints(org.olat.modules.portfolio.model.StandardMediaRenderingHints) BinderPageUsage(org.olat.modules.portfolio.model.BinderPageUsage) TextBoxListElement(org.olat.core.gui.components.form.flexible.elements.TextBoxListElement) HashSet(java.util.HashSet)

Example 49 with FormLink

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

the class TitleEditorController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    List<String> headingFormatLinkNames = new ArrayList<>();
    for (int i = 1; i <= 6; i++) {
        FormLink headingFormatLink = uifactory.addFormLink("h" + i, "h" + i, "h" + i, null, formLayout, Link.LINK);
        headingFormatLinkNames.add(headingFormatLink.getComponent().getComponentName());
    }
    flc.getFormItemComponent().contextPut("headingFormatLinkNames", headingFormatLinkNames);
    String cmpId = "title-" + CodeHelper.getRAMUniqueID() + "h";
    String content = titlePart.getContent();
    titleItem = uifactory.addRichTextElementForStringDataCompact(cmpId, null, content, 8, 80, null, formLayout, ureq.getUserSession(), getWindowControl());
    titleItem.getEditorConfiguration().setSendOnBlur(true);
    titleItem.getEditorConfiguration().disableMenuAndMenuBar();
    staticItem = uifactory.addStaticTextElement(cmpId + "_static", contentOrExample(content), formLayout);
    flc.getFormItemComponent().contextPut("cmpId", cmpId);
}
Also used : ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 50 with FormLink

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

the class AbstractItemListController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source == itemsTable) {
        if (event instanceof SelectionEvent) {
            SelectionEvent se = (SelectionEvent) event;
            if ("rSelect".equals(se.getCommand())) {
                ItemRow row = model.getObject(se.getIndex());
                if (row != null) {
                    doClick(ureq, row);
                }
            } else if ("select-item".equals(se.getCommand())) {
                ItemRow row = getModel().getObject(se.getIndex());
                if (row != null) {
                    doSelect(ureq, row);
                }
            } else if ("quick-view".equals(se.getCommand())) {
                int rowIndex = se.getIndex();
                if (rowIndex >= 0) {
                    if (itemsTable.isDetailsExpended(rowIndex)) {
                        itemsTable.collapseDetails(rowIndex);
                    } else {
                        itemsTable.collapseAllDetails();
                        ItemRow row = getModel().getObject(rowIndex);
                        if (row != null) {
                            itemsTable.expandDetails(rowIndex);
                            QuestionItem item = qpoolService.loadItemById(row.getKey());
                            previewCtrl.updateItem(ureq, item);
                            quickViewMetadataCtrl.setItem(ureq, item);
                        }
                    }
                }
            }
        }
    } else if (source instanceof FormLink) {
        FormLink link = (FormLink) source;
        if ("select".equals(link.getCmd())) {
            ItemRow row = (ItemRow) link.getUserObject();
            doSelect(ureq, row);
        } else if ("mark".equals(link.getCmd())) {
            ItemRow row = (ItemRow) link.getUserObject();
            if (doMark(row)) {
                link.setIconLeftCSS(Mark.MARK_CSS_LARGE);
            } else {
                link.setIconLeftCSS(Mark.MARK_ADD_CSS_LARGE);
            }
            link.getComponent().setDirty(true);
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) QuestionItem(org.olat.modules.qpool.QuestionItem)

Aggregations

FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)376 ArrayList (java.util.ArrayList)108 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)64 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)40 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)36 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)34 List (java.util.List)30 FormItem (org.olat.core.gui.components.form.flexible.FormItem)28 HashMap (java.util.HashMap)26 FlexiTableSearchEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent)24 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)22 Date (java.util.Date)18 Map (java.util.Map)18 Link (org.olat.core.gui.components.link.Link)18 Identity (org.olat.core.id.Identity)18 Component (org.olat.core.gui.components.Component)16 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)16 FormEvent (org.olat.core.gui.components.form.flexible.impl.FormEvent)16 Controller (org.olat.core.gui.control.Controller)16 Event (org.olat.core.gui.control.Event)16