fixed display submissions bug

This commit is contained in:
David Baldwynn 2015-11-12 14:24:26 -08:00
parent 6ef2c500dc
commit a72306c846
9 changed files with 785 additions and 25 deletions

View file

@ -146,7 +146,6 @@ exports.listSubmissions = function(req, res) {
var _form = req.form; var _form = req.form;
var _user = req.user; var _user = req.user;
console.log('listSubmissions'); console.log('listSubmissions');
// console.log(_form);
FormSubmission.find({ form: _form._id }).exec(function(err, _submissions) { FormSubmission.find({ form: _form._id }).exec(function(err, _submissions) {
if (err) { if (err) {

View file

@ -205,13 +205,13 @@ FormSubmissionSchema.pre('save', function (next) {
//Check for IP Address of submitting person //Check for IP Address of submitting person
FormSubmissionSchema.pre('save', function (next){ FormSubmissionSchema.pre('save', function (next){
var that = this; var self = this;
if(this.ipAddr){ if(this.ipAddr){
if(this.isModified('ipAddr')){ if(this.isModified('ipAddr')){
satelize.satelize({ip: this.ipAddr}, function(err, geoData){ satelize.satelize({ip: this.ipAddr}, function(err, geoData){
if (err) next( new Error(err.message) ); if (err) next( new Error(err.message) );
that.geoLocation = JSON.parse(geoData); self.geoLocation = JSON.parse(geoData);
next(); next();
}); });
} }
@ -222,23 +222,23 @@ FormSubmissionSchema.pre('save', function (next){
//Generate autofilled PDF if flags are set //Generate autofilled PDF if flags are set
FormSubmissionSchema.pre('save', function (next) { FormSubmissionSchema.pre('save', function (next) {
var fdfData, dest_filename, dest_path, var fdfData, dest_filename, dest_path,
that = this, self = this,
_form = this.form; _form = this.form;
if(this.pdf && this.pdf.path){ if(this.pdf && this.pdf.path){
dest_filename = that.title.replace(/ /g,'')+'_submission_'+Date.now()+'.pdf'; dest_filename = self.title.replace(/ /g,'')+'_submission_'+Date.now()+'.pdf';
var __path = this.pdf.path.split('/').slice(0,this.pdf.path.split('/').length-1).join('/'); var __path = this.pdf.path.split('/').slice(0,this.pdf.path.split('/').length-1).join('/');
dest_path = path.join(__path, dest_filename); dest_path = path.join(__path, dest_filename);
that.pdfFilePath = dest_path; self.pdfFilePath = dest_path;
pdfFiller.fillForm(that.pdf.path, dest_path, that.fdfData, function(err){ pdfFiller.fillForm(self.pdf.path, dest_path, self.fdfData, function(err){
if(err) { if(err) {
console.log('\n err.message: '+err.message); console.log('\n err.message: '+err.message);
next( new Error(err.message) ); next( new Error(err.message) );
} }
console.log('Field data from Form: '+that.title.replace(/ /g,'')+' outputed to new PDF: '+dest_path); console.log('Field data from Form: '+self.title.replace(/ /g,'')+' outputed to new PDF: '+dest_path);
next(); next();
}); });
} else { } else {

View file

@ -0,0 +1,758 @@
[
{
"_id": "56450d120761e9d7d68d3543",
"lastModified": "2015-11-12T22:05:06.380Z",
"fdfData": null,
"admin": "55d270df2749c1ceb47c0f8b",
"form": "5644dde5507b2572635dcd50",
"title": "Sample Form",
"timeElapsed": 11.925,
"percentageComplete": 75,
"__v": 0,
"created": "2015-11-12T22:05:06.378Z",
"form_fields": [
{
"_id": "5644e0d5507b2572635dcd56",
"fieldValue": "",
"fieldType": "statement",
"title": "Statement2",
"lastModified": "2015-11-12T18:56:21.730Z",
"created": "2015-11-12T18:56:21.660Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": true,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.769Z",
"title": "Short Text2",
"fieldType": "textfield",
"fieldValue": "first",
"_id": "5644dde7507b2572635dcd51",
"created": "2015-11-12T18:43:51.290Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.770Z",
"title": "Short Text3",
"fieldType": "textfield",
"fieldValue": "first",
"_id": "5644dde7507b2572635dcd52",
"created": "2015-11-12T18:43:51.977Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.771Z",
"title": "Paragraph Text2",
"fieldType": "textarea",
"fieldValue": "first",
"_id": "5644ddea507b2572635dcd54",
"created": "2015-11-12T18:43:54.594Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.771Z",
"title": "Rating2",
"fieldType": "rating",
"fieldValue": 1,
"_id": "5644e0d4507b2572635dcd55",
"created": "2015-11-12T18:56:20.324Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
}
]
},
{
"_id": "56450d1d0761e9d7d68d3544",
"lastModified": "2015-11-12T22:05:17.806Z",
"fdfData": null,
"admin": "55d270df2749c1ceb47c0f8b",
"form": "5644dde5507b2572635dcd50",
"title": "Sample Form",
"timeElapsed": 10.301,
"percentageComplete": 75,
"__v": 0,
"created": "2015-11-12T22:05:17.805Z",
"form_fields": [
{
"_id": "5644e0d5507b2572635dcd56",
"fieldValue": "",
"fieldType": "statement",
"title": "Statement2",
"lastModified": "2015-11-12T18:56:21.730Z",
"created": "2015-11-12T18:56:21.660Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": true,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.769Z",
"title": "Short Text2",
"fieldType": "textfield",
"fieldValue": "second",
"_id": "5644dde7507b2572635dcd51",
"created": "2015-11-12T18:43:51.290Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.770Z",
"title": "Short Text3",
"fieldType": "textfield",
"fieldValue": "second",
"_id": "5644dde7507b2572635dcd52",
"created": "2015-11-12T18:43:51.977Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.771Z",
"title": "Paragraph Text2",
"fieldType": "textarea",
"fieldValue": "second",
"_id": "5644ddea507b2572635dcd54",
"created": "2015-11-12T18:43:54.594Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.771Z",
"title": "Rating2",
"fieldType": "rating",
"fieldValue": 3,
"_id": "5644e0d4507b2572635dcd55",
"created": "2015-11-12T18:56:20.324Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
}
]
},
{
"_id": "56450d260761e9d7d68d3545",
"lastModified": "2015-11-12T22:05:26.874Z",
"fdfData": null,
"admin": "55d270df2749c1ceb47c0f8b",
"form": "5644dde5507b2572635dcd50",
"title": "Sample Form",
"timeElapsed": 7.975,
"percentageComplete": 75,
"__v": 0,
"created": "2015-11-12T22:05:26.874Z",
"form_fields": [
{
"_id": "5644e0d5507b2572635dcd56",
"fieldValue": "",
"fieldType": "statement",
"title": "Statement2",
"lastModified": "2015-11-12T18:56:21.730Z",
"created": "2015-11-12T18:56:21.660Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": true,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.769Z",
"title": "Short Text2",
"fieldType": "textfield",
"fieldValue": "third",
"_id": "5644dde7507b2572635dcd51",
"created": "2015-11-12T18:43:51.290Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.770Z",
"title": "Short Text3",
"fieldType": "textfield",
"fieldValue": "third",
"_id": "5644dde7507b2572635dcd52",
"created": "2015-11-12T18:43:51.977Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.771Z",
"title": "Paragraph Text2",
"fieldType": "textarea",
"fieldValue": "third",
"_id": "5644ddea507b2572635dcd54",
"created": "2015-11-12T18:43:54.594Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.771Z",
"title": "Rating2",
"fieldType": "rating",
"fieldValue": 2,
"_id": "5644e0d4507b2572635dcd55",
"created": "2015-11-12T18:56:20.324Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
}
]
},
{
"_id": "56450d320761e9d7d68d3546",
"lastModified": "2015-11-12T22:05:38.717Z",
"fdfData": null,
"admin": "55d270df2749c1ceb47c0f8b",
"form": "5644dde5507b2572635dcd50",
"title": "Sample Form",
"timeElapsed": 10.47,
"percentageComplete": 75,
"__v": 0,
"created": "2015-11-12T22:05:38.716Z",
"form_fields": [
{
"_id": "5644e0d5507b2572635dcd56",
"fieldValue": "",
"fieldType": "statement",
"title": "Statement2",
"lastModified": "2015-11-12T18:56:21.730Z",
"created": "2015-11-12T18:56:21.660Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": true,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.769Z",
"title": "Short Text2",
"fieldType": "textfield",
"fieldValue": "fourth",
"_id": "5644dde7507b2572635dcd51",
"created": "2015-11-12T18:43:51.290Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.770Z",
"title": "Short Text3",
"fieldType": "textfield",
"fieldValue": "fourth",
"_id": "5644dde7507b2572635dcd52",
"created": "2015-11-12T18:43:51.977Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.771Z",
"title": "Paragraph Text2",
"fieldType": "textarea",
"fieldValue": "fourth",
"_id": "5644ddea507b2572635dcd54",
"created": "2015-11-12T18:43:54.594Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
},
{
"lastModified": "2015-11-12T21:30:20.771Z",
"title": "Rating2",
"fieldType": "rating",
"fieldValue": 2,
"_id": "5644e0d4507b2572635dcd55",
"created": "2015-11-12T18:56:20.324Z",
"validFieldTypes": [
"textfield",
"date",
"email",
"link",
"legal",
"url",
"textarea",
"statement",
"welcome",
"thankyou",
"file",
"dropdown",
"scale",
"rating",
"radio",
"checkbox",
"hidden",
"yes_no",
"natural",
"number"
],
"deletePreserved": false,
"disabled": false,
"required": true,
"fieldOptions": [],
"description": ""
}
]
}
]

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('forms').directive('configureFormDirective', ['$rootScope', '$http', 'Upload', '$timeout', 'TimeCounter', 'Auth', 'FormFields', 'CurrentForm', angular.module('forms').directive('configureFormDirective', ['$rootScope', '$http', 'Upload', 'CurrentForm',
function ($rootScope, $http, Upload, $timeout, TimeCounter, Auth, FormFields, CurrentForm) { function ($rootScope, $http, Upload, CurrentForm) {
return { return {
templateUrl: 'modules/forms/views/directiveViews/form/configure-form.client.view.html', templateUrl: 'modules/forms/views/directiveViews/form/configure-form.client.view.html',
restrict: 'E', restrict: 'E',
@ -52,7 +52,6 @@ angular.module('forms').directive('configureFormDirective', ['$rootScope', '$htt
console.log(files) console.log(files)
if (files && files.length) { if (files && files.length) {
// for (var i = 0; i < files.length; i++) {
var file = files[0]; var file = files[0];
console.log(file); console.log(file);

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('forms').directive('editFormDirective', ['$rootScope', '$q', '$http', '$timeout', 'TimeCounter', 'Auth', 'FormFields', angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormFields',
function ($rootScope, $q, $http, $timeout, TimeCounter, Auth, FormFields) { function ($rootScope, FormFields) {
return { return {
templateUrl: 'modules/forms/views/directiveViews/form/edit-form.client.view.html', templateUrl: 'modules/forms/views/directiveViews/form/edit-form.client.view.html',
restrict: 'E', restrict: 'E',

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', '$http', 'Upload', '$timeout', 'TimeCounter', 'Auth', 'FormFields', angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', '$http',
function ($rootScope, $http, Upload, $timeout, TimeCounter, Auth, FormFields) { function ($rootScope, $http) {
return { return {
templateUrl: 'modules/forms/views/directiveViews/form/edit-submissions-form.client.view.html', templateUrl: 'modules/forms/views/directiveViews/form/edit-submissions-form.client.view.html',
restrict: 'E', restrict: 'E',
@ -48,13 +48,18 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
var _tmpSubFormFields, var _tmpSubFormFields,
defaultFormFields = _.cloneDeep($scope.myform.form_fields); defaultFormFields = _.cloneDeep($scope.myform.form_fields);
// console.log('before textField2: '+data[0].form_fields[1].fieldValue);
//Iterate through form's submissions //Iterate through form's submissions
for(var i=0; i<data.length; i++){ for(var i=0; i<data.length; i++){
_tmpSubFormFields = _.merge(defaultFormFields, data[i].form_fields); for(var x=0; x<data[i].form_fields; x++){
data[i].form_fields = _tmpSubFormFields; oldValue = data[i].form_fields[x].fieldValue || '';
data[i].form_fields[x] = _.merge(defaultFormFields, data[i].form_fields);
data[i].form_fields[x].fieldValue = oldValue;
}
data[i].selected = false; data[i].selected = false;
} }
console.log(data); // console.log('after textField2: '+data[0].form_fields[1].fieldValue);
$scope.table.rows = data; $scope.table.rows = data;

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('forms').directive('fieldIconDirective', function($http, $compile) { angular.module('forms').directive('fieldIconDirective', function() {
return { return {
template: '<i class="{{typeIcon}}"></i>', template: '<i class="{{typeIcon}}"></i>',
@ -29,6 +29,5 @@ angular.module('forms').directive('fieldIconDirective', function($http, $compile
}; };
$scope.typeIcon = iconTypeMap[$scope.typeName]; $scope.typeIcon = iconTypeMap[$scope.typeName];
}, },
}; };
}); });

View file

@ -8,8 +8,8 @@ var __indexOf = [].indexOf || function(item) {
return -1; return -1;
}; };
angular.module('forms').directive('fieldDirective', ['$templateCache', '$http', '$compile', '$rootScope', angular.module('forms').directive('fieldDirective', ['$http', '$compile', '$rootScope',
function($templateCache, $http, $compile, $rootScope) { function($http, $compile, $rootScope) {
var getTemplateUrl = function(field) { var getTemplateUrl = function(field) {

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('forms').directive('submitFormDirective', ['$http', '$timeout', 'TimeCounter', 'Auth', '$filter', '$rootScope', angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter', '$filter', '$rootScope', 'Auth',
function ($http, $timeout, TimeCounter, Auth, $filter, $rootScope) { function ($http, TimeCounter, $filter, $rootScope, Auth) {
return { return {
templateUrl: 'modules/forms/views/directiveViews/form/submit-form.client.view.html', templateUrl: 'modules/forms/views/directiveViews/form/submit-form.client.view.html',
restrict: 'E', restrict: 'E',