fixed autosaving bug
This commit is contained in:
parent
2d15ae3dd5
commit
52632f3328
|
@ -232,11 +232,10 @@ exports.read = function(req, res) {
|
|||
* Update a form
|
||||
*/
|
||||
exports.update = function(req, res) {
|
||||
debugger;
|
||||
var form = req.form;
|
||||
|
||||
|
||||
if(req.body.changes){
|
||||
console.log('SENDING DIFFS\n\n\n');
|
||||
var formChanges = req.body.changes;
|
||||
|
||||
formChanges.forEach(function (change) {
|
||||
|
|
|
@ -55,12 +55,8 @@ module.exports = function (io, socket) {
|
|||
// a user has visited our page - add them to the visitorsData object
|
||||
socket.on('form-visitor-data', function(data) {
|
||||
|
||||
console.log('\n\nuser has visited our page');
|
||||
|
||||
visitorsData[socket.id] = data;
|
||||
|
||||
console.log(data);
|
||||
|
||||
|
||||
if (data.isSubmitted) {
|
||||
saveVisitorData(data, function () {
|
||||
console.log('\n\n user submitted form');
|
||||
|
|
|
@ -80,38 +80,35 @@ angular.module('forms').directive('autoSaveForm', ['$rootScope', '$timeout', fun
|
|||
newValue = angular.copy(newValue);
|
||||
oldValue = angular.copy(oldValue);
|
||||
|
||||
newValue.form_fields = _.removeDateFields(newValue.form_fields);
|
||||
oldValue.form_fields = _.removeDateFields(oldValue.form_fields);
|
||||
newValue.form_fields = _.removeDateFields(newValue.form_fields);
|
||||
oldValue.form_fields = _.removeDateFields(oldValue.form_fields);
|
||||
|
||||
var changedFields = !_.isEqual(oldValue.form_fields,newValue.form_fields) || !_.isEqual(oldValue.startPage, newValue.startPage);
|
||||
var changedFields = !!DeepDiff.diff(oldValue, newValue) && DeepDiff.diff(oldValue, newValue).length > 0;
|
||||
|
||||
if(oldValue.hasOwnProperty('plugins.oscarhost.settings.fieldMap')){
|
||||
changedFieldMap = !!oldValue.plugins.oscarhost.settings.fieldMap && !_.isEqual(oldValue.plugins.oscarhost.settings.fieldMap,newValue.plugins.oscarhost.settings.fieldMap);
|
||||
}
|
||||
//If our form is undefined, don't save form
|
||||
if( !newValue || !oldValue || !changedFields){
|
||||
$rootScope.finishedRender = true;
|
||||
return;
|
||||
}
|
||||
|
||||
//If our form is undefined, don't save form
|
||||
if( (!newValue && !oldValue) || !oldValue ){
|
||||
return;
|
||||
}
|
||||
if(oldValue.form_fields.length === 0) {
|
||||
$rootScope.finishedRender = true;
|
||||
}
|
||||
|
||||
// console.log('Autosaving');
|
||||
// console.log('\n\n----------');
|
||||
// console.log('!$dirty: '+ !$formCtrl.$dirty );
|
||||
// console.log('changedFields: '+changedFields);
|
||||
console.log('Autosaving');
|
||||
console.log('\n\n----------');
|
||||
console.log('!$dirty: '+ !$formCtrl.$dirty );
|
||||
console.log('changedFields: '+changedFields);
|
||||
// console.log('changedFieldMap: '+changedFieldMap);
|
||||
// console.log('finishedRender: '+$rootScope.finishedRender);
|
||||
// console.log('!saveInProgress: '+!$rootScope.saveInProgress);
|
||||
console.log('finishedRender: '+$rootScope.finishedRender);
|
||||
console.log('!saveInProgress: '+!$rootScope.saveInProgress);
|
||||
// console.log('newValue: '+newValue);
|
||||
// console.log('oldValue: '+oldValue);
|
||||
// console.log(oldValue.form_fields);
|
||||
// console.log(newValue.form_fields);
|
||||
|
||||
if(oldValue.form_fields.length === 0) {
|
||||
$rootScope.finishedRender = true;
|
||||
}
|
||||
|
||||
//Save form ONLY IF rendering is finished, form_fields have been changed AND currently not save in progress
|
||||
if( $rootScope.finishedRender && (changedFields && !$formCtrl.$dirty) && !$rootScope.saveInProgress) {
|
||||
if( $rootScope.finishedRender && (changedFields) && !$rootScope.saveInProgress) {
|
||||
|
||||
if(savePromise) {
|
||||
$timeout.cancel(savePromise);
|
||||
|
@ -120,7 +117,7 @@ angular.module('forms').directive('autoSaveForm', ['$rootScope', '$timeout', fun
|
|||
|
||||
savePromise = $timeout(function() {
|
||||
$rootScope.saveInProgress = true;
|
||||
|
||||
|
||||
delete newValue.visible_form_fields;
|
||||
delete newValue.visible_form_fields;
|
||||
var _diff = DeepDiff.diff(oldValue, newValue);
|
||||
|
|
|
@ -248,10 +248,7 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField
|
|||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
]);
|
||||
|
|
|
@ -75,7 +75,6 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
|||
|
||||
var visitors = $scope.myform.analytics.visitors;
|
||||
|
||||
console.log(visitors);
|
||||
for(var i=0; i<visitors.length; i++){
|
||||
var visitor = visitors[i];
|
||||
var deviceType = visitor.deviceType;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// Create a controller method for sending visitor data
|
||||
function send(form, lastActiveIndex, timeElapsed) {
|
||||
// Create a new message object
|
||||
var visitorData = {
|
||||
/*var visitorData = {
|
||||
referrer: document.referrer,
|
||||
isSubmitted: form.submitted,
|
||||
formId: form._id,
|
||||
|
@ -42,15 +42,15 @@
|
|||
}
|
||||
console.log(visitorData.deviceType);
|
||||
Socket.emit('form-visitor-data', visitorData);
|
||||
});
|
||||
});*/
|
||||
|
||||
}
|
||||
|
||||
function init(){
|
||||
// Make sure the Socket is connected
|
||||
if (!Socket.socket) {
|
||||
/*if (!Socket.socket) {
|
||||
Socket.connect();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
var service = {
|
||||
|
|
Loading…
Reference in a new issue