Merge branch 'master' of github.com:whitef0x0/tellform

This commit is contained in:
David Baldwynn 2016-11-14 14:14:25 -05:00 committed by David Baldwynn
commit 601dcd64e4
3 changed files with 101 additions and 107 deletions

View file

@ -231,7 +231,7 @@ FormSchema.virtual('analytics.fields').get(function () {
} }
return sum; return sum;
}, 0); }, 0);
}else { } else {
continueViews = _.reduce(visitors, function(sum, visitorObj){ continueViews = _.reduce(visitors, function(sum, visitorObj){
if(visitorObj.lastActiveField+'' === field._id+'' && visitorObj.isSubmitted){ if(visitorObj.lastActiveField+'' === field._id+'' && visitorObj.isSubmitted){
return sum + 1; return sum + 1;
@ -293,116 +293,112 @@ FormSchema.pre('save', function (next) {
return cb(err); return cb(err);
} else { } else {
_original = original; _original = original;
//console.log('_original');
//console.log(_original);
return cb(null); return cb(null);
} }
}); });
}, function(cb) {
return cb(null);
}, },
function(cb) { function(cb) {
var hasIds = true; var hasIds = true;
for(var i=0; i<that.form_fields.length; i++){ for(var i=0; i<that.form_fields.length; i++){
if(!that.form_fields.hasOwnProperty('_id')){ if(!that.form_fields.hasOwnProperty('_id')){
hasIds = false; hasIds = false;
break; break;
}
} }
if(that.isModified('form_fields') && that.form_fields && _original && hasIds){ }
if(that.isModified('form_fields') && that.form_fields && _original && hasIds){
var old_form_fields = _original.form_fields, var old_form_fields = _original.form_fields,
new_ids = _.map(_.pluck(that.form_fields, 'id'), function(id){ return ''+id;}), new_ids = _.map(_.pluck(that.form_fields, 'id'), function(id){ return ''+id;}),
old_ids = _.map(_.pluck(old_form_fields, 'id'), function(id){ return ''+id;}), old_ids = _.map(_.pluck(old_form_fields, 'id'), function(id){ return ''+id;}),
deletedIds = getDeletedIndexes(old_ids, new_ids); deletedIds = getDeletedIndexes(old_ids, new_ids);
//Preserve fields that have at least one submission //Preserve fields that have at least one submission
if( deletedIds.length > 0 ){ if( deletedIds.length > 0 ){
var modifiedSubmissions = []; var modifiedSubmissions = [];
async.forEachOfSeries(deletedIds, async.forEachOfSeries(deletedIds,
function (deletedIdIndex, key, cb_id) { function (deletedIdIndex, key, cb_id) {
var deleted_id = old_ids[deletedIdIndex]; var deleted_id = old_ids[deletedIdIndex];
//Find FormSubmissions that contain field with _id equal to 'deleted_id' //Find FormSubmissions that contain field with _id equal to 'deleted_id'
FormSubmission. FormSubmission.
find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {submissionId: deleted_id} } }). find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {submissionId: deleted_id} } }).
exec(function(err, submissions){ exec(function(err, submissions){
if(err) { if(err) {
console.error(err); console.error(err);
return cb_id(err); return cb_id(err);
} else {
//Delete field if there are no submission(s) found
if (submissions.length) {
//Add submissions
modifiedSubmissions.push.apply(modifiedSubmissions, submissions);
}
return cb_id(null);
}
});
},
function (err) {
if(err){
console.error(err.message);
return cb(err);
} else { } else {
//Delete field if there are no submission(s) found
if (submissions.length) {
//Add submissions
modifiedSubmissions.push.apply(modifiedSubmissions, submissions);
}
//Iterate through all submissions with modified form_fields return cb_id(null);
async.forEachOfSeries(modifiedSubmissions, function (submission, key, callback) {
//Iterate through ids of deleted fields
for (var i = 0; i < deletedIds.length; i++) {
var index = _.findIndex(submission.form_fields, function (field) {
var tmp_id = field._id + '';
return tmp_id === old_ids[deletedIds[i]];
});
var deletedField = submission.form_fields[index];
//Hide field if it exists
if (deletedField) {
// console.log('deletedField\n-------\n\n');
// console.log(deletedField);
//Delete old form_field
submission.form_fields.splice(index, 1);
deletedField.deletePreserved = true;
//Move deleted form_field to start
submission.form_fields.unshift(deletedField);
that.form_fields.unshift(deletedField);
// console.log('form.form_fields\n--------\n\n');
// console.log(that.form_fields);
}
}
submission.save(function (err) {
if (err) return callback(err);
else return callback(null);
});
}, function (err) {
if (err) {
console.error(err.message);
return cb(err);
}
else return cb();
});
} }
});
},
function (err) {
if(err){
console.error(err.message);
return cb(err);
} else {
//Iterate through all submissions with modified form_fields
async.forEachOfSeries(modifiedSubmissions, function (submission, key, callback) {
//Iterate through ids of deleted fields
for (var i = 0; i < deletedIds.length; i++) {
var index = _.findIndex(submission.form_fields, function (field) {
var tmp_id = field._id + '';
return tmp_id === old_ids[deletedIds[i]];
});
var deletedField = submission.form_fields[index];
//Hide field if it exists
if (deletedField) {
// console.log('deletedField\n-------\n\n');
// console.log(deletedField);
//Delete old form_field
submission.form_fields.splice(index, 1);
deletedField.deletePreserved = true;
//Move deleted form_field to start
submission.form_fields.unshift(deletedField);
that.form_fields.unshift(deletedField);
// console.log('form.form_fields\n--------\n\n');
// console.log(that.form_fields);
}
}
submission.save(function (err) {
if (err) return callback(err);
else return callback(null);
});
}, function (err) {
if (err) {
console.error(err.message);
return cb(err);
}
else return cb();
});
} }
); }
} );
else return cb(null);
} }
else return cb(null); else return cb(null);
}], }
function(err, results){ else return cb(null);
if (err) return next(err); }],
return next(); function(err, results){
}); if (err) return next(err);
return next();
});
}); });
mongoose.model('Form', FormSchema); mongoose.model('Form', FormSchema);

View file

@ -334,7 +334,7 @@ angular.module('forms').config(['$translateProvider', function ($translateProvid
SUBMIT: 'Submit', SUBMIT: 'Submit',
UPLOAD_FILE: 'Upload your File' UPLOAD_FILE: 'Upload your File'
}); });
}]); }]);
'use strict'; 'use strict';
@ -1276,7 +1276,7 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$loca
angular.module('users').controller('PasswordController', ['$scope', '$stateParams', '$state', 'User', angular.module('users').controller('PasswordController', ['$scope', '$stateParams', '$state', 'User',
function($scope, $stateParams, $state, User) { function($scope, $stateParams, $state, User) {
$scope.error = ''; $scope.error = '';
// Submit forgotten password account id // Submit forgotten password account id
@ -1764,7 +1764,7 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope
$scope.setForm = function(form){ $scope.setForm = function(form){
$scope.myform = form; $scope.myform = form;
}; };
$rootScope.resetForm = function(){ $rootScope.resetForm = function(){
$scope.myform = Forms.get({ $scope.myform = Forms.get({
formId: $stateParams.formId formId: $stateParams.formId
@ -2256,7 +2256,6 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField
$scope.addNewLogicJump = function (field_index) { $scope.addNewLogicJump = function (field_index) {
var form_fields = $scope.myform.form_fields; var form_fields = $scope.myform.form_fields;
var currField = form_fields[field_index]; var currField = form_fields[field_index];
console.log(currField);
if (form_fields.length > 1 && currField._id) { if (form_fields.length > 1 && currField._id) {
var newLogicJump = { var newLogicJump = {
@ -2480,7 +2479,7 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
/* /*
** Analytics Functions ** Analytics Functions
*/ */
$scope.AverageTimeElapsed = (function(){ $scope.AverageTimeElapsed = (function(){
var totalTime = 0; var totalTime = 0;
var numSubmissions = $scope.table.rows.length; var numSubmissions = $scope.table.rows.length;
@ -2681,15 +2680,15 @@ angular.module('forms').service('FormFields', [
// }, // },
// { // {
// name : 'stripe', // name : 'stripe',
// value : 'Payment' // value : 'Payment'
// }, // },
{ {
name : 'statement', name : 'statement',
value : 'Statement' value : 'Statement'
} }
]; ];
} }
]); ]);
'use strict'; 'use strict';
@ -2702,7 +2701,7 @@ angular.module('forms').factory('Submissions', ['$resource',
formId: '@_id' formId: '@_id'
}, { }, {
'query' : { 'query' : {
method: 'GET', method: 'GET',
isArray: true, isArray: true,
}, },
'update': { 'update': {
@ -2987,7 +2986,7 @@ angular.module('forms').directive('onFinishRender', ["$rootScope", "$timeout", f
return { return {
restrict: 'A', restrict: 'A',
link: function (scope, element, attrs) { link: function (scope, element, attrs) {
//Don't do anything if we don't have a ng-repeat on the current element //Don't do anything if we don't have a ng-repeat on the current element
if(!element.attr('ng-repeat') && !element.attr('data-ng-repeat')){ if(!element.attr('ng-repeat') && !element.attr('data-ng-repeat')){
return; return;

View file

@ -61,14 +61,13 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField
// LOGIC JUMP METHODS // LOGIC JUMP METHODS
$scope.removeLogicJump = function (field_index) { $scope.removeLogicJump = function (field_index) {
var currField = $scope.myform.form_fields[field_index]; $scope.myform.form_fields[field_index].logicJump.fieldA = null;
currField.logicJump = {}; $scope.myform.form_fields[field_index].logicJump.valueB = null;
}; };
$scope.addNewLogicJump = function (field_index) { $scope.addNewLogicJump = function (field_index) {
var form_fields = $scope.myform.form_fields; var form_fields = $scope.myform.form_fields;
var currField = form_fields[field_index]; var currField = form_fields[field_index];
console.log(currField);
if (form_fields.length > 1 && currField._id) { if (form_fields.length > 1 && currField._id) {
var newLogicJump = { var newLogicJump = {