Merge branch 'master' of github.com:whitef0x0/tellform
This commit is contained in:
commit
601dcd64e4
|
@ -231,7 +231,7 @@ FormSchema.virtual('analytics.fields').get(function () {
|
|||
}
|
||||
return sum;
|
||||
}, 0);
|
||||
}else {
|
||||
} else {
|
||||
continueViews = _.reduce(visitors, function(sum, visitorObj){
|
||||
if(visitorObj.lastActiveField+'' === field._id+'' && visitorObj.isSubmitted){
|
||||
return sum + 1;
|
||||
|
@ -293,116 +293,112 @@ FormSchema.pre('save', function (next) {
|
|||
return cb(err);
|
||||
} else {
|
||||
_original = original;
|
||||
//console.log('_original');
|
||||
//console.log(_original);
|
||||
return cb(null);
|
||||
}
|
||||
});
|
||||
}, function(cb) {
|
||||
return cb(null);
|
||||
},
|
||||
function(cb) {
|
||||
var hasIds = true;
|
||||
for(var i=0; i<that.form_fields.length; i++){
|
||||
if(!that.form_fields.hasOwnProperty('_id')){
|
||||
hasIds = false;
|
||||
break;
|
||||
}
|
||||
function(cb) {
|
||||
var hasIds = true;
|
||||
for(var i=0; i<that.form_fields.length; i++){
|
||||
if(!that.form_fields.hasOwnProperty('_id')){
|
||||
hasIds = false;
|
||||
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,
|
||||
new_ids = _.map(_.pluck(that.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);
|
||||
var old_form_fields = _original.form_fields,
|
||||
new_ids = _.map(_.pluck(that.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);
|
||||
|
||||
//Preserve fields that have at least one submission
|
||||
if( deletedIds.length > 0 ){
|
||||
//Preserve fields that have at least one submission
|
||||
if( deletedIds.length > 0 ){
|
||||
|
||||
var modifiedSubmissions = [];
|
||||
var modifiedSubmissions = [];
|
||||
|
||||
async.forEachOfSeries(deletedIds,
|
||||
function (deletedIdIndex, key, cb_id) {
|
||||
async.forEachOfSeries(deletedIds,
|
||||
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'
|
||||
FormSubmission.
|
||||
find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {submissionId: deleted_id} } }).
|
||||
exec(function(err, submissions){
|
||||
if(err) {
|
||||
console.error(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);
|
||||
//Find FormSubmissions that contain field with _id equal to 'deleted_id'
|
||||
FormSubmission.
|
||||
find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {submissionId: deleted_id} } }).
|
||||
exec(function(err, submissions){
|
||||
if(err) {
|
||||
console.error(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);
|
||||
}
|
||||
|
||||
//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();
|
||||
});
|
||||
return cb_id(null);
|
||||
}
|
||||
});
|
||||
},
|
||||
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);
|
||||
}],
|
||||
function(err, results){
|
||||
if (err) return next(err);
|
||||
return next();
|
||||
});
|
||||
}
|
||||
else return cb(null);
|
||||
}],
|
||||
function(err, results){
|
||||
if (err) return next(err);
|
||||
return next();
|
||||
});
|
||||
});
|
||||
|
||||
mongoose.model('Form', FormSchema);
|
||||
|
|
19
public/dist/application.js
vendored
19
public/dist/application.js
vendored
|
@ -334,7 +334,7 @@ angular.module('forms').config(['$translateProvider', function ($translateProvid
|
|||
SUBMIT: 'Submit',
|
||||
UPLOAD_FILE: 'Upload your File'
|
||||
});
|
||||
|
||||
|
||||
}]);
|
||||
|
||||
'use strict';
|
||||
|
@ -1276,7 +1276,7 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$loca
|
|||
|
||||
angular.module('users').controller('PasswordController', ['$scope', '$stateParams', '$state', 'User',
|
||||
function($scope, $stateParams, $state, User) {
|
||||
|
||||
|
||||
$scope.error = '';
|
||||
|
||||
// Submit forgotten password account id
|
||||
|
@ -1764,7 +1764,7 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope
|
|||
$scope.setForm = function(form){
|
||||
$scope.myform = form;
|
||||
};
|
||||
|
||||
|
||||
$rootScope.resetForm = function(){
|
||||
$scope.myform = Forms.get({
|
||||
formId: $stateParams.formId
|
||||
|
@ -2256,7 +2256,6 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField
|
|||
$scope.addNewLogicJump = function (field_index) {
|
||||
var form_fields = $scope.myform.form_fields;
|
||||
var currField = form_fields[field_index];
|
||||
console.log(currField);
|
||||
if (form_fields.length > 1 && currField._id) {
|
||||
|
||||
var newLogicJump = {
|
||||
|
@ -2480,7 +2479,7 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
|||
/*
|
||||
** Analytics Functions
|
||||
*/
|
||||
|
||||
|
||||
$scope.AverageTimeElapsed = (function(){
|
||||
var totalTime = 0;
|
||||
var numSubmissions = $scope.table.rows.length;
|
||||
|
@ -2681,15 +2680,15 @@ angular.module('forms').service('FormFields', [
|
|||
// },
|
||||
// {
|
||||
// name : 'stripe',
|
||||
// value : 'Payment'
|
||||
// value : 'Payment'
|
||||
// },
|
||||
{
|
||||
name : 'statement',
|
||||
value : 'Statement'
|
||||
value : 'Statement'
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
]);
|
||||
|
||||
'use strict';
|
||||
|
@ -2702,7 +2701,7 @@ angular.module('forms').factory('Submissions', ['$resource',
|
|||
formId: '@_id'
|
||||
}, {
|
||||
'query' : {
|
||||
method: 'GET',
|
||||
method: 'GET',
|
||||
isArray: true,
|
||||
},
|
||||
'update': {
|
||||
|
@ -2987,7 +2986,7 @@ angular.module('forms').directive('onFinishRender', ["$rootScope", "$timeout", f
|
|||
return {
|
||||
restrict: 'A',
|
||||
link: function (scope, element, attrs) {
|
||||
|
||||
|
||||
//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')){
|
||||
return;
|
||||
|
|
|
@ -61,14 +61,13 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField
|
|||
|
||||
// LOGIC JUMP METHODS
|
||||
$scope.removeLogicJump = function (field_index) {
|
||||
var currField = $scope.myform.form_fields[field_index];
|
||||
currField.logicJump = {};
|
||||
$scope.myform.form_fields[field_index].logicJump.fieldA = null;
|
||||
$scope.myform.form_fields[field_index].logicJump.valueB = null;
|
||||
};
|
||||
|
||||
$scope.addNewLogicJump = function (field_index) {
|
||||
var form_fields = $scope.myform.form_fields;
|
||||
var currField = form_fields[field_index];
|
||||
console.log(currField);
|
||||
if (form_fields.length > 1 && currField._id) {
|
||||
|
||||
var newLogicJump = {
|
||||
|
|
Loading…
Reference in a new issue