'use strict'; function removeDateFieldsFunc(o) { var clone = _.clone(o); function eachObject(v,k){ if(k === 'lastModified' || k === 'created'){ delete clone[k]; } } for(var i=0; i 0; var changedFields = !!DeepDiff.diff(oldValue.form_fields, newValue.form_fields) && DeepDiff.diff(oldValue.form_fields, newValue.form_fields).length > 0; //If our form's startPage or form fields have not changed, don't autosave form if(!changedFields && !changedStartPage){ $rootScope.finishedRender = true; return; } if(oldValue.form_fields.length === 0) { $rootScope.finishedRender = true; } console.log('Autosaving'); console.log('\n\n----------'); console.log('$dirty: '+ $formCtrl.$dirty ); // console.log('changedFieldMap: '+changedFieldMap); // 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); //Save form ONLY IF rendering is finished, form_fields have been changed AND currently not save in progress if($rootScope.finishedRender && (changedFields || changedStartPage) && !$rootScope.saveInProgress) { if(savePromise) { $timeout.cancel(savePromise); savePromise = null; } savePromise = $timeout(function() { $rootScope.saveInProgress = true; var _diff = DeepDiff.diff(oldValue, newValue); debounceSave(_diff); }); } //If we are finished rendering then form saving should be finished else if($rootScope.finishedRender && $rootScope.saveInProgress){ $rootScope.saveInProgress = false; } }, true); }); } }; }]);