1
0
ohmyform/app/models/form_field.server.model.js

116 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-06-29 15:51:29 -07:00
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
2015-09-18 09:32:17 -07:00
relationship = require('mongoose-relationship'),
2015-10-06 13:14:38 -07:00
mUtilities = require('mongoose-utilities'),
2015-09-18 09:32:17 -07:00
_ = require('lodash'),
2015-09-10 15:06:28 -07:00
Schema = mongoose.Schema;
2015-06-29 15:51:29 -07:00
2015-10-06 13:14:38 -07:00
var FieldOptionSchema = new Schema({
option_id: {
type: Number,
},
option_title: {
type: String,
},
option_value: {
type: String,
trim: true,
},
});
2015-06-29 15:51:29 -07:00
/**
2015-10-06 13:14:38 -07:00
* FormField Schema
2015-06-29 15:51:29 -07:00
*/
var FormFieldSchema = new Schema({
2015-09-18 09:32:17 -07:00
// formSubmission: {
// type: Schema.ObjectId,
// ref: 'FormSubmission',
// childPath: 'form_fields'
// },
title: {
2015-06-29 15:51:29 -07:00
type: String,
trim: true,
2015-10-06 13:14:38 -07:00
required: 'Field Title cannot be blank',
2015-06-29 15:51:29 -07:00
},
description: {
type: String,
default: '',
},
2015-09-03 11:21:56 -07:00
2015-09-18 09:32:17 -07:00
logicJump: {
type: Schema.Types.ObjectId,
ref: 'LogicJump'
},
2015-09-03 11:21:56 -07:00
2015-10-06 13:14:38 -07:00
fieldOptions: [FieldOptionSchema],
2015-06-29 15:51:29 -07:00
required: {
type: Boolean,
2015-06-30 04:05:44 -07:00
default: true,
2015-06-29 15:51:29 -07:00
},
disabled: {
type: Boolean,
default: false,
},
2015-07-27 11:11:43 -07:00
deletePreserved: {
type: Boolean,
default: false
},
2015-10-30 11:40:02 -07:00
validFieldTypes: {
type: [String]
},
2015-06-29 15:51:29 -07:00
fieldType: {
type: String,
2015-10-06 13:14:38 -07:00
required: true,
2015-10-30 11:40:02 -07: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 15:51:29 -07:00
},
fieldValue: Schema.Types.Mixed
2015-06-29 15:51:29 -07:00
});
2015-09-18 09:32:17 -07:00
// FormFieldSchema.plugin(relationship, { relationshipPathName:'formSubmission' });
2015-10-06 13:14:38 -07:00
FormFieldSchema.plugin(mUtilities.timestamp, {
createdPath: 'created',
modifiedPath: 'lastModified',
useVirtual: false
});
2015-08-18 14:44:36 -07:00
2015-10-30 13:14:48 -07:00
FormFieldSchema.pre('save', function (next){
this.validFieldTypes = mongoose.model('Field').schema.path('fieldType').enumValues;
next();
});
2015-10-30 11:40:02 -07:00
2015-08-18 14:44:36 -07:00
2015-09-18 09:32:17 -07:00
mongoose.model('Field', FormFieldSchema);
2015-10-06 13:14:38 -07:00
module.exports = FormFieldSchema;
2015-09-18 09:32:17 -07:00