Refactored formSave to remove old survey logic as well as remove unnecessary event emit.

This commit is contained in:
Michael Abashian
2016-04-13 14:47:20 -04:00
parent 90f9e5185a
commit 946cec2b7a
2 changed files with 101 additions and 155 deletions

View File

@@ -323,15 +323,22 @@
// Save // Save
$scope.formSave = function () { $scope.formSave = function () {
var fld, data = {};
$scope.invalid_survey = false; $scope.invalid_survey = false;
if ($scope.removeGatherFormFields) {
$scope.removeGatherFormFields(); // users can't save a survey with a scan job
if($scope.job_type.value === "scan" && $scope.survey_enabled === true){
$scope.survey_enabled = false;
} }
$scope.removeGatherFormFields = $scope.$on('GatherFormFields', function(e, data) { // Can't have a survey enabled without a survey
if($scope.survey_enabled === true && $scope.survey_exists!==true){
$scope.survey_enabled = false;
}
generator.clearApiErrors(); generator.clearApiErrors();
Wait('start'); Wait('start');
data = {};
var fld;
try { try {
for (fld in form.fields) { for (fld in form.fields) {
if (form.fields[fld].type === 'select' && fld !== 'playbook') { if (form.fields[fld].type === 'select' && fld !== 'playbook') {
@@ -392,37 +399,6 @@
Wait('stop'); Wait('stop');
Alert("Error", "Error parsing extra variables. Parser returned: " + err); 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
if($scope.job_type.value === "scan" && $scope.survey_enabled === true){
$scope.survey_enabled = false;
}
// Can't have a survey enabled without a survey
if($scope.survey_enabled === true && $scope.survey_exists!==true){
$scope.survey_enabled = false;
}
$scope.$emit("GatherFormFields");
}; };

View File

@@ -420,15 +420,22 @@ 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(); // users can't save a survey with a scan job
if($scope.job_type.value === "scan" && $scope.survey_enabled === true){
$scope.survey_enabled = false;
} }
$scope.removeGatherFormFields = $scope.$on('GatherFormFields', function(e, data) { // Can't have a survey enabled without a survey
if($scope.survey_enabled === true && $scope.survey_exists!==true){
$scope.survey_enabled = false;
}
generator.clearApiErrors(); generator.clearApiErrors();
Wait('start'); Wait('start');
data = {};
var fld;
try { try {
// Make sure we have valid variable data // Make sure we have valid variable data
data.extra_vars = ToJSON($scope.parseType, $scope.variables, true); data.extra_vars = ToJSON($scope.parseType, $scope.variables, true);
@@ -458,43 +465,6 @@ export default
Wait('stop'); Wait('stop');
Alert("Error", "Error parsing extra variables. Parser returned: " + err); 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
if($scope.job_type.value === "scan" && $scope.survey_enabled === true){
$scope.survey_enabled = false;
}
if($scope.survey_enabled === true && $scope.survey_exists!==true){
// $scope.$emit("PromptForSurvey");
// The original design for this was a pop up that would prompt the user if they wanted to create a
// 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
// surveys.
$scope.invalid_survey = true;
return;
} else {
$scope.$emit("GatherFormFields");
}
}; };