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 (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) {

View File

@ -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(){