Code coverage report for api/data_list/SubExperimentDataList.js

Statements: 72.73% (24 / 33)      Branches: 50% (13 / 26)      Functions: 66.67% (4 / 6)      Lines: 72.73% (24 / 33)      Ignored: none     

All files » api/data_list/ » SubExperimentDataList.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 921 1 1 1 1                   1 5 4   5 5     1                                                                       5 5         2     2 2             1       1 1 1 1 1   1         1  
var DataList = require("./DataList").DataList;
var Stimulus = require("./../datum/Stimulus").Stimulus;
var DocumentCollection = require("./../datum/DocumentCollection").DocumentCollection;
var Comments = require("./../comment/Comments").Comments;
var ContextualizableObject = require("./../locales/ContextualizableObject").ContextualizableObject;
 
/**
 * @class The SubExperimentDataList allows the user to add additional information
 *  which can be used for experiments using the datum in the datalist.
 *
 * @name  SubExperimentDataList
 * @extends DataList
 * @constructs
 */
var SubExperimentDataList = function SubExperimentDataList(options) {
  if (!this._fieldDBtype) {
    this._fieldDBtype = "SubExperimentDataList";
  }
  this.debug("Constructing SubExperimentDataList ", options);
  DataList.apply(this, arguments);
};
 
SubExperimentDataList.prototype = Object.create(DataList.prototype, /** @lends SubExperimentDataList.prototype */ {
  constructor: {
    value: SubExperimentDataList
  },
 
  // Internal models: used by the parse function
  INTERNAL_MODELS: {
    value: {
      comments: Comments,
      docs: DocumentCollection,
      title: ContextualizableObject,
      description: ContextualizableObject,
      instructions: ContextualizableObject,
      item: Stimulus
    }
  },
 
  subexperiments: {
    get: function() {
      if (this.docs && this.docs.length > 0) {
        return this.docs;
      }
      return this.docIds;
    },
    set: function(value) {
      if ((value && value[0] && typeof value[0] === "object") || value.constructor === DocumentCollection) {
        this.docs = value;
      } else {
        this.docIds = value;
        this._subexperiments = value;
      }
    }
  },
 
  trials: {
    get: function() {
      Eif (this.docs && this.docs.length > 0) {
        return this.docs;
      }
      return this.docIds;
    },
    set: function(value) {
      Iif ((value && value[0] && typeof value[0] === "object") || value.constructor === DocumentCollection) {
        this.docs = value;
      } else {
        this.docIds = value;
        this._trials = value;
      }
    }
  },
 
  toJSON: {
    value: function(includeEvenEmptyAttributes, removeEmptyAttributes) {
      this.debug("Customizing toJSON ", includeEvenEmptyAttributes, removeEmptyAttributes);
      // Force docIds to be set to current docs
      // this._subexperiments = this.docIds;
      // this._trials = this.docIds;
      var json = DataList.prototype.toJSON.apply(this, arguments);
      this.debug(json);
      Eif (this.docs && this.docs.toJSON) {
        this.todo("only save trials/subexperiments if there are responses in the trials, or if the experiment started or somethign. ");
        json.results = this.docs.toJSON();
      }
      return json;
    }
  }
 
});
exports.SubExperimentDataList = SubExperimentDataList;