src/includes/constraints.js
function (data) {
        var that = this,
            restrictedKeys = [],
            unrestrictedData = {},
            maxSpecificity = -1;

        // Find most specific location that could restrict current data
        collection_util.each(that.constraints, function (constraint, id) {
            collection_util.each(constraint.locations, function (location, i) {
                if (location.containsData(data) && location.specificity > maxSpecificity) {
                    maxSpecificity = location.specificity;
                }
            });
        });

        if (maxSpecificity >= 0) {

            // Для городов-регионов нужно также отсечь и город
            if (data.region_kladr_id && data.region_kladr_id === data.city_kladr_id) {
                restrictedKeys.push.apply(restrictedKeys, that.type.dataComponentsById['city'].fields);
            }

            // Collect all fieldnames from all restricted components
            collection_util.each(that.type.dataComponents.slice(0, maxSpecificity + 1), function (component, i) {
                restrictedKeys.push.apply(restrictedKeys, component.fields);
            });

            // Copy skipping restricted fields
            collection_util.each(data, function (value, key) {
                if (restrictedKeys.indexOf(key) === -1) {
                    unrestrictedData[key] = value;
                }
            });
        } else {
            unrestrictedData = data;
        }

        return unrestrictedData;
    }
function (data) {
        var that = this,
            restrictedKeys = [],
            unrestrictedData = {},
            maxSpecificity = -1;

        // Find most specific location that could restrict current data
        collection_util.each(that.constraints, function (constraint, id) {
            collection_util.each(constraint.locations, function (location, i) {
                if (location.containsData(data) && location.specificity > maxSpecificity) {
                    maxSpecificity = location.specificity;
                }
            });
        });

        if (maxSpecificity >= 0) {

            // Для городов-регионов нужно также отсечь и город
            if (data.region_kladr_id && data.region_kladr_id === data.city_kladr_id) {
                restrictedKeys.push.apply(restrictedKeys, that.type.dataComponentsById['city'].fields);
            }

            // Collect all fieldnames from all restricted components
            collection_util.each(that.type.dataComponents.slice(0, maxSpecificity + 1), function (component, i) {
                restrictedKeys.push.apply(restrictedKeys, component.fields);
            });

            // Copy skipping restricted fields
            collection_util.each(data, function (value, key) {
                if (restrictedKeys.indexOf(key) === -1) {
                    unrestrictedData[key] = value;
                }
            });
        } else {
            unrestrictedData = data;
        }

        return unrestrictedData;
    }
function ( data ) { var that = this , restrictedKeys = [ ] , unrestrictedData = { } , maxSpecificity = - 1 ; // Find most specific location that could restrict current data collection_util . each ( that . constraints , function ( constraint , id ) { collection_util . each ( constraint . locations , function ( location , i ) { if ( location . containsData ( data ) && location . specificity > maxSpecificity ) { maxSpecificity = location . specificity ; } } ) ; } ) ; if ( maxSpecificity >= 0 ) { // Для городов-регионов нужно также отсечь и город if ( data . region_kladr_id && data . region_kladr_id === data . city_kladr_id ) { restrictedKeys . push . apply ( restrictedKeys , that . type . dataComponentsById [ 'city' ] . fields ) ; } // Collect all fieldnames from all restricted components collection_util . each ( that . type . dataComponents . slice ( 0 , maxSpecificity + 1 ) , function ( component , i ) { restrictedKeys . push . apply ( restrictedKeys , component . fields ) ; } ) ; // Copy skipping restricted fields collection_util . each ( data , function ( value , key ) { if ( restrictedKeys . indexOf ( key ) === - 1 ) { unrestrictedData [ key ] = value ; } } ) ; } else { unrestrictedData = data ; } return unrestrictedData ; }
Pick only fields that absent in restriction
Pick only fields that absent in restriction