From d3e793e9ca6370cffac8a3dea10bb6c2bc3dd452 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Sun, 21 Sep 2014 13:16:06 -0400 Subject: [PATCH] changed survey maker to a modal window --- awx/ui/static/js/app.js | 1 + awx/ui/static/js/controllers/JobTemplates.js | 458 ++++++------ awx/ui/static/js/forms/SurveyMaker.js | 24 +- awx/ui/static/js/forms/SurveyQuestion.js | 9 +- awx/ui/static/js/helpers/Survey.js | 697 +++++++++++++++++++ awx/ui/static/partials/job_templates.html | 2 + awx/ui/static/partials/survey_maker.html | 4 +- awx/ui/templates/ui/index.html | 1 + 8 files changed, 966 insertions(+), 230 deletions(-) create mode 100644 awx/ui/static/js/helpers/Survey.js diff --git a/awx/ui/static/js/app.js b/awx/ui/static/js/app.js index e6453d0613..90cff95d24 100644 --- a/awx/ui/static/js/app.js +++ b/awx/ui/static/js/app.js @@ -109,6 +109,7 @@ angular.module('Tower', [ 'LogViewerOptionsDefinition', 'EventViewerHelper', 'HostEventsViewerHelper', + 'SurveyHelper', 'JobDetailHelper', 'SocketIO', 'lrInfiniteScroll', diff --git a/awx/ui/static/js/controllers/JobTemplates.js b/awx/ui/static/js/controllers/JobTemplates.js index 922704cecc..274be543eb 100644 --- a/awx/ui/static/js/controllers/JobTemplates.js +++ b/awx/ui/static/js/controllers/JobTemplates.js @@ -111,7 +111,7 @@ JobTemplatesList.$inject = ['$scope', '$rootScope', '$location', '$log', '$route function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, GetBasePath, InventoryList, CredentialList, ProjectList, LookUpInit, md5Setup, ParseTypeChange, Wait, Empty, ToJSON, - CallbackHelpInit, Store) { + CallbackHelpInit, SurveyControllerInit) { ClearScope(); @@ -124,7 +124,6 @@ function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routePa selectPlaybook, checkSCMStatus, callback; - $scope.Store = Store; CallbackHelpInit({ scope: $scope }); generator.inject(form, { mode: 'add', related: false, scope: $scope }); @@ -133,7 +132,7 @@ function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routePa // Make sure the form controller knows there was a change $scope[form.name + '_form'].setDirty(); }; - + $scope.mode = "add"; $scope.parseType = 'yaml'; ParseTypeChange({ scope: $scope, field_id: 'job_templates_variables', onChange: callback }); @@ -198,6 +197,12 @@ function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routePa input_type: "radio" }); + SurveyControllerInit({ + scope: $scope, + parent_scope: $scope, + // iterator: 'schedule' + }); + // Update playbook select whenever project value changes selectPlaybook = function (oldValue, newValue) { var url; @@ -274,117 +279,129 @@ function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routePa input_type: "radio" }); - if ($scope.removeLoadJobs) { - $scope.rmoveLoadJobs(); + if ($scope.removeSurveySaved) { + $scope.rmoveSurveySaved(); } - $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"]; - } + $scope.removeSurveySaved = $scope.$on('SurveySaved', function() { + Wait('stop'); + $('#job_templates_survey_enabled_chbox').attr('checked', true); + $('#job_templates_delete_survey_btn').show(); + $('#job_templates_edit_survey_btn').show(); + $('#job_templates_create_survey_btn').hide(); - // 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"); - } + // 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"]; + // } - $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); - } + // // 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() { setTimeout(function() { $scope.$apply(function() { $location.path('/job_templates'); }); }, 500); @@ -426,24 +443,20 @@ function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routePa Rest.post(data) .success(function(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'); + //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: survey.name, description: survey.description, spec: survey.spec }) + Rest.post({ name: $scope.survey_name, description: $scope.survey_description, spec: $scope.survey_questions }) .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) { ProcessErrors($scope, data, status, form, { hdr: 'Error!', @@ -467,11 +480,11 @@ function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routePa } }; //navigate to the survey maker - $scope.editSurvey = function() { - $location.path($location.path() + '/survey/edit'); - }; + // $scope.editSurvey = function() { + // $location.path($location.path() + '/survey/edit'); + // }; //delete a survey by posting a blank survey - $scope.deleteSurvey = function() { + // $scope.deleteSurvey = function() { // $location.path($location.path() + '/survey/add'); // Wait('start'); // var url = defaultUrl+ id + '/survey_spec/'; @@ -479,55 +492,60 @@ function JobTemplatesAdd($scope, $rootScope, $compile, $location, $log, $routePa // 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(); + // $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 - $scope.addSurvey = function() { - 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); - } - }; + // $scope.addSurvey = function() { + // SurveyControllerInit({ + // scope: $scope, + // parent_scope: $scope, + // iterator: 'schedule' + // }); + // 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', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit', - 'md5Setup', 'ParseTypeChange', 'Wait', 'Empty', 'ToJSON', 'CallbackHelpInit', 'Store' + 'md5Setup', 'ParseTypeChange', 'Wait', 'Empty', 'ToJSON', 'CallbackHelpInit', 'SurveyControllerInit' ]; @@ -535,7 +553,7 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList, CredentialList, ProjectList, LookUpInit, GetBasePath, md5Setup, ParseTypeChange, JobStatusToolTip, FormatDate, Wait, Stream, Empty, Prompt, ParseVariableString, ToJSON, SchedulesControllerInit, JobsControllerInit, JobsListUpdate, - GetChoices, SchedulesListInit, SchedulesList, CallbackHelpInit, PlaybookRun, Store) + GetChoices, SchedulesListInit, SchedulesList, CallbackHelpInit, PlaybookRun, SurveyControllerInit) { ClearScope(); @@ -551,13 +569,11 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP checkSCMStatus, getPlaybooks, callback, choicesCount = 0; - $scope.Store = Store; - CallbackHelpInit({ scope: $scope }); SchedulesList.well = false; generator.inject(form, { mode: 'edit', related: true, scope: $scope }); - + $scope.mode = 'edit'; $scope.parseType = 'yaml'; $scope.showJobType = false; @@ -573,6 +589,12 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP { value: 3, label: 'Debug' } ]; + SurveyControllerInit({ + scope: $scope, + parent_scope: $scope, + id: id + }); + callback = function() { // Make sure the form controller knows there was a change $scope[form.name + '_form'].$setDirty(); @@ -803,6 +825,18 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP }); }); + if ($scope.removeSurveySaved) { + $scope.rmoveSurveySaved(); + } + $scope.removeSurveySaved = $scope.$on('SurveySaved', function() { + Wait('stop'); + $('#job_templates_survey_enabled_chbox').attr('checked', true); + $('#job_templates_delete_survey_btn').show(); + $('#job_templates_edit_survey_btn').show(); + $('#job_templates_create_survey_btn').hide(); + + }); + if ($scope.removeLoadJobs) { $scope.rmoveLoadJobs(); } @@ -1070,66 +1104,66 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP }; //navigate to the survey maker - $scope.addSurvey = function() { - $location.path($location.path() + '/survey/add'); - }; + // $scope.addSurvey = function() { + // $location.path($location.path() + '/survey/add'); + // }; //navigate to the survey maker - $scope.editSurvey = function() { - $scope.Store("survey_for_new_job_template", false); - $location.path($location.path() + '/survey/edit'); - }; + // $scope.editSurvey = function() { + // $scope.Store("survey_for_new_job_template", false); + // $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/'; + // //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 () { - Wait('stop'); - $('#job_templates_delete_survey_btn').hide(); - $('#job_templates_edit_survey_btn').hide(); - $('#job_templates_create_survey_btn').show(); + // Rest.setUrl(url); + // Rest.post({}) + // .success(function () { + // 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 }); - }); - }; + // }) + // .error(function (data, status) { + // ProcessErrors($scope, data, status, form, { hdr: 'Error!', + // msg: 'Failed to add new survey. Post returned status: ' + status }); + // }); + // }; - // Related set: Delete button - $scope['delete'] = function (set, itm_id, name, title) { - $rootScope.flashMessage = null; + // // Related set: Delete button + // $scope['delete'] = function (set, itm_id, name, title) { + // $rootScope.flashMessage = null; - var action = function () { - var url = defaultUrl + id + '/' + set + '/'; - Rest.setUrl(url); - Rest.post({ - id: itm_id, - disassociate: 1 - }) - .success(function () { - $('#prompt-modal').modal('hide'); - $scope.search(form.related[set].iterator); - }) - .error(function (data, status) { - $('#prompt-modal').modal('hide'); - ProcessErrors($scope, data, status, null, { hdr: 'Error!', - msg: 'Call to ' + url + ' failed. POST returned status: ' + status }); - }); - }; + // var action = function () { + // var url = defaultUrl + id + '/' + set + '/'; + // Rest.setUrl(url); + // Rest.post({ + // id: itm_id, + // disassociate: 1 + // }) + // .success(function () { + // $('#prompt-modal').modal('hide'); + // $scope.search(form.related[set].iterator); + // }) + // .error(function (data, status) { + // $('#prompt-modal').modal('hide'); + // ProcessErrors($scope, data, status, null, { hdr: 'Error!', + // msg: 'Call to ' + url + ' failed. POST returned status: ' + status }); + // }); + // }; - Prompt({ - hdr: 'Delete', - body: 'Are you sure you want to remove ' + name + ' from ' + $scope.name + ' ' + title + '?', - action: action - }); + // Prompt({ + // hdr: 'Delete', + // body: 'Are you sure you want to remove ' + name + ' from ' + $scope.name + ' ' + title + '?', + // action: action + // }); - }; + // }; } JobTemplatesEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm', @@ -1137,5 +1171,5 @@ JobTemplatesEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$l 'ReturnToCaller', 'ClearScope', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit', 'GetBasePath', 'md5Setup', 'ParseTypeChange', 'JobStatusToolTip', 'FormatDate', 'Wait', 'Stream', 'Empty', 'Prompt', 'ParseVariableString', 'ToJSON', 'SchedulesControllerInit', 'JobsControllerInit', 'JobsListUpdate', 'GetChoices', - 'SchedulesListInit', 'SchedulesList', 'CallbackHelpInit', 'PlaybookRun' , "Store" + 'SchedulesListInit', 'SchedulesList', 'CallbackHelpInit', 'PlaybookRun' , 'SurveyControllerInit' ]; \ No newline at end of file diff --git a/awx/ui/static/js/forms/SurveyMaker.js b/awx/ui/static/js/forms/SurveyMaker.js index 2eb676d188..1dcf2b7903 100644 --- a/awx/ui/static/js/forms/SurveyMaker.js +++ b/awx/ui/static/js/forms/SurveyMaker.js @@ -17,9 +17,9 @@ angular.module('SurveyMakerFormDefinition', []) addTitle: 'Add Survey', //Title in add mode editTitle: 'Edit Survey', //Title in edit mode name: 'survey_maker', //entity or model name in singular form - well: true, - //breadCrumbs:true, - // collapse: true, + // // well: true, + breadCrumbs: false, + // // collapse: true, // collapseTitle: "Properties", // collapseMode: 'edit', // collapseOpen: true, @@ -54,21 +54,21 @@ angular.module('SurveyMakerFormDefinition', []) type: 'custom', control: ''+ '
'+ - ''+ + ''+ '
' } }, buttons: { //for now always generates