Example #1
0
Request = function(config) {
    var t = this;
    t.klass = Request;

    config = isObject(config) ? config : {};

    // constructor
    t.method = isString(config.method) ? config.method : 'GET';
    t.headers = isObject(config.headers) ? config.headers : null;
    t.dataType = isString(config.dataType) ? config.dataType : null;
    t.contentType = isString(config.contentType) ? config.contentType : null;
    t.success = isFunction(config.success) ? config.success : function() { t.defaultSuccess(); };
    t.error = isFunction(config.error) ? config.error : function() { t.defaultError(); };
    t.complete = isFunction(config.complete) ? config.complete : function() { t.defaultComplete(); };

    t.type = isString(config.type) ? config.type : 'ajax';
    t.baseUrl = isString(config.baseUrl) ? config.baseUrl : '';
    t.params = arrayFrom(config.params);
    t.manager = config.manager || null;

    t.beforeRun = isFunction(config.beforeRun) ? config.beforeRun : null;

    // defaults
    t.defaultSuccess = function() {
        var t = this;

        if (t.manager) {
            t.manager.ok(t);
        }
    };

    t.defaultError = function() {};
    t.defaultComplete = function() {};
};
    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;
    };
    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;
    };
Example #4
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 #5
0
        util.layout.setSessionStorage = function(session, obj, url) {
            if (GIS.isSessionStorage) {
                var dhis2 = JSON.parse(sessionStorage.getItem('dhis2')) || {};
                dhis2[session] = obj;
                sessionStorage.setItem('dhis2', JSON.stringify(dhis2));

                if (isString(url)) {
                    window.location.href = url;
                }
            }
        };
Example #6
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;
            });
Example #7
0
        util.message.alert = function(obj) {
            var html;

            if (!obj || (isObject(obj) && !obj.message && !obj.responseText)) {
                return;
            }

            // if response object
            if (isObject(obj) && obj.responseText && !obj.message) {
                obj = JSON.parse(obj.responseText);
            }

            // if string
            if (isString(obj)) {
                obj = {
                    status: 'ERROR',
                    message: obj
                };
            }

            // plugin message
            html = obj.httpStatusCode ? 'Code: ' + obj.httpStatusCode + '<br>' : '';
            html += obj.httpStatus ? 'Status: ' + obj.httpStatus + '<br><br>' : '';
            html += obj.message + (obj.message.substr(obj.message.length - 1) === '.' ? '' : '.');

            if (gis.viewport && gis.viewport.centerRegion) {
                Ext.create('Ext.window.Window', {
                    title: obj.status,
                    modal: true,
                    destroyOnBlur: true,
                    html: html,
                    bodyStyle: 'padding: 12px; background: #fff; max-width: 600px; max-height: ' + gis.viewport.centerRegion.getHeight() / 2 + 'px',
                    listeners: {
                        show: function (win) {
                            win.setPosition(win.getPosition()[0], win.getPosition()[1] / 2);
                            if (!win.hasDestroyOnBlurHandler) {
                                gis.util.gui.window.addDestroyOnBlurHandler(win);
                            }
                        }
                    }
                }).show();
            } else if (gis.container) { // Dashboard
                gis.instance.getContainer().style.display = 'none';
                var alertDiv = document.createElement('div');
                alertDiv.className = 'dhis2-map-widget-alert';
                alertDiv.innerHTML = html;
                gis.container.appendChild(alertDiv);
            }

            if (gis.mask) {
                gis.mask.hide();
            }
        };
Example #8
0
        api.layout.Record = function(config) {
            var record;

            // id: string

            if (!isObject(config)) {
                //console.log('Record config is not an object', config);
                return;
            }

            if (!isString(config.id)) {
                console.log('Record id is not text', config);
                return;
            }

            record = Ext.clone(config);

            if (isString(config.name)) {
                record.name = config.name;
            }

            return record;
        };
Example #9
0
        success: function(obj, success, r) {
            var id = (r.getResponseHeader('location') || '').split('/').pop();

            if (!isString(id)) {
                console.log('Layout post', 'Invalid id', id);
            }

            if (doUnmask) {
                uiManager.unmask();
            }

            if (fn) {
                fn(id, success, r);
            }
        }
Example #10
0
        util.date.getYYYYMMDD = function(param) {
            if (!isString(param)) {
                if (!(Object.prototype.toString.call(param) === '[object Date]' && param.toString() !== 'Invalid date')) {
                    return null;
                }
            }

            var date = new Date(param),
                month = '' + (1 + date.getMonth()),
                day = '' + date.getDate();

            month = month.length === 1 ? '0' + month : month;
            day = day.length === 1 ? '0' + day : day;

            return date.getFullYear() + '-' + month + '-' + day;
        };
Example #11
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 #12
0
            return function() {
                if (!isObject(config)) {
                    console.log('Header is not an object', config);
                    return;
                }

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

                if (!isBoolean(config.meta)) {
                    console.log('Header meta is not boolean', config);
                    return;
                }

                header.name = config.name;
                header.meta = config.meta;

                return Ext.clone(header);
            }();
Example #13
0
Layout.prototype.sort = function(table) {
    var id = this.sorting.id,
        direction = this.sorting.direction,
        dimension = this.rows[0],
        response = this.getResponse(),
        idValueMap = table ? table.idValueMap : response.getIdValueMap(),
        records = [],
        ids,
        sortingId,
        obj;

    if (!isString(id)) {
        return;
    }

    ids = this.getDimensionNameRecordIdsMap(response)[dimension.dimension];

    ids.forEach(function(item) {
        sortingId = parseFloat(idValueMap[(new ResponseRowIdCombination([id, item]).get())]);

        obj = {
            id: item,
            sortingId: isNumber(sortingId) ? sortingId : (Number.MAX_VALUE * -1)
        };

        records.push(obj);
    });

    // sort
    arraySort(records, direction, 'sortingId');

    // dimension
    dimension.items = records;
    dimension.sorted = true;

    dimension = new Dimension(dimension);

    this.sorting.id = id;
};
Example #14
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 #15
0
Request.prototype.setType = function(type) {
    if (isString(type)) {
        this.type = type;
    }
};
Example #16
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;
};
Example #17
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 #18
0
    /**
     * @method createActionsFromNames
     *
     * @param {String[]} [actionNames=[]] Names of the actions to create.
     * @param {String} [prefix] Prefix to prepend to all the action identifiers.
     *
     * @returns {{}}
     *
     * @description
     * Returns an object with the given names as keys and instanced of the Action class as actions.
     */
    createActionsFromNames(actionNames = [], prefix = undefined) {
        const actions = {};
        let actionPrefix = prefix;

        if (prefix && isString(prefix)) {
            actionPrefix = `${prefix}.`;
        } else {
            actionPrefix = '';
        }

        actionNames.forEach(actionName => {
            actions[actionName] = this.create(actionPrefix + actionName);
        });

        return actions;
    },
};

export default Action;
Example #19
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 #20
0
function isIntegerValidator(value) {
    if (isString(value) && /\./.test(value)) {
        return false;
    }
    return Number.parseInt(value, 10) === Number.parseFloat(value);
}
Example #21
0
 util.json.encodeString = function(str) {
     return isString(str) ? str.replace(/[^a-zA-Z 0-9(){}<>_!+;:?*&%#-]+/g,'') : str;
 };
Example #22
0
 config.hasDimension = function(id) {
     return isString(id) && this.findExact('id', id) != -1 ? true : false;
 };
Example #23
0
    getTdHtml = function(config, metaDataId) {
        var color,
            bgColor,
            legends,
            colSpan,
            rowSpan,
            htmlValue,
            displayDensity,
            fontSize,
            isNumeric = isObject(config) && isString(config.type) && config.type.substr(0,5) === 'value' && !config.empty,
            isValue = isNumeric && config.type === 'value',
            cls = '',
            html = '',
            getHtmlValue;

        getHtmlValue = function(config) {
            var str = config.htmlValue,
                n = parseFloat(config.htmlValue);

            if (config.collapsed) {
                return '';
            }

            if (isValue) {
                if (isBoolean(str)) {
                    return str;
                }

                //if (!isNumber(n) || n != str || new Date(str).toString() !== 'Invalid Date') {
                if (!isNumber(n) || n != str) {
                    return str;
                }

                return n;
            }

            return str || '';
        }

        if (!isObject(config)) {
            return '';
        }

        if (config.hidden || config.collapsed) {
            return '';
        }

        // number of cells
        tdCount = tdCount + 1;

        // background color from legend set
        if (isValue && layout.legendSet && layout.legendSet.legends) {
            var value = parseFloat(config.value);
            legends = layout.legendSet.legends;

            for (var i = 0; i < legends.length; i++) {
                if (value >= legends[i].startValue && value <= legends[i].endValue) {
                    color = legends[i].color;
                    bgColor = legends[i].bgColor;
                }
            }
        }

        colSpan = config.colSpan ? 'colspan="' + config.colSpan + '" ' : '';
        rowSpan = config.rowSpan ? 'rowspan="' + config.rowSpan + '" ' : '';
        htmlValue = getHtmlValue(config);
        htmlValue = config.type !== 'dimension' ? prettyPrint(htmlValue, layout.digitGroupSeparator) : htmlValue;

        cls += config.hidden ? ' td-hidden' : '';
        cls += config.collapsed ? ' td-collapsed' : '';
        cls += isValue ? ' pointer' : '';
        //cls += bgColor ? ' legend' : (config.cls ? ' ' + config.cls : '');
        cls += config.cls ? ' ' + config.cls : '';

        // if sorting
        if (isString(metaDataId)) {
            cls += ' td-sortable';

            sortableIdObjects.push({
                id: metaDataId,
                uuid: config.uuid
            });
        }

        html += '<td ' + (config.uuid ? ('id="' + config.uuid + '" ') : '');
        html += ' class="' + cls + '" ' + colSpan + rowSpan;

        //if (bgColor && isValue) {
            //html += 'style="color:' + bgColor + ';padding:' + displayDensity + '; font-size:' + fontSize + ';"' + '>' + htmlValue + '</td>';
            //html += '>';
            //html += '<div class="legendCt">';
            //html += '<div class="number ' + config.cls + '" style="padding:' + displayDensity + '; padding-right:3px; font-size:' + fontSize + '">' + htmlValue + '</div>';
            //html += '<div class="arrowCt ' + config.cls + '">';
            //html += '<div class="arrow" style="border-bottom:8px solid transparent; border-right:8px solid ' + bgColor + '">&nbsp;</div>';
            //html += '</div></div></div></td>';
        //}
        //else {
            html += 'style="' +
            (color && isValue ? 'color:' + color + '; ' : '') +
            (bgColor && isValue ? 'background-color:' + bgColor + '; ' : '') +
             '">' + htmlValue + '</td>';
        //}

        return html;
    };
Example #24
0
 param.forEach(function(item) {
     if (isString(item)) {
         t.params.push(item);
     }
 });
Example #25
0
        util.geojson.decode = function(organisationUnits, levelOrder) {
            var features = [];

            levelOrder = levelOrder || 'ASC';

            // sort
            util.array.sort(organisationUnits, levelOrder, 'le');

            for (var i = 0, ou, coord, gpid = '', gppg = '', type; i < organisationUnits.length; i++) {
                ou = organisationUnits[i];
                coord = JSON.parse(ou.co);

                // Only add features with coordinates
                if (coord && coord.length) {
                    type = 'Point';
                    if (ou.ty === 2) {
                        type = 'Polygon';
                        if (ou.co.substring(0, 4) === '[[[[') {
                            type = 'MultiPolygon';
                        }
                    }

                    // grand parent
                    if (isString(ou.pg) && ou.pg.length) {
                        var ids = arrayClean(ou.pg.split('/'));

                        // grand parent id
                        if (ids.length >= 2) {
                            gpid = ids[ids.length - 2];
                        }

                        // grand parent parentgraph
                        if (ids.length > 2) {
                            gppg = '/' + ids.slice(0, ids.length - 2).join('/');
                        }
                    }

                    features.push({
                        type: 'Feature',
                        id: ou.id,
                        geometry: {
                            type: type,
                            coordinates: coord
                        },
                        properties: {
                            id: ou.id,
                            name: ou.na,
                            hasCoordinatesDown: ou.hcd,
                            hasCoordinatesUp: ou.hcu,
                            level: ou.le,
                            grandParentParentGraph: gppg,
                            grandParentId: gpid,
                            parentGraph: ou.pg,
                            parentId: ou.pi,
                            parentName: ou.pn
                        }
                    });
                }
            }

            return features;
        };
Example #26
0
Request.prototype.setBaseUrl = function(baseUrl) {
    if (isString(baseUrl)) {
        this.baseUrl = baseUrl;
    }
};