2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
var mongoose = require('mongoose'),
|
2015-09-18 16:32:17 +00:00
|
|
|
relationship = require('mongoose-relationship'),
|
2015-10-06 20:14:38 +00:00
|
|
|
mUtilities = require('mongoose-utilities'),
|
2015-09-18 16:32:17 +00:00
|
|
|
_ = require('lodash'),
|
2015-09-10 22:06:28 +00:00
|
|
|
Schema = mongoose.Schema;
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-10-06 20:14:38 +00:00
|
|
|
var FieldOptionSchema = new Schema({
|
|
|
|
option_id: {
|
|
|
|
type: Number,
|
|
|
|
},
|
|
|
|
|
|
|
|
option_title: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
|
|
|
|
option_value: {
|
|
|
|
type: String,
|
|
|
|
trim: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-10-06 20:24:02 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
/**
|
2015-10-06 20:14:38 +00:00
|
|
|
* FormField Schema
|
2015-06-29 22:51:29 +00:00
|
|
|
*/
|
|
|
|
var FormFieldSchema = new Schema({
|
2015-09-18 16:32:17 +00:00
|
|
|
// formSubmission: {
|
|
|
|
// type: Schema.ObjectId,
|
|
|
|
// ref: 'FormSubmission',
|
|
|
|
// childPath: 'form_fields'
|
|
|
|
// },
|
|
|
|
|
2015-07-21 23:25:45 +00:00
|
|
|
title: {
|
2015-06-29 22:51:29 +00:00
|
|
|
type: String,
|
|
|
|
trim: true,
|
2015-10-06 20:14:38 +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
|
|
|
|
2015-09-18 16:32:17 +00:00
|
|
|
logicJump: {
|
|
|
|
type: Schema.Types.ObjectId,
|
|
|
|
ref: 'LogicJump'
|
|
|
|
},
|
2015-09-03 18:21:56 +00:00
|
|
|
|
2015-10-06 20:14:38 +00:00
|
|
|
fieldOptions: [FieldOptionSchema],
|
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-10-30 18:40:02 +00:00
|
|
|
validFieldTypes: {
|
|
|
|
type: [String]
|
|
|
|
},
|
2015-06-29 22:51:29 +00:00
|
|
|
fieldType: {
|
|
|
|
type: String,
|
2015-10-06 20:14:38 +00:00
|
|
|
required: true,
|
2015-10-30 18:40:02 +00:00
|
|
|
enum: [
|
|
|
|
'textfield',
|
|
|
|
'date',
|
|
|
|
'email',
|
|
|
|
'link',
|
|
|
|
'legal',
|
|
|
|
'url',
|
|
|
|
'textarea',
|
|
|
|
'statement',
|
|
|
|
'welcome',
|
|
|
|
'thankyou',
|
|
|
|
'file',
|
|
|
|
'dropdown',
|
|
|
|
'scale',
|
|
|
|
'rating',
|
|
|
|
'radio',
|
|
|
|
'checkbox',
|
|
|
|
'hidden',
|
|
|
|
'yes_no',
|
|
|
|
'natural',
|
|
|
|
'number'
|
|
|
|
],
|
2015-06-29 22:51:29 +00:00
|
|
|
},
|
2015-07-21 23:25:45 +00:00
|
|
|
fieldValue: Schema.Types.Mixed
|
2015-06-29 22:51:29 +00:00
|
|
|
});
|
|
|
|
|
2015-09-18 16:32:17 +00:00
|
|
|
// FormFieldSchema.plugin(relationship, { relationshipPathName:'formSubmission' });
|
2015-10-06 20:14:38 +00:00
|
|
|
FormFieldSchema.plugin(mUtilities.timestamp, {
|
|
|
|
createdPath: 'created',
|
|
|
|
modifiedPath: 'lastModified',
|
|
|
|
useVirtual: false
|
|
|
|
});
|
2015-08-18 21:44:36 +00:00
|
|
|
|
2015-10-30 18:40:02 +00:00
|
|
|
// FormFieldSchema.pre('init', function (next){
|
|
|
|
// this.validFieldTypes = Field.schema.path('fieldType').enumValues;
|
|
|
|
// });
|
|
|
|
|
2015-08-18 21:44:36 +00:00
|
|
|
|
2015-09-18 16:32:17 +00:00
|
|
|
mongoose.model('Field', FormFieldSchema);
|
|
|
|
|
2015-10-06 20:14:38 +00:00
|
|
|
module.exports = FormFieldSchema;
|
2015-09-18 16:32:17 +00:00
|
|
|
|