setting AD_HOC_COMMANDS on scope slightly differently to make select2 happy long time

fixing jshint
This commit is contained in:
jaredevantabor
2017-01-23 17:56:16 -08:00
parent 483fbb6f24
commit d1c33e46db
2 changed files with 33 additions and 11 deletions

View File

@@ -67,7 +67,18 @@ export default [
if (data[key] !== null && typeof data[key] === 'object') { if (data[key] !== null && typeof data[key] === 'object') {
if (Array.isArray(data[key])) { if (Array.isArray(data[key])) {
//handle arrays //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 { } else {
//handle nested objects //handle nested objects
if(ConfigurationUtils.isEmpty(data[key])) { if(ConfigurationUtils.isEmpty(data[key])) {
@@ -284,6 +295,10 @@ export default [
ConfigurationService.patchConfiguration(payload) ConfigurationService.patchConfiguration(payload)
.then(function() { .then(function() {
$scope[key] = $scope.configDataResolve[key].default; $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(); loginUpdate();
}) })
.catch(function(error) { .catch(function(error) {

View File

@@ -72,26 +72,33 @@ export default [
// Flag to avoid re-rendering and breaking Select2 dropdowns on tab switching // Flag to avoid re-rendering and breaking Select2 dropdowns on tab switching
var dropdownRendered = false; var dropdownRendered = false;
$scope.$on('populated', function() {
var opts = []; function populateAdhocCommand(flag){
_.each(ConfigurationUtils.listToArray($scope.$parent.AD_HOC_COMMANDS), function(command) { var ad_hoc_commands = $scope.$parent.AD_HOC_COMMANDS.split(',');
opts.push({ $scope.$parent.AD_HOC_COMMANDS = _.map(ad_hoc_commands, (item) => _.find($scope.$parent.AD_HOC_COMMANDS_options, { value: item }));
id: command,
text: command if(flag !== undefined){
}); dropdownRendered = flag;
}); }
if(!dropdownRendered) { if(!dropdownRendered) {
dropdownRendered = true; dropdownRendered = true;
CreateSelect2({ CreateSelect2({
element: '#configuration_jobs_template_AD_HOC_COMMANDS', element: '#configuration_jobs_template_AD_HOC_COMMANDS',
multiple: true, multiple: true,
placeholder: i18n._('Select commands'), placeholder: i18n._('Select commands')
opts: opts
}); });
} }
}
$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 // Fix for bug where adding selected opts causes form to be $dirty and triggering modal
// TODO Find better solution for this bug // TODO Find better solution for this bug
$timeout(function(){ $timeout(function(){