tellform/app/models/form_field.server.model.js

108 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-06-29 22:51:29 +00:00
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
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-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({
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,
2016-04-29 02:48:02 +00:00
default: ''
2015-06-29 22:51:29 +00:00
},
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,
2016-04-29 02:48:02 +00:00
default: true
2015-06-29 22:51:29 +00:00
},
disabled: {
type: Boolean,
2016-04-29 02:48:02 +00:00
default: false
2015-06-29 22:51:29 +00:00
},
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'
2016-04-29 02:48:02 +00:00
]
2015-06-29 22:51:29 +00:00
},
fieldValue: Schema.Types.Mixed
2015-06-29 22:51:29 +00:00
});
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 20:14:48 +00:00
FormFieldSchema.pre('save', function (next){
this.validFieldTypes = mongoose.model('Field').schema.path('fieldType').enumValues;
next();
});
2015-10-30 18:40:02 +00:00
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