lib/api/formtools/list.js
function getActiveFilters (req, selectedFilters, data, modelName, cb) {

    if (!req) {
        throw new Error('req is required.');
    }

    if (!selectedFilters || !Array.isArray(selectedFilters) || !selectedFilters.length) {
        throw new Error('selectedFilters is required and must be of type Array and cannot be empty.');
    }

    if (typeof modelName !== 'string' || !modelName.length) {
        throw new Error('modelName is required and must be of type String and cannot be empty.');
    }

    if (!(!Object.is(data, null) && !Array.isArray(data) && data === Object(data))) {
        throw new Error('data is required and must be of type Object.');
    }

    linz.api.model.list(req, modelName, function (err, list) {

        if (err) {
            return cb(err);
        }

        if (!Object.keys(list.filters).length) {
            return cb(null);
        }

        var activeFilters = {};

        async.each(selectedFilters, function (fieldName, filtersDone) {

            // call the filter binder to render active filter form controls with form value added
            list.filters[fieldName].filter.bind(fieldName, data, function (filterErr, result) {

                if (filterErr) {
                    return filtersDone(filterErr);
                }

                activeFilters[fieldName] = {
                    label: list.filters[fieldName].label,
                    controls: result
                }

                return filtersDone(null);

            });

        }, function (filterErr) {

            return cb(filterErr, activeFilters);

        });

    });

}
function getActiveFilters (req, selectedFilters, data, modelName, cb) {

    if (!req) {
        throw new Error('req is required.');
    }

    if (!selectedFilters || !Array.isArray(selectedFilters) || !selectedFilters.length) {
        throw new Error('selectedFilters is required and must be of type Array and cannot be empty.');
    }

    if (typeof modelName !== 'string' || !modelName.length) {
        throw new Error('modelName is required and must be of type String and cannot be empty.');
    }

    if (!(!Object.is(data, null) && !Array.isArray(data) && data === Object(data))) {
        throw new Error('data is required and must be of type Object.');
    }

    linz.api.model.list(req, modelName, function (err, list) {

        if (err) {
            return cb(err);
        }

        if (!Object.keys(list.filters).length) {
            return cb(null);
        }

        var activeFilters = {};

        async.each(selectedFilters, function (fieldName, filtersDone) {

            // call the filter binder to render active filter form controls with form value added
            list.filters[fieldName].filter.bind(fieldName, data, function (filterErr, result) {

                if (filterErr) {
                    return filtersDone(filterErr);
                }

                activeFilters[fieldName] = {
                    label: list.filters[fieldName].label,
                    controls: result
                }

                return filtersDone(null);

            });

        }, function (filterErr) {

            return cb(filterErr, activeFilters);

        });

    });

}
function getActiveFilters ( req , selectedFilters , data , modelName , cb ) { if ( ! req ) { throw new Error ( 'req is required.' ) ; } if ( ! selectedFilters || ! Array . isArray ( selectedFilters ) || ! selectedFilters . length ) { throw new Error ( 'selectedFilters is required and must be of type Array and cannot be empty.' ) ; } if ( typeof modelName !== 'string' || ! modelName . length ) { throw new Error ( 'modelName is required and must be of type String and cannot be empty.' ) ; } if ( ! ( ! Object . is ( data , null ) && ! Array . isArray ( data ) && data === Object ( data ) ) ) { throw new Error ( 'data is required and must be of type Object.' ) ; } linz . api . model . list ( req , modelName , function ( err , list ) { if ( err ) { return cb ( err ) ; } if ( ! Object . keys ( list . filters ) . length ) { return cb ( null ) ; } var activeFilters = { } ; async . each ( selectedFilters , function ( fieldName , filtersDone ) { // call the filter binder to render active filter form controls with form value added list . filters [ fieldName ] . filter . bind ( fieldName , data , function ( filterErr , result ) { if ( filterErr ) { return filtersDone ( filterErr ) ; } activeFilters [ fieldName ] = { label : list . filters [ fieldName ] . label , controls : result } return filtersDone ( null ) ; } ) ; } , function ( filterErr ) { return cb ( filterErr , activeFilters ) ; } ) ; } ) ; }
Get active filters from form post data
@param {Array}   selectedFilters An array of selected filter field names
@param {Object}   data            Form data
@param {String}   modelName       Name of model
@param {Function} cb              Callback function
@return {Object} or undefined
@api public
Get active filters from form post data