/** Model object to encapsulate the current user preferences */

modulejs.define( "preferences", [
  "lib/lodash",
  "lib/jquery"
], function(
  _,
  $
) {
  "use strict";

  var Preferences = function() {
    this.initialize();
  };

  _.extend( Preferences.prototype, {
    initialize: function() {
      this._prefs = {};
      var prefs = this._prefs;

      var selections = $("#preferences").serializeArray();
      _.each( selections, function( selection ) {
        var name = selection.name;

        if (name.match( /\[\]/ )) {
          var simpleName = name.replace( "[]", "" );

          if (!prefs[simpleName]) {
            prefs[simpleName] = [];
          }
          prefs[simpleName].push( selection.value );
        }
        else {
          prefs[name] = selection.value;
        }
      } );
    },

    region: function() {
      return this._prefs.region;
    },

    from: function() {
      return this._prefs.from;
    },

    to: function() {
      return this._prefs.to;
    },

    aspects: function() {
      var inds = this._prefs.ai || [];
      var cats = this._prefs.ac || [];
      var pairs = cartesianProductOf( inds, cats );

      return _.map( pairs, function( pair ) {
        return pair[0] + _.upperFirst( pair[1] );
      } );
    }
  } );

  function cartesianProductOf() {
    return _.reduce(arguments, function(a, b) {
      return _.flatten(_.map(a, function(x) {
        return _.map(b, function(y) {
          return x.concat([y]);
        });
      }));
    }, [ [] ]);
  };

  return Preferences;
} );

@@ -1011,14 +1011,116 @@
     
-aspect
+/** @return The currently selected indicators, optionally limited to just a given selection */%0A    indicator
 s: f
@@ -1119,32 +1119,38 @@
 ators: function(
+ only 
 ) %7B%0A      var in
@@ -1147,20 +1147,18 @@
     var 
+a
 i
-nds
  = this.
@@ -1184,89 +1184,638 @@
     
-var cats = this._prefs.ac %7C%7C %5B%5D;%0A      var pairs = cartesianProductOf( inds, cats
+if (only && only.indicators) %7B%0A        ai = _.intersection( only.indicators, ai );%0A      %7D%0A%0A      return ai;%0A    %7D,%0A%0A    /** @return The currently selected categories, optionally limited to just a given selection */%0A    categories: function( only ) %7B%0A      var ac = this._prefs.ac %7C%7C %5B%5D;%0A      if (only && only.categories) %7B%0A        ac = _.intersection( only.categories, ac );%0A      %7D%0A%0A      return ac;%0A    %7D,%0A%0A    /** @return The selected aspects, optionally limited to only certain indicators or categories */%0A    aspects: function( only ) %7B%0A      var pairs = cartesianProductOf( this.indicators( only ), this.categories( only )
  );%0A

Extend preferences to return the indicator and category parts of the selected aspects separately. Also added basic filtering, so that only aspects of interest can be selected.