mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 19:37:38 -02:30
survey maker for going from add/edit job template to add/edit survey maker
This commit is contained in:
@@ -111,7 +111,7 @@ JobTemplatesList.$inject = ['$scope', '$rootScope', '$location', '$log', '$route
|
|||||||
function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm,
|
function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm,
|
||||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, GetBasePath,
|
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, GetBasePath,
|
||||||
InventoryList, CredentialList, ProjectList, LookUpInit, md5Setup, ParseTypeChange, Wait, Empty, ToJSON,
|
InventoryList, CredentialList, ProjectList, LookUpInit, md5Setup, ParseTypeChange, Wait, Empty, ToJSON,
|
||||||
CallbackHelpInit) {
|
CallbackHelpInit, Store) {
|
||||||
|
|
||||||
ClearScope();
|
ClearScope();
|
||||||
|
|
||||||
@@ -124,6 +124,7 @@ function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
selectPlaybook, checkSCMStatus,
|
selectPlaybook, checkSCMStatus,
|
||||||
callback;
|
callback;
|
||||||
|
|
||||||
|
$scope.Store = Store;
|
||||||
CallbackHelpInit({ scope: $scope });
|
CallbackHelpInit({ scope: $scope });
|
||||||
|
|
||||||
generator.inject(form, { mode: 'add', related: false, scope: $scope });
|
generator.inject(form, { mode: 'add', related: false, scope: $scope });
|
||||||
@@ -273,6 +274,118 @@ function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
input_type: "radio"
|
input_type: "radio"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if ($scope.removeLoadJobs) {
|
||||||
|
$scope.rmoveLoadJobs();
|
||||||
|
}
|
||||||
|
$scope.removeLoadJobs = $scope.$on('LoadJobs', function() {
|
||||||
|
// Retrieve detail record and prepopulate the form
|
||||||
|
var i, fld, data = $scope.Store("saved_job_template_for_survey").fields;
|
||||||
|
for (fld in form.fields) {
|
||||||
|
if (fld !== 'variables' && data[fld] !== null && data[fld] !== undefined) {
|
||||||
|
if (form.fields[fld].type === 'select') {
|
||||||
|
if(fld==="playbook"){
|
||||||
|
$scope[fld+"_options"] = data[fld+"_options"];
|
||||||
|
for (i = 0; i < $scope[fld + '_options'].length; i++) {
|
||||||
|
if (data[fld] === $scope[fld + '_options'][i]) {
|
||||||
|
$scope[fld] = $scope[fld + '_options'][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($scope[fld + '_options'] && $scope[fld + '_options'].length > 0) {
|
||||||
|
for (i = 0; i < $scope[fld + '_options'].length; i++) {
|
||||||
|
if (data[fld] === $scope[fld + '_options'][i].value) {
|
||||||
|
$scope[fld] = $scope[fld + '_options'][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$scope[fld] = data[fld];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$scope[fld] = data[fld];
|
||||||
|
if ( fld === "inventory" || fld === 'project' || fld === "credential" || fld === "cloud_credential"){
|
||||||
|
$scope[fld+"_name"] = data[fld+"_name"];
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (fld === 'variables') {
|
||||||
|
// // Parse extra_vars, converting to YAML.
|
||||||
|
// $scope.variables = ParseVariableString(data.extra_vars);
|
||||||
|
// master.variables = $scope.variables;
|
||||||
|
// }
|
||||||
|
if(fld ==='survey_enabled'){
|
||||||
|
$('#job_templates_survey_enabled_chbox').attr('checked', $scope[fld]);
|
||||||
|
$('#job_templates_delete_survey_btn').show();
|
||||||
|
$('#job_templates_edit_survey_btn').show();
|
||||||
|
$('#job_templates_create_survey_btn').hide();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
master[fld] = $scope[fld];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if (fld === 'variables') {
|
||||||
|
// // Parse extra_vars, converting to YAML.
|
||||||
|
// $scope.variables = ParseVariableString(data.extra_vars);
|
||||||
|
// master.variables = $scope.variables;
|
||||||
|
// }
|
||||||
|
|
||||||
|
$scope.ask_variables_on_launch = (data.ask_variables_on_launch) ? 'true' : 'false';
|
||||||
|
master.ask_variables_on_launch = $scope.ask_variables_on_launch;
|
||||||
|
|
||||||
|
// relatedSets = form.relatedSets(data.related);
|
||||||
|
|
||||||
|
if (data.host_config_key) {
|
||||||
|
$scope.example_config_key = data.host_config_key;
|
||||||
|
}
|
||||||
|
// $scope.example_template_id = id;
|
||||||
|
// $scope.setCallbackHelp();
|
||||||
|
|
||||||
|
// $scope.callback_url = $scope.callback_server_path + ((data.related.callback) ? data.related.callback :
|
||||||
|
// GetBasePath('job_templates') + id + '/callback/');
|
||||||
|
// master.callback_url = $scope.callback_url;
|
||||||
|
|
||||||
|
LookUpInit({
|
||||||
|
scope: $scope,
|
||||||
|
form: form,
|
||||||
|
current_item: data.inventory,
|
||||||
|
list: InventoryList,
|
||||||
|
field: 'inventory',
|
||||||
|
input_type: "radio"
|
||||||
|
});
|
||||||
|
|
||||||
|
LookUpInit({
|
||||||
|
url: GetBasePath('credentials') + '?kind=ssh',
|
||||||
|
scope: $scope,
|
||||||
|
form: form,
|
||||||
|
current_item: data.credential,
|
||||||
|
list: CredentialList,
|
||||||
|
field: 'credential',
|
||||||
|
hdr: 'Select Machine Credential',
|
||||||
|
input_type: "radio"
|
||||||
|
});
|
||||||
|
|
||||||
|
LookUpInit({
|
||||||
|
scope: $scope,
|
||||||
|
form: form,
|
||||||
|
current_item: data.project,
|
||||||
|
list: ProjectList,
|
||||||
|
field: 'project',
|
||||||
|
input_type: "radio"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if(Empty($scope.Store("saved_job_template_for_survey"))===false){
|
||||||
|
$scope.$emit("LoadJobs");
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.$on("$destroy", function(){
|
||||||
|
// alert('are you sure you wana leave?');
|
||||||
|
if($scope.Store("saved_job_template_for_survey").editing_survey!==true){
|
||||||
|
$scope.Store("saved_job_template_for_survey", false);
|
||||||
|
$scope.Store('survey_for_new_job_template' , false);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
function saveCompleted() {
|
function saveCompleted() {
|
||||||
setTimeout(function() { $scope.$apply(function() { $location.path('/job_templates'); }); }, 500);
|
setTimeout(function() { $scope.$apply(function() { $location.path('/job_templates'); }); }, 500);
|
||||||
}
|
}
|
||||||
@@ -313,6 +426,24 @@ function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
Rest.post(data)
|
Rest.post(data)
|
||||||
.success(function(data) {
|
.success(function(data) {
|
||||||
$scope.$emit('templateSaveSuccess', data);
|
$scope.$emit('templateSaveSuccess', data);
|
||||||
|
$scope.Store("saved_job_template_for_survey", false);
|
||||||
|
|
||||||
|
|
||||||
|
var url = data.url+ 'survey_spec/',
|
||||||
|
survey = $scope.Store('survey_for_new_job_template');
|
||||||
|
Rest.setUrl(url);
|
||||||
|
Rest.post({ name: survey.name, description: survey.description, spec: survey.spec })
|
||||||
|
.success(function () {
|
||||||
|
Wait('stop');
|
||||||
|
$scope.Store("survey_for_new_job_template", false);
|
||||||
|
// $location.path("/job_templates/"+id);
|
||||||
|
|
||||||
|
})
|
||||||
|
.error(function (data, status) {
|
||||||
|
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||||
|
msg: 'Failed to add new survey. Post returned status: ' + status });
|
||||||
|
});
|
||||||
|
// $scope.$emit('templateSaveSuccess', data);
|
||||||
})
|
})
|
||||||
.error(function (data, status) {
|
.error(function (data, status) {
|
||||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||||
@@ -335,17 +466,68 @@ function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
$scope[fld] = master[fld];
|
$scope[fld] = master[fld];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
//navigate to the survey maker
|
||||||
|
$scope.editSurvey = function() {
|
||||||
|
$location.path($location.path() + '/survey/edit');
|
||||||
|
};
|
||||||
|
//delete a survey by posting a blank survey
|
||||||
|
$scope.deleteSurvey = function() {
|
||||||
|
// $location.path($location.path() + '/survey/add');
|
||||||
|
// Wait('start');
|
||||||
|
// var url = defaultUrl+ id + '/survey_spec/';
|
||||||
|
|
||||||
|
// Rest.setUrl(url);
|
||||||
|
// Rest.post({})
|
||||||
|
// .success(function () {
|
||||||
|
$scope.Store("survey_for_new_job_template", false);
|
||||||
|
Wait('stop');
|
||||||
|
$('#job_templates_delete_survey_btn').hide();
|
||||||
|
$('#job_templates_edit_survey_btn').hide();
|
||||||
|
$('#job_templates_create_survey_btn').show();
|
||||||
|
|
||||||
|
// })
|
||||||
|
// .error(function (data, status) {
|
||||||
|
// ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||||
|
// msg: 'Failed to add new survey. Post returned status: ' + status });
|
||||||
|
// });
|
||||||
|
};
|
||||||
|
|
||||||
//navigate to the survey maker
|
//navigate to the survey maker
|
||||||
$scope.addSurvey = function() {
|
$scope.addSurvey = function() {
|
||||||
$location.path($location.path() + '/survey/add');
|
var data = {}, fld;
|
||||||
|
try {
|
||||||
|
for (fld in form.fields) {
|
||||||
|
if (form.fields[fld].type === 'select' && fld !== 'playbook') {
|
||||||
|
data[fld] = $scope[fld].value;
|
||||||
|
} else {
|
||||||
|
if (fld !== 'variables') {
|
||||||
|
data[fld] = $scope[fld];
|
||||||
|
if(fld === "inventory" || fld === "project" || fld === "credential" || fld === "cloud_credential" ){
|
||||||
|
data[fld+"_name"] = $scope[fld + "_name"];
|
||||||
|
}
|
||||||
|
if(fld === "playbook"){
|
||||||
|
data[fld+"_options"] = $scope[fld+"_options"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.extra_vars = ToJSON($scope.parseType, $scope.variables, true);
|
||||||
|
$scope.Store("saved_job_template_for_survey", {
|
||||||
|
"editing_survey" : true,
|
||||||
|
"fields" : data
|
||||||
|
});
|
||||||
|
$location.path($location.path() + '/survey/add');
|
||||||
|
} catch (err) {
|
||||||
|
Wait('stop');
|
||||||
|
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
JobTemplatesAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm',
|
JobTemplatesAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm',
|
||||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope',
|
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope',
|
||||||
'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit',
|
'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit',
|
||||||
'md5Setup', 'ParseTypeChange', 'Wait', 'Empty', 'ToJSON', 'CallbackHelpInit'
|
'md5Setup', 'ParseTypeChange', 'Wait', 'Empty', 'ToJSON', 'CallbackHelpInit', 'Store'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@@ -353,7 +535,7 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList,
|
Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList,
|
||||||
CredentialList, ProjectList, LookUpInit, GetBasePath, md5Setup, ParseTypeChange, JobStatusToolTip, FormatDate,
|
CredentialList, ProjectList, LookUpInit, GetBasePath, md5Setup, ParseTypeChange, JobStatusToolTip, FormatDate,
|
||||||
Wait, Stream, Empty, Prompt, ParseVariableString, ToJSON, SchedulesControllerInit, JobsControllerInit, JobsListUpdate,
|
Wait, Stream, Empty, Prompt, ParseVariableString, ToJSON, SchedulesControllerInit, JobsControllerInit, JobsListUpdate,
|
||||||
GetChoices, SchedulesListInit, SchedulesList, CallbackHelpInit, PlaybookRun)
|
GetChoices, SchedulesListInit, SchedulesList, CallbackHelpInit, PlaybookRun, Store)
|
||||||
{
|
{
|
||||||
|
|
||||||
ClearScope();
|
ClearScope();
|
||||||
@@ -369,6 +551,8 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
checkSCMStatus, getPlaybooks, callback,
|
checkSCMStatus, getPlaybooks, callback,
|
||||||
choicesCount = 0;
|
choicesCount = 0;
|
||||||
|
|
||||||
|
$scope.Store = Store;
|
||||||
|
|
||||||
CallbackHelpInit({ scope: $scope });
|
CallbackHelpInit({ scope: $scope });
|
||||||
|
|
||||||
SchedulesList.well = false;
|
SchedulesList.well = false;
|
||||||
@@ -595,6 +779,7 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
$scope.removeEnableSurvey();
|
$scope.removeEnableSurvey();
|
||||||
}
|
}
|
||||||
$scope.removeEnableSurvey = $scope.$on('EnableSurvey', function(fld) {
|
$scope.removeEnableSurvey = $scope.$on('EnableSurvey', function(fld) {
|
||||||
|
|
||||||
$('#job_templates_survey_enabled_chbox').attr('checked', $scope[fld]);
|
$('#job_templates_survey_enabled_chbox').attr('checked', $scope[fld]);
|
||||||
Rest.setUrl(defaultUrl + id+ '/survey_spec/');
|
Rest.setUrl(defaultUrl + id+ '/survey_spec/');
|
||||||
Rest.get()
|
Rest.get()
|
||||||
@@ -642,8 +827,19 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$scope[fld] = data[fld];
|
$scope[fld] = data[fld];
|
||||||
if(fld ==='survey_enabled' && $scope[fld]===true){
|
if(fld ==='survey_enabled'){
|
||||||
$scope.$emit('EnableSurvey', fld);
|
// $scope.$emit('EnableSurvey', fld);
|
||||||
|
$('#job_templates_survey_enabled_chbox').attr('checked', $scope[fld]);
|
||||||
|
if(Empty(data.related.survey_spec)){
|
||||||
|
$('#job_templates_delete_survey_btn').hide();
|
||||||
|
$('#job_templates_edit_survey_btn').hide();
|
||||||
|
$('#job_templates_create_survey_btn').show();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$('#job_templates_delete_survey_btn').show();
|
||||||
|
$('#job_templates_edit_survey_btn').show();
|
||||||
|
$('#job_templates_create_survey_btn').hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
master[fld] = $scope[fld];
|
master[fld] = $scope[fld];
|
||||||
@@ -848,6 +1044,31 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//handler for 'Enable Survey' button
|
||||||
|
$scope.surveyEnabled = function(){
|
||||||
|
Rest.setUrl(defaultUrl + id+ '/');
|
||||||
|
Rest.patch({"survey_enabled": $scope.survey_enabled})
|
||||||
|
.success(function (data) {
|
||||||
|
|
||||||
|
if(Empty(data.related.survey_spec)){
|
||||||
|
$('#job_templates_delete_survey_btn').hide();
|
||||||
|
$('#job_templates_edit_survey_btn').hide();
|
||||||
|
$('#job_templates_create_survey_btn').show();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$('#job_templates_delete_survey_btn').show();
|
||||||
|
$('#job_templates_edit_survey_btn').show();
|
||||||
|
$('#job_templates_create_survey_btn').hide();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.error(function (data, status) {
|
||||||
|
ProcessErrors($scope, data, status, form, {
|
||||||
|
hdr: 'Error!',
|
||||||
|
msg: 'Failed to retrieve save survey_enabled: ' + $routeParams.template_id + '. GET status: ' + status
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
//navigate to the survey maker
|
//navigate to the survey maker
|
||||||
$scope.addSurvey = function() {
|
$scope.addSurvey = function() {
|
||||||
$location.path($location.path() + '/survey/add');
|
$location.path($location.path() + '/survey/add');
|
||||||
@@ -855,6 +1076,7 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
|
|
||||||
//navigate to the survey maker
|
//navigate to the survey maker
|
||||||
$scope.editSurvey = function() {
|
$scope.editSurvey = function() {
|
||||||
|
$scope.Store("survey_for_new_job_template", false);
|
||||||
$location.path($location.path() + '/survey/edit');
|
$location.path($location.path() + '/survey/edit');
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -911,9 +1133,9 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
}
|
}
|
||||||
|
|
||||||
JobTemplatesEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm',
|
JobTemplatesEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm',
|
||||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit',
|
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit',
|
||||||
'ReturnToCaller', 'ClearScope', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit',
|
'ReturnToCaller', 'ClearScope', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit',
|
||||||
'GetBasePath', 'md5Setup', 'ParseTypeChange', 'JobStatusToolTip', 'FormatDate', 'Wait', 'Stream', 'Empty', 'Prompt',
|
'GetBasePath', 'md5Setup', 'ParseTypeChange', 'JobStatusToolTip', 'FormatDate', 'Wait', 'Stream', 'Empty', 'Prompt',
|
||||||
'ParseVariableString', 'ToJSON', 'SchedulesControllerInit', 'JobsControllerInit', 'JobsListUpdate', 'GetChoices',
|
'ParseVariableString', 'ToJSON', 'SchedulesControllerInit', 'JobsControllerInit', 'JobsListUpdate', 'GetChoices',
|
||||||
'SchedulesListInit', 'SchedulesList', 'CallbackHelpInit', 'PlaybookRun'
|
'SchedulesListInit', 'SchedulesList', 'CallbackHelpInit', 'PlaybookRun' , "Store"
|
||||||
];
|
];
|
||||||
@@ -10,13 +10,27 @@
|
|||||||
/**
|
/**
|
||||||
* @ngdoc function
|
* @ngdoc function
|
||||||
* @name controllers.function:SurveyMaker
|
* @name controllers.function:SurveyMaker
|
||||||
* @description This controller's for the survey maker page
|
* @description This controller's for the survey maker page.
|
||||||
|
* The survey maker interacts with the job template page, and the two go hand in hand. The scenarios are:
|
||||||
|
* New job template - add new survey
|
||||||
|
* New job template - edit new survey
|
||||||
|
* Edit existing job template - add new survey
|
||||||
|
* Edit Existing job template - edit existing survey
|
||||||
|
*
|
||||||
|
* Adding a new survey to any page takes the user to the Add New Survey page
|
||||||
|
* Adding a new survey to a new job template saves the survey to session memory (navigating to survey maker forces us to save JT in memory temporarily)
|
||||||
|
* Adding a new survey to an existing job template send the survey to the API
|
||||||
|
* Editing an existing survey takes the user to the Edit Survey page
|
||||||
|
* Editing a survey attached to a new job template saves the survey to session memory (saves the job template in session memory)
|
||||||
|
* Editing a survey attached to an existing job template saves the survey to the API
|
||||||
|
*
|
||||||
|
* The variables in local memory are cleaned out whenever the user navigates to a page (other than the Survey Maker page)
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function SurveyMakerAdd($scope, $rootScope, $compile, $location, $log, $routeParams, SurveyMakerForm,
|
function SurveyMakerAdd($scope, $rootScope, $compile, $location, $log, $routeParams, SurveyMakerForm,
|
||||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, GetBasePath,
|
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, GetBasePath,
|
||||||
ReturnToCaller, Wait, SurveyQuestionForm) {
|
ReturnToCaller, Wait, SurveyQuestionForm, Store) {
|
||||||
|
|
||||||
ClearScope();
|
ClearScope();
|
||||||
|
|
||||||
@@ -27,7 +41,7 @@ function SurveyMakerAdd($scope, $rootScope, $compile, $location, $log, $routePar
|
|||||||
id = $location.path().replace(/^\//, '').split('/')[1];
|
id = $location.path().replace(/^\//, '').split('/')[1];
|
||||||
|
|
||||||
$scope.survey_questions=[];
|
$scope.survey_questions=[];
|
||||||
|
$scope.Store = Store;
|
||||||
$scope.answer_types=[
|
$scope.answer_types=[
|
||||||
{name: 'Text' , type: 'text'},
|
{name: 'Text' , type: 'text'},
|
||||||
{name: 'Textarea', type: 'textarea'},
|
{name: 'Textarea', type: 'textarea'},
|
||||||
@@ -152,22 +166,65 @@ function SurveyMakerAdd($scope, $rootScope, $compile, $location, $log, $routePar
|
|||||||
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
|
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.formSave = function () {
|
||||||
|
generator.clearApiErrors();
|
||||||
|
Wait('start');
|
||||||
|
var url;
|
||||||
|
if(!$scope.Store("survey_for_new_job_template") && $scope.Store("survey_for_new_job_template")!==false){
|
||||||
|
$scope.Store('survey_for_new_job_template', {
|
||||||
|
// survey_created: true,
|
||||||
|
name: $scope.survey_name,
|
||||||
|
description: $scope.survey_description,
|
||||||
|
spec:$scope.survey_questions
|
||||||
|
});
|
||||||
|
Wait('stop');
|
||||||
|
$location.path("/job_templates/add/");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
url = GetBasePath(base)+ id + '/survey_spec/';
|
||||||
|
|
||||||
|
Rest.setUrl(url);
|
||||||
|
Rest.post({ name: $scope.survey_name, description: $scope.survey_description, spec:$scope.survey_questions })
|
||||||
|
.success(function () {
|
||||||
|
Wait('stop');
|
||||||
|
$location.path("/job_templates/"+id);
|
||||||
|
})
|
||||||
|
.error(function (data, status) {
|
||||||
|
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||||
|
msg: 'Failed to add new survey. Post returned status: ' + status });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
$scope.formSave = function () {
|
$scope.formSave = function () {
|
||||||
generator.clearApiErrors();
|
generator.clearApiErrors();
|
||||||
Wait('start');
|
Wait('start');
|
||||||
var url = GetBasePath(base)+ id + '/survey_spec/';
|
if($scope.Store("saved_job_template_for_survey")){
|
||||||
|
$scope.Store('survey_for_new_job_template', {
|
||||||
Rest.setUrl(url);
|
// survey_created: true,
|
||||||
Rest.post({ name: $scope.survey_name, description: $scope.survey_description, spec:$scope.survey_questions })
|
name: $scope.survey_name,
|
||||||
.success(function () {
|
description: $scope.survey_description,
|
||||||
Wait('stop');
|
spec:$scope.survey_questions
|
||||||
$location.path("/job_templates/"+id);
|
|
||||||
})
|
|
||||||
.error(function (data, status) {
|
|
||||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
|
||||||
msg: 'Failed to add new survey. Post returned status: ' + status });
|
|
||||||
});
|
});
|
||||||
|
Wait('stop');
|
||||||
|
$location.path("/job_templates/add/");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
var url = GetBasePath(base)+ id + '/survey_spec/';
|
||||||
|
Rest.setUrl(url);
|
||||||
|
Rest.post({ name: $scope.survey_name, description: $scope.survey_description, spec:$scope.survey_questions })
|
||||||
|
.success(function () {
|
||||||
|
Wait('stop');
|
||||||
|
$location.path("/job_templates/"+id);
|
||||||
|
})
|
||||||
|
.error(function (data, status) {
|
||||||
|
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||||
|
msg: 'Failed to add new survey. Post returned status: ' + status });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Cancel
|
// Cancel
|
||||||
@@ -178,12 +235,12 @@ function SurveyMakerAdd($scope, $rootScope, $compile, $location, $log, $routePar
|
|||||||
}
|
}
|
||||||
|
|
||||||
SurveyMakerAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'SurveyMakerForm',
|
SurveyMakerAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'SurveyMakerForm',
|
||||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath', 'ReturnToCaller', 'Wait', 'SurveyQuestionForm'
|
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath', 'ReturnToCaller', 'Wait', 'SurveyQuestionForm', 'Store'
|
||||||
];
|
];
|
||||||
|
|
||||||
function SurveyMakerEdit($scope, $rootScope, $compile, $location, $log, $routeParams, SurveyMakerForm,
|
function SurveyMakerEdit($scope, $rootScope, $compile, $location, $log, $routeParams, SurveyMakerForm,
|
||||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, GetBasePath,
|
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, GetBasePath,
|
||||||
ReturnToCaller, Wait, SurveyQuestionForm) {
|
ReturnToCaller, Wait, SurveyQuestionForm, Store) {
|
||||||
|
|
||||||
ClearScope();
|
ClearScope();
|
||||||
|
|
||||||
@@ -191,7 +248,8 @@ function SurveyMakerEdit($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
var generator = GenerateForm,
|
var generator = GenerateForm,
|
||||||
form = SurveyMakerForm,
|
form = SurveyMakerForm,
|
||||||
base = $location.path().replace(/^\//, '').split('/')[0],
|
base = $location.path().replace(/^\//, '').split('/')[0],
|
||||||
id = $location.path().replace(/^\//, '').split('/')[1];
|
id = $location.path().replace(/^\//, '').split('/')[1],
|
||||||
|
i, data;
|
||||||
|
|
||||||
$scope.survey_questions=[];
|
$scope.survey_questions=[];
|
||||||
|
|
||||||
@@ -205,6 +263,7 @@ function SurveyMakerEdit($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
{name: 'Float', type: 'number'}
|
{name: 'Float', type: 'number'}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$scope.Store = Store;
|
||||||
|
|
||||||
generator.inject(form, { mode: 'edit', related: false, scope: $scope});
|
generator.inject(form, { mode: 'edit', related: false, scope: $scope});
|
||||||
generator.reset();
|
generator.reset();
|
||||||
@@ -291,45 +350,56 @@ function SurveyMakerEdit($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
|
|
||||||
Wait('start');
|
Wait('start');
|
||||||
|
|
||||||
Rest.setUrl(GetBasePath(base)+ id + '/survey_spec/');
|
if($scope.Store("saved_job_template_for_survey") && $scope.Store("saved_job_template_for_survey").editing_survey===true){
|
||||||
Rest.get()
|
data = $scope.Store("survey_for_new_job_template");
|
||||||
.success(function (data) {
|
$scope.survey_name = data.name;
|
||||||
var i;
|
$scope.survey_description = data.description;
|
||||||
$scope.survey_name = data.name;
|
$scope.survey_questions = data.spec;
|
||||||
$scope.survey_description = data.description;
|
for(i=0; i<$scope.survey_questions.length; i++){
|
||||||
$scope.survey_questions = data.spec;
|
$scope.finalizeQuestion($scope.survey_questions[i]);
|
||||||
for(i=0; i<$scope.survey_questions.length; i++){
|
}
|
||||||
$scope.finalizeQuestion($scope.survey_questions[i]);
|
Wait('stop');
|
||||||
}
|
}
|
||||||
Wait('stop');
|
else{
|
||||||
// LoadBreadCrumbs({ path: '/organizations/' + id, title: data.name });
|
Rest.setUrl(GetBasePath(base)+ id + '/survey_spec/');
|
||||||
// for (fld in form.fields) {
|
Rest.get()
|
||||||
// if (data[fld]) {
|
.success(function (data) {
|
||||||
// $scope[fld] = data[fld];
|
var i;
|
||||||
// master[fld] = data[fld];
|
$scope.survey_name = data.name;
|
||||||
// }
|
$scope.survey_description = data.description;
|
||||||
// }
|
$scope.survey_questions = data.spec;
|
||||||
|
for(i=0; i<$scope.survey_questions.length; i++){
|
||||||
|
$scope.finalizeQuestion($scope.survey_questions[i]);
|
||||||
|
}
|
||||||
|
Wait('stop');
|
||||||
|
// LoadBreadCrumbs({ path: '/organizations/' + id, title: data.name });
|
||||||
|
// for (fld in form.fields) {
|
||||||
|
// if (data[fld]) {
|
||||||
|
// $scope[fld] = data[fld];
|
||||||
|
// master[fld] = data[fld];
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// related = data.related;
|
// related = data.related;
|
||||||
// for (set in form.related) {
|
// for (set in form.related) {
|
||||||
// if (related[set]) {
|
// if (related[set]) {
|
||||||
// relatedSets[set] = {
|
// relatedSets[set] = {
|
||||||
// url: related[set],
|
// url: related[set],
|
||||||
// iterator: form.related[set].iterator
|
// iterator: form.related[set].iterator
|
||||||
// };
|
// };
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
|
||||||
// RelatedSearchInit({ scope: $scope, form: form, relatedSets: relatedSets });
|
|
||||||
// RelatedPaginateInit({ scope: $scope, relatedSets: relatedSets });
|
|
||||||
// $scope.$emit('organizationLoaded');
|
|
||||||
})
|
|
||||||
.error(function (data, status) {
|
|
||||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
|
||||||
msg: 'Failed to retrieve organization: ' + $routeParams.id + '. GET status: ' + status });
|
|
||||||
});
|
|
||||||
|
|
||||||
|
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
||||||
|
// RelatedSearchInit({ scope: $scope, form: form, relatedSets: relatedSets });
|
||||||
|
// RelatedPaginateInit({ scope: $scope, relatedSets: relatedSets });
|
||||||
|
// $scope.$emit('organizationLoaded');
|
||||||
|
})
|
||||||
|
.error(function (data, status) {
|
||||||
|
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||||
|
msg: 'Failed to retrieve organization: ' + $routeParams.id + '. GET status: ' + status });
|
||||||
|
});
|
||||||
|
}
|
||||||
$scope.submitQuestion = function(){
|
$scope.submitQuestion = function(){
|
||||||
var form = SurveyQuestionForm,
|
var form = SurveyQuestionForm,
|
||||||
data = {},
|
data = {},
|
||||||
@@ -375,18 +445,31 @@ function SurveyMakerEdit($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
$scope.formSave = function () {
|
$scope.formSave = function () {
|
||||||
generator.clearApiErrors();
|
generator.clearApiErrors();
|
||||||
Wait('start');
|
Wait('start');
|
||||||
var url = GetBasePath(base)+ id + '/survey_spec/';
|
var url;
|
||||||
|
if($scope.Store("survey_for_new_job_template") && $scope.Store("survey_for_new_job_template")!==false){
|
||||||
Rest.setUrl(url);
|
$scope.Store('survey_for_new_job_template', {
|
||||||
Rest.post({ name: $scope.survey_name, description: $scope.survey_description, spec:$scope.survey_questions })
|
// survey_created: true,
|
||||||
.success(function () {
|
name: $scope.survey_name,
|
||||||
Wait('stop');
|
description: $scope.survey_description,
|
||||||
$location.path("/job_templates/"+id);
|
spec:$scope.survey_questions
|
||||||
})
|
|
||||||
.error(function (data, status) {
|
|
||||||
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
|
||||||
msg: 'Failed to add new survey. Post returned status: ' + status });
|
|
||||||
});
|
});
|
||||||
|
Wait('stop');
|
||||||
|
$location.path("/job_templates/add/");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
url = GetBasePath(base)+ id + '/survey_spec/';
|
||||||
|
|
||||||
|
Rest.setUrl(url);
|
||||||
|
Rest.post({ name: $scope.survey_name, description: $scope.survey_description, spec:$scope.survey_questions })
|
||||||
|
.success(function () {
|
||||||
|
Wait('stop');
|
||||||
|
$location.path("/job_templates/"+id);
|
||||||
|
})
|
||||||
|
.error(function (data, status) {
|
||||||
|
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
|
||||||
|
msg: 'Failed to add new survey. Post returned status: ' + status });
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Cancel
|
// Cancel
|
||||||
@@ -397,7 +480,7 @@ function SurveyMakerEdit($scope, $rootScope, $compile, $location, $log, $routePa
|
|||||||
}
|
}
|
||||||
|
|
||||||
SurveyMakerEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'SurveyMakerForm',
|
SurveyMakerEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'SurveyMakerForm',
|
||||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath', 'ReturnToCaller', 'Wait', 'SurveyQuestionForm'
|
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath', 'ReturnToCaller', 'Wait', 'SurveyQuestionForm', 'Store'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ angular.module('JobTemplateFormDefinition', ['SchedulesListDefinition', 'Complet
|
|||||||
job_type: {
|
job_type: {
|
||||||
label: 'Job Type',
|
label: 'Job Type',
|
||||||
type: 'select',
|
type: 'select',
|
||||||
ngOptions: 'type.label for type in job_type_options',
|
ngOptions: 'type.label for type in job_type_options track by type.value',
|
||||||
"default": 0,
|
"default": 0,
|
||||||
addRequired: true,
|
addRequired: true,
|
||||||
editRequired: true,
|
editRequired: true,
|
||||||
@@ -106,7 +106,7 @@ angular.module('JobTemplateFormDefinition', ['SchedulesListDefinition', 'Complet
|
|||||||
playbook: {
|
playbook: {
|
||||||
label: 'Playbook',
|
label: 'Playbook',
|
||||||
type:'select',
|
type:'select',
|
||||||
ngOptions: 'book for book in playbook_options',
|
ngOptions: 'book for book in playbook_options track by book',
|
||||||
id: 'playbook-select',
|
id: 'playbook-select',
|
||||||
awRequiredWhen: {variable: "playbookrequired", init: "true" },
|
awRequiredWhen: {variable: "playbookrequired", init: "true" },
|
||||||
column: 1,
|
column: 1,
|
||||||
@@ -180,7 +180,7 @@ angular.module('JobTemplateFormDefinition', ['SchedulesListDefinition', 'Complet
|
|||||||
verbosity: {
|
verbosity: {
|
||||||
label: 'Verbosity',
|
label: 'Verbosity',
|
||||||
type: 'select',
|
type: 'select',
|
||||||
ngOptions: 'v.label for v in verbosity_options',
|
ngOptions: 'v.label for v in verbosity_options track by v.value',
|
||||||
"default": 0,
|
"default": 0,
|
||||||
addRequired: true,
|
addRequired: true,
|
||||||
editRequired: true,
|
editRequired: true,
|
||||||
@@ -261,6 +261,7 @@ angular.module('JobTemplateFormDefinition', ['SchedulesListDefinition', 'Complet
|
|||||||
editRequird: false,
|
editRequird: false,
|
||||||
trueValue: 'true',
|
trueValue: 'true',
|
||||||
falseValue: 'false',
|
falseValue: 'false',
|
||||||
|
ngChange: "surveyEnabled()",
|
||||||
column: 2,
|
column: 2,
|
||||||
awPopOver: "<p>If checked, user will be prompted at job launch with a series of questions related to the job.</p>",
|
awPopOver: "<p>If checked, user will be prompted at job launch with a series of questions related to the job.</p>",
|
||||||
dataPlacement: 'right',
|
dataPlacement: 'right',
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ angular.module('SurveyQuestionFormDefinition', [])
|
|||||||
realName: 'answer_type',
|
realName: 'answer_type',
|
||||||
label: 'Answer Type',
|
label: 'Answer Type',
|
||||||
type: 'select',
|
type: 'select',
|
||||||
ngOptions: 'answer_types.name for answer_types in answer_types',
|
ngOptions: 'answer_types.name for answer_types in answer_types track by answer_types.type',
|
||||||
addRequired: true,
|
addRequired: true,
|
||||||
editRequired: true,
|
editRequired: true,
|
||||||
column: 1
|
column: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user