Revert all should only revert the fields on the current tab

instead of reverting all the settings, throughout CTiT
This commit is contained in:
Jared Tabor 2017-06-26 15:24:51 -07:00
parent 2d9df199c6
commit d6c1842de9
2 changed files with 29 additions and 17 deletions

View File

@ -450,12 +450,39 @@ export default [
};
var resetAll = function() {
var keys = _.keys(formDefs[formTracker.getCurrent()].fields);
var payload = {};
clearApiErrors();
_.each(keys, function(key) {
payload[key] = $scope.configDataResolve[key].default;
});
Wait('start');
ConfigurationService.resetAll()
ConfigurationService.patchConfiguration(payload)
.then(function() {
populateFromApi();
$scope[formTracker.currentFormName()].$setPristine();
$scope.$broadcast('CUSTOM_LOGO_reverted');
let keys = _.keys(formDefs[formTracker.getCurrent()].fields);
_.each(keys, function(key) {
$scope[key] = $scope.configDataResolve[key].default;
if($scope[key + '_field'].type === "select"){
// We need to re-instantiate the Select2 element
// after resetting the value. Example:
$scope.$broadcast(key+'_populated', null, false);
}
else if($scope[key + '_field'].reset === "CUSTOM_LOGO"){
$scope.$broadcast(key+'_reverted');
}
else if($scope[key + '_field'].type === "textarea" && _.isArray($scope.configDataResolve[key].default)){
$scope[key] = ConfigurationUtils.arrayToList($scope[key], key);
}
else if($scope[key + '_field'].hasOwnProperty('codeMirror')){
$scope[key] = '{}';
$scope.$broadcast('codeMirror_populated', key);
}
});
})
.catch(function(error) {
ProcessErrors($scope, error, status, formDefs[formTracker.getCurrent()],

View File

@ -68,21 +68,6 @@ export default ['$rootScope', 'GetBasePath', 'ProcessErrors', '$q', '$http', 'Re
deferred.reject(error);
});
return deferred.promise;
},
resetAll: function() {
var deferred = $q.defer();
Rest.setUrl(url);
Rest.destroy()
.success(function(data) {
deferred.resolve(data);
})
.error(function(error) {
deferred.reject(error);
});
return deferred.promise;
}
};