CallBackery

 view release on metacpan or  search on metacpan

lib/CallBackery/qooxdoo/callbackery/source/class/callbackery/ui/plugin/Table.js  view on Meta::CPAN

/* ************************************************************************
   Copyright: 2013 OETIKER+PARTNER AG
   License:   GPLv3 or later
   Authors:   Tobi Oetiker <tobi@oetiker.ch>
   Utf8Check: äöü
************************************************************************ */

/**
 * Table Visualization Widget.
 */
qx.Class.define('callbackery.ui.plugin.Table', {
    extend: callbackery.ui.plugin.Form,
    /**
     * create a page for the View Tab with the given title
     *
     * @param vizWidget {Widget} visualization widget to embedd
     */
    properties: {
        selection: {
            init: {}
        }
    },
    members: {
        _populate() {
            this.setLayout(new qx.ui.layout.VBox(0));
            if (this._cfg.introText) {
                this.add(new qx.ui.basic.Label(this.xtr(this._cfg.introText)).set({ rich: true }));
            }
            this.add(this._createToolbar());
            this.add(this._createTable(), { flex: 1 });
        },
        _createToolbar() {
            var that = this;
            var cfg = this._cfg;
            var toolbar = new qx.ui.toolbar.ToolBar();
            var action = this._action = new callbackery.ui.plugin.Action(
                cfg, qx.ui.toolbar.Button,
                new qx.ui.layout.HBox(0),
                function () {
                    if (that._form.validate()) {
                        var rpcData = that._form.getData();
                        rpcData['selection'] = that.getSelection();
                        return rpcData;
                    }
                    else {
                        return false;
                    }
                },
                this
            );
            action.set({
                paddingLeft: -10
            });
            let mobileMenu = new qx.ui.form.MenuButton(this.tr("Menu"), null, action.getMobileMenu());
            toolbar.add(mobileMenu);
            toolbar.setOverflowIndicator(mobileMenu);
            toolbar.setOverflowHandling(true);

            toolbar.add(action);
            toolbar.setRemovePriority(action, 1);
            toolbar.addSpacer();
            var form = this._form = new callbackery.ui.form.Auto(cfg.form, null, callbackery.ui.form.renderer.HBox, this);
            toolbar.add(form);
            return toolbar;
        },
        _createTable() {
            var cfg = this._cfg;
            var model = this._model = new callbackery.data.RemoteTableModel(cfg, this._getParentFormData);
            var table = this._table = new qx.ui.table.Table(model, {
                tableColumnModel: function (obj) {
                    return new qx.ui.table.columnmodel.Resize(obj);
                }
            }).set({
                showCellFocusIndicator: false
            });
            table.getDataRowRenderer().setHighlightFocusRow(false);
            var ctxMenu = this._action.getTableContextMenu();
            if (ctxMenu) {
                table.setContextMenu(ctxMenu);
            }
            var defaultAction = this._action.getDefaultAction();
            if (defaultAction) {
                table.addListener('cellDbltap', defaultAction, this._action);
            }
            var tcm = table.getTableColumnModel();
            var resizeBehavior = tcm.getBehavior();
            cfg.table.forEach(function (col, i) {
                var cr;
                switch (col.type) {
                    case 'boolean':
                        cr = new qx.ui.table.cellrenderer.Boolean;
                        break;
                    case 'html':
                        cr = new qx.ui.table.cellrenderer.Html;
                        break;
                    case 'date':
                        cr = new qx.ui.table.cellrenderer.Date;
                        if (col.format != null) {
                            cr.setDateFormat(new qx.util.format.DateFormat(col.format));
                        }
                        break;
                    case 'str':
                    case 'string':
                        cr = new qx.ui.table.cellrenderer.String(
                            col.align, col.color, col.style, col.weight
                        );
                        break;
                    case 'num':
                    case 'number':
                        cr = new qx.ui.table.cellrenderer.Number(
                            col.align, col.color, col.style, col.weight
                        );
                        if (col.format != null) {
                            cr.setNumberFormat(
                                new callbackery.util.format.NumberFormat()
                                    .set(col.format)
                            );
                        }
                        break;
                }
                if (cr) {
                    tcm.setDataCellRenderer(i, cr);
                }
                if ('visible' in col) {
                    tcm.setColumnVisible(i, col.visible);
                }
            });

            let setColumnResizeBehavior = () => {
                let flexList = [];
                let totalFlex = 0;
                cfg.table.forEach((col, i) => {
                    if (tcm.isColumnVisible(i) && col.width) {
                        let match = String(col.width).match(/^(\d+)\*/);
                        if (match) {
                            let flex = parseInt(match[1]);
                            totalFlex += flex;
                            flexList[i] = flex;
                        }



( run in 0.590 second using v1.01-cache-2.11-cpan-39bf76dae61 )