diff --git a/awx/ui/static/js/controllers/SurveyMaker.js b/awx/ui/static/js/controllers/SurveyMaker.js deleted file mode 100644 index fa03ce401b..0000000000 --- a/awx/ui/static/js/controllers/SurveyMaker.js +++ /dev/null @@ -1,629 +0,0 @@ -/************************************ - * Copyright (c) 2014 AnsibleWorks, Inc. - * - * - * SurveyMaker.js - * - * Controller functions for the survey maker - * - */ -/** - * @ngdoc function - * @name controllers.function:SurveyMaker - * @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'; - -function SurveyMakerAdd($scope, $rootScope, $compile, $location, $log, $routeParams, SurveyMakerForm, - GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, GetBasePath, - ReturnToCaller, Wait, SurveyQuestionForm, Store) { - - ClearScope(); - - // Inject dynamic view - var generator = GenerateForm, - form = SurveyMakerForm, - base = $location.path().replace(/^\//, '').split('/')[0], - id = $location.path().replace(/^\//, '').split('/')[1]; - - $scope.survey_questions=[]; - $scope.Store = Store; - $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'} - ]; - - - generator.inject(form, { mode: 'add', related: false, scope: $scope}); - generator.reset(); - // LoadBreadCrumbs(); - // LoadBreadCrumbs({ - // path: '/job_templates/' + id + '/survey', - // title: 'jared rocks', // $scope.job_id + ' - ', //+ data.summary_fields.job_template.name, - // altPath: '/job_templates/' + id + '/survey', - // }); - - $scope.addQuestion = function(){ - - GenerateForm.inject(SurveyQuestionForm, {mode:'modal', id:'new_question', scope:$scope, breadCrumbs: false}); - }; - $scope.addQuestion(); - -// $('#question_shadow').mouseenter(function(){ -// $('#question_shadow').css({ -// "opacity": "1", -// "border": "1px solid", -// "border-color": "rgb(204,204,204)", -// "border-radius": "4px" -// }); -// $('#question_add_btn').show(); -// }); - -// $('#question_shadow').mouseleave(function(){ -// $('#question_shadow').css({ -// "opacity": ".4", -// "border": "1px dashed", -// "border-color": "rgb(204,204,204)", -// "border-radius": "4px" -// }); -// $('#question_add_btn').hide(); -// }) - - - // $('#question_shadow').on("click" , function(){ - // // var survey_width = $('#survey_maker_question_area').width()-10, - // // html = ""; - - // // $('#add_question_btn').attr('disabled', 'disabled') - // // $('#survey_maker_question_area').append(html); - // addQuestion(); - // $('#question_shadow').hide(); - // $('#question_shadow').css({ - // "opacity": ".4", - // "border": "1px dashed", - // "border-color": "rgb(204,204,204)", - // "border-radius": "4px" - // }); - // }); - $scope.finalizeQuestion= function(data, labels){ - var key, - html = '
'; - - for (key in data) { - html+='
'+data[key]+'
\n'; - } - - html+='
'; - - $('#finalized_questions').before(html); - $('#add_question_btn').show(); - $('#add_question_btn').removeAttr('disabled'); - $('#survey_maker_save_btn').removeAttr('disabled'); - }; - - $('#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.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 - $scope.formSave = function () { - generator.clearApiErrors(); - Wait('start'); - if($scope.Store("saved_job_template_for_survey")){ - $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{ - 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 - $scope.formReset = function () { - $rootScope.flashMessage = null; - generator.reset(); - }; -} - -SurveyMakerAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'SurveyMakerForm', - 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath', 'ReturnToCaller', 'Wait', 'SurveyQuestionForm', 'Store' -]; - -function SurveyMakerEdit($scope, $rootScope, $compile, $location, $log, $routeParams, SurveyMakerForm, - GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ClearScope, GetBasePath, - ReturnToCaller, Wait, SurveyQuestionForm, Store) { - - ClearScope(); - - // Inject dynamic view - var generator = GenerateForm, - form = SurveyMakerForm, - base = $location.path().replace(/^\//, '').split('/')[0], - id = $location.path().replace(/^\//, '').split('/')[1], - i, data; - - $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.Store = Store; - - generator.inject(form, { mode: 'edit', related: false, scope: $scope}); - generator.reset(); - // LoadBreadCrumbs(); - // LoadBreadCrumbs({ - // path: '/job_templates/' + id + '/survey', - // title: 'jared rocks', // $scope.job_id + ' - ', //+ data.summary_fields.job_template.name, - // altPath: '/job_templates/' + id + '/survey', - // }); - - $scope.addQuestion = function(){ - - GenerateForm.inject(SurveyQuestionForm, {mode:'add', id:'new_question', scope:$scope, breadCrumbs: false}); - }; - // $scope.addQuestion(); - -// $('#question_shadow').mouseenter(function(){ -// $('#question_shadow').css({ -// "opacity": "1", -// "border": "1px solid", -// "border-color": "rgb(204,204,204)", -// "border-radius": "4px" -// }); -// $('#question_add_btn').show(); -// }); - -// $('#question_shadow').mouseleave(function(){ -// $('#question_shadow').css({ -// "opacity": ".4", -// "border": "1px dashed", -// "border-color": "rgb(204,204,204)", -// "border-radius": "4px" -// }); -// $('#question_add_btn').hide(); -// }) - - - // $('#question_shadow').on("click" , function(){ - // // var survey_width = $('#survey_maker_question_area').width()-10, - // // html = ""; - - // // $('#add_question_btn').attr('disabled', 'disabled') - // // $('#survey_maker_question_area').append(html); - // addQuestion(); - // $('#question_shadow').hide(); - // $('#question_shadow').css({ - // "opacity": ".4", - // "border": "1px dashed", - // "border-color": "rgb(204,204,204)", - // "border-radius": "4px" - // }); - // }); - $scope.finalizeQuestion= function(data){ - var key, - 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" - }, - html = '
'; - - for (key in data) { - html+='
'+data[key]+'
\n'; - } - - html+='
'; - - $('#finalized_questions').before(html); - $('#add_question_btn').show(); - $('#add_question_btn').removeAttr('disabled'); - $('#survey_maker_save_btn').removeAttr('disabled'); - }; - - $('#add_question_btn').on("click" , function(){ - $scope.addQuestion(); - $('#add_question_btn').attr('disabled', 'disabled'); - }); - - Wait('start'); - - if($scope.Store("saved_job_template_for_survey") && $scope.Store("saved_job_template_for_survey").editing_survey===true){ - data = $scope.Store("survey_for_new_job_template"); - $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'); - } - else{ - Rest.setUrl(GetBasePath(base)+ id + '/survey_spec/'); - Rest.get() - .success(function (data) { - var i; - $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; - // for (set in form.related) { - // if (related[set]) { - // relatedSets[set] = { - // url: related[set], - // 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 }); - }); - } - $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); - } - }; - // Save - $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 }); - }); - } - }; - - // Cancel - $scope.formReset = function () { - $rootScope.flashMessage = null; - generator.reset(); - }; -} - -SurveyMakerEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'SurveyMakerForm', - 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ClearScope', 'GetBasePath', 'ReturnToCaller', 'Wait', 'SurveyQuestionForm', 'Store' -]; - - - -// function OrganizationsEdit($scope, $rootScope, $compile, $location, $log, $routeParams, OrganizationForm, GenerateForm, Rest, -// Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, Prompt, ClearScope, GetBasePath, Wait, Stream) { - -// ClearScope(); - -// // Inject dynamic view -// var form = OrganizationForm, -// generator = GenerateForm, -// defaultUrl = GetBasePath('organizations'), -// base = $location.path().replace(/^\//, '').split('/')[0], -// master = {}, -// id = $routeParams.organization_id, -// relatedSets = {}; - -// generator.inject(form, { mode: 'edit', related: true, scope: $scope}); -// generator.reset(); - -// // After the Organization is loaded, retrieve each related set -// if ($scope.organizationLoadedRemove) { -// $scope.organizationLoadedRemove(); -// } -// $scope.organizationLoadedRemove = $scope.$on('organizationLoaded', function () { -// for (var set in relatedSets) { -// $scope.search(relatedSets[set].iterator); -// } -// Wait('stop'); -// }); - -// // Retrieve detail record and prepopulate the form -// Wait('start'); -// Rest.setUrl(defaultUrl + id + '/'); -// Rest.get() -// .success(function (data) { -// var fld, related, set; -// 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; -// for (set in form.related) { -// if (related[set]) { -// relatedSets[set] = { -// url: related[set], -// 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 }); -// }); - - -// // Save changes to the parent -// $scope.formSave = function () { -// var fld, params = {}; -// generator.clearApiErrors(); -// Wait('start'); -// for (fld in form.fields) { -// params[fld] = $scope[fld]; -// } -// Rest.setUrl(defaultUrl + id + '/'); -// Rest.put(params) -// .success(function () { -// Wait('stop'); -// master = params; -// $rootScope.flashMessage = "Your changes were successfully saved!"; -// }) -// .error(function (data, status) { -// ProcessErrors($scope, data, status, OrganizationForm, { hdr: 'Error!', -// msg: 'Failed to update organization: ' + id + '. PUT status: ' + status }); -// }); -// }; - -// $scope.showActivity = function () { -// Stream({ -// scope: $scope -// }); -// }; - -// // Reset the form -// $scope.formReset = function () { -// $rootScope.flashMessage = null; -// generator.reset(); -// for (var fld in master) { -// $scope[fld] = master[fld]; -// } -// }; - -// // Related set: Add button -// $scope.add = function (set) { -// $rootScope.flashMessage = null; -// $location.path('/' + base + '/' + $routeParams.organization_id + '/' + set); -// }; - -// // Related set: Edit button -// $scope.edit = function (set, id) { -// $rootScope.flashMessage = null; -// $location.path('/' + set + '/' + id); -// }; - -// // Related set: Delete button -// $scope['delete'] = function (set, itm_id, name, title) { -// $rootScope.flashMessage = null; - -// var action = function () { -// Wait('start'); -// var url = defaultUrl + $routeParams.organization_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 -// }); - -// }; -// } - -// OrganizationsEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'OrganizationForm', 'GenerateForm', -// 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit', 'Prompt', 'ClearScope', 'GetBasePath', -// 'Wait', 'Stream' -// ]; \ No newline at end of file diff --git a/awx/ui/static/js/forms/SurveyQuestion.js b/awx/ui/static/js/forms/SurveyQuestion.js index 2217e1316c..d4409959aa 100644 --- a/awx/ui/static/js/forms/SurveyQuestion.js +++ b/awx/ui/static/js/forms/SurveyQuestion.js @@ -98,12 +98,12 @@ angular.module('SurveyQuestionFormDefinition', []) type: 'custom', control: '
'+ '
'+ - ''+ - '
This is not valid integer!
'+ + ''+ + '
This is not valid float!
'+ '
'+ '
'+ - ''+ - '
This is not valid integer!
'+ + ''+ + '
This is not valid float!
'+ '
'+ '
', ngShow: 'type.type==="float" ', @@ -138,45 +138,19 @@ angular.module('SurveyQuestionFormDefinition', []) ''+ '
This is not valid integer!
'+ '
The value must be in range {{int_min}} to {{int_max}}!
'+ - // 'value = {{default_int}}
'+ - // 'value.$valid = {{survey_question_form.default_int.$valid}}'+ '', - - // '
'+ - // '
'+ - // '
'+ - // '
This is not valid integer!
', - - - // '
'+ - // '
'+ - - // '
This is not valid integer!
'+ - // // '
'+ - // '
'+ - // '
', - - - - - - - - //
- // - //
A value is required!
- //
- //
- column: 2, ngShow: 'type.type === "integer" ' }, default_float: { realName: 'default_answer', type: 'custom', - control: '
'+ - '
', + control: '
'+ + ''+ + ''+ + '
This is not valid float!
'+ + '
The value must be in range {{float_min}} to {{float_max}}!
'+ + '
', column: 2, ngShow: 'type.type=== "float" ' }, diff --git a/awx/ui/static/js/helpers/Survey.js b/awx/ui/static/js/helpers/Survey.js index 9163dfcb50..f4d98ed813 100644 --- a/awx/ui/static/js/helpers/Survey.js +++ b/awx/ui/static/js/helpers/Survey.js @@ -284,7 +284,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', index = params.index, required, element, choices, i, checked, - max, min, defaultValue, numberValidation, + max, min, defaultValue, html = ""; @@ -304,15 +304,17 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', if(!Empty(question.question_description)){ html += '
'+question.question_description+'
\n'; } - defaultValue = (question.default) ? question.default : ""; + // defaultValue = (question.default) ? question.default : ""; if(question.type === 'text' ){ + defaultValue = (question.default) ? question.default : ""; html+='
'+ '
'+ ''+ '
'; } if(question.type === "textarea"){ + defaultValue = (question.default) ? question.default : (question.default_textarea) ? question.default_textarea: "" ; html+='
'+ '
'+ ''+ @@ -321,7 +323,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', if(question.type === 'multiplechoice' || question.type === "multiselect"){ choices = question.choices.split(/\n/); element = (question.type==="multiselect") ? "checkbox" : 'radio'; - + question.default = (question.default) ? question.default : (question.default_multiselect) ? question.default_multiselect : "" ; for( i = 0; i'+ @@ -330,13 +332,23 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', } } - if(question.type === 'integer' || question.type === "float"){ - min = (question.min) ? question.min : ""; - max = (question.max) ? question.max : "" ; - numberValidation = (question.type==="integer") ? "integer" : 'float'; + if(question.type === 'integer'){ + min = (!Empty(question.min)) ? question.min : ""; + max = (!Empty(question.max)) ? question.max : "" ; + defaultValue = (!Empty(question.default)) ? question.default : (!Empty(question.default_int)) ? question.default_int : "" ; html+='
'+ '
'+ - ''+ + ''+ + '
'; + + } + if(question.type === "float"){ + min = (!Empty(question.min)) ? question.min : ""; + max = (!Empty(question.max)) ? question.max : "" ; + defaultValue = (!Empty(question.default)) ? question.default : (!Empty(question.default_float)) ? question.default_float : "" ; + html+='
'+ + '
'+ + ''+ '
'; } @@ -462,7 +474,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', var scope = params.scope, index = params.index, - element, fld, i, + element, fld, i, pre, form = SurveyQuestionForm; $('#add_question_btn').hide(); @@ -473,9 +485,12 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', // $('#new_question .aw-form-well').remove(); GenerateForm.inject(form, { id: 'question_'+index, mode: 'edit' , related: false, scope:scope, breadCrumbs: false}); for(fld in form.fields){ - if( fld === 'answer_options_number'){ - $('#answer_min').val(scope.survey_questions[index].min); - $('#answer_max').val(scope.survey_questions[index].max); + if( fld === 'float_options' || fld === 'int_options'){ + pre = fld.substr(0, fld.indexOf('_')); + scope[pre+'_min'] = scope.survey_questions[index].min; + scope[pre+'_max'] = scope.survey_questions[index].max; + // $('#'+pre+'_min').val(scope.survey_questions[index].min); + // $('#'+pre+'_max').val(scope.survey_questions[index].max); } if( fld === 'default_int' || fld === 'default_float'){ $("#"+fld ).val(scope.survey_questions[index].default); @@ -554,9 +569,13 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', }); }; scope.addQuestion = function(){ + GenerateForm.inject(form, { id:'new_question', mode: 'add' , scope:scope, related: false, breadCrumbs: false}); scope.required = true; //set the required checkbox to true via the ngmodel attached to scope.required. - + scope.int_min = null; + scope.int_max = null; + scope.float_min = null; + scope.float_max = null; }; scope.addNewQuestion = function(){ @@ -673,9 +692,9 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', scope.submitQuestion = function(){ var form = SurveyQuestionForm, data = {}, - labels={}, - min= "min", - max = "max", + // labels={}, + // min= "min", + // max = "max", fld, key, elementID; //generator.clearApiErrors(); Wait('start'); @@ -688,40 +707,25 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', if(scope[fld]){ if(fld === "type"){ data[fld] = scope[fld].type; - // if(scope[fld].type==="textarea"){ - // data["default"] = scope.default_textarea; - // } - // if(scope[fld].type==="multiselect"){ - // data["default"] = scope.default_multiselect; - // } + if(scope[fld].type === 'float'){ - data[min] = $('#answer_min').val(); - data[max] = $('#answer_max').val(); - labels[min]= "Min"; - labels[max]= "Max"; - // data["default"] = $('#default_float').val(); //scope.default_float; + data.min = scope.float_min; + data.max = scope.float_max; + data.default = scope.default_float; + } if(scope[fld].type==="integer" ){ - data[min] = $('#answer_min').val(); - data[max] = $('#answer_max').val(); - labels[min]= "Min"; - labels[max]= "Max"; - // data["default"] = $('#default_int').val(); //scope.default_int; + data.min = scope.int_min; + data.max = scope.int_max; + data.default = scope.default_int; + } } else{ data[fld] = scope[fld]; - if( fld === 'default_int' || fld === 'default_float' ){ - data['default'] = $('#'+fld).val(); - } - if(fld==="default_textarea" ){ - data['default'] = scope.default_textarea; - } - if(fld==="default_multiselect"){ - data['default'] = scope.default_multiselect; - } + } - labels[fld] = form.fields[fld].label; + } } Wait('stop'); diff --git a/awx/ui/static/lib/ansible/directives.js b/awx/ui/static/lib/ansible/directives.js index 33569afb31..4e4fa4f733 100644 --- a/awx/ui/static/lib/ansible/directives.js +++ b/awx/ui/static/lib/ansible/directives.js @@ -141,6 +141,25 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job }; }]) + + .directive('smartFloat', function() { + var FLOAT_REGEXP = /^\-?\d+((\.|\,)\d+)?$/; + return { + require: 'ngModel', + link: function(scope, elm, attrs, ctrl) { + ctrl.$parsers.unshift(function(viewValue) { + if (FLOAT_REGEXP.test(viewValue)) { + ctrl.$setValidity('float', true); + return parseFloat(viewValue.replace(',', '.')); + } else { + ctrl.$setValidity('float', false); + return undefined; + } + }); + } + }; + }) + // integer Validate that input is of type integer. Taken from Angular developer // guide, form examples. Add min and max directives, and this will check // entered values is within the range.