index.js
function sanitizeSpontaneousAreas(req, data, page, callback) {
    var toSanitize = [];
    _.each(data, function(val, key) {
      if (typeof(val) === 'object') {
        if (val.type === 'area') {
          if (_.has(page, key) && ((typeof(page[key]) !== 'object') || (page[key].type !== 'area'))) {
            // Spontaneous areas may not replace properties that are not areas
            return;
          }
          toSanitize.push({ key: key, items: val.items });
        }
      }
    });
    return async.eachSeries(toSanitize, function(entry, callback) {
      return apos.sanitizeItems(req, entry.items || [], function(err, _items) {
        if (err) {
          return callback(err);
        }
        entry.items = _items;
        return callback(null);
      });
    }, function(err) {
      if (err) {
        return callback(err);
      }
      _.each(toSanitize, function(entry) {
        page[entry.key] = { type: 'area', items: entry.items };
      });
      return callback(null);
    });
  }
function sanitizeSpontaneousAreas(req, data, page, callback) {
    var toSanitize = [];
    _.each(data, function(val, key) {
      if (typeof(val) === 'object') {
        if (val.type === 'area') {
          if (_.has(page, key) && ((typeof(page[key]) !== 'object') || (page[key].type !== 'area'))) {
            // Spontaneous areas may not replace properties that are not areas
            return;
          }
          toSanitize.push({ key: key, items: val.items });
        }
      }
    });
    return async.eachSeries(toSanitize, function(entry, callback) {
      return apos.sanitizeItems(req, entry.items || [], function(err, _items) {
        if (err) {
          return callback(err);
        }
        entry.items = _items;
        return callback(null);
      });
    }, function(err) {
      if (err) {
        return callback(err);
      }
      _.each(toSanitize, function(entry) {
        page[entry.key] = { type: 'area', items: entry.items };
      });
      return callback(null);
    });
  }
function sanitizeSpontaneousAreas ( req , data , page , callback ) { var toSanitize = [ ] ; _ . each ( data , function ( val , key ) { if ( typeof ( val ) === 'object' ) { if ( val . type === 'area' ) { if ( _ . has ( page , key ) && ( ( typeof ( page [ key ] ) !== 'object' ) || ( page [ key ] . type !== 'area' ) ) ) { // Spontaneous areas may not replace properties that are not areas return ; } toSanitize . push ( { key : key , items : val . items } ) ; } } } ) ; return async . eachSeries ( toSanitize , function ( entry , callback ) { return apos . sanitizeItems ( req , entry . items || [ ] , function ( err , _items ) { if ( err ) { return callback ( err ) ; } entry . items = _items ; return callback ( null ) ; } ) ; } , function ( err ) { if ( err ) { return callback ( err ) ; } _ . each ( toSanitize , function ( entry ) { page [ entry . key ] = { type : 'area' , items : entry . items } ; } ) ; return callback ( null ) ; } ) ; }
Both the new and edit page operations utilize this to deal with areas that arise spontaneously via page templates rather than being hardcoded in the schema. The rule is that if an otherwise unknown property is an object with a "type" sub-property set to "area", that is accepted and sanitized as an area.
Both the new and edit page operations utilize this to deal with areas that arise spontaneously via page templates rather than being hardcoded in the schema . The rule is that if an otherwise unknown property is an object with a type sub - property set to area that is accepted and sanitized as an area .