From d1c33e46db1bdd04e0c2473ffb37d959bda1379d Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Mon, 23 Jan 2017 17:56:16 -0800 Subject: [PATCH] setting AD_HOC_COMMANDS on scope slightly differently to make select2 happy long time fixing jshint --- .../configuration/configuration.controller.js | 17 +++++++++++- .../configuration-jobs.controller.js | 27 ++++++++++++------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/awx/ui/client/src/configuration/configuration.controller.js b/awx/ui/client/src/configuration/configuration.controller.js index 153434ef84..f9319300a9 100644 --- a/awx/ui/client/src/configuration/configuration.controller.js +++ b/awx/ui/client/src/configuration/configuration.controller.js @@ -67,7 +67,18 @@ export default [ if (data[key] !== null && typeof data[key] === 'object') { if (Array.isArray(data[key])) { //handle arrays - $scope[key] = ConfigurationUtils.arrayToList(data[key], key); + //having to do this particular check b/c + // we want the options w/o a space, and + // the ConfigurationUtils.arrayToList() + // does a string.split(', ') w/ an extra space + // behind the comma. + if(key === "AD_HOC_COMMANDS"){ + $scope[key] = data[key].toString(); + } + else{ + $scope[key] = ConfigurationUtils.arrayToList(data[key], key); + } + } else { //handle nested objects if(ConfigurationUtils.isEmpty(data[key])) { @@ -284,6 +295,10 @@ export default [ ConfigurationService.patchConfiguration(payload) .then(function() { $scope[key] = $scope.configDataResolve[key].default; + if(key === "AD_HOC_COMMANDS"){ + $scope.AD_HOC_COMMANDS = $scope.AD_HOC_COMMANDS.toString(); + $scope.$broadcast('adhoc_populated', null, false); + } loginUpdate(); }) .catch(function(error) { diff --git a/awx/ui/client/src/configuration/jobs-form/configuration-jobs.controller.js b/awx/ui/client/src/configuration/jobs-form/configuration-jobs.controller.js index 953167c3f5..708ea3c28c 100644 --- a/awx/ui/client/src/configuration/jobs-form/configuration-jobs.controller.js +++ b/awx/ui/client/src/configuration/jobs-form/configuration-jobs.controller.js @@ -72,26 +72,33 @@ export default [ // Flag to avoid re-rendering and breaking Select2 dropdowns on tab switching var dropdownRendered = false; - $scope.$on('populated', function() { - var opts = []; - _.each(ConfigurationUtils.listToArray($scope.$parent.AD_HOC_COMMANDS), function(command) { - opts.push({ - id: command, - text: command - }); - }); + + function populateAdhocCommand(flag){ + var ad_hoc_commands = $scope.$parent.AD_HOC_COMMANDS.split(','); + $scope.$parent.AD_HOC_COMMANDS = _.map(ad_hoc_commands, (item) => _.find($scope.$parent.AD_HOC_COMMANDS_options, { value: item })); + + if(flag !== undefined){ + dropdownRendered = flag; + } if(!dropdownRendered) { dropdownRendered = true; CreateSelect2({ element: '#configuration_jobs_template_AD_HOC_COMMANDS', multiple: true, - placeholder: i18n._('Select commands'), - opts: opts + placeholder: i18n._('Select commands') }); } + } + $scope.$on('adhoc_populated', function(e, data, flag) { + populateAdhocCommand(flag); }); + + $scope.$on('populated', function(e, data, flag) { + populateAdhocCommand(flag); + }); + // Fix for bug where adding selected opts causes form to be $dirty and triggering modal // TODO Find better solution for this bug $timeout(function(){