2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
var mongoose = require('mongoose'),
|
|
|
|
Schema = mongoose.Schema;
|
|
|
|
|
|
|
|
// questionType Validation
|
|
|
|
function validateFormFieldType(value) {
|
|
|
|
if (!value || typeof myVar !== 'string' ) { return false; }
|
|
|
|
|
2015-06-30 16:15:16 +00:00
|
|
|
var validTypes = [
|
|
|
|
'textfield',
|
2015-07-06 04:29:05 +00:00
|
|
|
'date',
|
2015-06-30 16:15:16 +00:00
|
|
|
'email',
|
|
|
|
'legal',
|
|
|
|
'url',
|
|
|
|
'number',
|
2015-07-06 04:29:05 +00:00
|
|
|
|
|
|
|
'textarea',
|
|
|
|
'statement',
|
|
|
|
'welcome',
|
|
|
|
'thankyou',
|
|
|
|
|
|
|
|
'file',
|
|
|
|
|
|
|
|
'dropdown',
|
|
|
|
'scale',
|
|
|
|
'rating',
|
2015-06-30 16:15:16 +00:00
|
|
|
'radio',
|
|
|
|
'checkbox',
|
2015-07-06 04:29:05 +00:00
|
|
|
|
2015-06-30 16:15:16 +00:00
|
|
|
'hidden',
|
|
|
|
];
|
2015-06-30 14:21:53 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
if (validTypes.indexOf(value) > -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Question Schema
|
|
|
|
*/
|
|
|
|
var FormFieldSchema = new Schema({
|
|
|
|
created: {
|
|
|
|
type: Date,
|
|
|
|
default: Date.now
|
|
|
|
},
|
2015-07-04 04:57:06 +00:00
|
|
|
name: {
|
2015-06-29 22:51:29 +00:00
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
trim: true,
|
|
|
|
required: 'Title cannot be blank'
|
|
|
|
},
|
|
|
|
description: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
2015-07-06 04:29:05 +00:00
|
|
|
options: [{
|
|
|
|
type: String
|
|
|
|
}]
|
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,
|
|
|
|
},
|
|
|
|
fieldType: {
|
|
|
|
type: String,
|
|
|
|
required: 'Field type cannot be blank',
|
|
|
|
validate: [validateFormFieldType, 'Invalid field type']
|
|
|
|
},
|
2015-07-04 04:57:06 +00:00
|
|
|
value: Schema.Types.Mixed
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = FormFieldSchema;
|
|
|
|
|
|
|
|
// mongoose.model('Field', FormFieldSchema);
|