Example #1
0
    var setDimensions = function(layout) {

        // columns
        if (isArray(layout.columns)) {
            layout.columns.forEach(function(dimension) {
                addDimension({
                    id: dimension.dimension,
                    name: dimensionConfig.get(dimension.dimension).name
                }, colStore);
            });
        }

        // rows
        if (isArray(layout.rows)) {
            layout.rows.forEach(function(dimension) {
                addDimension({
                    id: dimension.dimension,
                    name: dimensionConfig.get(dimension.dimension).name
                }, rowStore);
            });
        }

        // filters
        if (isArray(layout.filters)) {
            layout.filters.forEach(function(dimension) {
                addDimension({
                    id: dimension.dimension,
                    name: dimensionConfig.get(dimension.dimension).name
                }, filterStore);
            });
        }
    };
    validateView = function(view) {
        if (!(isArray(view.rows) && view.rows.length && isString(view.rows[0].dimension) && isArray(view.rows[0].items) && view.rows[0].items.length)) {
            GIS.logg.push([view.rows, layer.id + '.rows: dimension array']);
            alert('No organisation units selected');
            return false;
        }

        return view;
    };
    validateView = function(view) {
        if (!(isObject(view.organisationUnitGroupSet) && isString(view.organisationUnitGroupSet.id))) {
            GIS.logg.push([view.organisationUnitGroupSet.id, layer.id + '.organisationUnitGroupSet.id: string']);
            alert(GIS.i18n.no_groupset_selected);
            return false;
        }

        if (!(isArray(view.rows) && view.rows.length && isString(view.rows[0].dimension) && isArray(view.rows[0].items) && view.rows[0].items.length)) {
            GIS.logg.push([view.rows, layer.id + '.rows: dimension array']);
            alert('No organisation units selected');
            return false;
        }

        return view;
    };
Example #4
0
 util.map.isValidCoordinate = function(coord) {
     return isArray(coord)
         && coord.length === 2
         && coord[0] >= -180
         && coord[0] <= 180
         && coord[1] >= -90
         && coord[1] <= 90;
 };
Example #5
0
            return function() {
                var headers = [];

                if (!(config && isObject(config))) {
                    gis.alert('Data response invalid', config);
                    return false;
                }

                if (!(config.headers && isArray(config.headers))) {
                    gis.alert('Data response invalid', config);
                    return false;
                }

                for (var i = 0, header; i < config.headers.length; i++) {
                    header = api.response.Header(config.headers[i]);

                    if (header) {
                        headers.push(header);
                    }
                }

                config.headers = headers;

                if (!config.headers.length) {
                    gis.alert('No valid response headers', config);
                    return;
                }

                if (!(isArray(config.rows) && config.rows.length > 0)) {
                    gis.alert('No values found', config);
                    return false;
                }

                if (config.headers.length !== config.rows[0].length) {
                    gis.alert('Data invalid', config);
                    return false;
                }

                response.headers = config.headers;
                response.metaData = config.metaData;
                response.width = config.width;
                response.height = config.height;
                response.rows = config.rows;

                return response;
            }();
Example #6
0
        api.layout.Dimension = function(config) {
            var dimension = {};

            // dimension: string

            // items: [Record]

            if (!isObject(config)) {
                //console.log('Dimension config is not an object: ' + config);
                return;
            }

            if (!isString(config.dimension)) {
                console.log('Dimension name is not text', config);
                return;
            }

            if (config.dimension !== conf.finals.dimension.category.objectName) {
                var records = [];

                if (!isArray(config.items)) {
                    console.log('Dimension items is not an array', config);
                    return;
                }

                for (var i = 0, record; i < config.items.length; i++) {
                    record = api.layout.Record(config.items[i]);

                    if (record) {
                        records.push(record);
                    }
                }

                config.items = records;

                /* TODO: Breaks loading of event favorite
                 if (!config.items.length) {
                 console.log('Dimension has no valid items', config);
                 return;
                 }
                 */
            }

            dimension.dimension = config.dimension;
            dimension.items = config.items;

            if (config.objectName) {
                dimension.objectName = config.objectName;
            }

            if (config.filter) {
                dimension.filter = config.filter;
            }

            return Ext.clone(dimension);
        };
Example #7
0
        util.array.getLength = function(array, suppressWarning) {
            if (!isArray(array)) {
                if (!suppressWarning) {
                    console.log('support.prototype.array.getLength: not an array');
                }

                return null;
            }

            return array.length;
        };
Example #8
0
            array.sort( function(a, b) {

                // if object, get the property values
                if (isObject(a) && isObject(b)) {
                    a = a[key];
                    b = b[key];
                }

                // if array, get from the right index
                if (isArray(a) && isArray(b)) {
                    a = a[key];
                    b = b[key];
                }

                // string
                if (isString(a) && isString(b)) {
                    a = a.toLowerCase();
                    b = b.toLowerCase();

                    if (direction === 'DESC') {
                        return a < b ? 1 : (a > b ? -1 : 0);
                    }
                    else {
                        return a < b ? -1 : (a > b ? 1 : 0);
                    }
                }
                // number
                else if (isNumber(a) && isNumber(b)) {
                    return direction === 'DESC' ? b - a : a - b;
                }

                else if (a === undefined || a === null) {
                    return emptyFirst ? -1 : 1;
                }

                else if (b === undefined || b === null) {
                    return emptyFirst ? 1 : -1;
                }

                return -1;
            });
        getParentGraphMap: function() {
            var selection = this.getSelectionModel().getSelection(),
                map = {};

            if (isArray(selection) && selection.length) {
                for (var i = 0, pathArray; i < selection.length; i++) {
                    pathArray = selection[i].getPath().split('/');
                    map[pathArray.pop()] = pathArray.join('/');
                }
            }

            return map;
        },
Example #10
0
        util.dhis.getDataDimensionItemTypes = function(dataDimensionItems) {
            var types = [];

            if (isArray(dataDimensionItems) && dataDimensionItems.length) {
                for (var i = 0; i < dataDimensionItems.length; i++) {
                    if (isObject(dataDimensionItems[i])) {
                        types.push(dataDimensionItems[i].dataDimensionItemType);
                    }
                }
            }

            return types;
        };
Example #11
0
                                        data: function() {
                                            var periodType = gis.init.systemSettings.infrastructuralPeriodType.id,
                                                generator = gis.init.periodGenerator,
                                                //periods = generator.filterFuturePeriodsExceptCurrent(generator.generateReversedPeriods(periodType, this.periodOffset)) || [];
                                                periods = generator.filterFuturePeriodsExceptCurrent(generator.generateReversedPeriods(periodType, undefined)) || [];

                                            if (isArray(periods) && periods.length) {
                                                for (var i = 0; i < periods.length; i++) {
                                                    periods[i].id = periods[i].iso;
                                                }

                                                periods = periods.slice(0,5);
                                            }

                                            return periods;
                                        }()
Example #12
0
function TwoPanelSelector(props) {
    const {children, childWrapStyle, ...otherProps} = props;
    const styles = {
        mainStyle: {
            flex: 1,
            display: 'flex',
            flexOrientation: 'row',
            marginTop: '8rem',
        },
    };
    let childrenToRender;

    if (isArray(children)) {
        // More than two children defeats the purpose of a two panel layout and was probably not what the
        // user of the component intended to do.
        if (children.length > 2) {
            log.warn('You passed more than two children to the <TwoPanel /> component, it requires exactly two');
        }

        // We will always only render two children even when more are passed.
        childrenToRender = children.slice(0, 2);
    } else {
        // Just a single child was passed, log a warning because this will only fill the left bar with content.
        // And it was probably not what the user intended to do.
        log.warn('You passed just one child to the <TwoPanel /> component, it requires exactly two');
        childrenToRender = [children];
    }

    const flexedChilden = childrenToRender
        .map((childComponent, index) => {
            const childStyle = Object
                .assign({}, childWrapStyle, {
                    flex: props.sizeRatio[index],
                    paddingRight: (index === children.length - 1) ? '2rem' : undefined,
                });

            return (
                <div key={index} style={childStyle}>{childComponent}</div>
            );
        });

    return (
        <main {...otherProps} style={styles.mainStyle}>
            {flexedChilden}
        </main>
    );
}
Example #13
0
                            items: function() {
                                var a = [];

                                if (att.name) {
                                    a.push({html: GIS.i18n.name, cls: 'gis-panel-html-title'}, {html: att.name, cls: 'gis-panel-html'}, {cls: 'gis-panel-html-separator'});
                                }

                                if (ou.parent) {
                                    a.push({html: GIS.i18n.parent_unit, cls: 'gis-panel-html-title'}, {html: ou.parent.name, cls: 'gis-panel-html'}, {cls: 'gis-panel-html-separator'});
                                }

                                if (ou.code) {
                                    a.push({html: GIS.i18n.code, cls: 'gis-panel-html-title'}, {html: ou.code, cls: 'gis-panel-html'}, {cls: 'gis-panel-html-separator'});
                                }

                                if (ou.address) {
                                    a.push({html: GIS.i18n.address, cls: 'gis-panel-html-title'}, {html: ou.address, cls: 'gis-panel-html'}, {cls: 'gis-panel-html-separator'});
                                }

                                if (ou.email) {
                                    a.push({html: GIS.i18n.email, cls: 'gis-panel-html-title'}, {html: ou.email, cls: 'gis-panel-html'}, {cls: 'gis-panel-html-separator'});
                                }

                                if (ou.phoneNumber) {
                                    a.push({html: GIS.i18n.phone_number, cls: 'gis-panel-html-title'}, {html: ou.phoneNumber, cls: 'gis-panel-html'}, {cls: 'gis-panel-html-separator'});
                                }

                                if (isString(ou.coordinates)) {
                                    var co = ou.coordinates.replace("[","").replace("]","").replace(",",", ");
                                    a.push({html: GIS.i18n.coordinates, cls: 'gis-panel-html-title'}, {html: co, cls: 'gis-panel-html'}, {cls: 'gis-panel-html-separator'});
                                }

                                if (isArray(ou.organisationUnitGroups) && ou.organisationUnitGroups.length) {
                                    var html = '';

                                    for (var i = 0; i < ou.organisationUnitGroups.length; i++) {
                                        html += ou.organisationUnitGroups[i].name;
                                        html += i < ou.organisationUnitGroups.length - 1 ? '<br/>' : '';
                                    }

                                    a.push({html: GIS.i18n.groups, cls: 'gis-panel-html-title'}, {html: html, cls: 'gis-panel-html'}, {cls: 'gis-panel-html-separator'});
                                }

                                return a;
                            }()
Example #14
0
        util.array.getObjectMap = function(array, idProperty, nameProperty, namePrefix) {
            if (!(isArray(array) && array.length)) {
                return {};
            }

            var o = {};
            idProperty = idProperty || 'id';
            nameProperty = nameProperty || 'name';
            namePrefix = namePrefix || '';

            for (var i = 0, obj; i < array.length; i++) {
                obj = array[i];

                o[namePrefix + obj[idProperty]] = obj[nameProperty];
            }

            return o;
        };
Example #15
0
            getValidatedDimensionArray = function(dimensionArray) {
                var dimensions = [];

                if (!(dimensionArray && isArray(dimensionArray) && dimensionArray.length)) {
                    return;
                }


                for (var i = 0, dimension; i < dimensionArray.length; i++) {
                    dimension = api.layout.Dimension(dimensionArray[i]);

                    if (dimension) {
                        dimensions.push(dimension);
                    }
                }

                dimensionArray = dimensions;

                return dimensionArray.length ? dimensionArray : null;
            };
            url = function () {
                var params = '?ou=ou:';

                for (var i = 0; i < items.length; i++) {
                    params += items[i].id;
                    params += i !== items.length - 1 ? ';' : '';
                }

                params += '&displayProperty=' + displayProperty.toUpperCase();

                if (isArray(view.userOrgUnit) && view.userOrgUnit.length) {
                    params += '&userOrgUnit=';

                    for (var i = 0; i < view.userOrgUnit.length; i++) {
                        params += view.userOrgUnit[i] + (i < view.userOrgUnit.length - 1 ? ';' : '');
                    }
                }

                return gis.init.contextPath + '/api/geoFeatures.json' + params;
            }(),
Example #17
0
Request.prototype.add = function(param) {
    var t = this;

    if (isString(param)) {
        t.params.push(param);
    }
    else if (isArray(param)) {
        param.forEach(function(item) {
            if (isString(item)) {
                t.params.push(item);
            }
        });
    }
    else if (isObject(param)) {
        for (var key in param) {
            if (param.hasOwnProperty(key) && !isEmpty(param[key])) {
                t.params.push(key + '=' + param[key]);
            }
        }
    }

    return this;
};
Example #18
0
        util.layout.getAnalytical = function(map) {
            var layout,
                layer;

            if (isObject(map) && isArray(map.mapViews) && map.mapViews.length) {
                for (var i = 0, view, id; i < map.mapViews.length; i++) {
                    view = map.mapViews[i];
                    id = view.layer;

                    if (gis.layer.hasOwnProperty(id) && gis.layer[id].layerCategory === gis.conf.finals.layer.category_thematic) {
                        layout = gis.api.layout.Layout(view);

                        if (layout) {
                            return layout;
                        }
                    }
                }
            }
            else {
                for (var key in gis.layer) {
                    if (gis.layer.hasOwnProperty(key) && key.substring(0, 8) === gis.conf.finals.layer.category_thematic && gis.layer[key].view) {
                        layer = gis.layer[key];
                        layout = gis.api.layout.Layout(layer.view);

                        if (layout) {
                            if (!layout.parentGraphMap && layer.widget) {
                                layout.parentGraphMap = layer.widget.getParentGraphMap();
                            }
                            return layout;
                        }
                    }
                }
            }

            return;
        };
Example #19
0
Layout.prototype.getUserOrgUnitUrl = function() {
    if (isArray(this.userOrgUnit) && this.userOrgUnit.length) {
        return 'userOrgUnit=' + this.userOrgUnit.join(';');
    }
};
Example #20
0
export default function SharingWindow(gis, sharing) {

    // Objects
    var UserGroupRow,

    // Functions
        getBody,

    // Components
        userGroupStore,
        userGroupField,
        userGroupButton,
        userGroupRowContainer,
        externalAccess,
        publicGroup,
        window;

    UserGroupRow = function(obj, isPublicAccess, disallowPublicAccess) {
        var getData,
            store,
            getItems,
            combo,
            getAccess,
            panel;

        getData = function() {
            var data = [
                {id: 'r-------', name: GIS.i18n.can_view},
                {id: 'rw------', name: GIS.i18n.can_edit_and_view}
            ];

            if (isPublicAccess) {
                data.unshift({id: '--------', name: GIS.i18n.none});
            }

            return data;
        }

        store = Ext.create('Ext.data.Store', {
            fields: ['id', 'name'],
            data: getData()
        });

        getItems = function() {
            var items = [];

            combo = Ext.create('Ext.form.field.ComboBox', {
                style: 'margin-bottom:2px',
                fieldLabel: isPublicAccess ? GIS.i18n.public_access : obj.name,
                labelStyle: 'color:#333',
                cls: 'gis-combo',
                width: 380,
                labelWidth: 250,
                queryMode: 'local',
                valueField: 'id',
                displayField: 'name',
                labelSeparator: null,
                editable: false,
                disabled: !!disallowPublicAccess,
                value: obj.access || 'rw------',
                store: store
            });

            items.push(combo);

            if (!isPublicAccess) {
                items.push(Ext.create('Ext.Img', {
                    src: 'images/grid-delete_16.png',
                    style: 'margin-top:2px; margin-left:7px',
                    overCls: 'pointer',
                    width: 16,
                    height: 16,
                    listeners: {
                        render: function(i) {
                            i.getEl().on('click', function(e) {
                                i.up('panel').destroy();
                                window.doLayout();
                            });
                        }
                    }
                }));
            }

            return items;
        };

        getAccess = function() {
            return {
                id: obj.id,
                name: obj.name,
                access: combo.getValue()
            };
        };

        panel = Ext.create('Ext.panel.Panel', {
            layout: 'column',
            bodyStyle: 'border:0 none',
            getAccess: getAccess,
            items: getItems()
        });

        return panel;
    };

    getBody = function() {
        var body = {
            object: {
                id: sharing.object.id,
                name: sharing.object.name,
                publicAccess: publicGroup.down('combobox').getValue(),
                externalAccess: externalAccess ? externalAccess.getValue() : false,
                user: {
                    id: gis.init.user.id,
                    name: gis.init.user.name
                }
            }
        };

        if (userGroupRowContainer.items.items.length > 1) {
            body.object.userGroupAccesses = [];
            for (var i = 1, item; i < userGroupRowContainer.items.items.length; i++) {
                item = userGroupRowContainer.items.items[i];
                body.object.userGroupAccesses.push(item.getAccess());
            }
        }

        return body;
    };

    // Initialize
    userGroupStore = Ext.create('Ext.data.Store', {
        fields: ['id', 'name'],
        proxy: {
            type: 'ajax',
            url: gis.init.contextPath + '/api/sharing/search',
            extraParams: {
                pageSize: 50
            },
            startParam: false,
            limitParam: false,
            reader: {
                type: 'json',
                root: 'userGroups'
            }
        }
    });

    userGroupField = Ext.create('Ext.form.field.ComboBox', {
        valueField: 'id',
        displayField: 'name',
        emptyText: GIS.i18n.search_for_user_groups,
        queryParam: 'key',
        queryDelay: 200,
        minChars: 1,
        hideTrigger: true,
        fieldStyle: 'height:26px; padding-left:6px; border-radius:1px; font-size:11px',
        style: 'margin-bottom:5px',
        width: 380,
        store: userGroupStore,
        listeners: {
            beforeselect: function(cb) { // beforeselect instead of select, fires regardless of currently selected item
                userGroupButton.enable();
            },
            afterrender: function(cb) {
                cb.inputEl.on('keyup', function() {
                    userGroupButton.disable();
                });
            }
        }
    });

    userGroupButton = Ext.create('Ext.button.Button', {
        text: '+',
        style: 'margin-left:2px; padding-right:4px; padding-left:4px; border-radius:1px',
        disabled: true,
        height: 26,
        handler: function(b) {
            userGroupRowContainer.add(UserGroupRow({
                id: userGroupField.getValue(),
                name: userGroupField.getRawValue(),
                access: 'r-------'
            }));

            userGroupField.clearValue();
            b.disable();
        }
    });

    userGroupRowContainer = Ext.create('Ext.container.Container', {
        bodyStyle: 'border:0 none'
    });

    if (sharing.meta.allowExternalAccess) {
        externalAccess = userGroupRowContainer.add({
            xtype: 'checkbox',
            fieldLabel: GIS.i18n.allow_external_access,
            labelSeparator: '',
            labelWidth: 250,
            checked: !!sharing.object.externalAccess
        });
    }

    publicGroup = userGroupRowContainer.add(UserGroupRow({
        id: sharing.object.id,
        name: sharing.object.name,
        access: sharing.object.publicAccess
    }, true, !sharing.meta.allowPublicAccess));

    if (isArray(sharing.object.userGroupAccesses)) {
        for (var i = 0, userGroupRow; i < sharing.object.userGroupAccesses.length; i++) {
            userGroupRow = UserGroupRow(sharing.object.userGroupAccesses[i]);
            userGroupRowContainer.add(userGroupRow);
        }
    }

    window = Ext.create('Ext.window.Window', {
        title: 'Sharing settings',
        bodyStyle: 'padding:5px 5px 3px; background-color:#fff',
        resizable: false,
        modal: true,
        destroyOnBlur: true,
        items: [
            {
                html: sharing.object.name,
                bodyStyle: 'border:0 none; font-weight:bold; color:#333',
                style: 'margin-bottom:7px'
            },
            {
                xtype: 'container',
                layout: 'column',
                bodyStyle: 'border:0 none',
                items: [
                    userGroupField,
                    userGroupButton
                ]
            },
            {
                html: GIS.i18n.created_by + ' ' + sharing.object.user.name,
                bodyStyle: 'border:0 none; color:#777',
                style: 'margin-top:2px;margin-bottom:7px'
            },
            userGroupRowContainer
        ],
        bbar: [
            '->',
            {
                text: 'Save',
                handler: function() {
                    Ext.Ajax.request({
                        url: gis.init.contextPath + '/api/sharing?type=map&id=' + sharing.object.id,
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/json'
                        },
                        params: JSON.stringify(getBody())
                    });

                    window.destroy();
                }
            }
        ],
        listeners: {
            show: function(w) {
                var pos = gis.viewport.favoriteWindow.getPosition();
                w.setPosition(pos[0] + 5, pos[1] + 5);

                if (!w.hasDestroyOnBlurHandler) {
                    gis.util.gui.window.addDestroyOnBlurHandler(w);
                }

                gis.viewport.favoriteWindow.destroyOnBlur = false;
            },
            destroy: function() {
                gis.viewport.favoriteWindow.destroyOnBlur = true;
            }
        }
    });

    return window;
};
Example #21
0
            return function() {
                var objectNames =   [],
                    dimConf = conf.finals.dimension,
                    isOu = false,
                    isOuc = false,
                    isOugc = false;

                config = validateSpecialCases(config);

                if (!config) {
                    return;
                }

                config.columns = getValidatedDimensionArray(config.columns);
                config.rows = getValidatedDimensionArray(config.rows);
                config.filters = getValidatedDimensionArray(config.filters);

                if (!config.rows) {
                    console.log('Organisation unit dimension is invalid', config.rows);
                    return;
                }

                if (arrayContains([gis.layer.thematic1.id, gis.layer.thematic2.id, gis.layer.thematic3.id, gis.layer.thematic4.id], config.layer)) {
                    if (!config.columns) {
                        return;
                    }
                }

                // Collect object names and user orgunits
                for (var i = 0, dim, dims = arrayClean([].concat(config.columns, config.rows, config.filters)); i < dims.length; i++) {
                    dim = dims[i];

                    if (dim) {

                        // Object names
                        if (isString(dim.dimension)) {
                            objectNames.push(dim.dimension);
                        }

                        // user orgunits
                        if (dim.dimension === dimConf.organisationUnit.objectName && isArray(dim.items)) {
                            for (var j = 0; j < dim.items.length; j++) {
                                if (dim.items[j].id === 'USER_ORGUNIT') {
                                    isOu = true;
                                }
                                else if (dim.items[j].id === 'USER_ORGUNIT_CHILDREN') {
                                    isOuc = true;
                                }
                                else if (dim.items[j].id === 'USER_ORGUNIT_GRANDCHILDREN') {
                                    isOugc = true;
                                }
                            }
                        }
                    }
                }

                // Layout
                layout.columns = config.columns;
                layout.rows = config.rows;
                layout.filters = config.filters;

                // program
                if (isObject(config.program) && config.program.id) {
                    layout.program = config.program;
                }

                // program stage
                if (isObject(config.programStage) && config.programStage.id) {
                    layout.programStage = config.programStage;
                }

                if (config.startDate) {
                    layout.startDate = config.startDate.substring(0, 10);
                }

                if (config.endDate) {
                    layout.endDate = config.endDate.substring(0, 10);
                }

                if (config.valueType) {
                    layout.valueType = config.valueType;
                }

                if (config.eventClustering) {
                    layout.eventClustering = config.eventClustering;
                }

                if (config.eventPointColor) {
                    layout.eventPointColor = config.eventPointColor;
                }

                if (config.eventPointRadius) {
                    layout.eventPointRadius = config.eventPointRadius;
                }

                // Properties
                layout.layer = isString(config.layer) && !isEmpty(config.layer) ? config.layer : 'thematic1';
                layout.classes = isNumber(config.classes) && !isEmpty(config.classes) ? config.classes : 5;
                layout.method = isNumber(config.method) && !isEmpty(config.method) ? config.method : 2;
                layout.colorLow = isString(config.colorLow) && !isEmpty(config.colorLow) ? config.colorLow : 'ff0000';
                layout.colorHigh = isString(config.colorHigh) && !isEmpty(config.colorHigh) ? config.colorHigh : '00ff00';
                layout.radiusLow = isNumber(config.radiusLow) && !isEmpty(config.radiusLow) ? config.radiusLow : 5;
                layout.radiusHigh = isNumber(config.radiusHigh) && !isEmpty(config.radiusHigh) ? config.radiusHigh : 15;
                layout.opacity = isNumber(config.opacity) && !isEmpty(config.opacity) ? config.opacity : gis.conf.layout.layer.opacity;
                layout.areaRadius = config.areaRadius;

                layout.labels = !!config.labels;

                layout.labelFontSize = config.labelFontSize || '11px';
                layout.labelFontSize = parseInt(layout.labelFontSize) + 'px';

                layout.labelFontWeight = isString(config.labelFontWeight) || isNumber(config.labelFontWeight) ? config.labelFontWeight : 'normal';
                layout.labelFontWeight = arrayContains(['normal', 'bold', 'bolder', 'lighter'], layout.labelFontWeight) ? layout.labelFontWeight : 'normal';
                layout.labelFontWeight = isNumber(parseInt(layout.labelFontWeight)) && parseInt(layout.labelFontWeight) <= 1000 ? layout.labelFontWeight.toString() : layout.labelFontWeight;

                layout.labelFontStyle = arrayContains(['normal', 'italic', 'oblique'], config.labelFontStyle) ? config.labelFontStyle : 'normal';

                layout.labelFontColor = isString(config.labelFontColor) || isNumber(config.labelFontColor) ? config.labelFontColor : 'normal';
                layout.labelFontColor = isNumber(layout.labelFontColor) ? layout.labelFontColor.toString() : layout.labelFontColor;
                layout.labelFontColor = layout.labelFontColor.charAt(0) !== '#' ? '#' + layout.labelFontColor : layout.labelFontColor;

                layout.hidden = !!config.hidden;

                layout.userOrganisationUnit = isOu;
                layout.userOrganisationUnitChildren = isOuc;
                layout.userOrganisationUnitGrandChildren = isOugc;

                layout.parentGraphMap = isObject(config.parentGraphMap) ? config.parentGraphMap : null;

                layout.legendSet = config.legendSet;

                layout.organisationUnitGroupSet = config.organisationUnitGroupSet;

                layout.dataDimensionItems = config.dataDimensionItems;

                layout.key = config.key; // Earth Engine layer

                if (arrayFrom(config.userOrgUnit).length) {
                    layout.userOrgUnit = arrayFrom(config.userOrgUnit);
                }

                // relative period date
                if (util.date.getYYYYMMDD(config.relativePeriodDate)) {
                    layout.relativePeriodDate = support.prototype.date.getYYYYMMDD(config.relativePeriodDate);
                }

                return Ext.apply(layout, forceApplyConfig);
            }();
Example #22
0
	setMap = function() {
		var basemap = gis.map.basemap || 'openStreetMap',
			views = gis.map.mapViews,
			handler,
			layer;

		// title
		if (gis.dashboard && gis.container && gis.map && gis.map.name) {
			gis.container.childNodes[0].innerText = gis.map.name;
		}

		if (!(isArray(views) && views.length)) {
			if (gis.mask) {
				gis.mask.hide();
			}
			gis.alert(GIS.i18n.favorite_outdated_create_new);
			return;
		}

		for (var i = 0, applyView; i < views.length; i++) {
			applyView = applyViews ? applyViews[i] : null;
			views[i] = gis.api.layout.Layout(views[i], applyView);
		}

		views = arrayClean(views);

		if (!views.length) {
			if (gis.mask) {
				gis.mask.hide();
			}
			return;
		}

		if (gis.viewport && gis.viewport.favoriteWindow && gis.viewport.favoriteWindow.isVisible()) {
			gis.viewport.favoriteWindow.destroy();
		}

		clearAllLayers();

		// Add basemap
		if (basemap !== 'none' && gis.layer[basemap]) {
			layer = gis.layer[basemap];
			if (layer.instance) { // Layer instance already exist
				gis.instance.addLayer(layer.instance);
			} else { // Create and add layer instance
				layer.instance = gis.instance.addLayer(layer.config);
			}

			if (layer.item) {
				layer.item.setValue(true, 1);
			}
		}

		// Add views/overlays
		for (var i = 0, layout, layer; i < views.length; i++) {
			layout = views[i];
			layer = gis.layer[layout.layer];

			handler = layer.handler(gis, layer);
			handler.updateGui = !gis.el;
			handler.callBack = callBack;
			handler.load(layout);
		}
	};
Example #23
0
Layout = function(c, applyConfig, forceApplyConfig) {
    var t = this;
    t.klass = Layout;

    c = isObject(c) ? c : {};
    $.extend(c, applyConfig);

    // private
    var _appManager = t.klass.appManager;
    var _source = '/api/analytics';
    var _format = 'json';

    var _response;
    var _access;

    var _dataDimensionItems;

    // constructor
    t.columns = (Axis(c.columns)).val();
    t.rows = (Axis(c.rows)).val();
    t.filters = (Axis(c.filters)).val(true);

    t.showColTotals = isBoolean(c.colTotals) ? c.colTotals : (isBoolean(c.showColTotals) ? c.showColTotals : true);
    t.showRowTotals = isBoolean(c.rowTotals) ? c.rowTotals : (isBoolean(c.showRowTotals) ? c.showRowTotals : true);
    t.showColCumulativeTotals = isBoolean(c.colCumulativeTotals) ? c.colCumulativeTotals : (isBoolean(c.showColCumulativeTotals) ? c.showColCumulativeTotals : false);
    t.showRowCumulativeTotals = isBoolean(c.rowCumulativeTotals) ? c.rowCumulativeTotals : (isBoolean(c.showRowCumulativeTotals) ? c.showRowCumulativeTotals : false);
    t.showColSubTotals = isBoolean(c.colSubTotals) ? c.colSubTotals : (isBoolean(c.showColSubTotals) ? c.showColSubTotals : true);
    t.showRowSubTotals = isBoolean(c.rowSubTotals) ? c.rowSubTotals : (isBoolean(c.showRowSubTotals) ? c.showRowSubTotals : true);
    t.showDimensionLabels = isBoolean(c.showDimensionLabels) ? c.showDimensionLabels : (isBoolean(c.showDimensionLabels) ? c.showDimensionLabels : true);
    t.hideEmptyRows = isBoolean(c.hideEmptyRows) ? c.hideEmptyRows : false;
    t.skipRounding = isBoolean(c.skipRounding) ? c.skipRounding : false;
    t.aggregationType = isString(c.aggregationType) ? c.aggregationType : t.klass.optionConfig.getAggregationType('def').id;
    t.dataApprovalLevel = isObject(c.dataApprovalLevel) && isString(c.dataApprovalLevel.id) ? c.dataApprovalLevel : null;
    t.showHierarchy = isBoolean(c.showHierarchy) ? c.showHierarchy : false;
    t.completedOnly = isBoolean(c.completedOnly) ? c.completedOnly : false;
    t.displayDensity = isString(c.displayDensity) && !isEmpty(c.displayDensity) ? c.displayDensity : t.klass.optionConfig.getDisplayDensity('normal').id;
    t.fontSize = isString(c.fontSize) && !isEmpty(c.fontSize) ? c.fontSize : t.klass.optionConfig.getFontSize('normal').id;
    t.digitGroupSeparator = isString(c.digitGroupSeparator) && !isEmpty(c.digitGroupSeparator) ? c.digitGroupSeparator : t.klass.optionConfig.getDigitGroupSeparator('space').id;

    t.legendSet = (new Record(c.legendSet)).val(true);

    t.parentGraphMap = isObject(c.parentGraphMap) ? c.parentGraphMap : null;

    if (isObject(c.program)) {
        t.program = c.program;
    }

        // report table
    t.reportingPeriod = isObject(c.reportParams) && isBoolean(c.reportParams.paramReportingPeriod) ? c.reportParams.paramReportingPeriod : (isBoolean(c.reportingPeriod) ? c.reportingPeriod : false);
    t.organisationUnit =  isObject(c.reportParams) && isBoolean(c.reportParams.paramOrganisationUnit) ? c.reportParams.paramOrganisationUnit : (isBoolean(c.organisationUnit) ? c.organisationUnit : false);
    t.parentOrganisationUnit = isObject(c.reportParams) && isBoolean(c.reportParams.paramParentOrganisationUnit) ? c.reportParams.paramParentOrganisationUnit : (isBoolean(c.parentOrganisationUnit) ? c.parentOrganisationUnit : false);

    t.regression = isBoolean(c.regression) ? c.regression : false;
    t.cumulative = isBoolean(c.cumulative) ? c.cumulative : false;
    t.sortOrder = isNumber(c.sortOrder) ? c.sortOrder : 0;
    t.topLimit = isNumber(c.topLimit) ? c.topLimit : 0;

        // Legend set
    if (_appManager.legendSets && t.legendSet && t.legendSet.id)  {
        for (var i = 0, legendSet; i < _appManager.legendSets.length; i++) {
            legendSet = _appManager.legendSets[i];
            if (legendSet.id === t.legendSet.id) {
                $.extend(t.legendSet, legendSet);
                break;
            }
         }
    }
        // sharing
    _access = isObject(c.access) ? c.access : null;

        // data dimension items
    _dataDimensionItems = isArray(c.dataDimensionItems) ? c.dataDimensionItems : null;

        // non model

        // id
    if (isString(c.id)) {
        t.id = c.id;
    }

        // name
    if (isString(c.name)) {
        t.name = c.name;
    }

        // sorting
    if (isObject(c.sorting) && isDefined(c.sorting.id) && isString(c.sorting.direction)) {
        t.sorting = c.sorting;
    }

        // displayProperty
    if (isString(c.displayProperty)) {
        t.displayProperty = c.displayProperty;
    }

        // userOrgUnit
    if (arrayFrom(c.userOrgUnit).length) {
        t.userOrgUnit = arrayFrom(c.userOrgUnit);
    }

        // relative period date
    if (DateManager.getYYYYMMDD(c.relativePeriodDate)) {
        t.relativePeriodDate = DateManager.getYYYYMMDD(c.relativePeriodDate);
    }

    if (c.el && isString(c.el)) {
        t.el = c.el;
    }

    $.extend(t, forceApplyConfig);

    // setter/getter
    t.getResponse = function() {
        return _response;
    };

    t.setResponse = function(r) {
        _response = r;
    };

    t.getAccess = function() {
        return _access;
    };

    t.setAccess = function(a) {
        _access = a;
    };

    t.getDataDimensionItems = function() {
        return _dataDimensionItems;
    };

    t.setDataDimensionItems = function(a) {
        _dataDimensionItems = a;
    };

    t.getRequestPath = function(s, f) {
        return t.klass.appManager.getPath() + (s || _source) + '.' + (f || _format);
    };
};
Example #24
0
    getRowHtmlArray = function() {
        var a = [],
            axisAllObjects = [],
            xValueObjects,
            totalValueObjects = [],
            cumulativeTotalValueObjects = [],
            mergedObjects = [],
            valueItemsCopy,
            colAxisSize = colAxis.type ? colAxis.size : 1,
            rowAxisSize = rowAxis.type ? rowAxis.size : 1,
            recursiveReduce;

        recursiveReduce = function(obj) {
            if (!obj.children) {
                obj.collapsed = true;

                if (obj.parent) {
                    obj.parent.oldestSibling.children--;
                }
            }

            if (obj.parent) {
                recursiveReduce(obj.parent.oldestSibling);
            }
        };

        // dimension
        if (rowAxis.type) {
            for (var i = 0, row; i < rowAxis.size; i++) {
                row = [];

                for (var j = 0, obj, newObj; j < rowAxis.dims; j++) {
                    obj = rowAxis.objects.all[j][i];
                    obj.type = 'dimension';
                    obj.cls = 'pivot-dim td-nobreak' + (layout.showHierarchy ? ' align-left' : '');
                    obj.noBreak = true;
                    obj.hidden = !(obj.rowSpan || obj.colSpan);
                    obj.htmlValue = response.getItemName(obj.id, layout.showHierarchy, true);

                    row.push(obj);
                }

                axisAllObjects.push(row);
            }
        }
        else {
            if (layout.showDimensionLabels) {
                axisAllObjects.push([{
                    type: 'transparent',
                    cls: 'pivot-transparent-row'
                }]);
            }
        }


//axisAllObjects = [ [ dim, dim ]
//                   [ dim, dim ]
//                   [ dim, dim ]
//                   [ dim, dim ] ];

        // value
        for (var i = 0, valueItemsRow, valueObjectsRow; i < rowAxisSize; i++) {
            valueItemsRow = [];
            valueObjectsRow = [];

            for (var j = 0, rric, value, responseValue, htmlValue, empty, _uuid, uuids; j < colAxisSize; j++) {
                rric = new ResponseRowIdCombination();
                empty = false;
                uuids = [];

                // meta data uid
                rric.add(colAxis.type ? colAxis.ids[j] : '');
                rric.add(rowAxis.type ? rowAxis.ids[i] : '');

                // value html element id
                _uuid = uuid();

                // get uuids array from colaxis/rowaxis leaf
                if (colAxis.type) {
                    uuids = uuids.concat(colAxis.objects.all[colAxis.dims - 1][j].uuids);
                }
                if (rowAxis.type) {
                    uuids = uuids.concat(rowAxis.objects.all[rowAxis.dims - 1][i].uuids);
                }

                // value, htmlValue
                responseValue = idValueMap[rric.get()];

                if (isDefined(responseValue)) {
                    value = getValue(responseValue);
                    htmlValue = responseValue;
                }
                else {
                    value = 0;
                    htmlValue = '&nbsp;';
                    empty = true;
                }

                valueItemsRow.push(value);
                valueObjectsRow.push({
                    uuid: _uuid,
                    type: 'value',
                    cls: 'pivot-value' + (empty ? ' cursor-default' : ''),
                    value: value,
                    htmlValue: htmlValue,
                    empty: empty,
                    uuids: uuids
                });

                // map element id to dim element ids
                uuidDimUuidsMap[_uuid] = uuids;
            }

            valueItems.push(valueItemsRow);
            valueObjects.push(valueObjectsRow);
        }

        // totals
        if (colAxis.type && doRowTotals()) {
            for (var i = 0, empty = [], total = 0; i < valueObjects.length; i++) {
                for (j = 0, obj; j < valueObjects[i].length; j++) {
                    obj = valueObjects[i][j];

                    empty.push(obj.empty);
                    total += obj.value;
                }

                // row totals
                totalValueObjects.push({
                    type: 'valueTotal',
                    cls: 'pivot-value-total',
                    value: total,
                    htmlValue: arrayContains(empty, false) ? getRoundedHtmlValue(total) : '',
                    empty: !arrayContains(empty, false)
                });

                // add row totals to idValueMap to make sorting on totals possible
                if (doSortableColumnHeaders()) {
                    var totalIdComb = new ResponseRowIdCombination(['total', rowAxis.ids[i]]),
                        isEmpty = !arrayContains(empty, false);

                    idValueMap[totalIdComb.get()] = isEmpty ? null : total;
                }

                empty = [];
                total = 0;
            }
        }

        // cumulative totals
        if (colAxis.type && doRowCumulativeTotals()) {
            for (var i = 0, empty = [], total = 0; i < valueObjects.length; i++) {
                for (j = 0, obj; j < valueObjects[i].length; j++) {
                    obj = valueObjects[i][j];
                    empty.push(obj.empty);
                    total += obj.value;
                }

                cumulativeTotalValueObjects.push({
                    type: 'valueTotal',
                    cls: 'pivot-value-total',
                    value: total,
                    htmlValue: arrayContains(empty, false) ? getRoundedHtmlValue(total) : '',
                    empty: !arrayContains(empty, false)
                });

                empty = [];
            }
        }

        // hide empty rows (dims/values/totals)
        if (colAxis.type && rowAxis.type) {
            if (layout.hideEmptyRows) {
                for (var i = 0, valueRow, isValueRowEmpty, dimLeaf; i < valueObjects.length; i++) {
                    valueRow = valueObjects[i];
                    isValueRowEmpty = !arrayContains(arrayPluck(valueRow, 'empty'), false);

                    // if value row is empty
                    if (isValueRowEmpty) {

                        // hide values by adding collapsed = true to all items
                        for (var j = 0; j < valueRow.length; j++) {
                            valueRow[j].collapsed = true;
                        }

                        // hide totals by adding collapsed = true to all items
                        if (doRowTotals()) {
                            totalValueObjects[i].collapsed = true;
                        }
                        
                        // hide cumulative totals by adding collapsed = true to all items
                        if (doRowCumulativeTotals()) {
                            cumulativeTotalValueObjects[i].collapsed = true;
                        }

                        // hide/reduce parent dim span
                        dimLeaf = axisAllObjects[i][rowAxis.dims-1];
                        recursiveReduce(dimLeaf);
                    }
                }
            }
        }

        xValueObjects = valueObjects;

        // col subtotals
        if (doRowSubTotals()) {
            var tmpValueObjects = [];

            for (var i = 0, row, rowSubTotal, colCount; i < xValueObjects.length; i++) {
                row = [];
                rowSubTotal = 0;
                colCount = 0;

                for (var j = 0, item, collapsed = [], empty = []; j < xValueObjects[i].length; j++) {
                    item = xValueObjects[i][j];
                    rowSubTotal += item.value;
                    empty.push(!!item.empty);
                    collapsed.push(!!item.collapsed);
                    colCount++;

                    row.push(item);

                    if (colCount === colUniqueFactor) {
                        var isEmpty = !arrayContains(empty, false);
                        row.push({
                            type: 'valueSubtotal',
                            cls: 'pivot-value-subtotal' + (isEmpty ? ' cursor-default' : ''),
                            value: rowSubTotal,
                            htmlValue: isEmpty ? '&nbsp;' : getRoundedHtmlValue(rowSubTotal),
                            empty: isEmpty,
                            collapsed: !arrayContains(collapsed, false)
                        });

                        colCount = 0;
                        rowSubTotal = 0;
                        empty = [];
                        collapsed = [];
                    }
                }

                tmpValueObjects.push(row);
            }

            xValueObjects = tmpValueObjects;
        }

        // row subtotals
        if (doColSubTotals()) {
            var tmpAxisAllObjects = [],
                tmpValueObjects = [],
                tmpTotalValueObjects = [],
                getAxisSubTotalRow;

            getAxisSubTotalRow = function(collapsed) {
                var row = [];

                for (var i = 0, obj; i < rowAxis.dims; i++) {
                    obj = {};
                    obj.type = 'dimensionSubtotal';
                    obj.cls = 'pivot-dim-subtotal cursor-default';
                    obj.collapsed = arrayContains(collapsed, true);

                    if (i === 0) {
                        obj.htmlValue = '&nbsp;';
                        obj.colSpan = rowAxis.dims;
                    }
                    else {
                        obj.hidden = true;
                    }

                    row.push(obj);
                }

                return row;
            };

            // tmpAxisAllObjects
            for (var i = 0, row, collapsed = []; i < axisAllObjects.length; i++) {
                tmpAxisAllObjects.push(axisAllObjects[i]);
                collapsed.push(!!axisAllObjects[i][0].collapsed);

                // insert subtotal after last objects
                if (!isArray(axisAllObjects[i+1]) || !!axisAllObjects[i+1][0].root) {
                    tmpAxisAllObjects.push(getAxisSubTotalRow(collapsed));

                    collapsed = [];
                }
            }

            // tmpValueObjects
            for (var i = 0; i < tmpAxisAllObjects.length; i++) {
                tmpValueObjects.push([]);
            }

            for (var i = 0; i < xValueObjects[0].length; i++) {
                for (var j = 0, rowCount = 0, tmpCount = 0, subTotal = 0, empty = [], collapsed, item; j < xValueObjects.length; j++) {
                    item = xValueObjects[j][i];
                    tmpValueObjects[tmpCount++].push(item);
                    subTotal += item.value;
                    empty.push(!!item.empty);
                    rowCount++;

                    if (axisAllObjects[j][0].root) {
                        collapsed = !!axisAllObjects[j][0].collapsed;
                    }

                    if (!isArray(axisAllObjects[j+1]) || axisAllObjects[j+1][0].root) {
                        var isEmpty = !arrayContains(empty, false);

                        tmpValueObjects[tmpCount++].push({
                            type: item.type === 'value' ? 'valueSubtotal' : 'valueSubtotalTotal',
                            value: subTotal,
                            htmlValue: isEmpty ? '&nbsp;' : getRoundedHtmlValue(subTotal),
                            collapsed: collapsed,
                            cls: (item.type === 'value' ? 'pivot-value-subtotal' : 'pivot-value-subtotal-total') + (isEmpty ? ' cursor-default' : '')
                        });
                        rowCount = 0;
                        subTotal = 0;
                        empty = [];
                    }
                }
            }

            // tmpTotalValueObjects
            for (var i = 0, obj, collapsed = [], empty = [], subTotal = 0, count = 0; i < totalValueObjects.length; i++) {
                obj = totalValueObjects[i];
                tmpTotalValueObjects.push(obj);

                collapsed.push(!!obj.collapsed);
                empty.push(!!obj.empty);
                subTotal += obj.value;
                count++;

                if (count === rowAxis.span[0]) {
                    var isEmpty = !arrayContains(empty, false);

                    tmpTotalValueObjects.push({
                        type: 'valueTotalSubgrandtotal',
                        cls: 'pivot-value-total-subgrandtotal' + (isEmpty ? ' cursor-default' : ''),
                        value: subTotal,
                        htmlValue: isEmpty ? '&nbsp;' : getRoundedHtmlValue(subTotal),
                        empty: isEmpty,
                        collapsed: !arrayContains(collapsed, false)
                    });

                    collapsed = [];
                    empty = [];
                    subTotal = 0;
                    count = 0;
                }
            }

            axisAllObjects = tmpAxisAllObjects;
            xValueObjects = tmpValueObjects;
            totalValueObjects = tmpTotalValueObjects;
        }

        // merge dim, value, total
        for (var i = 0, row; i < xValueObjects.length; i++) {
            row = [];

            //if (rowAxis) {
                row = row.concat(axisAllObjects[i]);
            //}

            row = row.concat(xValueObjects[i]);

            if (colAxis.type) {
                row = row.concat(totalValueObjects[i]);
                row = row.concat(cumulativeTotalValueObjects[i]);
            }

            mergedObjects.push(row);
        }

        // create html items
        for (var i = 0, row; i < mergedObjects.length; i++) {
            row = [];

            for (var j = 0; j < mergedObjects[i].length; j++) {
                row.push(getTdHtml(mergedObjects[i][j]));
            }

            a.push(row);
        }

        return a;
    };
Example #25
0
Layout.prototype.req = function(source, format, isSorted, isTableLayout) {
    var optionConfig = this.klass.optionConfig,
        displayProperty = this.displayProperty || this.klass.appManager.getAnalyticsDisplayProperty(),
        request = new Request();

    var defAggTypeId = optionConfig.getAggregationType('def').id;

    // dimensions
    this.getDimensions(false, isSorted).forEach(function(dimension) {
        request.add(dimension.url(isSorted));
    });

    // filters
    if (this.filters) {
        this.filters.forEach(function(dimension) {
            request.add(dimension.url(isSorted, null, true));
        });
    }

    // skip rounding
    if (this.skipRounding) {
        request.add('skipRounding=true');
    }

    // display property
    request.add('displayProperty=' + displayProperty.toUpperCase());

    // normal request only
    if (!isTableLayout) {

        // hierarchy
        if (this.showHierarchy) {
            request.add('hierarchyMeta=true');
        }

        // completed only
        if (this.completedOnly) {
            request.add('completedOnly=true');
        }

        // aggregation type
        if (isString(this.aggregationType) && this.aggregationType !== defAggTypeId) {
            request.add('aggregationType=' + this.aggregationType);
        }

        // user org unit
        if (isArray(this.userOrgUnit) && this.userOrgUnit.length) {
            request.add(this.getUserOrgUnitUrl());
        }

        // data approval level
        if (isObject(this.dataApprovalLevel) && isString(this.dataApprovalLevel.id) && this.dataApprovalLevel.id !== 'DEFAULT') {
            request.add('approvalLevel=' + this.dataApprovalLevel.id);
        }

        // relative period date
        if (this.relativePeriodDate) {
            request.add('relativePeriodDate=' + this.relativePeriodDate);
        }
    }
    else {

        // table layout
        request.add('tableLayout=true');

        // columns
        request.add('columns=' + this.getDimensionNames(false, false, this.columns).join(';'));

        // rows
        request.add('rows=' + this.getDimensionNames(false, false, this.rows).join(';'));

        // hide empty rows
        if (this.hideEmptyRows) {
            request.add('hideEmptyRows=true');
        }
    }

    // base
    request.setBaseUrl(this.getRequestPath(source, format));

    return request;
};
    loadData = function (view, features) {
        var success;

        view = view || layer.view;
        features = features || layer.featureStore.features;

        var dimConf = gis.conf.finals.dimension,
            paramString = '?',
            dxItems = view.columns[0].items,
            isOperand = view.columns[0].dimension === dimConf.operand.objectName,
            peItems = view.filters[0].items,
            ouItems = view.rows[0].items,
            propertyMap = {
                'name': 'name',
                'displayName': 'name',
                'shortName': 'shortName',
                'displayShortName': 'shortName'
            },
            keyAnalysisDisplayProperty = gis.init.userAccount.settings.keyAnalysisDisplayProperty,
            displayProperty = propertyMap[keyAnalysisDisplayProperty] || propertyMap[view.displayProperty] || 'name';

        // ou
        paramString += 'dimension=ou:';

        for (var i = 0; i < ouItems.length; i++) {
            paramString += ouItems[i].id;
            paramString += i < ouItems.length - 1 ? ';' : '';
        }

        // dx
        paramString += '&dimension=dx:';

        for (var i = 0; i < dxItems.length; i++) {
            paramString += isOperand ? dxItems[i].id.split('.')[0] : dxItems[i].id;
            paramString += i < dxItems.length - 1 ? ';' : '';
        }

        // program
        if (view.program) {
            paramString += '&program=' + view.program.id;
        }

        paramString += isOperand ? '&dimension=co' : '';

        // pe
        paramString += '&filter=pe:';

        for (var i = 0; i < peItems.length; i++) {
            paramString += peItems[i].id;
            paramString += i < peItems.length - 1 ? ';' : '';
        }

        // display property
        paramString += '&displayProperty=' + displayProperty.toUpperCase();

        if (isArray(view.userOrgUnit) && view.userOrgUnit.length) {
            paramString += '&userOrgUnit=';

            for (var i = 0; i < view.userOrgUnit.length; i++) {
                paramString += view.userOrgUnit[i] + (i < view.userOrgUnit.length - 1 ? ';' : '');
            }
        }

        // relative period date
        if (view.relativePeriodDate) {
            paramString += '&relativePeriodDate=' + view.relativePeriodDate;
        }

        success = function (json) {
            var response = gis.api.response.Response(json), // validate
                featureMap = {},
                valueMap = {},
                ouIndex,
                valueIndex,
                valueFeatures = [], // only include features with values
                values = []; // to find min and max values

            if (!response) {
                gis.mask.hide();
                return;
            }

            // ou index, value index
            for (var i = 0; i < response.headers.length; i++) {
                if (response.headers[i].name === dimConf.organisationUnit.dimensionName) {
                    ouIndex = i;
                }
                else if (response.headers[i].name === dimConf.value.dimensionName) {
                    valueIndex = i;
                }
            }

            // Feature map
            for (var i = 0, id; i < features.length; i++) {
                var id = features[i].id;
                featureMap[id] = true;
            }

            // Value map
            for (var i = 0; i < response.rows.length; i++) {
                var id = response.rows[i][ouIndex],
                    value = parseFloat(response.rows[i][valueIndex]);

                valueMap[id] = value;
            }

            for (var i = 0; i < features.length; i++) {
                var feature = features[i],
                    id = feature.id;

                if (featureMap.hasOwnProperty(id) && valueMap.hasOwnProperty(id)) {
                    feature.properties.value = valueMap[id];
                    valueFeatures.push(feature);
                    values.push(valueMap[id]);
                }
            }

            // Sort values in ascending order
            values.sort(function (a, b) {
                return a - b;
            });

            // TODO: Temporarilty fix
            gis.data = {
                metaData: response.metaData,
                features: valueFeatures,
                values: values
            };

            gis.response = response;

            loadLegend(view);
        };

        Ext.Ajax.request({
            url: gis.init.contextPath + '/api/analytics.json' + paramString,
            disableCaching: false,
            failure: function (r) {
                gis.alert(r);
            },
            success: function (r) {
                success(JSON.parse(r.responseText));
            }
        });
    };