From a72306c8463df999a2fb5c581a9760dbe1a61806 Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Thu, 12 Nov 2015 14:24:26 -0800 Subject: [PATCH] fixed display submissions bug --- app/controllers/forms.server.controller.js | 1 - app/models/form_submission.server.model.js | 14 +- docs/example_submission_data.json | 758 ++++++++++++++++++ .../configure-form.client.directive.js | 5 +- .../directives/edit-form.client.directive.js | 4 +- .../edit-submissions-form.client.directive.js | 15 +- .../directives/field-icon.client.directive.js | 3 +- .../directives/field.client.directive.js | 4 +- .../submit-form.client.directive.js | 6 +- 9 files changed, 785 insertions(+), 25 deletions(-) create mode 100644 docs/example_submission_data.json diff --git a/app/controllers/forms.server.controller.js b/app/controllers/forms.server.controller.js index 7c98c8cd..bc6e21f5 100644 --- a/app/controllers/forms.server.controller.js +++ b/app/controllers/forms.server.controller.js @@ -146,7 +146,6 @@ exports.listSubmissions = function(req, res) { var _form = req.form; var _user = req.user; console.log('listSubmissions'); - // console.log(_form); FormSubmission.find({ form: _form._id }).exec(function(err, _submissions) { if (err) { diff --git a/app/models/form_submission.server.model.js b/app/models/form_submission.server.model.js index d0fc554f..1818e118 100644 --- a/app/models/form_submission.server.model.js +++ b/app/models/form_submission.server.model.js @@ -205,13 +205,13 @@ FormSubmissionSchema.pre('save', function (next) { //Check for IP Address of submitting person FormSubmissionSchema.pre('save', function (next){ - var that = this; + var self = this; if(this.ipAddr){ if(this.isModified('ipAddr')){ satelize.satelize({ip: this.ipAddr}, function(err, geoData){ if (err) next( new Error(err.message) ); - that.geoLocation = JSON.parse(geoData); + self.geoLocation = JSON.parse(geoData); next(); }); } @@ -222,23 +222,23 @@ FormSubmissionSchema.pre('save', function (next){ //Generate autofilled PDF if flags are set FormSubmissionSchema.pre('save', function (next) { var fdfData, dest_filename, dest_path, - that = this, + self = this, _form = this.form; 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('/'); 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) { console.log('\n err.message: '+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(); }); } else { diff --git a/docs/example_submission_data.json b/docs/example_submission_data.json new file mode 100644 index 00000000..9e2f9a0c --- /dev/null +++ b/docs/example_submission_data.json @@ -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": "" + } + ] + } +] \ No newline at end of file diff --git a/public/modules/forms/directives/configure-form.client.directive.js b/public/modules/forms/directives/configure-form.client.directive.js index c856b3ea..ec3a4346 100644 --- a/public/modules/forms/directives/configure-form.client.directive.js +++ b/public/modules/forms/directives/configure-form.client.directive.js @@ -1,7 +1,7 @@ 'use strict'; -angular.module('forms').directive('configureFormDirective', ['$rootScope', '$http', 'Upload', '$timeout', 'TimeCounter', 'Auth', 'FormFields', 'CurrentForm', - function ($rootScope, $http, Upload, $timeout, TimeCounter, Auth, FormFields, CurrentForm) { +angular.module('forms').directive('configureFormDirective', ['$rootScope', '$http', 'Upload', 'CurrentForm', + function ($rootScope, $http, Upload, CurrentForm) { return { templateUrl: 'modules/forms/views/directiveViews/form/configure-form.client.view.html', restrict: 'E', @@ -52,7 +52,6 @@ angular.module('forms').directive('configureFormDirective', ['$rootScope', '$htt console.log(files) if (files && files.length) { - // for (var i = 0; i < files.length; i++) { var file = files[0]; console.log(file); diff --git a/public/modules/forms/directives/edit-form.client.directive.js b/public/modules/forms/directives/edit-form.client.directive.js index 375fe9b3..703b3439 100644 --- a/public/modules/forms/directives/edit-form.client.directive.js +++ b/public/modules/forms/directives/edit-form.client.directive.js @@ -1,7 +1,7 @@ 'use strict'; -angular.module('forms').directive('editFormDirective', ['$rootScope', '$q', '$http', '$timeout', 'TimeCounter', 'Auth', 'FormFields', - function ($rootScope, $q, $http, $timeout, TimeCounter, Auth, FormFields) { +angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormFields', + function ($rootScope, FormFields) { return { templateUrl: 'modules/forms/views/directiveViews/form/edit-form.client.view.html', restrict: 'E', diff --git a/public/modules/forms/directives/edit-submissions-form.client.directive.js b/public/modules/forms/directives/edit-submissions-form.client.directive.js index faed300b..6a004b5b 100644 --- a/public/modules/forms/directives/edit-submissions-form.client.directive.js +++ b/public/modules/forms/directives/edit-submissions-form.client.directive.js @@ -1,7 +1,7 @@ 'use strict'; -angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', '$http', 'Upload', '$timeout', 'TimeCounter', 'Auth', 'FormFields', - function ($rootScope, $http, Upload, $timeout, TimeCounter, Auth, FormFields) { +angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', '$http', + function ($rootScope, $http) { return { templateUrl: 'modules/forms/views/directiveViews/form/edit-submissions-form.client.view.html', restrict: 'E', @@ -48,13 +48,18 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', var _tmpSubFormFields, defaultFormFields = _.cloneDeep($scope.myform.form_fields); + // console.log('before textField2: '+data[0].form_fields[1].fieldValue); + //Iterate through form's submissions for(var i=0; i', @@ -29,6 +29,5 @@ angular.module('forms').directive('fieldIconDirective', function($http, $compile }; $scope.typeIcon = iconTypeMap[$scope.typeName]; }, - }; }); \ No newline at end of file diff --git a/public/modules/forms/directives/field.client.directive.js b/public/modules/forms/directives/field.client.directive.js index 3a170f68..ae6193c9 100644 --- a/public/modules/forms/directives/field.client.directive.js +++ b/public/modules/forms/directives/field.client.directive.js @@ -8,8 +8,8 @@ var __indexOf = [].indexOf || function(item) { return -1; }; -angular.module('forms').directive('fieldDirective', ['$templateCache', '$http', '$compile', '$rootScope', - function($templateCache, $http, $compile, $rootScope) { +angular.module('forms').directive('fieldDirective', ['$http', '$compile', '$rootScope', + function($http, $compile, $rootScope) { var getTemplateUrl = function(field) { diff --git a/public/modules/forms/directives/submit-form.client.directive.js b/public/modules/forms/directives/submit-form.client.directive.js index 4071d25a..93bd7dd0 100644 --- a/public/modules/forms/directives/submit-form.client.directive.js +++ b/public/modules/forms/directives/submit-form.client.directive.js @@ -1,9 +1,9 @@ 'use strict'; -angular.module('forms').directive('submitFormDirective', ['$http', '$timeout', 'TimeCounter', 'Auth', '$filter', '$rootScope', - function ($http, $timeout, TimeCounter, Auth, $filter, $rootScope) { +angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter', '$filter', '$rootScope', 'Auth', + function ($http, TimeCounter, $filter, $rootScope, Auth) { 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', scope: { myform:'='