Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
|
69de0eaa40 | ||
|
17edc21dea |
|
@ -331,117 +331,6 @@ function formFieldsAllHaveIds(form_fields){
|
|||
return true;
|
||||
}
|
||||
|
||||
FormSchema.pre('save', function (next) {
|
||||
var that = this;
|
||||
var _original;
|
||||
|
||||
async.series([
|
||||
function(cb) {
|
||||
that.constructor
|
||||
.findOne({_id: that._id}).exec(function (err, original) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
} else if (!original){
|
||||
return next();
|
||||
} else {
|
||||
_original = original;
|
||||
return cb(null);
|
||||
}
|
||||
});
|
||||
},
|
||||
function(cb) {
|
||||
if(that.form_fields && that.isModified('form_fields') && formFieldsAllHaveIds(that.toObject().form_fields)){
|
||||
|
||||
var current_form = that.toObject(),
|
||||
old_form_fields = _original.toObject().form_fields,
|
||||
new_ids = _.map(_.map(current_form.form_fields, 'globalId'), function(id){ return ''+id;}),
|
||||
old_ids = _.map(_.map(old_form_fields, 'globalId'), function(id){ return ''+id;}),
|
||||
deletedIds = getDeletedIndexes(old_ids, new_ids);
|
||||
|
||||
//Check if any form_fileds were deleted
|
||||
if( deletedIds.length > 0 ){
|
||||
|
||||
var modifiedSubmissions = [];
|
||||
|
||||
async.forEachOfSeries(deletedIds,
|
||||
function (deletedIdIndex, key, cb_id) {
|
||||
|
||||
var deleted_id = old_ids[deletedIdIndex];
|
||||
//Find FormSubmissions that contain field with _id equal to 'deleted_id'
|
||||
FormSubmission.
|
||||
find({ form: that, form_fields: {$elemMatch: {globalId: deleted_id} } }).
|
||||
exec(function(err, submissions){
|
||||
if(err) {
|
||||
return cb_id(err);
|
||||
}
|
||||
|
||||
//Preserve fields that have at least one submission
|
||||
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);
|
||||
}
|
||||
|
||||
//Iterate through all submissions with modified form_fields
|
||||
async.forEachOfSeries(modifiedSubmissions, function (submission, key, callback) {
|
||||
|
||||
var submission_form_fields = submission.toObject().form_fields;
|
||||
var currentform_form_fields = that.toObject().form_fields;
|
||||
|
||||
//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.globalId + '';
|
||||
return tmp_id === old_ids[deletedIds[i]];
|
||||
});
|
||||
|
||||
var deletedField = submission_form_fields[index];
|
||||
|
||||
//Hide field if it exists
|
||||
if (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);
|
||||
currentform_form_fields.unshift(deletedField);
|
||||
}
|
||||
}
|
||||
submission.form_fields = submission_form_fields;
|
||||
that.form_fields = currentform_form_fields;
|
||||
|
||||
return callback(null);
|
||||
}, function (err) {
|
||||
return cb(err);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return cb(null);
|
||||
}
|
||||
} else {
|
||||
return cb(null);
|
||||
}
|
||||
}
|
||||
],
|
||||
function(err){
|
||||
if(err){
|
||||
return next(err);
|
||||
}
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
FormSchema.index({created: 1});
|
||||
|
||||
mongoose.model('Form', FormSchema);
|
||||
|
|
|
@ -17,5 +17,6 @@
|
|||
"RESET_PASSWORD_CONFIRMATION_EMAIL_PARAGRAPH_1": "Ceci est un message de courtoisie pour confirmer que votre mot de passe a été modifié.",
|
||||
"RESET_PASSWORD_REQUEST_EMAIL_PARAGRAPH_1": "Voici un lien spécial qui vous permettra de réinitialiser votre mot de passe Veuillez noter qu'il expirera dans une heure pour votre protection:",
|
||||
"RESET_PASSWORD_REQUEST_EMAIL_LINK_TEXT": "Réinitialiser votre mot de passe",
|
||||
"RESET_PASSWORD_REQUEST_EMAIL_PARAGRAPH_2": "Si vous ne l'avez pas demandé, veuillez ignorer cet e-mail et votre mot de passe restera inchangé."
|
||||
"RESET_PASSWORD_REQUEST_EMAIL_PARAGRAPH_2": "Si vous ne l'avez pas demandé, veuillez ignorer cet e-mail et votre mot de passe restera inchangé.",
|
||||
"RESET_PASSWORD_CONFIRMATION_EMAIL_BODY_1": "RESET_PASSWORD_CONFIRMATION_EMAIL_BODY_1"
|
||||
}
|
4454
public/dist/application.js
vendored
4454
public/dist/application.js
vendored
File diff suppressed because one or more lines are too long
7
public/dist/application.min.js
vendored
7
public/dist/application.min.js
vendored
File diff suppressed because one or more lines are too long
18
public/dist/form_populate_template_cache.js
vendored
18
public/dist/form_populate_template_cache.js
vendored
File diff suppressed because one or more lines are too long
31
public/dist/vendor.min.js
vendored
31
public/dist/vendor.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -3,7 +3,7 @@
|
|||
//TODO: DAVID: URGENT: Make this a $resource that fetches valid field types from server
|
||||
angular.module('forms').service('FormFields', [ '$rootScope', '$translate', '$window',
|
||||
function($rootScope, $translate, $window) {
|
||||
$translate.use($window.user.language);
|
||||
$translate.use($rootScope.language);
|
||||
console.log($translate.instant('SHORT_TEXT'));
|
||||
|
||||
this.types = [
|
||||
|
|
Loading…
Reference in a new issue