lib/Models/AbsIttCatalogItem.js
function loadConcepts(item) {
  if (!defined(item._loadConceptsPromise)) {
    var absConcepts = [];
    var promises = item._conceptIds
      .filter(function(conceptId) {
        return item.conceptsNotToLoad.indexOf(conceptId) === -1;
      })
      .map(function(conceptId) {
        var parameters = {
          method: "GetCodeListValue",
          datasetid: item.datasetId,
          concept: conceptId,
          format: "json"
        };
        var conceptCodesUrl = item._baseUrl + "?" + objectToQuery(parameters);

        return loadJson(conceptCodesUrl)
          .then(function(json) {
            // If this is a region type, only include valid region codes (eg. AUS, SA4, but not GCCSA).
            // Valid region codes must have a total population data file, eg. data/2011Census_TOT_SA4.csv
            var codes = json.codes;
            if (conceptId === item.regionTypeConcept) {
              codes = codes.filter(function(absCode) {
                return allowedRegionCodes.indexOf(absCode.code) >= 0;
              });
            }
            // We have loaded the file, process it into an AbsConcept.
            var concept = new AbsConcept({
              id: conceptId,
              codes: codes,
              filter: item.filter,
              allowMultiple: !(
                conceptId === item.regionTypeConcept ||
                item.uniqueValuedConcepts.indexOf(conceptId) >= 0
              ),
              activeItemsChangedCallback: function() {
                // Close any picked features, as the description of any associated with this catalog item may change.
                item.terria.pickedFeatures = undefined;
                rebuildData(item);
              }
            });
            // Give the concept its human-readable name.
            concept.name = getHumanReadableConceptName(
              item._conceptNamesMap,
              concept
            );
            absConcepts.push(concept);
          })
          .otherwise(throwLoadError.bind(null, item, "GetCodeListValue"));
      });

    item._loadConceptsPromise = when.all(promises).then(function() {
      // All the AbsConcept objects have been created, we just need to order them correctly and save them.
      // Put the region type concept first.
      var makeFirst = item.regionTypeConcept;
      absConcepts.sort(function(a, b) {
        return a.id === makeFirst
          ? -1
          : b.id === makeFirst
          ? 1
          : a.name > b.name
          ? 1
          : -1;
      });
      item._concepts = absConcepts;
    });
  }
  return item._loadConceptsPromise;
}
function loadConcepts(item) {
  if (!defined(item._loadConceptsPromise)) {
    var absConcepts = [];
    var promises = item._conceptIds
      .filter(function(conceptId) {
        return item.conceptsNotToLoad.indexOf(conceptId) === -1;
      })
      .map(function(conceptId) {
        var parameters = {
          method: "GetCodeListValue",
          datasetid: item.datasetId,
          concept: conceptId,
          format: "json"
        };
        var conceptCodesUrl = item._baseUrl + "?" + objectToQuery(parameters);

        return loadJson(conceptCodesUrl)
          .then(function(json) {
            // If this is a region type, only include valid region codes (eg. AUS, SA4, but not GCCSA).
            // Valid region codes must have a total population data file, eg. data/2011Census_TOT_SA4.csv
            var codes = json.codes;
            if (conceptId === item.regionTypeConcept) {
              codes = codes.filter(function(absCode) {
                return allowedRegionCodes.indexOf(absCode.code) >= 0;
              });
            }
            // We have loaded the file, process it into an AbsConcept.
            var concept = new AbsConcept({
              id: conceptId,
              codes: codes,
              filter: item.filter,
              allowMultiple: !(
                conceptId === item.regionTypeConcept ||
                item.uniqueValuedConcepts.indexOf(conceptId) >= 0
              ),
              activeItemsChangedCallback: function() {
                // Close any picked features, as the description of any associated with this catalog item may change.
                item.terria.pickedFeatures = undefined;
                rebuildData(item);
              }
            });
            // Give the concept its human-readable name.
            concept.name = getHumanReadableConceptName(
              item._conceptNamesMap,
              concept
            );
            absConcepts.push(concept);
          })
          .otherwise(throwLoadError.bind(null, item, "GetCodeListValue"));
      });

    item._loadConceptsPromise = when.all(promises).then(function() {
      // All the AbsConcept objects have been created, we just need to order them correctly and save them.
      // Put the region type concept first.
      var makeFirst = item.regionTypeConcept;
      absConcepts.sort(function(a, b) {
        return a.id === makeFirst
          ? -1
          : b.id === makeFirst
          ? 1
          : a.name > b.name
          ? 1
          : -1;
      });
      item._concepts = absConcepts;
    });
  }
  return item._loadConceptsPromise;
}
function loadConcepts ( item ) { if ( ! defined ( item . _loadConceptsPromise ) ) { var absConcepts = [ ] ; var promises = item . _conceptIds . filter ( function ( conceptId ) { return item . conceptsNotToLoad . indexOf ( conceptId ) === - 1 ; } ) . map ( function ( conceptId ) { var parameters = { method : "GetCodeListValue" , datasetid : item . datasetId , concept : conceptId , format : "json" } ; var conceptCodesUrl = item . _baseUrl + "?" + objectToQuery ( parameters ) ; return loadJson ( conceptCodesUrl ) . then ( function ( json ) { // If this is a region type, only include valid region codes (eg. AUS, SA4, but not GCCSA). // Valid region codes must have a total population data file, eg. data/2011Census_TOT_SA4.csv var codes = json . codes ; if ( conceptId === item . regionTypeConcept ) { codes = codes . filter ( function ( absCode ) { return allowedRegionCodes . indexOf ( absCode . code ) >= 0 ; } ) ; } // We have loaded the file, process it into an AbsConcept. var concept = new AbsConcept ( { id : conceptId , codes : codes , filter : item . filter , allowMultiple : ! ( conceptId === item . regionTypeConcept || item . uniqueValuedConcepts . indexOf ( conceptId ) >= 0 ) , activeItemsChangedCallback : function ( ) { // Close any picked features, as the description of any associated with this catalog item may change. item . terria . pickedFeatures = undefined ; rebuildData ( item ) ; } } ) ; // Give the concept its human-readable name. concept . name = getHumanReadableConceptName ( item . _conceptNamesMap , concept ) ; absConcepts . push ( concept ) ; } ) . otherwise ( throwLoadError . bind ( null , item , "GetCodeListValue" ) ) ; } ) ; item . _loadConceptsPromise = when . all ( promises ) . then ( function ( ) { // All the AbsConcept objects have been created, we just need to order them correctly and save them. // Put the region type concept first. var makeFirst = item . regionTypeConcept ; absConcepts . sort ( function ( a , b ) { return a . id === makeFirst ? - 1 : b . id === makeFirst ? 1 : a . name > b . name ? 1 : - 1 ; } ) ; item . _concepts = absConcepts ; } ) ; } return item . _loadConceptsPromise ; }
Loads concept codes.
As they are loaded, each is processed into a tree of AbsCodes under an AbsConcept.
Returns a promise which, when resolved, indicates that item._concepts is complete.
The promise is cached, since the promise won't ever change for a given datasetId.
@private
@param  {AbsIttCatalogItem} item This catalog item.
@return {Promise} Promise.
Loads concept codes . As they are loaded each is processed into a tree of AbsCodes under an AbsConcept . Returns a promise which when resolved indicates that item . _concepts is complete . The promise is cached since the promise won t ever change for a given datasetId .