mirror of
https://github.com/ansible/awx.git
synced 2026-03-09 05:29:26 -02:30
Refactored formSave to remove old survey logic as well as remove unnecessary event emit.
This commit is contained in:
@@ -323,95 +323,8 @@
|
|||||||
|
|
||||||
// Save
|
// Save
|
||||||
$scope.formSave = function () {
|
$scope.formSave = function () {
|
||||||
|
var fld, data = {};
|
||||||
$scope.invalid_survey = false;
|
$scope.invalid_survey = false;
|
||||||
if ($scope.removeGatherFormFields) {
|
|
||||||
$scope.removeGatherFormFields();
|
|
||||||
}
|
|
||||||
$scope.removeGatherFormFields = $scope.$on('GatherFormFields', function(e, data) {
|
|
||||||
generator.clearApiErrors();
|
|
||||||
Wait('start');
|
|
||||||
data = {};
|
|
||||||
var fld;
|
|
||||||
try {
|
|
||||||
for (fld in form.fields) {
|
|
||||||
if (form.fields[fld].type === 'select' && fld !== 'playbook') {
|
|
||||||
data[fld] = $scope[fld].value;
|
|
||||||
} else {
|
|
||||||
if (fld !== 'variables' && fld !== 'survey') {
|
|
||||||
data[fld] = $scope[fld];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data.extra_vars = ToJSON($scope.parseType, $scope.variables, true);
|
|
||||||
if(data.job_type === 'scan' && $scope.default_scan === true){
|
|
||||||
data.project = "";
|
|
||||||
data.playbook = "";
|
|
||||||
}
|
|
||||||
// We only want to set the survey_enabled flag to true for this job template if a survey exists
|
|
||||||
// and it's been enabled. By default, survey_enabled is explicitly set to true but if no survey
|
|
||||||
// is created then we don't want it enabled.
|
|
||||||
data.survey_enabled = ($scope.survey_enabled && $scope.survey_exists) ? $scope.survey_enabled : false;
|
|
||||||
Rest.setUrl(defaultUrl);
|
|
||||||
Rest.post(data)
|
|
||||||
.success(function(data) {
|
|
||||||
$scope.$emit('templateSaveSuccess', data);
|
|
||||||
|
|
||||||
$scope.addedItem = data.id;
|
|
||||||
|
|
||||||
Refresh({
|
|
||||||
scope: $scope,
|
|
||||||
set: 'job_templates',
|
|
||||||
iterator: 'job_template',
|
|
||||||
url: $scope.current_url
|
|
||||||
});
|
|
||||||
|
|
||||||
if($scope.survey_questions && $scope.survey_questions.length > 0){
|
|
||||||
//once the job template information is saved we submit the survey info to the correct endpoint
|
|
||||||
var url = data.url+ 'survey_spec/';
|
|
||||||
Rest.setUrl(url);
|
|
||||||
Rest.post({ name: $scope.survey_name, description: $scope.survey_description, spec: $scope.survey_questions })
|
|
||||||
.success(function () {
|
|
||||||
Wait('stop');
|
|
||||||
|
|
||||||
})
|
|
||||||
.error(function (data, status) {
|
|
||||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
|
||||||
msg: 'Failed to add new survey. Post returned status: ' + status });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
.error(function (data, status) {
|
|
||||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
|
||||||
msg: 'Failed to add new job template. POST returned status: ' + status
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
Wait('stop');
|
|
||||||
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
if ($scope.removePromptForSurvey) {
|
|
||||||
$scope.removePromptForSurvey();
|
|
||||||
}
|
|
||||||
$scope.removePromptForSurvey = $scope.$on('PromptForSurvey', function() {
|
|
||||||
var action = function () {
|
|
||||||
// $scope.$emit("GatherFormFields");
|
|
||||||
Wait('start');
|
|
||||||
$('#prompt-modal').modal('hide');
|
|
||||||
$scope.addSurvey();
|
|
||||||
|
|
||||||
};
|
|
||||||
Prompt({
|
|
||||||
hdr: 'Incomplete Survey',
|
|
||||||
body: '<div class="Prompt-bodyQuery">Do you want to create a survey before proceeding?</div>',
|
|
||||||
action: action
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// users can't save a survey with a scan job
|
// users can't save a survey with a scan job
|
||||||
if($scope.job_type.value === "scan" && $scope.survey_enabled === true){
|
if($scope.job_type.value === "scan" && $scope.survey_enabled === true){
|
||||||
@@ -422,7 +335,70 @@
|
|||||||
$scope.survey_enabled = false;
|
$scope.survey_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.$emit("GatherFormFields");
|
generator.clearApiErrors();
|
||||||
|
|
||||||
|
Wait('start');
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (fld in form.fields) {
|
||||||
|
if (form.fields[fld].type === 'select' && fld !== 'playbook') {
|
||||||
|
data[fld] = $scope[fld].value;
|
||||||
|
} else {
|
||||||
|
if (fld !== 'variables' && fld !== 'survey') {
|
||||||
|
data[fld] = $scope[fld];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.extra_vars = ToJSON($scope.parseType, $scope.variables, true);
|
||||||
|
if(data.job_type === 'scan' && $scope.default_scan === true){
|
||||||
|
data.project = "";
|
||||||
|
data.playbook = "";
|
||||||
|
}
|
||||||
|
// We only want to set the survey_enabled flag to true for this job template if a survey exists
|
||||||
|
// and it's been enabled. By default, survey_enabled is explicitly set to true but if no survey
|
||||||
|
// is created then we don't want it enabled.
|
||||||
|
data.survey_enabled = ($scope.survey_enabled && $scope.survey_exists) ? $scope.survey_enabled : false;
|
||||||
|
Rest.setUrl(defaultUrl);
|
||||||
|
Rest.post(data)
|
||||||
|
.success(function(data) {
|
||||||
|
$scope.$emit('templateSaveSuccess', data);
|
||||||
|
|
||||||
|
$scope.addedItem = data.id;
|
||||||
|
|
||||||
|
Refresh({
|
||||||
|
scope: $scope,
|
||||||
|
set: 'job_templates',
|
||||||
|
iterator: 'job_template',
|
||||||
|
url: $scope.current_url
|
||||||
|
});
|
||||||
|
|
||||||
|
if($scope.survey_questions && $scope.survey_questions.length > 0){
|
||||||
|
//once the job template information is saved we submit the survey info to the correct endpoint
|
||||||
|
var url = data.url+ 'survey_spec/';
|
||||||
|
Rest.setUrl(url);
|
||||||
|
Rest.post({ name: $scope.survey_name, description: $scope.survey_description, spec: $scope.survey_questions })
|
||||||
|
.success(function () {
|
||||||
|
Wait('stop');
|
||||||
|
|
||||||
|
})
|
||||||
|
.error(function (data, status) {
|
||||||
|
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||||
|
msg: 'Failed to add new survey. Post returned status: ' + status });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
.error(function (data, status) {
|
||||||
|
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||||
|
msg: 'Failed to add new job template. POST returned status: ' + status
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
Wait('stop');
|
||||||
|
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -420,80 +420,50 @@ export default
|
|||||||
|
|
||||||
// Save changes to the parent
|
// Save changes to the parent
|
||||||
$scope.formSave = function () {
|
$scope.formSave = function () {
|
||||||
|
var fld, data = {};
|
||||||
$scope.invalid_survey = false;
|
$scope.invalid_survey = false;
|
||||||
if ($scope.removeGatherFormFields) {
|
|
||||||
$scope.removeGatherFormFields();
|
|
||||||
}
|
|
||||||
$scope.removeGatherFormFields = $scope.$on('GatherFormFields', function(e, data) {
|
|
||||||
generator.clearApiErrors();
|
|
||||||
Wait('start');
|
|
||||||
data = {};
|
|
||||||
var fld;
|
|
||||||
try {
|
|
||||||
// Make sure we have valid variable data
|
|
||||||
data.extra_vars = ToJSON($scope.parseType, $scope.variables, true);
|
|
||||||
if(data.extra_vars === undefined ){
|
|
||||||
throw 'undefined variables';
|
|
||||||
}
|
|
||||||
for (fld in form.fields) {
|
|
||||||
if (form.fields[fld].type === 'select' && fld !== 'playbook') {
|
|
||||||
data[fld] = $scope[fld].value;
|
|
||||||
} else {
|
|
||||||
if (fld !== 'variables' && fld !== 'callback_url') {
|
|
||||||
data[fld] = $scope[fld];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Rest.setUrl(defaultUrl + id + '/');
|
|
||||||
Rest.put(data)
|
|
||||||
.success(function (data) {
|
|
||||||
$scope.$emit('templateSaveSuccess', data);
|
|
||||||
})
|
|
||||||
.error(function (data, status) {
|
|
||||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
|
||||||
msg: 'Failed to update job template. PUT returned status: ' + status });
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
Wait('stop');
|
|
||||||
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
if ($scope.removePromptForSurvey) {
|
|
||||||
$scope.removePromptForSurvey();
|
|
||||||
}
|
|
||||||
$scope.removePromptForSurvey = $scope.$on('PromptForSurvey', function() {
|
|
||||||
var action = function () {
|
|
||||||
// $scope.$emit("GatherFormFields");
|
|
||||||
Wait('start');
|
|
||||||
$('#prompt-modal').modal('hide');
|
|
||||||
$scope.addSurvey();
|
|
||||||
|
|
||||||
};
|
|
||||||
Prompt({
|
|
||||||
hdr: 'Incomplete Survey',
|
|
||||||
body: '<div class="Prompt-bodyQuery">Do you want to create a survey before proceeding?</div>',
|
|
||||||
action: action
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// users can't save a survey with a scan job
|
// users can't save a survey with a scan job
|
||||||
if($scope.job_type.value === "scan" && $scope.survey_enabled === true){
|
if($scope.job_type.value === "scan" && $scope.survey_enabled === true){
|
||||||
$scope.survey_enabled = false;
|
$scope.survey_enabled = false;
|
||||||
}
|
}
|
||||||
|
// Can't have a survey enabled without a survey
|
||||||
if($scope.survey_enabled === true && $scope.survey_exists!==true){
|
if($scope.survey_enabled === true && $scope.survey_exists!==true){
|
||||||
// $scope.$emit("PromptForSurvey");
|
$scope.survey_enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
// The original design for this was a pop up that would prompt the user if they wanted to create a
|
generator.clearApiErrors();
|
||||||
// survey, because they had enabled one but not created it yet. We switched this for now so that
|
|
||||||
// an error message would be displayed by the survey buttons that tells the user to add a survey or disabled
|
Wait('start');
|
||||||
// surveys.
|
|
||||||
$scope.invalid_survey = true;
|
try {
|
||||||
return;
|
// Make sure we have valid variable data
|
||||||
} else {
|
data.extra_vars = ToJSON($scope.parseType, $scope.variables, true);
|
||||||
$scope.$emit("GatherFormFields");
|
if(data.extra_vars === undefined ){
|
||||||
|
throw 'undefined variables';
|
||||||
|
}
|
||||||
|
for (fld in form.fields) {
|
||||||
|
if (form.fields[fld].type === 'select' && fld !== 'playbook') {
|
||||||
|
data[fld] = $scope[fld].value;
|
||||||
|
} else {
|
||||||
|
if (fld !== 'variables' && fld !== 'callback_url') {
|
||||||
|
data[fld] = $scope[fld];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rest.setUrl(defaultUrl + id + '/');
|
||||||
|
Rest.put(data)
|
||||||
|
.success(function (data) {
|
||||||
|
$scope.$emit('templateSaveSuccess', data);
|
||||||
|
})
|
||||||
|
.error(function (data, status) {
|
||||||
|
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||||
|
msg: 'Failed to update job template. PUT returned status: ' + status });
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
Wait('stop');
|
||||||
|
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user