Merge branch 'dropdown_fix' into stage

This commit is contained in:
David Baldwynn 2016-06-04 20:14:03 -07:00
commit a11a175cf2
5 changed files with 47 additions and 9 deletions

View file

@ -395,7 +395,7 @@ FormSchema.pre('save', function (next) {
//Find FormSubmissions that contain field with _id equal to 'deleted_id' //Find FormSubmissions that contain field with _id equal to 'deleted_id'
FormSubmission. FormSubmission.
find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {_id: deleted_id} } }). find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {submissionId: deleted_id} } }).
exec(function(err, submissions){ exec(function(err, submissions){
if(err) { if(err) {
console.error(err); console.error(err);

View file

@ -60,6 +60,13 @@ function BaseFieldSchema(){
Schema.apply(this, arguments); Schema.apply(this, arguments);
this.add({ this.add({
isSubmission: {
type: Boolean,
default: false
},
submissionId: {
type: Schema.Types.ObjectId
},
title: { title: {
type: String, type: String,
trim: true, trim: true,
@ -138,6 +145,7 @@ function BaseFieldSchema(){
if(this.fieldType === 'rating' && this.ratingOptions.validShapes.length === 0){ if(this.fieldType === 'rating' && this.ratingOptions.validShapes.length === 0){
this.ratingOptions.validShapes = mongoose.model('RatingOptions').schema.path('shape').enumValues; this.ratingOptions.validShapes = mongoose.model('RatingOptions').schema.path('shape').enumValues;
} }
next(); next();
}); });
} }
@ -180,11 +188,26 @@ FormFieldSchema.pre('validate', function(next) {
} }
} }
if(error) return next();
});
//Submission fieldValue correction
FormFieldSchema.pre('save', function(next) {
console.log('pre save');
console.log(this.isSubmission);
console.log(this._id);
console.log(this.submissionId);
console.log(this.fieldType);
if(this.isSubmission && this.fieldType === 'dropdown'){
this.fieldValue = this.fieldValue.option_value;
}
return next(); return next();
}); });
var Field = mongoose.model('Field', FormFieldSchema); var Field = mongoose.model('Field', FormFieldSchema);
var RatingOptions = mongoose.model('RatingOptions', RatingFieldSchema); var RatingOptions = mongoose.model('RatingOptions', RatingFieldSchema);

View file

@ -17,6 +17,8 @@ var mongoose = require('mongoose'),
FieldSchema = require('./form_field.server.model.js'), FieldSchema = require('./form_field.server.model.js'),
OscarSecurity = require('../../scripts/oscarhost/OscarSecurity'); OscarSecurity = require('../../scripts/oscarhost/OscarSecurity');
var FieldSchema = require('./form_field.server.model.js');
var newDemoTemplate = { var newDemoTemplate = {
address: '880-9650 Velit. St.', address: '880-9650 Velit. St.',
city: '', city: '',
@ -41,6 +43,17 @@ var newDemoTemplate = {
yearOfBirth: '2015' yearOfBirth: '2015'
}; };
// Setter function for form_fields
function formFieldsSetter(form_fields){
for(var i=0; i<form_fields.length; i++){
form_fields[i].isSubmission = true;
form_fields[i].submissionId = form_fields[i]._id;
form_fields[i]._id = new mongoose.mongo.ObjectID();
}
return form_fields;
}
/** /**
* Form Submission Schema * Form Submission Schema
*/ */
@ -55,9 +68,7 @@ var FormSubmissionSchema = new Schema({
required: true required: true
}, },
form_fields: { form_fields: [FieldSchema],
type: [Schema.Types.Mixed]
},
form: { form: {
type: Schema.Types.ObjectId, type: Schema.Types.ObjectId,
@ -99,7 +110,7 @@ var FormSubmissionSchema = new Schema({
}, },
timeElapsed: { timeElapsed: {
type: Number, type: Number
}, },
percentageComplete: { percentageComplete: {
type: Number type: Number
@ -119,6 +130,8 @@ var FormSubmissionSchema = new Schema({
}); });
FormSubmissionSchema.path('form_fields').set(formFieldsSetter);
FormSubmissionSchema.plugin(mUtilities.timestamp, { FormSubmissionSchema.plugin(mUtilities.timestamp, {
createdPath: 'created', createdPath: 'created',
modifiedPath: 'lastModified', modifiedPath: 'lastModified',
@ -214,7 +227,7 @@ FormSubmissionSchema.pre('save', function (next) {
}); });
}); });
} }
}, }
], function(err, result) { ], function(err, result) {
if(err) return next(err); if(err) return next(err);

View file

@ -38,7 +38,7 @@
}, },
"resolutions": { "resolutions": {
"angular-bootstrap": "^0.14.0", "angular-bootstrap": "^0.14.0",
"angular": "1.4.x", "angular": "~1.4.7",
"angular-ui-select": "compiled" "angular-ui-select": "compiled"
}, },
"overrides": { "overrides": {

View file

@ -170,10 +170,12 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter'
document.querySelectorAll('.ng-invalid.focusOn')[0].focus(); document.querySelectorAll('.ng-invalid.focusOn')[0].focus();
}; };
$rootScope.goToInvalid = $scope.submitForm = function() { $rootScope.submitForm = $scope.submitForm = function() {
var _timeElapsed = TimeCounter.stopClock(); var _timeElapsed = TimeCounter.stopClock();
$scope.loading = true; $scope.loading = true;
var form = _.cloneDeep($scope.myform); var form = _.cloneDeep($scope.myform);
form.timeElapsed = _timeElapsed; form.timeElapsed = _timeElapsed;
form.percentageComplete = $filter('formValidity')($scope.myform) / $scope.myform.visible_form_fields.length * 100; form.percentageComplete = $filter('formValidity')($scope.myform) / $scope.myform.visible_form_fields.length * 100;