changed survey maker to a modal window

This commit is contained in:
Jared Tabor 2014-09-21 13:16:06 -04:00
parent 9520970817
commit d3e793e9ca
8 changed files with 966 additions and 230 deletions

View File

@ -109,6 +109,7 @@ angular.module('Tower', [
'LogViewerOptionsDefinition',
'EventViewerHelper',
'HostEventsViewerHelper',
'SurveyHelper',
'JobDetailHelper',
'SocketIO',
'lrInfiniteScroll',

View File

@ -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'
];

View File

@ -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: '<label for="survey"><span class="label-text prepend-asterisk">Questions</span></label>'+
'<div id="survey_maker_question_area"></div><div id="finalized_questions"></div>'+
'<button style="display:none" type="button" class="btn btn-sm btn-primary" id="add_question_btn" aw-tool-tip="Create a new question" data-placement="top" data-original-title="" title="" disabled><i class="fa fa-plus fa-lg"></i> Add Question</button>'+
'<button style="display:none" type="button" class="btn btn-sm btn-primary" id="add_question_btn" ng-click="addNewQuestion()" aw-tool-tip="Create a new question" data-placement="top" data-original-title="" title="" disabled><i class="fa fa-plus fa-lg"></i> Add Question</button>'+
'<div id="new_question"></div>'
}
},
buttons: { //for now always generates <button> tags
save: {
ngClick: 'formSave()', //$scope.function to call on click, optional
ngDisabled: true //Disable when $pristine or $invalid, optional
},
reset: {
ngClick: 'formReset()',
ngDisabled: true //Disabled when $pristine
}
// save: {
// ngClick: 'formSave()', //$scope.function to call on click, optional
// ngDisabled: true //Disable when $pristine or $invalid, optional
// },
// reset: {
// ngClick: 'formReset()',
// ngDisabled: true //Disabled when $pristine
// }
}
});

View File

@ -15,7 +15,7 @@ angular.module('SurveyQuestionFormDefinition', [])
.value('SurveyQuestionForm', {
addTitle: 'Add Question',
editTitle: '{{ survey_name }}',
// editTitle: '{{ survey_name }}',
name: 'question_unique',
well: true,
twoColumns: true,
@ -39,7 +39,6 @@ angular.module('SurveyQuestionFormDefinition', [])
type: 'text',
addRequired: true,
editRequired: true,
capitalize: false,
column: 1
},
question_description: {
@ -47,8 +46,8 @@ angular.module('SurveyQuestionFormDefinition', [])
label: 'Question Description',
type: 'textarea',
rows: 2,
addRequired: false,
editRequired: false,
addRequired: true,
editRequired: true,
column: 2
},
variable: {
@ -91,7 +90,7 @@ angular.module('SurveyQuestionFormDefinition', [])
rows: 3,
addRequired: true,
editRequired: true,
ngShow: 'type.type==="multipleselect" || type.type==="multiplechoice" ',
ngShow: 'type.type==="multiselect" || type.type==="multiplechoice" ',
awPopOver: '<p>Type an option on each line.</p>'+
'<p>For example the following input:<br><br>Apple<br>\n Banana<br>\n Cherry<br><br>would be displayed as:</p>\n'+
'<ol><li>Apple</li><li>Banana</li><li>Cherry</li><ol>',

View File

@ -0,0 +1,697 @@
/*********************************************
* Copyright (c) 2014 AnsibleWorks, Inc.
*/
/**
* @ngdoc function
* @name helpers.function:Schedules
* @description
* Schedules Helper
*
* Display the scheduler widget in a dialog
*
*/
'use strict';
angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', 'SearchHelper', 'PaginationHelpers', 'ListGenerator', 'ModalDialog',
'GeneratorHelpers'])
.factory('ShowSurveyModal', ['Wait', 'CreateDialog', function(Wait, CreateDialog) {
return function(params) {
// Set modal dimensions based on viewport width
var buttons,
scope = params.scope,
callback = params.callback,
title = params.title;
buttons = [{
"label": "Cancel",
"onClick": function() {
$(this).dialog('close');
},
"icon": "fa-times",
"class": "btn btn-default",
"id": "survey-close-button"
},{
"label": "Save",
"onClick": function() {
setTimeout(function(){
scope.$apply(function(){
scope.saveSurvey();
});
});
},
"icon": "fa-check",
"class": "btn btn-primary",
"id": "survey-save-button"
}];
CreateDialog({
id: 'survey-modal-dialog',
title: title,
scope: scope,
buttons: buttons,
width: 700,
height: 725,
minWidth: 400,
onClose: function() {
$('#survey-modal-dialog #form-container').empty();
},
onOpen: function() {
Wait('stop');
$('#survey-tabs a:first').tab('show');
// $('#surveyName').focus();
// $('#rrule_nlp_description').dblclick(function() {
// setTimeout(function() { scope.$apply(function() { scope.showRRule = (scope.showRRule) ? false : true; }); }, 100);
// });
},
callback: callback
});
};
}])
.factory('EditSurvey', ['$routeParams','SchedulerInit', 'ShowSurveyModal', 'Wait', 'Rest', 'ProcessErrors', 'GetBasePath', 'GenerateForm', 'SurveyMakerForm',
function($routeParams, SchedulerInit, ShowSurveyModal, Wait, Rest, ProcessErrors, GetBasePath, GenerateForm,SurveyMakerForm) {
return function(params) {
var scope = params.scope,
id = params.id,
// callback = params.callback,
tempSurv = {},
generator = GenerateForm,
form = SurveyMakerForm,
labels={
"type": "Type",
"question_name": "Question Text",
"question_description": "Question Description",
"variable": "Answer Varaible Name",
"choices": "Choices",
"min": "Min",
"max": "Max",
"required": "Required",
"default": "Default Answer"
},
url = GetBasePath('job_templates') + id + '/survey_spec/', i;
if (scope.removeDialogReady) {
scope.removeDialogReady();
}
scope.removeDialogReady = scope.$on('DialogReady', function() {
$('#survey-modal-dialog').dialog('open');
// $('#schedulerName').focus();
// setTimeout(function() {
// scope.$apply(function() {
// scheduler.setRRule(schedule.rrule);
// scheduler.setName(schedule.name);
// });
// }, 300);
});
scope.saveSurvey = function() {
Wait('start');
if(scope.mode==="add"){
$('#survey-modal-dialog').dialog('close');
scope.$emit('SurveySaved');
}
else{
// 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');
$('#survey-modal-dialog').dialog('close');
scope.$emit('SurveySaved');
})
.error(function (data, status) {
ProcessErrors(scope, data, status, form, { hdr: 'Error!',
msg: 'Failed to add new survey. Post returned status: ' + status });
});
}
};
Wait('start');
if(scope.mode === 'add'){
tempSurv.survey_name = scope.survey_name;
tempSurv.survey_description = scope.survey_description;
generator.inject(form, { id: 'survey-modal-dialog' , mode: 'edit', related: false, scope: scope, breadCrumbs: false });
ShowSurveyModal({ title: "Edit Survey", scope: scope, callback: 'DialogReady' });
scope.survey_name = tempSurv.survey_name;
scope.survey_description = tempSurv.survey_description;
// scope.survey_questions = data.spec;
for(i=0; i<scope.survey_questions.length; i++){
scope.finalizeQuestion(scope.survey_questions[i], labels);
}
}
else{
// Get the existing record
Rest.setUrl(url);
Rest.get()
.success(function (data) {
// var i;
generator.inject(form, { id: 'survey-modal-dialog' , mode: 'edit', related: false, scope: scope, breadCrumbs: false });
ShowSurveyModal({ title: "Edit Survey", scope: scope, callback: 'DialogReady' });
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], labels);
}
Wait('stop');
})
.error(function (data, status) {
ProcessErrors(scope, data, status, form, { hdr: 'Error!',
msg: 'Failed to retrieve organization: ' + $routeParams.id + '. GET status: ' + status });
});
}
};
}])
.factory('AddSurvey', ['$location', '$routeParams', 'SchedulerInit', 'ShowSurveyModal', 'Wait', 'GetBasePath', 'Empty',
'SchedulePost', 'GenerateForm', 'SurveyMakerForm',
function($location, $routeParams, SchedulerInit, ShowSurveyModal, Wait, GetBasePath, Empty, SchedulePost, GenerateForm, SurveyMakerForm) {
return function(params) {
var scope = params.scope,
// callback= params.callback,
// base = $location.path().replace(/^\//, '').split('/')[0],
// url = GetBasePath(base),
generator = GenerateForm,
form = SurveyMakerForm;
// if (!Empty($routeParams.template_id)) {
// url += $routeParams.template_id + '/survey_spec/';
// }
// else if (!Empty($routeParams.id)) {
// url += $routeParams.id + '/survey_spec/';
// }
if (scope.removeDialogReady) {
scope.removeDialogReady();
}
scope.removeDialogReady = scope.$on('DialogReady', function() {
scope.addQuestion();
$('#survey-modal-dialog').dialog('open');
// $('#surveyName').focus();
});
Wait('start');
$('#form-container').empty();
generator.inject(form, { id: 'survey-modal-dialog' , mode: 'add', related: false, scope: scope, breadCrumbs: false });
ShowSurveyModal({ title: "Add Survey", scope: scope, callback: 'DialogReady' });
if (scope.removeScheduleSaved) {
scope.removeScheduleSaved();
}
scope.removeScheduleSaved = scope.$on('ScheduleSaved', function() {
Wait('stop');
$('#survey-modal-dialog').dialog('close');
scope.$emit('surveySaved');
});
scope.saveSurvey = function() {
Wait('start');
$('#survey-modal-dialog').dialog('close');
scope.$emit('SurveySaved');
};
};
}])
.factory('SchedulePost', ['Rest', 'ProcessErrors', 'RRuleToAPI', 'Wait', function(Rest, ProcessErrors, RRuleToAPI, Wait) {
return function(params) {
var scope = params.scope,
url = params.url,
scheduler = params.scheduler,
mode = params.mode,
schedule = (params.schedule) ? params.schedule : {},
callback = params.callback,
newSchedule, rrule;
if (scheduler.isValid()) {
Wait('start');
newSchedule = scheduler.getValue();
rrule = scheduler.getRRule();
schedule.name = newSchedule.name;
schedule.rrule = RRuleToAPI(rrule.toString());
schedule.description = (/error/.test(rrule.toText())) ? '' : rrule.toText();
Rest.setUrl(url);
if (mode === 'add') {
Rest.post(schedule)
.success(function(){
if (callback) {
scope.$emit(callback);
}
else {
Wait('stop');
}
})
.error(function(data, status){
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'POST to ' + url + ' returned: ' + status });
});
}
else {
Rest.put(schedule)
.success(function(){
if (callback) {
scope.$emit(callback);
}
else {
Wait('stop');
}
})
.error(function(data, status){
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'POST to ' + url + ' returned: ' + status });
});
}
}
else {
return false;
}
};
}])
/**
* Inject the scheduler_dialog.html wherever needed
*/
.factory('LoadDialogPartial', ['Rest', '$compile', 'ProcessErrors', function(Rest, $compile, ProcessErrors) {
return function(params) {
var scope = params.scope,
element_id = params.element_id,
callback = params.callback,
url;
// Add the schedule_dialog.html partial
url = '/static/partials/schedule_dialog.html';
Rest.setUrl(url);
Rest.get()
.success(function(data) {
var e = angular.element(document.getElementById(element_id));
e.append(data);
$compile(e)(scope);
scope.$emit(callback);
})
.error(function(data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + url + ' failed. GET returned: ' + status });
});
};
}])
/**
* Flip a schedule's enable flag
*
* ToggleSchedule({
* scope: scope,
* id: schedule.id to update
* callback: scope.$emit label to call when update completes
* });
*
*/
.factory('ToggleSchedule', ['Wait', 'GetBasePath', 'ProcessErrors', 'Rest', function(Wait, GetBasePath, ProcessErrors, Rest) {
return function(params) {
var scope = params.scope,
id = params.id,
callback = params.callback,
url = GetBasePath('schedules') + id +'/';
// Perform the update
if (scope.removeScheduleFound) {
scope.removeScheduleFound();
}
scope.removeScheduleFound = scope.$on('ScheduleFound', function(e, data) {
data.enabled = (data.enabled) ? false : true;
Rest.put(data)
.success( function() {
if (callback) {
scope.$emit(callback, id);
}
else {
Wait('stop');
}
})
.error( function() {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to update schedule ' + id + ' PUT returned: ' + status });
});
});
Wait('start');
// Get the schedule
Rest.setUrl(url);
Rest.get()
.success(function(data) {
scope.$emit('ScheduleFound', data);
})
.error(function(data,status){
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to retrieve schedule ' + id + ' GET returned: ' + status });
});
};
}])
/**
* Delete a schedule. Prompts user to confirm delete
*
* DeleteSchedule({
* scope: $scope containing list of schedules
* id: id of schedule to delete
* callback: $scope.$emit label to call when delete is completed
* })
*
*/
.factory('DeleteSurvey', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', 'Prompt', 'Find',
function(GetBasePath, Rest, Wait, ProcessErrors, Prompt, Find) {
return function(params) {
var scope = params.scope,
id = params.id,
callback = params.callback,
action, schedule, list, url, hdr;
if (scope.schedules) {
list = scope.schedules;
}
else if (scope.scheduled_jobs) {
list = scope.scheduled_jobs;
}
url = GetBasePath('schedules') + id + '/';
schedule = Find({list: list, key: 'id', val: id });
hdr = 'Delete Schedule';
action = function () {
Wait('start');
Rest.setUrl(url);
Rest.destroy()
.success(function () {
$('#prompt-modal').modal('hide');
scope.$emit(callback, id);
})
.error(function (data, status) {
try {
$('#prompt-modal').modal('hide');
}
catch(e) {
// ignore
}
ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Call to ' + url +
' failed. DELETE returned: ' + status });
});
};
Prompt({
hdr: hdr,
body: "<div class=\"alert alert-info\">Are you sure you want to delete the <em>" + schedule.name + "</em> schedule?</div>",
action: action,
backdrop: false
});
};
}])
/**
* Convert rrule string to an API agreeable format
*
*/
.factory('RRuleToAPI', [ function() {
return function(rrule) {
var response;
response = rrule.replace(/(^.*(?=DTSTART))(DTSTART=.*?;)(.*$)/, function(str, p1, p2, p3) {
return p2.replace(/\;/,'').replace(/=/,':') + ' ' + 'RRULE:' + p1 + p3;
});
return response;
};
}])
.factory('SurveyControllerInit', ['$location', 'DeleteSurvey', 'EditSurvey', 'AddSurvey', 'GenerateForm', 'SurveyQuestionForm', 'Wait', 'Alert',
function($location, DeleteSurvey, EditSurvey, AddSurvey, GenerateForm, SurveyQuestionForm, Wait, Alert) {
return function(params) {
var scope = params.scope,
parent_scope = params.parent_scope,
id = params.id,
iterator = (params.iterator) ? params.iterator : scope.iterator,
base = $location.path().replace(/^\//, '').split('/')[0];
scope.survey_questions = [];
scope.answer_types=[
{name: 'Text' , type: 'text'},
{name: 'Textarea', type: 'textarea'},
{name: 'Multiple Choice (single select)', type: 'multiplechoice'},
{name: 'Multiple Choice (multiple select)', type: 'multiselect'},
{name: 'JSON', type: 'json'},
{name: 'Integer', type: 'integer'},
{name: 'Float', type: 'number'}
];
scope.deleteSurvey = function() {
// DeleteSchedule({
// scope: scope,
// id: id,
// callback: 'SchedulesRefresh'
// });
};
scope.editSurvey = function() {
EditSurvey({
scope: scope,
id: id,
// callback: 'SchedulesRefresh'
});
};
scope.addSurvey = function() {
AddSurvey({
scope: scope,
// callback: 'SchedulesRefresh'
});
};
scope.addQuestion = function(){
GenerateForm.inject(SurveyQuestionForm, { id:'new_question', scope:scope, breadCrumbs: false});
};
scope.finalizeQuestion= function(data, labels){
var key,
html = '<div class="question_final row">';
for (key in data) {
html+='<div class="col-xs-6"><label for="question_text"><span class="label-text">'+labels[key] +': </span></label>'+data[key]+'</div>\n';
}
html+='</div>';
$('#finalized_questions').before(html);
$('#add_question_btn').show();
$('#add_question_btn').removeAttr('disabled');
$('#survey_maker_save_btn').removeAttr('disabled');
};
scope.addNewQuestion = function(){
// $('#add_question_btn').on("click" , function(){
scope.addQuestion();
$('#add_question_btn').attr('disabled', 'disabled');
// });
};
scope.submitQuestion = function(){
var form = SurveyQuestionForm,
data = {},
labels={},
min= "min",
max = "max",
fld;
//generator.clearApiErrors();
Wait('start');
try {
for (fld in form.fields) {
if(scope[fld]){
if(fld === "type"){
data[fld] = scope[fld].type;
if(scope[fld].type==="integer" || scope[fld].type==="float"){
data[min] = $('#answer_min').val();
data[max] = $('#answer_max').val();
labels[min]= "Min";
labels[max]= "Max";
}
}
else{
data[fld] = scope[fld];
}
labels[fld] = form.fields[fld].label;
}
}
Wait('stop');
scope.survey_questions.push(data);
$('#new_question .aw-form-well').remove();
// for(fld in form.fields){
// $scope[fld] = '';
// }
scope.finalizeQuestion(data , labels);
} catch (err) {
Wait('stop');
Alert("Error", "Error parsing extra variables. Parser returned: " + err);
}
};
scope.refreshSchedules = function() {
if (base === 'jobs') {
parent_scope.refreshJobs();
}
else {
scope.search(iterator);
}
};
if (scope.removeSchedulesRefresh) {
scope.removeSchedulesRefresh();
}
scope.$on('SchedulesRefresh', function() {
scope.search(iterator);
});
};
}])
.factory('SchedulesListInit', [ function() {
return function(params) {
var scope = params.scope,
list = params.list,
choices = params.choices;
scope[list.name].forEach(function(item, item_idx) {
var fld, field,
itm = scope[list.name][item_idx];
itm.enabled = (itm.enabled) ? true : false;
if (itm.enabled) {
itm.play_tip = 'Schedule is active. Click to stop.';
itm.status = 'active';
itm.status_tip = 'Schedule is active. Click to stop.';
}
else {
itm.play_tip = 'Schedule is stopped. Click to activate.';
itm.status = 'stopped';
itm.status_tip = 'Schedule is stopped. Click to activate.';
}
itm.nameTip = item.name + " schedule. Click to edit.";
// Copy summary_field values
for (field in list.fields) {
fld = list.fields[field];
if (fld.sourceModel) {
if (itm.summary_fields[fld.sourceModel]) {
itm[field] = itm.summary_fields[fld.sourceModel][fld.sourceField];
}
}
}
// Set the item type label
if (list.fields.type) {
choices.every(function(choice) {
if (choice.value === item.type) {
itm.type_label = choice.label;
return false;
}
return true;
});
}
});
};
}])
/**
*
* Called from a controller to setup the scope for a schedules list
*
*/
.factory('LoadSchedulesScope', ['$compile', '$location', '$routeParams','SearchInit', 'PaginateInit', 'GenerateList', 'SchedulesControllerInit',
'SchedulesListInit', 'SearchWidget',
function($compile, $location, $routeParams, SearchInit, PaginateInit, GenerateList, SchedulesControllerInit, SchedulesListInit, SearchWidget) {
return function(params) {
var parent_scope = params.parent_scope,
scope = params.scope,
list = params.list,
id = params.id,
url = params.url,
pageSize = params.pageSize || 5,
spinner = (params.spinner === undefined) ? true : params.spinner,
base = $location.path().replace(/^\//, '').split('/')[0],
e, html;
if (base === 'jobs') {
// on jobs page the search widget appears on the right
html = SearchWidget({
iterator: list.iterator,
template: params.list,
includeSize: false
});
e = angular.element(document.getElementById(id + '-search-container')).append(html);
$compile(e)(scope);
GenerateList.inject(list, {
mode: 'edit',
id: id,
breadCrumbs: false,
scope: scope,
showSearch: false
});
}
else {
GenerateList.inject(list, {
mode: 'edit',
id: id,
breadCrumbs: false,
scope: scope,
searchSize: 'col-lg-6 col-md-6 col-sm-6 col-xs-12',
showSearch: true
});
}
SearchInit({
scope: scope,
set: list.name,
list: list,
url: url
});
PaginateInit({
scope: scope,
list: list,
url: url,
pageSize: pageSize
});
scope.iterator = list.iterator;
if (scope.removePostRefresh) {
scope.removePostRefresh();
}
scope.$on('PostRefresh', function(){
SchedulesControllerInit({
scope: scope,
parent_scope: parent_scope,
list: list
});
SchedulesListInit({
scope: scope,
list: list,
choices: parent_scope.type_choices
});
parent_scope.$emit('listLoaded');
});
if ($routeParams.id__int) {
scope[list.iterator + 'SearchField'] = 'id';
scope[list.iterator + 'SearchValue'] = $routeParams.id__int;
scope[list.iterator + 'SearchFieldLabel'] = 'ID';
}
scope.search(list.iterator, null, null, null, null, spinner);
};
}]);

View File

@ -2,4 +2,6 @@
<div ng-cloak id="htmlTemplate"></div>
<div ng-include="'/static/partials/schedule_dialog.html'"></div>
<div ng-include="'/static/partials/logviewer.html'"></div>
<div id="survey-modal-dialog">
<!-- <div id="edit-survey-modal-dialog" title="Edit Survey"> -->
</div>

View File

@ -1,3 +1,5 @@
<div class="tab-pane" id="survey_maker">
<!-- <div class="tab-pane" id="survey_maker"> -->
<div class="tab-pane" id="survey-modal-dailog">
<div id="htmlTemplate" class="ng-scope"></div>
<!-- <div id="survey-modal-dialog" title="Add Survey"></div> -->
</div>

View File

@ -154,6 +154,7 @@
<script src="{{ STATIC_URL }}js/helpers/Hosts.js"></script>
<script src="{{ STATIC_URL }}js/helpers/Variables.js"></script>
<script src="{{ STATIC_URL }}js/helpers/Schedules.js"></script>
<script src="{{ STATIC_URL }}js/helpers/Survey.js"></script>
<script src="{{ STATIC_URL }}js/helpers/LogViewer.js"></script>
<script src="{{ STATIC_URL }}js/helpers/EventViewer.js"></script>
<script src="{{ STATIC_URL }}js/helpers/JobDetail.js"></script>