From d6c1842de9a477fe1f934d4e7a5a2e7e58d4c404 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Mon, 26 Jun 2017 15:24:51 -0700 Subject: [PATCH] Revert all should only revert the fields on the current tab instead of reverting all the settings, throughout CTiT --- .../configuration/configuration.controller.js | 31 +++++++++++++++++-- .../configuration/configuration.service.js | 15 --------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/awx/ui/client/src/configuration/configuration.controller.js b/awx/ui/client/src/configuration/configuration.controller.js index b1d9063bc6..bb7a47dfeb 100644 --- a/awx/ui/client/src/configuration/configuration.controller.js +++ b/awx/ui/client/src/configuration/configuration.controller.js @@ -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()], diff --git a/awx/ui/client/src/configuration/configuration.service.js b/awx/ui/client/src/configuration/configuration.service.js index 99ec54afb7..f5e14c828e 100644 --- a/awx/ui/client/src/configuration/configuration.service.js +++ b/awx/ui/client/src/configuration/configuration.service.js @@ -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; } };