2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
var mongoose = require('mongoose'),
|
2015-09-03 18:21:56 +00:00
|
|
|
Schema = mongoose.Schema,
|
|
|
|
nools = require('nools');
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * LogicJump Schema
|
|
|
|
// */
|
|
|
|
// var LogicJump = new Schema({
|
|
|
|
// [
|
|
|
|
|
|
|
|
// ]
|
|
|
|
// type: Schema.Types.ObjectId,
|
|
|
|
// ref: 'FormSubmission'
|
|
|
|
// });
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Question Schema
|
|
|
|
*/
|
|
|
|
var FormFieldSchema = new Schema({
|
2015-08-18 21:44:36 +00:00
|
|
|
created: {
|
|
|
|
type: Date,
|
|
|
|
default: Date.now
|
|
|
|
},
|
|
|
|
lastModified: {
|
|
|
|
type: Date,
|
|
|
|
default: Date.now
|
|
|
|
},
|
2015-07-21 23:25:45 +00:00
|
|
|
title: {
|
2015-06-29 22:51:29 +00:00
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
trim: true,
|
2015-07-28 22:29:07 +00:00
|
|
|
required: 'Field title cannot be blank'
|
2015-06-29 22:51:29 +00:00
|
|
|
},
|
|
|
|
description: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
2015-09-03 18:21:56 +00:00
|
|
|
|
|
|
|
logicJumps: [{
|
|
|
|
type: String,
|
|
|
|
}],
|
|
|
|
|
2015-08-25 21:33:52 +00:00
|
|
|
//DAVID: TODO: SEMI-URGENT: Need to come up with a schema for field options
|
2015-07-07 01:21:43 +00:00
|
|
|
fieldOptions: [{
|
2015-07-21 23:25:45 +00:00
|
|
|
type: Schema.Types.Mixed
|
2015-07-07 01:21:43 +00:00
|
|
|
}],
|
2015-06-29 22:51:29 +00:00
|
|
|
required: {
|
|
|
|
type: Boolean,
|
2015-06-30 11:05:44 +00:00
|
|
|
default: true,
|
2015-06-29 22:51:29 +00:00
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2015-07-27 18:11:43 +00:00
|
|
|
|
|
|
|
deletePreserved: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2015-06-29 22:51:29 +00:00
|
|
|
fieldType: {
|
|
|
|
type: String,
|
|
|
|
required: 'Field type cannot be blank',
|
|
|
|
validate: [validateFormFieldType, 'Invalid field type']
|
|
|
|
},
|
2015-07-21 23:25:45 +00:00
|
|
|
fieldValue: Schema.Types.Mixed
|
2015-06-29 22:51:29 +00:00
|
|
|
});
|
|
|
|
|
2015-08-18 21:44:36 +00:00
|
|
|
FormFieldSchema.static('validTypes', function(){
|
|
|
|
return [
|
|
|
|
'textfield',
|
|
|
|
'date',
|
|
|
|
'email',
|
|
|
|
'legal',
|
|
|
|
'url',
|
|
|
|
'textarea',
|
|
|
|
'statement',
|
|
|
|
'welcome',
|
|
|
|
'thankyou',
|
|
|
|
'file',
|
|
|
|
'dropdown',
|
|
|
|
'scale',
|
|
|
|
'rating',
|
|
|
|
'radio',
|
|
|
|
'checkbox',
|
|
|
|
'hidden',
|
|
|
|
'yes_no',
|
|
|
|
'natural',
|
|
|
|
'number'
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
|
|
|
// fieldType Validation
|
|
|
|
function validateFormFieldType(value) {
|
|
|
|
if (!value) { return false; }
|
|
|
|
|
|
|
|
var validTypes = [
|
|
|
|
'textfield',
|
|
|
|
'date',
|
|
|
|
'email',
|
|
|
|
'legal',
|
|
|
|
'url',
|
|
|
|
'textarea',
|
|
|
|
'statement',
|
|
|
|
'welcome',
|
|
|
|
'thankyou',
|
|
|
|
'file',
|
|
|
|
'dropdown',
|
|
|
|
'scale',
|
|
|
|
'rating',
|
|
|
|
'radio',
|
|
|
|
'checkbox',
|
|
|
|
'hidden',
|
|
|
|
'yes_no',
|
|
|
|
'natural',
|
|
|
|
'number'
|
|
|
|
];
|
|
|
|
|
|
|
|
if (validTypes.indexOf(value) > -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-03 18:21:56 +00:00
|
|
|
module.exports = FormFieldSchema;
|