Search in sources :

Example 16 with FlexiTableSort

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

the class FlexiTableElementImpl method saveCustomSettings.

private void saveCustomSettings(UserRequest ureq) {
    if (StringHelper.containsNonWhitespace(persistentId)) {
        Preferences prefs = ureq.getUserSession().getGuiPreferences();
        boolean sortDirection = false;
        String sortedColKey = null;
        if (orderBy != null && orderBy.length > 0 && orderBy[0] != null) {
            sortDirection = orderBy[0].isAsc();
            String sortKey = orderBy[0].getKey();
            if (sortKey != null) {
                FlexiTableColumnModel colModel = dataModel.getTableColumnModel();
                for (int i = colModel.getColumnCount(); i-- > 0; ) {
                    FlexiColumnModel col = colModel.getColumnModel(i);
                    if (col.getSortKey() != null && sortKey.equals(col.getSortKey())) {
                        sortedColKey = col.getColumnKey();
                    }
                }
            }
            if (sortedColKey == null && sortOptions != null && sortOptions.getSorts() != null) {
                for (FlexiTableSort sortOption : sortOptions.getSorts()) {
                    if (sortOption.getSortKey().getKey().equals(sortKey)) {
                        sortedColKey = sortKey;
                    }
                }
            }
        }
        FlexiTablePreferences tablePrefs = new FlexiTablePreferences(getPageSize(), sortedColKey, sortDirection, convertColumnIndexToKeys(enabledColumnIndex), rendererType);
        prefs.put(FlexiTableElement.class, persistentId, tablePrefs);
        prefs.save();
    }
}
Also used : Preferences(org.olat.core.util.prefs.Preferences) FlexiTableSort(org.olat.core.gui.components.form.flexible.elements.FlexiTableSort)

Example 17 with FlexiTableSort

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

the class FlexiTableElementImpl method selectSortOption.

private void selectSortOption(String sortKey, boolean asc) {
    if (sortOptions != null) {
        for (FlexiTableSort sort : sortOptions.getSorts()) {
            boolean selected = sort.getSortKey().getKey().equals(sortKey);
            sort.setSelected(selected);
            if (selected) {
                sort.getSortKey().setAsc(asc);
            } else {
                sort.getSortKey().setAsc(false);
            }
        }
    }
}
Also used : FlexiTableSort(org.olat.core.gui.components.form.flexible.elements.FlexiTableSort)

Example 18 with FlexiTableSort

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

the class FlexiTableElementImpl method getSorts.

public List<FlexiTableSort> getSorts() {
    List<FlexiTableSort> sorts;
    if (sortOptions == null) {
        sorts = Collections.<FlexiTableSort>emptyList();
    } else if (sortOptions.getSorts() != null && sortOptions.getSorts().size() > 0) {
        sorts = sortOptions.getSorts();
    } else if (sortOptions.isFromColumnModel()) {
        FlexiTableColumnModel columnModel = getTableDataModel().getTableColumnModel();
        int cols = columnModel.getColumnCount();
        sorts = new ArrayList<>(cols);
        for (int i = 0; i < cols; i++) {
            FlexiColumnModel fcm = columnModel.getColumnModel(i);
            if (fcm.isSortable() && fcm.getSortKey() != null) {
                String header;
                if (StringHelper.containsNonWhitespace(fcm.getHeaderLabel())) {
                    header = fcm.getHeaderLabel();
                } else {
                    header = translator.translate(fcm.getHeaderKey());
                }
                sorts.add(new FlexiTableSort(header, fcm.getSortKey()));
            }
        }
        sortOptions.setSorts(sorts);
    } else {
        sorts = Collections.<FlexiTableSort>emptyList();
    }
    return sorts;
}
Also used : FlexiTableSort(org.olat.core.gui.components.form.flexible.elements.FlexiTableSort)

Example 19 with FlexiTableSort

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

the class AbstractFlexiTableRenderer method renderHeaderButtons.

protected void renderHeaderButtons(Renderer renderer, StringOutput sb, FlexiTableElementImpl ftE, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    Component searchCmp = ftE.getExtendedSearchComponent();
    if (searchCmp == null && !ftE.isExtendedSearchExpanded() && !ftE.isNumOfRowsEnabled() && !ftE.isFilterEnabled() && !ftE.isSortEnabled() && !ftE.isExportEnabled() && !ftE.isCustomizeColumns() && ftE.getAvailableRendererTypes().length <= 1) {
        return;
    }
    if (searchCmp != null && ftE.isExtendedSearchExpanded()) {
        renderer.render(searchCmp, sb, args);
    }
    sb.append("<div class='row clearfix o_table_toolbar'>").append("<div class='col-sm-6 col-xs-12 o_table_toolbar_left'>");
    if (searchCmp == null || !ftE.isExtendedSearchExpanded()) {
        renderHeaderSearch(renderer, sb, ftE, ubu, translator, renderResult, args);
    }
    sb.append("</div>");
    sb.append("<div class='col-sm-2 col-xs-4 o_table_row_count'>");
    if (ftE.isNumOfRowsEnabled()) {
        int rowCount = ftE.getTableDataModel().getRowCount();
        if (rowCount == 1) {
            sb.append(rowCount).append(" ").append(ftE.getTranslator().translate("table.entry"));
        } else if (rowCount > 1) {
            sb.append(rowCount).append(" ").append(ftE.getTranslator().translate("table.entries"));
        }
    }
    sb.append("</div><div class='col-sm-4 col-xs-8'><div class='pull-right'><div class='o_table_tools o_noprint'>");
    boolean empty = ftE.getTableDataModel().getRowCount() == 0;
    String filterIndication = null;
    // filter
    if (ftE.isFilterEnabled()) {
        List<FlexiTableFilter> filters = ftE.getFilters();
        if (filters != null && filters.size() > 0) {
            filterIndication = renderFilterDropdown(sb, ftE, filters);
        }
    }
    // sort
    if (ftE.isSortEnabled()) {
        List<FlexiTableSort> sorts = ftE.getSorts();
        if (sorts != null && sorts.size() > 0) {
            renderSortDropdown(sb, ftE, sorts);
        }
    }
    if (ftE.getExportButton() != null && ftE.isExportEnabled()) {
        sb.append("<div class='btn-group'>");
        ftE.getExportButton().setEnabled(!empty);
        renderFormItem(renderer, sb, ftE.getExportButton(), ubu, translator, renderResult, args);
        sb.append("</div> ");
    }
    if (ftE.getCustomButton() != null && ftE.isCustomizeColumns() && (ftE.getRendererType() == null || ftE.getRendererType() == FlexiTableRendererType.classic)) {
        sb.append("<div class='btn-group'>");
        renderFormItem(renderer, sb, ftE.getCustomButton(), ubu, translator, renderResult, args);
        sb.append("</div> ");
    }
    // switch type of tables
    FlexiTableRendererType[] types = ftE.getAvailableRendererTypes();
    if (types.length > 1) {
        sb.append("<div class='btn-group'>");
        for (FlexiTableRendererType type : types) {
            renderHeaderSwitchType(type, renderer, sb, ftE, ubu, translator, renderResult, args);
        }
        sb.append("</div> ");
    }
    sb.append("</div>");
    if (StringHelper.containsNonWhitespace(filterIndication)) {
        Form theForm = ftE.getRootForm();
        String dispatchId = ftE.getFormDispatchId();
        sb.append("<div class='o_table_tools_indications'>").append(filterIndication).append(" <a href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(theForm, dispatchId, 1, true, true, true, new NameValuePair("rm-filter", "true"))).append("\" title=\"").append(translator.translate("remove.filters")).append("\">").append("<i class='o_icon o_icon_remove o_icon-fw'> </i></a></div>");
    }
    sb.append("</div>");
    sb.append("</div></div>");
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) Form(org.olat.core.gui.components.form.flexible.impl.Form) FlexiTableFilter(org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter) Component(org.olat.core.gui.components.Component) FlexiTableSort(org.olat.core.gui.components.form.flexible.elements.FlexiTableSort)

Example 20 with FlexiTableSort

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

the class ForumMessageListController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    List<FlexiTableSort> sorts = new ArrayList<>();
    sorts.add(new FlexiTableSort(translate("natural.sort"), "natural"));
    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    if (withType) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ForumMessageCols.type, new StatusTypeCellRenderer()));
        sorts.add(new FlexiTableSort(translate(ForumMessageCols.type.i18nHeaderKey()), ForumMessageCols.type.name()));
    }
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ForumMessageCols.thread, "select", new StaticFlexiCellRenderer("select", new IndentCellRenderer())));
    sorts.add(new FlexiTableSort(translate(ForumMessageCols.thread.i18nHeaderKey()), ForumMessageCols.thread.name()));
    int colPos = USER_PROPS_OFFSET;
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        String propName = userPropertyHandler.getName();
        boolean visible = userManager.isMandatoryUserProperty(USER_PROPS_ID, userPropertyHandler);
        FlexiColumnModel col;
        if (UserConstants.FIRSTNAME.equals(propName) || UserConstants.LASTNAME.equals(propName)) {
            col = new DefaultFlexiColumnModel(userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos, "select", true, propName, new StaticFlexiCellRenderer("select", new TextFlexiCellRenderer()));
        } else {
            col = new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos, true, propName);
        }
        sorts.add(new FlexiTableSort(translate(userPropertyHandler.i18nColumnDescriptorLabelKey()), propName));
        columnsModel.addFlexiColumnModel(col);
        colPos++;
    }
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ForumMessageCols.lastModified));
    sorts.add(new FlexiTableSort(translate(ForumMessageCols.lastModified.i18nHeaderKey()), ForumMessageCols.lastModified.name()));
    dataModel = new ForumMessageDataModel(columnsModel, getTranslator());
    tableEl = uifactory.addTableElement(getWindowControl(), "messages", dataModel, getTranslator(), formLayout);
    tableEl.setCssDelegate(new MessageCssDelegate());
    FlexiTableSortOptions sortOptions = new FlexiTableSortOptions();
    sortOptions.setFromColumnModel(false);
    sortOptions.setSorts(sorts);
    tableEl.setSortSettings(sortOptions);
}
Also used : FlexiTableSortOptions(org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) FlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel) ArrayList(java.util.ArrayList) StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) TextFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer) FlexiTableSort(org.olat.core.gui.components.form.flexible.elements.FlexiTableSort) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

FlexiTableSort (org.olat.core.gui.components.form.flexible.elements.FlexiTableSort)20 ArrayList (java.util.ArrayList)8 SortKey (org.olat.core.commons.persistence.SortKey)8 FlexiTableSortOptions (org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions)8 Form (org.olat.core.gui.components.form.flexible.impl.Form)4 NameValuePair (org.olat.core.gui.components.form.flexible.impl.NameValuePair)4 Preferences (org.olat.core.util.prefs.Preferences)4 Component (org.olat.core.gui.components.Component)2 FlexiTableElement (org.olat.core.gui.components.form.flexible.elements.FlexiTableElement)2 FlexiTableFilter (org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter)2 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)2 FlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel)2 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)2 StaticFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer)2 TextFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer)2 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)2