<commit_before>// ***********************************************//
//                 models and stores
// ***********************************************//
require('akvo-flow/core-common');
require('akvo-flow/models/store_def-common');

FLOW.BaseModel = DS.Model.extend({
  keyId: DS.attr('number'),
  savingStatus: null,

  // this method calls the checkSaving method on the savingMessageControl, which
  // checks if there are any records inflight. If yes, it sets a boolean,
  // so a saving message can be displayed. savingStatus is used to capture the
  // moment that nothing is being saved anymore, but in the previous event it was
  // so we can turn off the saving message.
  anySaving: function () {
    if (this.get('isSaving') || this.get('isDirty') || this.get('savingStatus')) {
      FLOW.savingMessageControl.checkSaving();
    }
    this.set('savingStatus', (this.get('isSaving') || this.get('isDirty')));
  }.observes('isSaving', 'isDirty')
});

FLOW.CaddisflyTestDefinition = Ember.Object.extend({
    name: null,
    brand: null,
    uuid: null,

    displayName: function() {
        return this.get('name') + " (" + this.get('brand') +")";
    }.property(''),
});

FLOW.CascadeResource = FLOW.BaseModel.extend({
	name: DS.attr('string', {
	   defaultValue: ''
	}),
	version: DS.attr('number', {
		defaultValue: 1
	}),
	numLevels: DS.attr('number', {
		defaultValue: 1
	}),
	status: DS.attr('string', {
		defaultValue: 'NOT_PUBLISHED'
	}),
	levelNames: DS.attr('array', {defaultValue: []
	}),
});

FLOW.CascadeNode = FLOW.BaseModel.extend({
	name: DS.attr('string', {
	   defaultValue: ''
	}),
	code: DS.attr('string', {
		defaultValue: ''
	}),
	parentNodeId: DS.attr('number', {
		defaultValue: ''
	}),
	cascadeResourceId: DS.attr('number', {
		defaultValue: ''
	})
});

FLOW.SurveyGroup = FLOW.BaseModel.extend({
  description: DS.attr('string', {
    defaultValue: ''
  }),
  name: DS.attr('string', {
    defaultValue: ''
  }),
  path: DS.attr('string', {
    defaultValue: null
  }),
  ancestorIds: DS.attr('array', {
    defaultValue: []
  }),
  createdDateTime: DS.attr('string', {
    defaultValue: ''
  }),
  monitoringGroup: DS.attr('boolean', {
    defaultValue: false
  }),
  newLocaleSurveyId: DS.attr('number'),
  lastUpdateDateTime: DS.attr('string', {
    defaultValue: ''
  }),
  // the code field is used as name
  code: DS.attr('string', {
    defaultValue: ''
  }),

  parentId: DS.attr('number', {
    defaultValue: null
  }),

  projectType: DS.attr('string', {
    defaultValue: "PROJECT"
  }),

  privacyLevel: DS.attr('string', {
    defaultValue: "PRIVATE"
  }),

  defaultLanguageCode: DS.attr('string', {
    defaultValue: "en"
  }),

  published: DS.attr('boolean', {
    defaultValue: false
  }),

  requireDataApproval: DS.attr('boolean', {
      defaultValue: false
  }),

  dataApprovalGroupId: DS.attr('number', {
      defaultValue: null
  }),

  surveyList: DS.attr('array', {
    defaultValue: null
  })

});

FLOW.Survey = FLOW.BaseModel.extend({
  didLoad: function () {
    // set the survey group name
    var sg = FLOW.store.find(FLOW.SurveyGroup, this.get('surveyGroupId'));
    if (!Ember.empty(sg)) {
      this.set('surveyGroupName', sg.get('code'));
    }
  },

  defaultLanguageCode: DS.attr('string'),
  status: DS.attr('string'),
  sector: DS.attr('string'),
  code: DS.attr('string'),
  requireApproval: DS.attr('string'),
  version: DS.attr('string'),
  description: DS.attr('string'),
  name: DS.attr('string'),
  path: DS.attr('string'),
  ancestorIds: DS.attr('array'),
  pointType: DS.attr('string'),
  surveyGroupId: DS.attr('number'),
  createdDateTime: DS.attr('number'),
  lastUpdateDateTime: DS.attr('number'),
  instanceCount: DS.attr('number'),

  // This attribute is used for the 'Copy Survey' functionality
  // Most of the times is `null`
  sourceId: DS.attr('number', {
    defaultValue: null
  }),

  // used in the assignment edit page, not saved to backend
  surveyGroupName: null,

  allowEdit: function () {
	  return !this.get('isNew') && this.get('status') !== 'COPYING';
  }.property('status', 'isNew')

});

FLOW.QuestionGroup = FLOW.BaseModel.extend({
  order: DS.attr('number'),
  name: DS.attr('string'),
  path: DS.attr('string'),
  code: DS.attr('string'),
  surveyId: DS.attr('number'),
  status: DS.attr('string'),
  sourceId: DS.attr('number', {
    defaultValue: null
  }),
  repeatable: DS.attr('boolean', {
    defaultValue: false
  })
});

FLOW.Question = FLOW.BaseModel.extend({
  questionOptions: DS.hasMany('FLOW.QuestionOption'),

  allowDecimal: DS.attr('boolean', {
    defaultValue: false
  }),
  allowMultipleFlag: DS.attr('boolean', {
    defaultValue: false
  }),
  allowOtherFlag: DS.attr('boolean', {
    defaultValue: false
  }),
  localeNameFlag: DS.attr('boolean', {
	    defaultValue: false
	  }),
  localeLocationFlag: DS.attr('boolean', {
		defaultValue: false
  }),
  allowSign: DS.attr('boolean', {
    defaultValue: false
  }),
  geoLocked: DS.attr('boolean', {
	    defaultValue: false
	  }),
  requireDoubleEntry: DS.attr('boolean', {
    defaultValue: false
  }),
  collapseable: DS.attr('boolean', {
    defaultValue: false
  }),
  immutable: DS.attr('boolean', {
    defaultValue: false
  }),
  mandatoryFlag: DS.attr('boolean', {
    defaultValue: true
  }),
  dependentFlag: DS.attr('boolean', {
    defaultValue: false
  }),
  dependentQuestionAnswer: DS.attr('string'),
  dependentQuestionId: DS.attr('number'),
  maxVal: DS.attr('number', {
    defaultValue: null
  }),
  minVal: DS.attr('number', {
    defaultValue: null
  }),
  order: DS.attr('number'),
  cascadeResourceId: DS.attr('number'),
  caddisflyResourceUuid:DS.attr('string'),
  path: DS.attr('string'),
  questionGroupId: DS.attr('number'),
  surveyId: DS.attr('number'),
  variableName: DS.attr('string'),
  metricId: DS.attr('number'),
  text: DS.attr('string'),
  tip: DS.attr('string'),
  type: DS.attr('string', {
	defaultValue: "FREE_TEXT"
  }),
  // This attribute is used for the 'Copy Survey' functionality
  // Most of the times is `null`
  sourceId: DS.attr('number', {
	 defaultValue: null
  }),
  allowExternalSources: DS.attr('boolean', {
    defaultValue: false
  }),
  // Geoshape question type options
  allowPoints: DS.attr('boolean', {
    defaultValue: true
  }),
  allowLine: DS.attr('boolean', {
    defaultValue: true
  }),
  allowPolygon: DS.attr('boolean', {
    defaultValue: true
  })
});

FLOW.QuestionOption = FLOW.BaseModel.extend({
  question: DS.belongsTo('FLOW.Question'),
  order: DS.attr('number'),
  questionId: DS.attr('number'),
  text: DS.attr('string'),
  code: DS.attr('string'),
});

FLOW.DeviceGroup = FLOW.BaseModel.extend({
  code: DS.attr('string', {
    defaultValue: ''
  })
});

FLOW.Device = FLOW.BaseModel.extend({
  didLoad: function () {
    var combinedName;
    if (Ember.empty(this.get('deviceIdentifier'))) {
      combinedName = "no identifer";
    } else {
      combinedName = this.get('deviceIdentifier');
    }
    this.set('combinedName', combinedName + " " + this.get('phoneNumber'));
  },
  esn: DS.attr('string', {
    defaultValue: ''
  }),
  phoneNumber: DS.attr('string', {
    defaultValue: ''
  }),
  deviceIdentifier: DS.attr('string', {
    defaultValue: ''
  }),
  gallatinSoftwareManifest: DS.attr('string'),
  lastKnownLat: DS.attr('number', {
    defaultValue: 0
  }),
  lastKnownLon: DS.attr('number', {
    defaultValue: 0
  }),
  lastKnownAccuracy: DS.attr('number', {
    defaultValue: 0
  }),
  lastPositionDate: DS.attr('number', {
    defaultValue: ''
  }),
  deviceGroup: DS.attr('string', {
    defaultValue: ''
  }),
  deviceGroupName: DS.attr('string', {
    defaultValue: ''
  }),
  isSelected: false,
  combinedName: null
});

FLOW.SurveyAssignment = FLOW.BaseModel.extend({
  name: DS.attr('string'),
  startDate: DS.attr('number'),
  endDate: DS.attr('number'),
  devices: DS.attr('array'),
  surveys: DS.attr('array'),
  language: DS.attr('string')
});

FLOW.SurveyedLocale = DS.Model.extend({
  description: DS.attr('string', {
    defaultValue: ''
  }),
  keyId: DS.attr('number'),
  latitude: DS.attr('number'),
  longitude: DS.attr('number'),
  displayName: DS.attr('string'),
  lastUpdateDateTime: DS.attr('number'),
  surveyGroupId: DS.attr('number'),
  identifier: DS.attr('string'),
  primaryKey: 'keyId'
});

// Explicitly avoid to use belongTo and hasMany as
// Ember-Data lacks of partial loading
// https://github.com/emberjs/data/issues/51
FLOW.PlacemarkDetail = FLOW.BaseModel.extend({
  placemarkId: DS.attr('number'),
  collectionDate: DS.attr('number'),
  order: DS.attr('number'),
  questionText: DS.attr('string'),
  metricName: DS.attr('string'),
  stringValue: DS.attr('string'),
  questionType: DS.attr('string')
});

FLOW.Placemark = FLOW.BaseModel.extend({
	latitude: DS.attr('number'),
	longitude: DS.attr('number'),
	count: DS.attr('number'),
	level: DS.attr('number'),
	surveyId: DS.attr('number'),
	detailsId: DS.attr('number'),
	collectionDate: DS.attr('number')
});

FLOW.SurveyInstance = FLOW.BaseModel.extend({
  approvedFlag: DS.attr('string'),
  approximateLocationFlag: DS.attr('string'),
  surveyInstanceId: DS.attr('number'),
  surveyId: DS.attr('number'),
  surveyedLocaleId:DS.attr('number'),
  collectionDate: DS.attr('number'),
  surveyCode: DS.attr('string'),
  submitterName: DS.attr('string'),
  deviceIdentifier: DS.attr('string'),
  surveyedLocaleIdentifier: DS.attr('string'),
  surveyedLocaleDisplayName: DS.attr('string')
});

FLOW.QuestionAnswer = FLOW.BaseModel.extend({
  value: DS.attr('string'),
  type: DS.attr('string'),
  oldValue: DS.attr('string'),
  surveyId: DS.attr('number'),
  collectionDate: DS.attr('number'),
  surveyInstanceId: DS.attr('number'),
  iteration: DS.attr('number'),
  questionID: DS.attr('string'), //TODO should be number?
  questionText: DS.attr('string')
});

FLOW.ApprovalGroup = FLOW.BaseModel.extend({
    name: DS.attr('string'),
    ordered: DS.attr('boolean'),
});

FLOW.ApprovalStep = FLOW.BaseModel.extend({
    approvalGroupId: DS.attr('number'),
    order: DS.attr('number'),
    title: DS.attr('string'),
    approverUserList: DS.attr('array', {
        defaultValue: null
    }),
});

FLOW.DataPointApproval = FLOW.BaseModel.extend({
    surveyedLocaleId: DS.attr('number'),

    approvalStepId: DS.attr('number'),

    approverUserName: DS.attr('string'),

    approvalDate: DS.attr('number'),

    status: DS.attr('string'),

    comment: DS.attr('string'),
});

FLOW.SurveyQuestionSummary = FLOW.BaseModel.extend({
  response: DS.attr('string'),
  count: DS.attr('number'),
  percentage: null,
  questionId: DS.attr('string')
});

FLOW.User = FLOW.BaseModel.extend({
  userName: DS.attr('string'),
  emailAddress: DS.attr('string'),
  admin: DS.attr('boolean', {
    defaultValue: 0
  }),
  superAdmin: DS.attr('boolean', {
    defaultValue: 0
  }),
  permissionList: DS.attr('string'),
  accessKey: DS.attr('string')
});

FLOW.UserConfig = FLOW.BaseModel.extend({
  group: DS.attr('string'),
  name: DS.attr('string'),
  value: DS.attr('string'),
  userId: DS.attr('number')
});

FLOW.Message = FLOW.BaseModel.extend({
  objectId: DS.attr('number'),
  lastUpdateDateTime: DS.attr('number'),
  userName: DS.attr('string'),
  objectTitle: DS.attr('string'),
  actionAbout: DS.attr('string'),
  shortMessage: DS.attr('string')
});

FLOW.Action = FLOW.BaseModel.extend({});

FLOW.Translation = FLOW.BaseModel.extend({
  didUpdate: function () {
    FLOW.translationControl.putSingleTranslationInList(this.get('parentType'), this.get('parentId'), this.get('text'), this.get('keyId'), false);
  },

  // can't use this at the moment, as the didCreate is fired before the id is back from the ajax call
  // didCreate: function(){
  //   console.log('didCreate',this.get('keyId'));
  //   FLOW.translationControl.putSingleTranslationInList(this.get('parentType'),this.get('parentId'),this.get('text'),this.get('keyId'), false);
  // },

  // temporary hack to fire the didCreate event after the keyId is known
  didCreateId: function () {
    if (!Ember.none(this.get('keyId')) && this.get('keyId') > 0) {
      FLOW.translationControl.putSingleTranslationInList(this.get('parentType'), this.get('parentId'), this.get('text'), this.get('keyId'), false);
    }
  }.observes('this.keyId'),

  didDelete: function () {
    FLOW.translationControl.putSingleTranslationInList(this.get('parentType'), this.get('parentId'), null, null, true);
  },

  parentType: DS.attr('string'),
  parentId: DS.attr('string'),
  surveyId: DS.attr('string'),
  questionGroupId: DS.attr('string'),
  text: DS.attr('string'),
  langCode: DS.attr('string')
});

FLOW.NotificationSubscription = FLOW.BaseModel.extend({
  notificationDestination: DS.attr('string'),
  notificationOption: DS.attr('string'),
  notificationMethod: DS.attr('string'),
  notificationType: DS.attr('string'),
  expiryDate: DS.attr('number'),
  entityId: DS.attr('number')
});

FLOW.SubCountry = FLOW.BaseModel.extend({
  countryCode: DS.attr('string'),
  level: DS.attr('number'),
  name: DS.attr('string'),
  parentKey: DS.attr('number'),
  parentName: DS.attr('string')
});

FLOW.Report = FLOW.BaseModel.extend({
  reportType: DS.attr('string'), //DATA_CLEANING/COMPREHENSIVE/...
  user: DS.attr('string'),
  formId: DS.attr('number'),
  state: DS.attr('string'), //IN_PROGRESS/FINISHED_SUCCESS/FINISHED_ERROR
  startDate: DS.attr('number'),
  endDate: DS.attr('number'),
  message: DS.attr('string'),
  createdDate: DS.attr('number'),
  lastModifiedDate: DS.attr('number'),
});
<commit_msg>[#2505] change report object properties<commit_after>// ***********************************************//
//                 models and stores
// ***********************************************//
require('akvo-flow/core-common');
require('akvo-flow/models/store_def-common');

FLOW.BaseModel = DS.Model.extend({
  keyId: DS.attr('number'),
  savingStatus: null,

  // this method calls the checkSaving method on the savingMessageControl, which
  // checks if there are any records inflight. If yes, it sets a boolean,
  // so a saving message can be displayed. savingStatus is used to capture the
  // moment that nothing is being saved anymore, but in the previous event it was
  // so we can turn off the saving message.
  anySaving: function () {
    if (this.get('isSaving') || this.get('isDirty') || this.get('savingStatus')) {
      FLOW.savingMessageControl.checkSaving();
    }
    this.set('savingStatus', (this.get('isSaving') || this.get('isDirty')));
  }.observes('isSaving', 'isDirty')
});

FLOW.CaddisflyTestDefinition = Ember.Object.extend({
    name: null,
    brand: null,
    uuid: null,

    displayName: function() {
        return this.get('name') + " (" + this.get('brand') +")";
    }.property(''),
});

FLOW.CascadeResource = FLOW.BaseModel.extend({
	name: DS.attr('string', {
	   defaultValue: ''
	}),
	version: DS.attr('number', {
		defaultValue: 1
	}),
	numLevels: DS.attr('number', {
		defaultValue: 1
	}),
	status: DS.attr('string', {
		defaultValue: 'NOT_PUBLISHED'
	}),
	levelNames: DS.attr('array', {defaultValue: []
	}),
});

FLOW.CascadeNode = FLOW.BaseModel.extend({
	name: DS.attr('string', {
	   defaultValue: ''
	}),
	code: DS.attr('string', {
		defaultValue: ''
	}),
	parentNodeId: DS.attr('number', {
		defaultValue: ''
	}),
	cascadeResourceId: DS.attr('number', {
		defaultValue: ''
	})
});

FLOW.SurveyGroup = FLOW.BaseModel.extend({
  description: DS.attr('string', {
    defaultValue: ''
  }),
  name: DS.attr('string', {
    defaultValue: ''
  }),
  path: DS.attr('string', {
    defaultValue: null
  }),
  ancestorIds: DS.attr('array', {
    defaultValue: []
  }),
  createdDateTime: DS.attr('string', {
    defaultValue: ''
  }),
  monitoringGroup: DS.attr('boolean', {
    defaultValue: false
  }),
  newLocaleSurveyId: DS.attr('number'),
  lastUpdateDateTime: DS.attr('string', {
    defaultValue: ''
  }),
  // the code field is used as name
  code: DS.attr('string', {
    defaultValue: ''
  }),

  parentId: DS.attr('number', {
    defaultValue: null
  }),

  projectType: DS.attr('string', {
    defaultValue: "PROJECT"
  }),

  privacyLevel: DS.attr('string', {
    defaultValue: "PRIVATE"
  }),

  defaultLanguageCode: DS.attr('string', {
    defaultValue: "en"
  }),

  published: DS.attr('boolean', {
    defaultValue: false
  }),

  requireDataApproval: DS.attr('boolean', {
      defaultValue: false
  }),

  dataApprovalGroupId: DS.attr('number', {
      defaultValue: null
  }),

  surveyList: DS.attr('array', {
    defaultValue: null
  })

});

FLOW.Survey = FLOW.BaseModel.extend({
  didLoad: function () {
    // set the survey group name
    var sg = FLOW.store.find(FLOW.SurveyGroup, this.get('surveyGroupId'));
    if (!Ember.empty(sg)) {
      this.set('surveyGroupName', sg.get('code'));
    }
  },

  defaultLanguageCode: DS.attr('string'),
  status: DS.attr('string'),
  sector: DS.attr('string'),
  code: DS.attr('string'),
  requireApproval: DS.attr('string'),
  version: DS.attr('string'),
  description: DS.attr('string'),
  name: DS.attr('string'),
  path: DS.attr('string'),
  ancestorIds: DS.attr('array'),
  pointType: DS.attr('string'),
  surveyGroupId: DS.attr('number'),
  createdDateTime: DS.attr('number'),
  lastUpdateDateTime: DS.attr('number'),
  instanceCount: DS.attr('number'),

  // This attribute is used for the 'Copy Survey' functionality
  // Most of the times is `null`
  sourceId: DS.attr('number', {
    defaultValue: null
  }),

  // used in the assignment edit page, not saved to backend
  surveyGroupName: null,

  allowEdit: function () {
	  return !this.get('isNew') && this.get('status') !== 'COPYING';
  }.property('status', 'isNew')

});

FLOW.QuestionGroup = FLOW.BaseModel.extend({
  order: DS.attr('number'),
  name: DS.attr('string'),
  path: DS.attr('string'),
  code: DS.attr('string'),
  surveyId: DS.attr('number'),
  status: DS.attr('string'),
  sourceId: DS.attr('number', {
    defaultValue: null
  }),
  repeatable: DS.attr('boolean', {
    defaultValue: false
  })
});

FLOW.Question = FLOW.BaseModel.extend({
  questionOptions: DS.hasMany('FLOW.QuestionOption'),

  allowDecimal: DS.attr('boolean', {
    defaultValue: false
  }),
  allowMultipleFlag: DS.attr('boolean', {
    defaultValue: false
  }),
  allowOtherFlag: DS.attr('boolean', {
    defaultValue: false
  }),
  localeNameFlag: DS.attr('boolean', {
	    defaultValue: false
	  }),
  localeLocationFlag: DS.attr('boolean', {
		defaultValue: false
  }),
  allowSign: DS.attr('boolean', {
    defaultValue: false
  }),
  geoLocked: DS.attr('boolean', {
	    defaultValue: false
	  }),
  requireDoubleEntry: DS.attr('boolean', {
    defaultValue: false
  }),
  collapseable: DS.attr('boolean', {
    defaultValue: false
  }),
  immutable: DS.attr('boolean', {
    defaultValue: false
  }),
  mandatoryFlag: DS.attr('boolean', {
    defaultValue: true
  }),
  dependentFlag: DS.attr('boolean', {
    defaultValue: false
  }),
  dependentQuestionAnswer: DS.attr('string'),
  dependentQuestionId: DS.attr('number'),
  maxVal: DS.attr('number', {
    defaultValue: null
  }),
  minVal: DS.attr('number', {
    defaultValue: null
  }),
  order: DS.attr('number'),
  cascadeResourceId: DS.attr('number'),
  caddisflyResourceUuid:DS.attr('string'),
  path: DS.attr('string'),
  questionGroupId: DS.attr('number'),
  surveyId: DS.attr('number'),
  variableName: DS.attr('string'),
  metricId: DS.attr('number'),
  text: DS.attr('string'),
  tip: DS.attr('string'),
  type: DS.attr('string', {
	defaultValue: "FREE_TEXT"
  }),
  // This attribute is used for the 'Copy Survey' functionality
  // Most of the times is `null`
  sourceId: DS.attr('number', {
	 defaultValue: null
  }),
  allowExternalSources: DS.attr('boolean', {
    defaultValue: false
  }),
  // Geoshape question type options
  allowPoints: DS.attr('boolean', {
    defaultValue: true
  }),
  allowLine: DS.attr('boolean', {
    defaultValue: true
  }),
  allowPolygon: DS.attr('boolean', {
    defaultValue: true
  })
});

FLOW.QuestionOption = FLOW.BaseModel.extend({
  question: DS.belongsTo('FLOW.Question'),
  order: DS.attr('number'),
  questionId: DS.attr('number'),
  text: DS.attr('string'),
  code: DS.attr('string'),
});

FLOW.DeviceGroup = FLOW.BaseModel.extend({
  code: DS.attr('string', {
    defaultValue: ''
  })
});

FLOW.Device = FLOW.BaseModel.extend({
  didLoad: function () {
    var combinedName;
    if (Ember.empty(this.get('deviceIdentifier'))) {
      combinedName = "no identifer";
    } else {
      combinedName = this.get('deviceIdentifier');
    }
    this.set('combinedName', combinedName + " " + this.get('phoneNumber'));
  },
  esn: DS.attr('string', {
    defaultValue: ''
  }),
  phoneNumber: DS.attr('string', {
    defaultValue: ''
  }),
  deviceIdentifier: DS.attr('string', {
    defaultValue: ''
  }),
  gallatinSoftwareManifest: DS.attr('string'),
  lastKnownLat: DS.attr('number', {
    defaultValue: 0
  }),
  lastKnownLon: DS.attr('number', {
    defaultValue: 0
  }),
  lastKnownAccuracy: DS.attr('number', {
    defaultValue: 0
  }),
  lastPositionDate: DS.attr('number', {
    defaultValue: ''
  }),
  deviceGroup: DS.attr('string', {
    defaultValue: ''
  }),
  deviceGroupName: DS.attr('string', {
    defaultValue: ''
  }),
  isSelected: false,
  combinedName: null
});

FLOW.SurveyAssignment = FLOW.BaseModel.extend({
  name: DS.attr('string'),
  startDate: DS.attr('number'),
  endDate: DS.attr('number'),
  devices: DS.attr('array'),
  surveys: DS.attr('array'),
  language: DS.attr('string')
});

FLOW.SurveyedLocale = DS.Model.extend({
  description: DS.attr('string', {
    defaultValue: ''
  }),
  keyId: DS.attr('number'),
  latitude: DS.attr('number'),
  longitude: DS.attr('number'),
  displayName: DS.attr('string'),
  lastUpdateDateTime: DS.attr('number'),
  surveyGroupId: DS.attr('number'),
  identifier: DS.attr('string'),
  primaryKey: 'keyId'
});

// Explicitly avoid to use belongTo and hasMany as
// Ember-Data lacks of partial loading
// https://github.com/emberjs/data/issues/51
FLOW.PlacemarkDetail = FLOW.BaseModel.extend({
  placemarkId: DS.attr('number'),
  collectionDate: DS.attr('number'),
  order: DS.attr('number'),
  questionText: DS.attr('string'),
  metricName: DS.attr('string'),
  stringValue: DS.attr('string'),
  questionType: DS.attr('string')
});

FLOW.Placemark = FLOW.BaseModel.extend({
	latitude: DS.attr('number'),
	longitude: DS.attr('number'),
	count: DS.attr('number'),
	level: DS.attr('number'),
	surveyId: DS.attr('number'),
	detailsId: DS.attr('number'),
	collectionDate: DS.attr('number')
});

FLOW.SurveyInstance = FLOW.BaseModel.extend({
  approvedFlag: DS.attr('string'),
  approximateLocationFlag: DS.attr('string'),
  surveyInstanceId: DS.attr('number'),
  surveyId: DS.attr('number'),
  surveyedLocaleId:DS.attr('number'),
  collectionDate: DS.attr('number'),
  surveyCode: DS.attr('string'),
  submitterName: DS.attr('string'),
  deviceIdentifier: DS.attr('string'),
  surveyedLocaleIdentifier: DS.attr('string'),
  surveyedLocaleDisplayName: DS.attr('string')
});

FLOW.QuestionAnswer = FLOW.BaseModel.extend({
  value: DS.attr('string'),
  type: DS.attr('string'),
  oldValue: DS.attr('string'),
  surveyId: DS.attr('number'),
  collectionDate: DS.attr('number'),
  surveyInstanceId: DS.attr('number'),
  iteration: DS.attr('number'),
  questionID: DS.attr('string'), //TODO should be number?
  questionText: DS.attr('string')
});

FLOW.ApprovalGroup = FLOW.BaseModel.extend({
    name: DS.attr('string'),
    ordered: DS.attr('boolean'),
});

FLOW.ApprovalStep = FLOW.BaseModel.extend({
    approvalGroupId: DS.attr('number'),
    order: DS.attr('number'),
    title: DS.attr('string'),
    approverUserList: DS.attr('array', {
        defaultValue: null
    }),
});

FLOW.DataPointApproval = FLOW.BaseModel.extend({
    surveyedLocaleId: DS.attr('number'),

    approvalStepId: DS.attr('number'),

    approverUserName: DS.attr('string'),

    approvalDate: DS.attr('number'),

    status: DS.attr('string'),

    comment: DS.attr('string'),
});

FLOW.SurveyQuestionSummary = FLOW.BaseModel.extend({
  response: DS.attr('string'),
  count: DS.attr('number'),
  percentage: null,
  questionId: DS.attr('string')
});

FLOW.User = FLOW.BaseModel.extend({
  userName: DS.attr('string'),
  emailAddress: DS.attr('string'),
  admin: DS.attr('boolean', {
    defaultValue: 0
  }),
  superAdmin: DS.attr('boolean', {
    defaultValue: 0
  }),
  permissionList: DS.attr('string'),
  accessKey: DS.attr('string')
});

FLOW.UserConfig = FLOW.BaseModel.extend({
  group: DS.attr('string'),
  name: DS.attr('string'),
  value: DS.attr('string'),
  userId: DS.attr('number')
});

FLOW.Message = FLOW.BaseModel.extend({
  objectId: DS.attr('number'),
  lastUpdateDateTime: DS.attr('number'),
  userName: DS.attr('string'),
  objectTitle: DS.attr('string'),
  actionAbout: DS.attr('string'),
  shortMessage: DS.attr('string')
});

FLOW.Action = FLOW.BaseModel.extend({});

FLOW.Translation = FLOW.BaseModel.extend({
  didUpdate: function () {
    FLOW.translationControl.putSingleTranslationInList(this.get('parentType'), this.get('parentId'), this.get('text'), this.get('keyId'), false);
  },

  // can't use this at the moment, as the didCreate is fired before the id is back from the ajax call
  // didCreate: function(){
  //   console.log('didCreate',this.get('keyId'));
  //   FLOW.translationControl.putSingleTranslationInList(this.get('parentType'),this.get('parentId'),this.get('text'),this.get('keyId'), false);
  // },

  // temporary hack to fire the didCreate event after the keyId is known
  didCreateId: function () {
    if (!Ember.none(this.get('keyId')) && this.get('keyId') > 0) {
      FLOW.translationControl.putSingleTranslationInList(this.get('parentType'), this.get('parentId'), this.get('text'), this.get('keyId'), false);
    }
  }.observes('this.keyId'),

  didDelete: function () {
    FLOW.translationControl.putSingleTranslationInList(this.get('parentType'), this.get('parentId'), null, null, true);
  },

  parentType: DS.attr('string'),
  parentId: DS.attr('string'),
  surveyId: DS.attr('string'),
  questionGroupId: DS.attr('string'),
  text: DS.attr('string'),
  langCode: DS.attr('string')
});

FLOW.NotificationSubscription = FLOW.BaseModel.extend({
  notificationDestination: DS.attr('string'),
  notificationOption: DS.attr('string'),
  notificationMethod: DS.attr('string'),
  notificationType: DS.attr('string'),
  expiryDate: DS.attr('number'),
  entityId: DS.attr('number')
});

FLOW.SubCountry = FLOW.BaseModel.extend({
  countryCode: DS.attr('string'),
  level: DS.attr('number'),
  name: DS.attr('string'),
  parentKey: DS.attr('number'),
  parentName: DS.attr('string')
});

FLOW.Report = FLOW.BaseModel.extend({
  reportType: DS.attr('string'), //DATA_CLEANING/COMPREHENSIVE/...
  user: DS.attr('string'),
  formId: DS.attr('number'),
  state: DS.attr('string'), //IN_PROGRESS/FINISHED_SUCCESS/FINISHED_ERROR
  startDate: DS.attr('string'),
  endDate: DS.attr('string'),
  message: DS.attr('string'),
  createdDate: DS.attr('number'),
  lastModifiedDate: DS.attr('number'),
  lastCollectionOnly: DS.attr('boolean', {
    defaultValue: false
  })
});
<|endoftext|>


<commit_before>// ***********************************************//
//                 models and stores
// ***********************************************//
require('akvo-flow/core-common');
require('akvo-flow/models/store_def-common');

FLOW.BaseModel = DS.Model.extend({
  keyId: DS.attr('number'),
  savingStatus: null,

  // this method calls the checkSaving method on the savingMessageControl, which
  // checks if there are any records inflight. If yes, it sets a boolean,
  // so a saving message can be displayed. savingStatus is used to capture the
  // moment that nothing is being saved anymore, but in the previous event it was
  // so we can turn off the saving message.
  anySaving: function () {
    if (this.get('isSaving') || this.get('isDirty') || this.get('savingStatus')) {
      FLOW.savingMessageControl.checkSaving();
    }
    this.set('savingStatus', (this.get('isSaving') || this.get('isDirty')));
  }.observes('isSaving', 'isDirty')
});

FLOW.CascadeResource = FLOW.BaseModel.extend({
	name: DS.attr('string', {
	   defaultValue: ''
	}),
	version: DS.attr('number', {
		defaultValue: 1
	}),
	numLevels: DS.attr('number', {
		defaultValue: 1
	}),
	status: DS.attr('string', {
		defaultValue: 'NOT_PUBLISHED'
	}),
	levelNames: DS.attr('array', {defaultValue: []
	}),
});

FLOW.CascadeNode = FLOW.BaseModel.extend({
	name: DS.attr('string', {
	   defaultValue: ''
	}),
	code: DS.attr('string', {
		defaultValue: ''
	}),
	parentNodeId: DS.attr('number', {
		defaultValue: ''
	}),
	cascadeResourceId: DS.attr('number', {
		defaultValue: ''
	})
});

FLOW.SurveyGroup = FLOW.BaseModel.extend({
  description: DS.attr('string', {
    defaultValue: ''
  }),
  name: DS.attr('string', {
    defaultValue: ''
  }),
  path: DS.attr('string', {
    defaultValue: null
  }),
  createdDateTime: DS.attr('string', {
    defaultValue: ''
  }),
  monitoringGroup: DS.attr('boolean', {
    defaultValue: false
  }),
  newLocaleSurveyId: DS.attr('number'),
  lastUpdateDateTime: DS.attr('string', {
    defaultValue: ''
  }),
  // the code field is used as name
  code: DS.attr('string', {
    defaultValue: ''
  }),

  parentId: DS.attr('number', {
    defaultValue: null
  }),

  projectType: DS.attr('string', {
    defaultValue: "PROJECT"
  }),

  privacyLevel: DS.attr('string', {
    defaultValue: "PRIVATE"
  }),

  defaultLanguageCode: DS.attr('string', {
    defaultValue: "en"
  }),

  published: DS.attr('boolean', {
    defaultValue: false
  })

});

FLOW.Survey = FLOW.BaseModel.extend({
  didLoad: function () {
    // set the survey group name
    var sg = FLOW.store.find(FLOW.SurveyGroup, this.get('surveyGroupId'));
    if (!Ember.empty(sg)) {
      this.set('surveyGroupName', sg.get('code'));
    }
  },

  defaultLanguageCode: DS.attr('string'),
  status: DS.attr('string'),
  sector: DS.attr('string'),
  code: DS.attr('string'),
  requireApproval: DS.attr('string'),
  version: DS.attr('string'),
  description: DS.attr('string'),
  name: DS.attr('string'),
  path: DS.attr('string'),
  pointType: DS.attr('string'),
  surveyGroupId: DS.attr('number'),
  createdDateTime: DS.attr('number'),
  lastUpdateDateTime: DS.attr('number'),
  instanceCount: DS.attr('number'),

  // This attribute is used for the 'Copy Survey' functionality
  // Most of the times is `null`
  sourceId: DS.attr('number', {
    defaultValue: null
  }),

  // used in the assignment edit page, not saved to backend
  surveyGroupName: null,

  allowEdit: function () {
	  return !this.get('isNew') && this.get('status') !== 'COPYING';
  }.property('status', 'isNew')

});

FLOW.QuestionGroup = FLOW.BaseModel.extend({
  order: DS.attr('number'),
  description: DS.attr('string'),
  name: DS.attr('string'),
  path: DS.attr('string'),
  code: DS.attr('string'),
  surveyId: DS.attr('number'),
  sourceId: DS.attr('number', {
    defaultValue: null
  })
});

FLOW.Question = FLOW.BaseModel.extend({
  questionOptions: DS.hasMany('FLOW.QuestionOption'),
  questionOptionList: null,
  allowDecimal: DS.attr('boolean', {
    defaultValue: false
  }),
  allowMultipleFlag: DS.attr('boolean', {
    defaultValue: false
  }),
  allowOtherFlag: DS.attr('boolean', {
    defaultValue: false
  }),
  localeNameFlag: DS.attr('boolean', {
	    defaultValue: false
	  }),
  localeLocationFlag: DS.attr('boolean', {
		defaultValue: false
  }),
  allowSign: DS.attr('boolean', {
    defaultValue: false
  }),
  geoLocked: DS.attr('boolean', {
	    defaultValue: false
	  }),
  requireDoubleEntry: DS.attr('boolean', {
    defaultValue: false
  }),
  collapseable: DS.attr('boolean', {
    defaultValue: false
  }),
  immutable: DS.attr('boolean', {
    defaultValue: false
  }),
  isName: DS.attr('boolean', {
    defaultValue: false
  }),
  mandatoryFlag: DS.attr('boolean', {
    defaultValue: true
  }),
  dependentFlag: DS.attr('boolean', {
    defaultValue: false
  }),
  dependentQuestionAnswer: DS.attr('string'),
  dependentQuestionId: DS.attr('number'),
  maxVal: DS.attr('number', {
    defaultValue: null
  }),
  minVal: DS.attr('number', {
    defaultValue: null
  }),
  order: DS.attr('number'),
  cascadeResourceId: DS.attr('number'),
  path: DS.attr('string'),
  questionGroupId: DS.attr('number'),
  surveyId: DS.attr('number'),
  questionId: DS.attr('string'),
  metricId: DS.attr('number'),
  text: DS.attr('string'),
  tip: DS.attr('string'),
  type: DS.attr('string', {
	defaultValue: "FREE_TEXT"
  }),
  // This attribute is used for the 'Copy Survey' functionality
  // Most of the times is `null`
  sourceId: DS.attr('number', {
	 defaultValue: null
  }),
  allowExternalSources: DS.attr('boolean', {
    defaultValue: false
  })
});

FLOW.QuestionOption = FLOW.BaseModel.extend({
  question: DS.belongsTo('FLOW.Question'),
  order: DS.attr('number'),
  questionId: DS.attr('number'),
  text: DS.attr('string')
});

FLOW.DeviceGroup = FLOW.BaseModel.extend({
  code: DS.attr('string', {
    defaultValue: ''
  })
});

FLOW.Device = FLOW.BaseModel.extend({
  didLoad: function () {
    var combinedName;
    if (Ember.empty(this.get('deviceIdentifier'))) {
      combinedName = "no identifer";
    } else {
      combinedName = this.get('deviceIdentifier');
    }
    this.set('combinedName', combinedName + " " + this.get('phoneNumber'));
  },
  esn: DS.attr('string', {
    defaultValue: ''
  }),
  phoneNumber: DS.attr('string', {
    defaultValue: ''
  }),
  deviceIdentifier: DS.attr('string', {
    defaultValue: ''
  }),
  gallatinSoftwareManifest: DS.attr('string'),
  lastKnownLat: DS.attr('number', {
    defaultValue: 0
  }),
  lastKnownLon: DS.attr('number', {
    defaultValue: 0
  }),
  lastKnownAccuracy: DS.attr('number', {
    defaultValue: 0
  }),
  lastPositionDate: DS.attr('number', {
    defaultValue: ''
  }),
  deviceGroup: DS.attr('string', {
    defaultValue: ''
  }),
  deviceGroupName: DS.attr('string', {
    defaultValue: ''
  }),
  isSelected: false,
  combinedName: null
});

FLOW.SurveyAssignment = FLOW.BaseModel.extend({
  name: DS.attr('string'),
  startDate: DS.attr('number'),
  endDate: DS.attr('number'),
  devices: DS.attr('array'),
  surveys: DS.attr('array'),
  language: DS.attr('string')
});

FLOW.SurveyedLocale = DS.Model.extend({
  description: DS.attr('string', {
    defaultValue: ''
  }),
  keyId: DS.attr('number'),
  latitude: DS.attr('number'),
  longitude: DS.attr('number'),
  displayName: DS.attr('string'),
  lastUpdateDateTime: DS.attr('number'),
  surveyGroupId: DS.attr('number'),
  identifier: DS.attr('string'),
  primaryKey: 'keyId'
});

// Explicitly avoid to use belongTo and hasMany as
// Ember-Data lacks of partial loading
// https://github.com/emberjs/data/issues/51
FLOW.PlacemarkDetail = FLOW.BaseModel.extend({
  placemarkId: DS.attr('number'),
  collectionDate: DS.attr('number'),
  order: DS.attr('number'),
  questionText: DS.attr('string'),
  metricName: DS.attr('string'),
  stringValue: DS.attr('string'),
  questionType: DS.attr('string')
});

FLOW.Placemark = FLOW.BaseModel.extend({
	latitude: DS.attr('number'),
	longitude: DS.attr('number'),
	count: DS.attr('number'),
	level: DS.attr('number'),
	surveyId: DS.attr('number'),
	detailsId: DS.attr('number'),
	collectionDate: DS.attr('number')
});

FLOW.SurveyInstance = FLOW.BaseModel.extend({
  approvedFlag: DS.attr('string'),
  approximateLocationFlag: DS.attr('string'),
  surveyId: DS.attr('number'),
  collectionDate: DS.attr('number'),
  surveyCode: DS.attr('string'),
  submitterName: DS.attr('string'),
  deviceIdentifier: DS.attr('string')
});

FLOW.QuestionAnswer = FLOW.BaseModel.extend({
  value: DS.attr('string'),
  type: DS.attr('string'),
  oldValue: DS.attr('string'),
  surveyId: DS.attr('number'),
  collectionDate: DS.attr('number'),
  surveyInstanceId: DS.attr('number'),
  questionID: DS.attr('string'),
  questionText: DS.attr('string')
});

FLOW.SurveyQuestionSummary = FLOW.BaseModel.extend({
  response: DS.attr('string'),
  count: DS.attr('number'),
  percentage: null,
  questionId: DS.attr('string')
});

FLOW.User = FLOW.BaseModel.extend({
  userName: DS.attr('string'),
  emailAddress: DS.attr('string'),
  admin: DS.attr('boolean', {
    defaultValue: 0
  }),
  superAdmin: DS.attr('boolean', {
    defaultValue: 0
  }),
  permissionList: DS.attr('string'),
  accessKey: DS.attr('string')
});

FLOW.UserConfig = FLOW.BaseModel.extend({
  group: DS.attr('string'),
  name: DS.attr('string'),
  value: DS.attr('string'),
  userId: DS.attr('number')
});

// this is called attribute in the dashboard, but metric in the backend, for historic reasons.
FLOW.Metric = FLOW.BaseModel.extend({
  organization: DS.attr('string'),
  name: DS.attr('string'),
  group: DS.attr('string'),
  valueType: DS.attr('string'),
  questionId: DS.attr('number')
});

FLOW.Message = FLOW.BaseModel.extend({
  objectId: DS.attr('number'),
  lastUpdateDateTime: DS.attr('number'),
  userName: DS.attr('string'),
  objectTitle: DS.attr('string'),
  actionAbout: DS.attr('string'),
  shortMessage: DS.attr('string')
});

FLOW.Action = FLOW.BaseModel.extend({});

FLOW.Translation = FLOW.BaseModel.extend({
  didUpdate: function () {
    FLOW.translationControl.putSingleTranslationInList(this.get('parentType'), this.get('parentId'), this.get('text'), this.get('keyId'), false);
  },

  // can't use this at the moment, as the didCreate is fired before the id is back from the ajax call
  // didCreate: function(){
  //   console.log('didCreate',this.get('keyId'));
  //   FLOW.translationControl.putSingleTranslationInList(this.get('parentType'),this.get('parentId'),this.get('text'),this.get('keyId'), false);
  // },

  // temporary hack to fire the didCreate event after the keyId is known
  didCreateId: function () {
    if (!Ember.none(this.get('keyId')) && this.get('keyId') > 0) {
      FLOW.translationControl.putSingleTranslationInList(this.get('parentType'), this.get('parentId'), this.get('text'), this.get('keyId'), false);
    }
  }.observes('this.keyId'),

  didDelete: function () {
    FLOW.translationControl.putSingleTranslationInList(this.get('parentType'), this.get('parentId'), null, null, true);
  },

  parentType: DS.attr('string'),
  parentId: DS.attr('string'),
  surveyId: DS.attr('string'),
  questionGroupId: DS.attr('string'),
  text: DS.attr('string'),
  langCode: DS.attr('string')
});

FLOW.NotificationSubscription = FLOW.BaseModel.extend({
  notificationDestination: DS.attr('string'),
  notificationOption: DS.attr('string'),
  notificationMethod: DS.attr('string'),
  notificationType: DS.attr('string'),
  expiryDate: DS.attr('number'),
  entityId: DS.attr('number')
});

FLOW.SubCountry = FLOW.BaseModel.extend({
  countryCode: DS.attr('string'),
  level: DS.attr('number'),
  name: DS.attr('string'),
  parentKey: DS.attr('number'),
  parentName: DS.attr('string')
});
<commit_msg>[#966] Adds the `surveyList` as property in the model<commit_after>// ***********************************************//
//                 models and stores
// ***********************************************//
require('akvo-flow/core-common');
require('akvo-flow/models/store_def-common');

FLOW.BaseModel = DS.Model.extend({
  keyId: DS.attr('number'),
  savingStatus: null,

  // this method calls the checkSaving method on the savingMessageControl, which
  // checks if there are any records inflight. If yes, it sets a boolean,
  // so a saving message can be displayed. savingStatus is used to capture the
  // moment that nothing is being saved anymore, but in the previous event it was
  // so we can turn off the saving message.
  anySaving: function () {
    if (this.get('isSaving') || this.get('isDirty') || this.get('savingStatus')) {
      FLOW.savingMessageControl.checkSaving();
    }
    this.set('savingStatus', (this.get('isSaving') || this.get('isDirty')));
  }.observes('isSaving', 'isDirty')
});

FLOW.CascadeResource = FLOW.BaseModel.extend({
	name: DS.attr('string', {
	   defaultValue: ''
	}),
	version: DS.attr('number', {
		defaultValue: 1
	}),
	numLevels: DS.attr('number', {
		defaultValue: 1
	}),
	status: DS.attr('string', {
		defaultValue: 'NOT_PUBLISHED'
	}),
	levelNames: DS.attr('array', {defaultValue: []
	}),
});

FLOW.CascadeNode = FLOW.BaseModel.extend({
	name: DS.attr('string', {
	   defaultValue: ''
	}),
	code: DS.attr('string', {
		defaultValue: ''
	}),
	parentNodeId: DS.attr('number', {
		defaultValue: ''
	}),
	cascadeResourceId: DS.attr('number', {
		defaultValue: ''
	})
});

FLOW.SurveyGroup = FLOW.BaseModel.extend({
  description: DS.attr('string', {
    defaultValue: ''
  }),
  name: DS.attr('string', {
    defaultValue: ''
  }),
  path: DS.attr('string', {
    defaultValue: null
  }),
  createdDateTime: DS.attr('string', {
    defaultValue: ''
  }),
  monitoringGroup: DS.attr('boolean', {
    defaultValue: false
  }),
  newLocaleSurveyId: DS.attr('number'),
  lastUpdateDateTime: DS.attr('string', {
    defaultValue: ''
  }),
  // the code field is used as name
  code: DS.attr('string', {
    defaultValue: ''
  }),

  parentId: DS.attr('number', {
    defaultValue: null
  }),

  projectType: DS.attr('string', {
    defaultValue: "PROJECT"
  }),

  privacyLevel: DS.attr('string', {
    defaultValue: "PRIVATE"
  }),

  defaultLanguageCode: DS.attr('string', {
    defaultValue: "en"
  }),

  published: DS.attr('boolean', {
    defaultValue: false
  }),

  surveyList: DS.attr('array', {
	defaultValue: null
  })

});

FLOW.Survey = FLOW.BaseModel.extend({
  didLoad: function () {
    // set the survey group name
    var sg = FLOW.store.find(FLOW.SurveyGroup, this.get('surveyGroupId'));
    if (!Ember.empty(sg)) {
      this.set('surveyGroupName', sg.get('code'));
    }
  },

  defaultLanguageCode: DS.attr('string'),
  status: DS.attr('string'),
  sector: DS.attr('string'),
  code: DS.attr('string'),
  requireApproval: DS.attr('string'),
  version: DS.attr('string'),
  description: DS.attr('string'),
  name: DS.attr('string'),
  path: DS.attr('string'),
  pointType: DS.attr('string'),
  surveyGroupId: DS.attr('number'),
  createdDateTime: DS.attr('number'),
  lastUpdateDateTime: DS.attr('number'),
  instanceCount: DS.attr('number'),

  // This attribute is used for the 'Copy Survey' functionality
  // Most of the times is `null`
  sourceId: DS.attr('number', {
    defaultValue: null
  }),

  // used in the assignment edit page, not saved to backend
  surveyGroupName: null,

  allowEdit: function () {
	  return !this.get('isNew') && this.get('status') !== 'COPYING';
  }.property('status', 'isNew')

});

FLOW.QuestionGroup = FLOW.BaseModel.extend({
  order: DS.attr('number'),
  description: DS.attr('string'),
  name: DS.attr('string'),
  path: DS.attr('string'),
  code: DS.attr('string'),
  surveyId: DS.attr('number'),
  sourceId: DS.attr('number', {
    defaultValue: null
  })
});

FLOW.Question = FLOW.BaseModel.extend({
  questionOptions: DS.hasMany('FLOW.QuestionOption'),
  questionOptionList: null,
  allowDecimal: DS.attr('boolean', {
    defaultValue: false
  }),
  allowMultipleFlag: DS.attr('boolean', {
    defaultValue: false
  }),
  allowOtherFlag: DS.attr('boolean', {
    defaultValue: false
  }),
  localeNameFlag: DS.attr('boolean', {
	    defaultValue: false
	  }),
  localeLocationFlag: DS.attr('boolean', {
		defaultValue: false
  }),
  allowSign: DS.attr('boolean', {
    defaultValue: false
  }),
  geoLocked: DS.attr('boolean', {
	    defaultValue: false
	  }),
  requireDoubleEntry: DS.attr('boolean', {
    defaultValue: false
  }),
  collapseable: DS.attr('boolean', {
    defaultValue: false
  }),
  immutable: DS.attr('boolean', {
    defaultValue: false
  }),
  isName: DS.attr('boolean', {
    defaultValue: false
  }),
  mandatoryFlag: DS.attr('boolean', {
    defaultValue: true
  }),
  dependentFlag: DS.attr('boolean', {
    defaultValue: false
  }),
  dependentQuestionAnswer: DS.attr('string'),
  dependentQuestionId: DS.attr('number'),
  maxVal: DS.attr('number', {
    defaultValue: null
  }),
  minVal: DS.attr('number', {
    defaultValue: null
  }),
  order: DS.attr('number'),
  cascadeResourceId: DS.attr('number'),
  path: DS.attr('string'),
  questionGroupId: DS.attr('number'),
  surveyId: DS.attr('number'),
  questionId: DS.attr('string'),
  metricId: DS.attr('number'),
  text: DS.attr('string'),
  tip: DS.attr('string'),
  type: DS.attr('string', {
	defaultValue: "FREE_TEXT"
  }),
  // This attribute is used for the 'Copy Survey' functionality
  // Most of the times is `null`
  sourceId: DS.attr('number', {
	 defaultValue: null
  }),
  allowExternalSources: DS.attr('boolean', {
    defaultValue: false
  })
});

FLOW.QuestionOption = FLOW.BaseModel.extend({
  question: DS.belongsTo('FLOW.Question'),
  order: DS.attr('number'),
  questionId: DS.attr('number'),
  text: DS.attr('string')
});

FLOW.DeviceGroup = FLOW.BaseModel.extend({
  code: DS.attr('string', {
    defaultValue: ''
  })
});

FLOW.Device = FLOW.BaseModel.extend({
  didLoad: function () {
    var combinedName;
    if (Ember.empty(this.get('deviceIdentifier'))) {
      combinedName = "no identifer";
    } else {
      combinedName = this.get('deviceIdentifier');
    }
    this.set('combinedName', combinedName + " " + this.get('phoneNumber'));
  },
  esn: DS.attr('string', {
    defaultValue: ''
  }),
  phoneNumber: DS.attr('string', {
    defaultValue: ''
  }),
  deviceIdentifier: DS.attr('string', {
    defaultValue: ''
  }),
  gallatinSoftwareManifest: DS.attr('string'),
  lastKnownLat: DS.attr('number', {
    defaultValue: 0
  }),
  lastKnownLon: DS.attr('number', {
    defaultValue: 0
  }),
  lastKnownAccuracy: DS.attr('number', {
    defaultValue: 0
  }),
  lastPositionDate: DS.attr('number', {
    defaultValue: ''
  }),
  deviceGroup: DS.attr('string', {
    defaultValue: ''
  }),
  deviceGroupName: DS.attr('string', {
    defaultValue: ''
  }),
  isSelected: false,
  combinedName: null
});

FLOW.SurveyAssignment = FLOW.BaseModel.extend({
  name: DS.attr('string'),
  startDate: DS.attr('number'),
  endDate: DS.attr('number'),
  devices: DS.attr('array'),
  surveys: DS.attr('array'),
  language: DS.attr('string')
});

FLOW.SurveyedLocale = DS.Model.extend({
  description: DS.attr('string', {
    defaultValue: ''
  }),
  keyId: DS.attr('number'),
  latitude: DS.attr('number'),
  longitude: DS.attr('number'),
  displayName: DS.attr('string'),
  lastUpdateDateTime: DS.attr('number'),
  surveyGroupId: DS.attr('number'),
  identifier: DS.attr('string'),
  primaryKey: 'keyId'
});

// Explicitly avoid to use belongTo and hasMany as
// Ember-Data lacks of partial loading
// https://github.com/emberjs/data/issues/51
FLOW.PlacemarkDetail = FLOW.BaseModel.extend({
  placemarkId: DS.attr('number'),
  collectionDate: DS.attr('number'),
  order: DS.attr('number'),
  questionText: DS.attr('string'),
  metricName: DS.attr('string'),
  stringValue: DS.attr('string'),
  questionType: DS.attr('string')
});

FLOW.Placemark = FLOW.BaseModel.extend({
	latitude: DS.attr('number'),
	longitude: DS.attr('number'),
	count: DS.attr('number'),
	level: DS.attr('number'),
	surveyId: DS.attr('number'),
	detailsId: DS.attr('number'),
	collectionDate: DS.attr('number')
});

FLOW.SurveyInstance = FLOW.BaseModel.extend({
  approvedFlag: DS.attr('string'),
  approximateLocationFlag: DS.attr('string'),
  surveyId: DS.attr('number'),
  collectionDate: DS.attr('number'),
  surveyCode: DS.attr('string'),
  submitterName: DS.attr('string'),
  deviceIdentifier: DS.attr('string')
});

FLOW.QuestionAnswer = FLOW.BaseModel.extend({
  value: DS.attr('string'),
  type: DS.attr('string'),
  oldValue: DS.attr('string'),
  surveyId: DS.attr('number'),
  collectionDate: DS.attr('number'),
  surveyInstanceId: DS.attr('number'),
  questionID: DS.attr('string'),
  questionText: DS.attr('string')
});

FLOW.SurveyQuestionSummary = FLOW.BaseModel.extend({
  response: DS.attr('string'),
  count: DS.attr('number'),
  percentage: null,
  questionId: DS.attr('string')
});

FLOW.User = FLOW.BaseModel.extend({
  userName: DS.attr('string'),
  emailAddress: DS.attr('string'),
  admin: DS.attr('boolean', {
    defaultValue: 0
  }),
  superAdmin: DS.attr('boolean', {
    defaultValue: 0
  }),
  permissionList: DS.attr('string'),
  accessKey: DS.attr('string')
});

FLOW.UserConfig = FLOW.BaseModel.extend({
  group: DS.attr('string'),
  name: DS.attr('string'),
  value: DS.attr('string'),
  userId: DS.attr('number')
});

// this is called attribute in the dashboard, but metric in the backend, for historic reasons.
FLOW.Metric = FLOW.BaseModel.extend({
  organization: DS.attr('string'),
  name: DS.attr('string'),
  group: DS.attr('string'),
  valueType: DS.attr('string'),
  questionId: DS.attr('number')
});

FLOW.Message = FLOW.BaseModel.extend({
  objectId: DS.attr('number'),
  lastUpdateDateTime: DS.attr('number'),
  userName: DS.attr('string'),
  objectTitle: DS.attr('string'),
  actionAbout: DS.attr('string'),
  shortMessage: DS.attr('string')
});

FLOW.Action = FLOW.BaseModel.extend({});

FLOW.Translation = FLOW.BaseModel.extend({
  didUpdate: function () {
    FLOW.translationControl.putSingleTranslationInList(this.get('parentType'), this.get('parentId'), this.get('text'), this.get('keyId'), false);
  },

  // can't use this at the moment, as the didCreate is fired before the id is back from the ajax call
  // didCreate: function(){
  //   console.log('didCreate',this.get('keyId'));
  //   FLOW.translationControl.putSingleTranslationInList(this.get('parentType'),this.get('parentId'),this.get('text'),this.get('keyId'), false);
  // },

  // temporary hack to fire the didCreate event after the keyId is known
  didCreateId: function () {
    if (!Ember.none(this.get('keyId')) && this.get('keyId') > 0) {
      FLOW.translationControl.putSingleTranslationInList(this.get('parentType'), this.get('parentId'), this.get('text'), this.get('keyId'), false);
    }
  }.observes('this.keyId'),

  didDelete: function () {
    FLOW.translationControl.putSingleTranslationInList(this.get('parentType'), this.get('parentId'), null, null, true);
  },

  parentType: DS.attr('string'),
  parentId: DS.attr('string'),
  surveyId: DS.attr('string'),
  questionGroupId: DS.attr('string'),
  text: DS.attr('string'),
  langCode: DS.attr('string')
});

FLOW.NotificationSubscription = FLOW.BaseModel.extend({
  notificationDestination: DS.attr('string'),
  notificationOption: DS.attr('string'),
  notificationMethod: DS.attr('string'),
  notificationType: DS.attr('string'),
  expiryDate: DS.attr('number'),
  entityId: DS.attr('number')
});

FLOW.SubCountry = FLOW.BaseModel.extend({
  countryCode: DS.attr('string'),
  level: DS.attr('number'),
  name: DS.attr('string'),
  parentKey: DS.attr('number'),
  parentName: DS.attr('string')
});
<|endoftext|>


<commit_before>import React from 'react'
import assert from 'power-assert'
import { mount, shallow } from 'enzyme'

import Calculator from '../src/js/components/Calculator'
import Button from '../src/js/components/Button'

const createCalculator = () => {
  return mount(
    <Calculator
      initialAmount="0"
      positions={[]}
    />
  );
}

const clickButton = (calc, ...symbols) => {
  symbols.forEach(symbol => {
    const className = Button.symbolMap[symbol] ? Button.symbolMap[symbol] : '_' + symbol;
    calc.find('.react-currency-calculator__calculator-button.' + className).simulate('click')
  })
}

const getNumberState = (calc, stateName) => {
  return calc.state(stateName).toString()
}

describe('Calculator', () => {
  it('should display a number on the display when you press a numeric key.', function () {
    const calc = createCalculator()

    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "0")

    clickButton(calc, '1');
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "1")

    clickButton(calc, '2')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "12")

    clickButton(calc, '3')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "123")

    clickButton(calc, '4')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "1234")

    clickButton(calc, '5')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "12345")

    clickButton(calc, '6')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "123456")

    clickButton(calc, '7')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "1234567")

    clickButton(calc, '8')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "12345678")

    clickButton(calc, '9')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "123456789")

    clickButton(calc, '0')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "1234567890")

    clickButton(calc, '00')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "123456789000")
  })

  it('should calculate the addition with the plus key.', function () {
    const calc = createCalculator()

    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "0")

    clickButton(calc, '1', '+', '1', '=');
    assert(getNumberState(calc, 'amount') === '2')

    clickButton(calc, '+', '5')
    assert(getNumberState(calc, 'display') === "5")
    assert(getNumberState(calc, 'amount') === '2')
    clickButton(calc, '+')
    assert(getNumberState(calc, 'display') === '7')
    assert(getNumberState(calc, 'amount') === '7')

    clickButton(calc, '1', '00')
    assert(getNumberState(calc, 'display') === "100")
    assert(getNumberState(calc, 'amount') === '7')
    clickButton(calc, '=')
    assert(getNumberState(calc, 'display') === '107')
    assert(getNumberState(calc, 'amount') === '107')

  })
})
<commit_msg>Added the rest four arithmetic operation tests.<commit_after>import React from 'react'
import assert from 'power-assert'
import { mount, shallow } from 'enzyme'

import Calculator from '../src/js/components/Calculator'
import Button from '../src/js/components/Button'

const createCalculator = () => {
  return mount(
    <Calculator
      initialAmount="0"
      positions={[]}
    />
  );
}

const clickButton = (calc, ...symbols) => {
  symbols.forEach(symbol => {
    const className = Button.symbolMap[symbol] ? Button.symbolMap[symbol] : '_' + symbol;
    calc.find('.react-currency-calculator__calculator-buttons .react-currency-calculator__calculator-button.' + className).simulate('click')
  })
}

const getNumberState = (calc, stateName) => {
  return calc.state(stateName).toString()
}

describe('Calculator', () => {
  it('should display a number on the display when you press a numeric key.', function () {
    const calc = createCalculator()

    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "0")

    clickButton(calc, '1');
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "1")

    clickButton(calc, '2')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "12")

    clickButton(calc, '3')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "123")

    clickButton(calc, '4')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "1234")

    clickButton(calc, '5')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "12345")

    clickButton(calc, '6')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "123456")

    clickButton(calc, '7')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "1234567")

    clickButton(calc, '8')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "12345678")

    clickButton(calc, '9')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "123456789")

    clickButton(calc, '0')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "1234567890")

    clickButton(calc, '00')
    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "123456789000")
  })

  it('should calculate the addition with `+` key.', function () {
    const calc = createCalculator()

    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "0")

    clickButton(calc, '1', '+', '1', '=');
    assert(getNumberState(calc, 'amount') === '2')

    clickButton(calc, '+', '5')
    assert(getNumberState(calc, 'display') === "5")
    assert(getNumberState(calc, 'amount') === '2')
    clickButton(calc, '+')
    assert(getNumberState(calc, 'display') === '7')
    assert(getNumberState(calc, 'amount') === '7')

    clickButton(calc, '1', '00')
    assert(getNumberState(calc, 'display') === "100")
    assert(getNumberState(calc, 'amount') === '7')
    clickButton(calc, '=')
    assert(getNumberState(calc, 'display') === '107')
    assert(getNumberState(calc, 'amount') === '107')

  })

  it('should calculate the multiplication with `×` key.', function () {
    const calc = createCalculator()

    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "0")

    clickButton(calc, '2', '×', '2', '=');
    assert(getNumberState(calc, 'amount') === '4')

    clickButton(calc, '×', '5')
    assert(getNumberState(calc, 'display') === "5")
    assert(getNumberState(calc, 'amount') === '4')
    clickButton(calc, '×')
    assert(getNumberState(calc, 'display') === '20')
    assert(getNumberState(calc, 'amount') === '20')

    clickButton(calc, '1', '00')
    assert(getNumberState(calc, 'display') === "100")
    assert(getNumberState(calc, 'amount') === '20')
    clickButton(calc, '=')
    assert(getNumberState(calc, 'display') === '2000')
    assert(getNumberState(calc, 'amount') === '2000')

  })

  it('should calculate the subtraction with `-` key.', function () {
    const calc = createCalculator()

    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "0")

    clickButton(calc, '1', '00', '-', '2', '=');
    assert(getNumberState(calc, 'amount') === '98')

    clickButton(calc, '-', '1', '2')
    assert(getNumberState(calc, 'display') === "12")
    assert(getNumberState(calc, 'amount') === '98')
    clickButton(calc, '-')
    assert(getNumberState(calc, 'display') === '86')
    assert(getNumberState(calc, 'amount') === '86')

    clickButton(calc, '1', '00')
    assert(getNumberState(calc, 'display') === "100")
    assert(getNumberState(calc, 'amount') === '86')
    clickButton(calc, '=')
    assert(getNumberState(calc, 'display') === '-14')
    assert(getNumberState(calc, 'amount') === '-14')

  })

  it('should calculate the division with `÷` key.', function () {
    const calc = createCalculator()

    assert(getNumberState(calc, 'amount') === "0")
    assert(getNumberState(calc, 'display') === "0")

    clickButton(calc, '1', '2', '0', '÷', '2', '=');
    assert(getNumberState(calc, 'amount') === '60')

    clickButton(calc, '÷', '1', '2')
    assert(getNumberState(calc, 'display') === "12")
    assert(getNumberState(calc, 'amount') === '60')
    clickButton(calc, '÷')
    assert(getNumberState(calc, 'display') === '5')
    assert(getNumberState(calc, 'amount') === '5')

    clickButton(calc, '1', '00')
    assert(getNumberState(calc, 'display') === "100")
    assert(getNumberState(calc, 'amount') === '5')
    clickButton(calc, '=')
    assert(getNumberState(calc, 'display') === '0.05')
    assert(getNumberState(calc, 'amount') === '0.05')

  })
})
<|endoftext|>


<commit_before>// ***********************************************//
//                 Router
// ***********************************************//
require('akvo-flow/core-common');

FLOW.Router = Ember.Router.extend({
  enableLogging: true,
  loggedIn: false,
  location: 'none',
  //'hash'or 'none' for URLs

  resetState: function () {
    // We could have unsaved changes
    FLOW.store.commit();

    FLOW.selectedControl.set('selectedQuestionGroup', null);
    FLOW.selectedControl.set('selectedSurveyGroup', null);
    FLOW.selectedControl.set('selectedSurvey', null);
    FLOW.selectedControl.set('selectedQuestion', null);
    FLOW.selectedControl.set('selectedCascadeResource', null);
    FLOW.selectedControl.set('cascadeImportNumLevels', null);
    FLOW.selectedControl.set('cascadeImportIncludeCodes', null);
    FLOW.surveyControl.set('content', null);
    FLOW.questionControl.set('OPTIONcontent', null);
    FLOW.metaControl.set('since', null);
  },

  root: Ember.Route.extend({
    doNavSurveys: function (router, context) {
      router.transitionTo('navSurveys.index');
    },
    doNavDevices: function (router, context) {
      router.transitionTo('navDevices.index');
    },
    doNavData: function (router, context) {
      router.transitionTo('navData.index');
    },
    doNavReports: function (router, context) {
      router.transitionTo('navReports.index');
    },
    doNavMaps: function (router, context) {
      router.transitionTo('navMaps');
    },
    doNavUsers: function (router, context) {
      router.transitionTo('navUsers');
    },
    doNavMessages: function (router, context) {
      router.transitionTo('navMessages');
    },
    // not used at the moment
    doNavAdmin: function (router, context) {
      router.transitionTo('navAdmin');
    },

    // non-working code for transitioning to navHome at first entry of the app
    //    setup: function(router){
    //      router.send("goHome");
    //    },
    //    goHome:function(router){
    //      router.transitionTo('navHome');
    //    },
    index: Ember.Route.extend({
      route: '/',
      redirectsTo: 'navSurveys.index'
    }),

    // ******************* SURVEYS ROUTER ********************
    navSurveys: Ember.Route.extend({
      route: '/surveys',
      connectOutlets: function (router, event) {
        router.get('applicationController').connectOutlet('navSurveys');
        router.set('navigationController.selected', 'navSurveys');
      },

      doNewSurvey: function (router, event) {
        router.transitionTo('navSurveys.navSurveysNew');
      },

      doEditSurvey: function (router, event) {
        FLOW.selectedControl.set('selectedSurvey', event.context);
        router.transitionTo('navSurveys.navSurveysEdit.index');
      },

      doSurveysMain: function (router, event) {
        FLOW.selectedControl.set('selectedQuestion', null);
        router.transitionTo('navSurveys.navSurveysMain');
      },

      index: Ember.Route.extend({
        route: '/',
        redirectsTo: 'navSurveysMain'
      }),

      navSurveysMain: Ember.Route.extend({
        route: '/main',
        connectOutlets: function (router, event) {
          router.get('navSurveysController').connectOutlet({
            name: 'navSurveysMain'
          });
          FLOW.projectControl.populate();
          FLOW.projectControl.set('currentProject', null);
          FLOW.projectControl.set('newlyCreated', null);
          FLOW.selectedControl.set('selectedQuestionGroup', null);
          FLOW.selectedControl.set('selectedSurvey', null);
          FLOW.selectedControl.set('selectedQuestion', null);
          FLOW.questionControl.set('OPTIONcontent', null);
          FLOW.cascadeResourceControl.populate();
          FLOW.attributeControl.populate();
        }
      }),

      navSurveysNew: Ember.Route.extend({
        route: '/new',
        connectOutlets: function (router, event) {
          var newSurvey;

          newSurvey = FLOW.store.createRecord(FLOW.Survey, {
            "name": "",
            "defaultLanguageCode": "en",
            "requireApproval": false,
            "status": "NOT_PUBLISHED",
            "surveyGroupId": FLOW.selectedControl.selectedSurveyGroup.get('keyId'),
            "version":"1.0"
          });

          FLOW.selectedControl.set('selectedSurvey', newSurvey);
          router.transitionTo('navSurveys.navSurveysEdit.index');
        }
      }),

      navSurveysEdit: Ember.Route.extend({
        route: '/edit',
        connectOutlets: function (router, event) {
          router.get('navSurveysController').connectOutlet({
            name: 'navSurveysEdit'
          });
          // all questions should be closed when we enter
          FLOW.selectedControl.set('selectedQuestion', null);
        },

        doEditQuestions: function (router, event) {
          router.transitionTo('navSurveys.navSurveysEdit.editQuestions');
        },

        index: Ember.Route.extend({
          route: '/',
          redirectsTo: 'editQuestions'
        }),

        manageNotifications: Ember.Route.extend({
          route: '/notifications',
          connectOutlets: function (router, event) {
            router.get('navSurveysEditController').connectOutlet({
              name: 'manageNotifications'
            });
            FLOW.notificationControl.populate();
          }
        }),

        manageTranslations: Ember.Route.extend({
          route: '/translations',
          connectOutlets: function (router, event) {
            router.get('navSurveysEditController').connectOutlet({
              name: 'manageTranslations'
            });
            FLOW.translationControl.populate();
          }
        }),

        editQuestions: Ember.Route.extend({
          route: '/questions',
          connectOutlets: function (router, event) {
            router.get('navSurveysEditController').connectOutlet({
              name: 'editQuestions'
            });

          }
        })
      })
    }),

    //********************** DEVICES ROUTER *******************
    navDevices: Ember.Route.extend({
      route: '/devices',
      connectOutlets: function (router, event) {
        router.get('applicationController').connectOutlet('navDevices');
        router.set('navigationController.selected', 'navDevices');
      },

      doCurrentDevices: function (router, event) {
        router.transitionTo('navDevices.currentDevices');
      },

      doAssignSurveysOverview: function (router, event) {
        router.transitionTo('navDevices.assignSurveysOverview');
      },

      doEditSurveysAssignment: function (router, event) {
        router.transitionTo('navDevices.editSurveysAssignment');
      },

      doSurveyBootstrap: function (router, event) {
        router.transitionTo('navDevices.surveyBootstrap');
      },

      index: Ember.Route.extend({
        route: '/',
        redirectsTo: 'currentDevices'
      }),

      currentDevices: Ember.Route.extend({
        route: '/current-devices',
        connectOutlets: function (router, context) {
          router.get('navDevicesController').connectOutlet('currentDevices');
          router.resetState();
          FLOW.deviceGroupControl.populate();
          FLOW.deviceControl.populate();
          FLOW.surveyAssignmentControl.populate();
          router.set('devicesSubnavController.selected', 'currentDevices');
        }
      }),

      assignSurveysOverview: Ember.Route.extend({
        route: '/assign-surveys',
        connectOutlets: function (router, context) {
          router.get('navDevicesController').connectOutlet('assignSurveysOverview');
          router.set('devicesSubnavController.selected', 'assignSurveys');
        }
      }),

      editSurveysAssignment: Ember.Route.extend({
        route: '/assign-surveys',
        connectOutlets: function (router, context) {
          router.get('navDevicesController').connectOutlet('editSurveyAssignment');
          router.set('devicesSubnavController.selected', 'assignSurveys');
        }
      }),

      surveyBootstrap: Ember.Route.extend({
        route: '/manual-transfer',
        connectOutlets: function (router, context) {
          router.get('navDevicesController').connectOutlet('surveyBootstrap');
          router.set('devicesSubnavController.selected', 'surveyBootstrap');
        }
      })
    }),

    // ******************* DATA ROUTER ***********************
    navData: Ember.Route.extend({
      route: '/data',
      connectOutlets: function (router, event) {
        router.get('applicationController').connectOutlet('navData');
        router.set('navigationController.selected', 'navData');
      },

      doInspectData: function (router, event) {
        router.transitionTo('navData.inspectData');
      },
      doManageAttributes: function (router, event) {
        router.transitionTo('navData.manageAttributes');
      },
      doBulkUpload: function (router, event) {
        router.transitionTo('navData.bulkUpload');
      },
      doDataCleaning: function (router, event) {
        router.transitionTo('navData.dataCleaning');
      },
      doCascadeResources: function (router, event) {
          router.transitionTo('navData.cascadeResources');
        },
      doMonitoringData: function (router, event) {
        router.transitionTo('navData.monitoringData');
      },

      doDataApproval: function (router, event) {
          router.transitionTo('navData.dataApproval.listApprovalGroups');
      },

      index: Ember.Route.extend({
        route: '/',
        redirectsTo: 'inspectData'
      }),

      inspectData: Ember.Route.extend({
        route: '/inspectdata',
        connectOutlets: function (router, context) {
          router.get('navDataController').connectOutlet('inspectData');
          router.set('datasubnavController.selected', 'inspectData');
          router.resetState();
        }
      }),

      manageAttributes: Ember.Route.extend({
        route: '/manageattributes',
        connectOutlets: function (router, context) {
          router.get('navDataController').connectOutlet('manageAttributes');
          router.set('datasubnavController.selected', 'manageAttributes');
          FLOW.attributeControl.populate();
        }
      }),

      bulkUpload: Ember.Route.extend({
        route: '/bulkupload',
        connectOutlets: function (router, context) {
          router.get('navDataController').connectOutlet('bulkUpload');
          router.set('datasubnavController.selected', 'bulkUpload');
        }
      }),

      dataCleaning: Ember.Route.extend({
        route: '/datacleaning',
        connectOutlets: function (router, context) {
          router.get('navDataController').connectOutlet('dataCleaning');
          router.set('datasubnavController.selected', 'dataCleaning');
          router.resetState();
        }
      }),

      cascadeResources: Ember.Route.extend({
          route: '/cascaderesources',
          connectOutlets: function (router, context) {
            router.get('navDataController').connectOutlet('cascadeResources');
            router.set('datasubnavController.selected', 'cascadeResources');
            FLOW.cascadeResourceControl.populate();
          }
        }),

      monitoringData: Ember.Route.extend({
        route: '/monitoringdata',
        connectOutlets: function (router, context) {
          router.get('navDataController').connectOutlet('monitoringData');
          router.set('datasubnavController.selected', 'monitoringData');
          router.resetState();
        }
      }),

      dataApproval: Ember.Route.extend({
          route: '/dataapproval',

          connectOutlets: function (router, context) {
              router.get('navDataController').connectOutlet('dataApproval');
              router.set('datasubnavController.selected', 'approvalGroup');
          },

          doEditApprovalSteps: function (router, event) {
              var approvalGroup = event.context;
              var approvalStepsController = router.get('approvalStepsController');
              if (approvalStepsController) {
                  approvalStepsController.loadApprovalSteps(approvalGroup);
              }
              router.transitionTo('navData.dataApproval.editApprovalSteps');
          },

          // default route for dataApproval tab
          listApprovalGroups: Ember.Route.extend({
              route: '/list',

              connectOutlets: function (router, context) {
                  router.get('dataApprovalController').connectOutlet('approvalMain', 'approvalGroup', FLOW.ApprovalGroup.find());
              },
          }),

          editApprovalSteps: Ember.Route.extend({
              route: '/approvalsteps',

              connectOutlets: function (router, context) {
                  router.get('dataApprovalController').connectOutlet('approvalMain', 'approvalSteps');
                  router.set('datasubnavController.selected', 'approvalGroup');
              },
          }),

          doSaveDataApproval: function (router, event) {
              router.transitionTo('navData.dataApproval.listApprovalGroups');
          },
      }),
    }),

    // ************************** REPORTS ROUTER **********************************
    navReports: Ember.Route.extend({
      route: '/reports',
      connectOutlets: function (router, context) {
        router.get('applicationController').connectOutlet('navReports');
        router.resetState();
        router.set('navigationController.selected', 'navReports');
      },

      doExportReports: function (router, event) {
        router.transitionTo('navReports.exportReports');
      },

      doChartReports: function (router, event) {
        router.transitionTo('navReports.chartReports');
      },

      doStatistics: function(router, event) {
        router.transitionTo('navReports.statistics');
      },

      index: Ember.Route.extend({
        route: '/',
        redirectsTo: 'chartReports'
      }),

      exportReports: Ember.Route.extend({
        route: '/exportreports',
        connectOutlets: function (router, context) {
          router.get('navReportsController').connectOutlet('exportReports');
          router.set('reportsSubnavController.selected', 'exportReports');
          router.resetState();
        }
      }),

      chartReports: Ember.Route.extend({
        route: '/chartreports',
        connectOutlets: function (router, context) {
          router.resetState();
          router.get('navReportsController').connectOutlet('chartReports');
          router.set('reportsSubnavController.selected', 'chartReports');
        }
      }),
      statistics: Ember.Route.extend({
        route: '/statistics',
        connectOutlets: function(router, context) {
          router.resetState();
          router.get('navReportsController').connectOutlet('statistics');
          router.set('reportsSubnavController.selected', 'statistics');
          FLOW.surveyGroupControl.populate();
        }
      })
    }),

    // ************************** MAPS ROUTER **********************************
    navMaps: Ember.Route.extend({
      route: '/maps',
      connectOutlets: function (router, context) {
        router.get('applicationController').connectOutlet('navMaps');
        router.set('navigationController.selected', 'navMaps');
      }
    }),

    // ************************** USERS ROUTER **********************************
    navUsers: Ember.Route.extend({
      route: '/users',
      connectOutlets: function (router, context) {
        router.get('applicationController').connectOutlet('navUsers');
        router.set('navigationController.selected', 'navUsers');
        FLOW.userControl.populate();
      }
    }),

    // ************************** MESSAGES ROUTER **********************************
    navMessages: Ember.Route.extend({
      route: '/users',
      connectOutlets: function (router, context) {
        router.get('applicationController').connectOutlet('navMessages');
        router.set('navigationController.selected', 'navMessages');
        FLOW.messageControl.populate();
        router.resetState();
      }
    }),

    // ************************** ADMIN ROUTER **********************************
    // not used at the moment
    navAdmin: Ember.Route.extend({
      route: '/admin',
      connectOutlets: function (router, context) {
        router.get('applicationController').connectOutlet('navAdmin');
        router.set('navigationController.selected', 'navAdmin');
      }
    })
  })
});
<commit_msg>[#1659] Set correct approval group list template in router<commit_after>// ***********************************************//
//                 Router
// ***********************************************//
require('akvo-flow/core-common');

FLOW.Router = Ember.Router.extend({
  enableLogging: true,
  loggedIn: false,
  location: 'none',
  //'hash'or 'none' for URLs

  resetState: function () {
    // We could have unsaved changes
    FLOW.store.commit();

    FLOW.selectedControl.set('selectedQuestionGroup', null);
    FLOW.selectedControl.set('selectedSurveyGroup', null);
    FLOW.selectedControl.set('selectedSurvey', null);
    FLOW.selectedControl.set('selectedQuestion', null);
    FLOW.selectedControl.set('selectedCascadeResource', null);
    FLOW.selectedControl.set('cascadeImportNumLevels', null);
    FLOW.selectedControl.set('cascadeImportIncludeCodes', null);
    FLOW.surveyControl.set('content', null);
    FLOW.questionControl.set('OPTIONcontent', null);
    FLOW.metaControl.set('since', null);
  },

  root: Ember.Route.extend({
    doNavSurveys: function (router, context) {
      router.transitionTo('navSurveys.index');
    },
    doNavDevices: function (router, context) {
      router.transitionTo('navDevices.index');
    },
    doNavData: function (router, context) {
      router.transitionTo('navData.index');
    },
    doNavReports: function (router, context) {
      router.transitionTo('navReports.index');
    },
    doNavMaps: function (router, context) {
      router.transitionTo('navMaps');
    },
    doNavUsers: function (router, context) {
      router.transitionTo('navUsers');
    },
    doNavMessages: function (router, context) {
      router.transitionTo('navMessages');
    },
    // not used at the moment
    doNavAdmin: function (router, context) {
      router.transitionTo('navAdmin');
    },

    // non-working code for transitioning to navHome at first entry of the app
    //    setup: function(router){
    //      router.send("goHome");
    //    },
    //    goHome:function(router){
    //      router.transitionTo('navHome');
    //    },
    index: Ember.Route.extend({
      route: '/',
      redirectsTo: 'navSurveys.index'
    }),

    // ******************* SURVEYS ROUTER ********************
    navSurveys: Ember.Route.extend({
      route: '/surveys',
      connectOutlets: function (router, event) {
        router.get('applicationController').connectOutlet('navSurveys');
        router.set('navigationController.selected', 'navSurveys');
      },

      doNewSurvey: function (router, event) {
        router.transitionTo('navSurveys.navSurveysNew');
      },

      doEditSurvey: function (router, event) {
        FLOW.selectedControl.set('selectedSurvey', event.context);
        router.transitionTo('navSurveys.navSurveysEdit.index');
      },

      doSurveysMain: function (router, event) {
        FLOW.selectedControl.set('selectedQuestion', null);
        router.transitionTo('navSurveys.navSurveysMain');
      },

      index: Ember.Route.extend({
        route: '/',
        redirectsTo: 'navSurveysMain'
      }),

      navSurveysMain: Ember.Route.extend({
        route: '/main',
        connectOutlets: function (router, event) {
          router.get('navSurveysController').connectOutlet({
            name: 'navSurveysMain'
          });
          FLOW.projectControl.populate();
          FLOW.projectControl.set('currentProject', null);
          FLOW.projectControl.set('newlyCreated', null);
          FLOW.selectedControl.set('selectedQuestionGroup', null);
          FLOW.selectedControl.set('selectedSurvey', null);
          FLOW.selectedControl.set('selectedQuestion', null);
          FLOW.questionControl.set('OPTIONcontent', null);
          FLOW.cascadeResourceControl.populate();
          FLOW.attributeControl.populate();
        }
      }),

      navSurveysNew: Ember.Route.extend({
        route: '/new',
        connectOutlets: function (router, event) {
          var newSurvey;

          newSurvey = FLOW.store.createRecord(FLOW.Survey, {
            "name": "",
            "defaultLanguageCode": "en",
            "requireApproval": false,
            "status": "NOT_PUBLISHED",
            "surveyGroupId": FLOW.selectedControl.selectedSurveyGroup.get('keyId'),
            "version":"1.0"
          });

          FLOW.selectedControl.set('selectedSurvey', newSurvey);
          router.transitionTo('navSurveys.navSurveysEdit.index');
        }
      }),

      navSurveysEdit: Ember.Route.extend({
        route: '/edit',
        connectOutlets: function (router, event) {
          router.get('navSurveysController').connectOutlet({
            name: 'navSurveysEdit'
          });
          // all questions should be closed when we enter
          FLOW.selectedControl.set('selectedQuestion', null);
        },

        doEditQuestions: function (router, event) {
          router.transitionTo('navSurveys.navSurveysEdit.editQuestions');
        },

        index: Ember.Route.extend({
          route: '/',
          redirectsTo: 'editQuestions'
        }),

        manageNotifications: Ember.Route.extend({
          route: '/notifications',
          connectOutlets: function (router, event) {
            router.get('navSurveysEditController').connectOutlet({
              name: 'manageNotifications'
            });
            FLOW.notificationControl.populate();
          }
        }),

        manageTranslations: Ember.Route.extend({
          route: '/translations',
          connectOutlets: function (router, event) {
            router.get('navSurveysEditController').connectOutlet({
              name: 'manageTranslations'
            });
            FLOW.translationControl.populate();
          }
        }),

        editQuestions: Ember.Route.extend({
          route: '/questions',
          connectOutlets: function (router, event) {
            router.get('navSurveysEditController').connectOutlet({
              name: 'editQuestions'
            });

          }
        })
      })
    }),

    //********************** DEVICES ROUTER *******************
    navDevices: Ember.Route.extend({
      route: '/devices',
      connectOutlets: function (router, event) {
        router.get('applicationController').connectOutlet('navDevices');
        router.set('navigationController.selected', 'navDevices');
      },

      doCurrentDevices: function (router, event) {
        router.transitionTo('navDevices.currentDevices');
      },

      doAssignSurveysOverview: function (router, event) {
        router.transitionTo('navDevices.assignSurveysOverview');
      },

      doEditSurveysAssignment: function (router, event) {
        router.transitionTo('navDevices.editSurveysAssignment');
      },

      doSurveyBootstrap: function (router, event) {
        router.transitionTo('navDevices.surveyBootstrap');
      },

      index: Ember.Route.extend({
        route: '/',
        redirectsTo: 'currentDevices'
      }),

      currentDevices: Ember.Route.extend({
        route: '/current-devices',
        connectOutlets: function (router, context) {
          router.get('navDevicesController').connectOutlet('currentDevices');
          router.resetState();
          FLOW.deviceGroupControl.populate();
          FLOW.deviceControl.populate();
          FLOW.surveyAssignmentControl.populate();
          router.set('devicesSubnavController.selected', 'currentDevices');
        }
      }),

      assignSurveysOverview: Ember.Route.extend({
        route: '/assign-surveys',
        connectOutlets: function (router, context) {
          router.get('navDevicesController').connectOutlet('assignSurveysOverview');
          router.set('devicesSubnavController.selected', 'assignSurveys');
        }
      }),

      editSurveysAssignment: Ember.Route.extend({
        route: '/assign-surveys',
        connectOutlets: function (router, context) {
          router.get('navDevicesController').connectOutlet('editSurveyAssignment');
          router.set('devicesSubnavController.selected', 'assignSurveys');
        }
      }),

      surveyBootstrap: Ember.Route.extend({
        route: '/manual-transfer',
        connectOutlets: function (router, context) {
          router.get('navDevicesController').connectOutlet('surveyBootstrap');
          router.set('devicesSubnavController.selected', 'surveyBootstrap');
        }
      })
    }),

    // ******************* DATA ROUTER ***********************
    navData: Ember.Route.extend({
      route: '/data',
      connectOutlets: function (router, event) {
        router.get('applicationController').connectOutlet('navData');
        router.set('navigationController.selected', 'navData');
      },

      doInspectData: function (router, event) {
        router.transitionTo('navData.inspectData');
      },
      doManageAttributes: function (router, event) {
        router.transitionTo('navData.manageAttributes');
      },
      doBulkUpload: function (router, event) {
        router.transitionTo('navData.bulkUpload');
      },
      doDataCleaning: function (router, event) {
        router.transitionTo('navData.dataCleaning');
      },
      doCascadeResources: function (router, event) {
          router.transitionTo('navData.cascadeResources');
        },
      doMonitoringData: function (router, event) {
        router.transitionTo('navData.monitoringData');
      },

      doDataApproval: function (router, event) {
          router.transitionTo('navData.dataApproval.listApprovalGroups');
      },

      index: Ember.Route.extend({
        route: '/',
        redirectsTo: 'inspectData'
      }),

      inspectData: Ember.Route.extend({
        route: '/inspectdata',
        connectOutlets: function (router, context) {
          router.get('navDataController').connectOutlet('inspectData');
          router.set('datasubnavController.selected', 'inspectData');
          router.resetState();
        }
      }),

      manageAttributes: Ember.Route.extend({
        route: '/manageattributes',
        connectOutlets: function (router, context) {
          router.get('navDataController').connectOutlet('manageAttributes');
          router.set('datasubnavController.selected', 'manageAttributes');
          FLOW.attributeControl.populate();
        }
      }),

      bulkUpload: Ember.Route.extend({
        route: '/bulkupload',
        connectOutlets: function (router, context) {
          router.get('navDataController').connectOutlet('bulkUpload');
          router.set('datasubnavController.selected', 'bulkUpload');
        }
      }),

      dataCleaning: Ember.Route.extend({
        route: '/datacleaning',
        connectOutlets: function (router, context) {
          router.get('navDataController').connectOutlet('dataCleaning');
          router.set('datasubnavController.selected', 'dataCleaning');
          router.resetState();
        }
      }),

      cascadeResources: Ember.Route.extend({
          route: '/cascaderesources',
          connectOutlets: function (router, context) {
            router.get('navDataController').connectOutlet('cascadeResources');
            router.set('datasubnavController.selected', 'cascadeResources');
            FLOW.cascadeResourceControl.populate();
          }
        }),

      monitoringData: Ember.Route.extend({
        route: '/monitoringdata',
        connectOutlets: function (router, context) {
          router.get('navDataController').connectOutlet('monitoringData');
          router.set('datasubnavController.selected', 'monitoringData');
          router.resetState();
        }
      }),

      dataApproval: Ember.Route.extend({
          route: '/dataapproval',

          connectOutlets: function (router, context) {
              router.get('navDataController').connectOutlet('dataApproval');
              router.set('datasubnavController.selected', 'approvalGroup');
          },

          doEditApprovalSteps: function (router, event) {
              var approvalGroup = event.context;
              var approvalStepsController = router.get('approvalStepsController');
              if (approvalStepsController) {
                  approvalStepsController.loadApprovalSteps(approvalGroup);
              }
              router.transitionTo('navData.dataApproval.editApprovalSteps');
          },

          // default route for dataApproval tab
          listApprovalGroups: Ember.Route.extend({
              route: '/list',

              connectOutlets: function (router, context) {
                  router.get('dataApprovalController').connectOutlet('approvalMain', 'approvalGroupList', FLOW.ApprovalGroup.find());
              },
          }),

          editApprovalSteps: Ember.Route.extend({
              route: '/approvalsteps',

              connectOutlets: function (router, context) {
                  router.get('dataApprovalController').connectOutlet('approvalMain', 'approvalSteps');
                  router.set('datasubnavController.selected', 'approvalGroup');
              },
          }),

          doSaveDataApproval: function (router, event) {
              router.transitionTo('navData.dataApproval.listApprovalGroups');
          },
      }),
    }),

    // ************************** REPORTS ROUTER **********************************
    navReports: Ember.Route.extend({
      route: '/reports',
      connectOutlets: function (router, context) {
        router.get('applicationController').connectOutlet('navReports');
        router.resetState();
        router.set('navigationController.selected', 'navReports');
      },

      doExportReports: function (router, event) {
        router.transitionTo('navReports.exportReports');
      },

      doChartReports: function (router, event) {
        router.transitionTo('navReports.chartReports');
      },

      doStatistics: function(router, event) {
        router.transitionTo('navReports.statistics');
      },

      index: Ember.Route.extend({
        route: '/',
        redirectsTo: 'chartReports'
      }),

      exportReports: Ember.Route.extend({
        route: '/exportreports',
        connectOutlets: function (router, context) {
          router.get('navReportsController').connectOutlet('exportReports');
          router.set('reportsSubnavController.selected', 'exportReports');
          router.resetState();
        }
      }),

      chartReports: Ember.Route.extend({
        route: '/chartreports',
        connectOutlets: function (router, context) {
          router.resetState();
          router.get('navReportsController').connectOutlet('chartReports');
          router.set('reportsSubnavController.selected', 'chartReports');
        }
      }),
      statistics: Ember.Route.extend({
        route: '/statistics',
        connectOutlets: function(router, context) {
          router.resetState();
          router.get('navReportsController').connectOutlet('statistics');
          router.set('reportsSubnavController.selected', 'statistics');
          FLOW.surveyGroupControl.populate();
        }
      })
    }),

    // ************************** MAPS ROUTER **********************************
    navMaps: Ember.Route.extend({
      route: '/maps',
      connectOutlets: function (router, context) {
        router.get('applicationController').connectOutlet('navMaps');
        router.set('navigationController.selected', 'navMaps');
      }
    }),

    // ************************** USERS ROUTER **********************************
    navUsers: Ember.Route.extend({
      route: '/users',
      connectOutlets: function (router, context) {
        router.get('applicationController').connectOutlet('navUsers');
        router.set('navigationController.selected', 'navUsers');
        FLOW.userControl.populate();
      }
    }),

    // ************************** MESSAGES ROUTER **********************************
    navMessages: Ember.Route.extend({
      route: '/users',
      connectOutlets: function (router, context) {
        router.get('applicationController').connectOutlet('navMessages');
        router.set('navigationController.selected', 'navMessages');
        FLOW.messageControl.populate();
        router.resetState();
      }
    }),

    // ************************** ADMIN ROUTER **********************************
    // not used at the moment
    navAdmin: Ember.Route.extend({
      route: '/admin',
      connectOutlets: function (router, context) {
        router.get('applicationController').connectOutlet('navAdmin');
        router.set('navigationController.selected', 'navAdmin');
      }
    })
  })
});
<|endoftext|>