diff --git a/awx/ui/client/legacy-styles/ansible-ui.less b/awx/ui/client/legacy-styles/ansible-ui.less index a765511b50..cfee86535e 100644 --- a/awx/ui/client/legacy-styles/ansible-ui.less +++ b/awx/ui/client/legacy-styles/ansible-ui.less @@ -2058,7 +2058,8 @@ tr td button i { margin-top: 10px; } -.select2-container--disabled,.select2-container--disabled .select2-selection--single{ +/* Overwrite select2 base styles for single/multiple selects so that match up with other form elements. Also overwrite disabled styles. */ +.select2-container--disabled,.select2-container--disabled .select2-selection--single,.select2-container--disabled .select2-selection--multiple { cursor: not-allowed !important; } @@ -2066,6 +2067,19 @@ tr td button i { opacity: .35; } +.select2-container--default .select2-selection--single { + background-color: @field-secondary-bg; + border: 1px solid #aaa; + border-radius: 4px; +} + +.select2-container--default .select2-selection--multiple { + background-color: @field-secondary-bg; + border: 1px solid #aaa; + border-radius: 4px; + cursor: text; +} + body.is-modalOpen { overflow: hidden; } diff --git a/awx/ui/client/legacy-styles/forms.less b/awx/ui/client/legacy-styles/forms.less index 4e78e5c0bd..4f65172302 100644 --- a/awx/ui/client/legacy-styles/forms.less +++ b/awx/ui/client/legacy-styles/forms.less @@ -30,6 +30,12 @@ min-height: 45px; } +.Form-secondaryTitle{ + color: @default-icon; + padding-bottom: 20px; + min-height: 40px; +} + .Form-title--is_superuser{ height:15px; color: @btn-txt; @@ -136,7 +142,7 @@ .Form-formGroup { flex: 1 0 auto; - margin-bottom: 25px; + margin-bottom: 20px; width: 33%; padding-right: 50px; } @@ -226,7 +232,6 @@ .Form-dropDown { height: 30px !important; - background-color: @field-secondary-bg!important; border-radius: 5px !important; border:1px solid @field-border!important; color: @field-input-text!important; @@ -431,6 +436,25 @@ input[type='radio']:checked:before { color: @btn-txt; } +.Form-surveyButton { + background-color: @default-link; + margin-right: 20px; + color: @default-bg; + text-transform: uppercase; + padding-left:15px; + padding-right: 15px; +} + +.Form-surveyButton:hover{ + background-color: @default-link-hov; + color: @default-bg; +} + +.Form-formGroup--singleColumn { + width: 100%; + padding-right: 0px; +} + @media only screen and (max-width: 650px) { .Form-formGroup { flex: 1 0 auto; diff --git a/awx/ui/client/legacy-styles/jquery-ui-overrides.less b/awx/ui/client/legacy-styles/jquery-ui-overrides.less index c40440bf8a..2f78c52051 100644 --- a/awx/ui/client/legacy-styles/jquery-ui-overrides.less +++ b/awx/ui/client/legacy-styles/jquery-ui-overrides.less @@ -28,8 +28,15 @@ table.ui-datepicker-calendar { font-weight: bold; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; line-height: 1; - opacity: .7; + opacity: 1; text-shadow: 0 1px 0 @white; + color:@default-second-border; + } + .close:hover{ + color:@default-icon; + } + .ui-widget { + font-family: 'Open Sans', sans-serif; } .ui-widget-header { border-radius: 0; diff --git a/awx/ui/client/src/forms/Inventories.js b/awx/ui/client/src/forms/Inventories.js index 746c8a49a9..a69bbebca8 100644 --- a/awx/ui/client/src/forms/Inventories.js +++ b/awx/ui/client/src/forms/Inventories.js @@ -49,7 +49,6 @@ export default variables: { label: 'Variables', type: 'textarea', - 'class': 'Form-textArea', addRequired: false, editRequird: false, rows: 6, diff --git a/awx/ui/client/src/forms/JobTemplates.js b/awx/ui/client/src/forms/JobTemplates.js index 36fce67368..565c882e5b 100644 --- a/awx/ui/client/src/forms/JobTemplates.js +++ b/awx/ui/client/src/forms/JobTemplates.js @@ -276,8 +276,8 @@ export default type: 'custom', column: 2, ngHide: "job_type.value === 'scan'" , - control: ''+ - '' + control: ''+ + '' } }, diff --git a/awx/ui/client/src/helpers/JobTemplates.js b/awx/ui/client/src/helpers/JobTemplates.js index 44a4604bca..8067cd2c67 100644 --- a/awx/ui/client/src/helpers/JobTemplates.js +++ b/awx/ui/client/src/helpers/JobTemplates.js @@ -78,7 +78,7 @@ angular.module('JobTemplatesHelper', ['Utilities']) .success(function (data) { var fld, i; for (fld in form.fields) { - if (fld !== 'variables' && data[fld] !== null && data[fld] !== undefined) { + if (fld !== 'variables' && fld !== 'survey' && data[fld] !== null && data[fld] !== undefined) { if (form.fields[fld].type === 'select') { if (scope[fld + '_options'] && scope[fld + '_options'].length > 0) { for (i = 0; i < scope[fld + '_options'].length; i++) { @@ -91,10 +91,8 @@ angular.module('JobTemplatesHelper', ['Utilities']) } } else { scope[fld] = data[fld]; - if(fld ==='survey_enabled'){ - if(!Empty(data.summary_fields.survey)) { - scope.survey_exists = true; - } + if(!Empty(data.summary_fields.survey)) { + scope.survey_exists = true; } } master[fld] = scope[fld]; @@ -114,6 +112,8 @@ angular.module('JobTemplatesHelper', ['Utilities']) Wait('stop'); scope.url = data.url; + scope.survey_enabled = data.survey_enabled; + scope.ask_variables_on_launch = (data.ask_variables_on_launch) ? 'true' : 'false'; master.ask_variables_on_launch = scope.ask_variables_on_launch; diff --git a/awx/ui/client/src/job-templates/add/job-templates-add.controller.js b/awx/ui/client/src/job-templates/add/job-templates-add.controller.js index 6c133102a1..5119ea8f42 100644 --- a/awx/ui/client/src/job-templates/add/job-templates-add.controller.js +++ b/awx/ui/client/src/job-templates/add/job-templates-add.controller.js @@ -337,16 +337,20 @@ if (form.fields[fld].type === 'select' && fld !== 'playbook') { data[fld] = $scope[fld].value; } else { - if (fld !== 'variables') { + if (fld !== 'variables' && fld !== 'survey') { data[fld] = $scope[fld]; } } } data.extra_vars = ToJSON($scope.parseType, $scope.variables, true); if(data.job_type === 'scan' && $scope.default_scan === true){ - data.project = ""; - data.playbook = ""; + data.project = ""; + data.playbook = ""; } + // We only want to set the survey_enabled flag to true for this job template if a survey exists + // and it's been enabled. By default, survey_enabled is explicitly set to true but if no survey + // is created then we don't want it enabled. + data.survey_enabled = ($scope.survey_enabled && $scope.survey_exists) ? $scope.survey_enabled : false; Rest.setUrl(defaultUrl); Rest.post(data) .success(function(data) { @@ -361,7 +365,7 @@ url: $scope.current_url }); - if(data.survey_enabled===true){ + if($scope.survey_questions && $scope.survey_questions.length > 0){ //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); @@ -413,19 +417,12 @@ if($scope.job_type.value === "scan" && $scope.survey_enabled === true){ $scope.survey_enabled = false; } + // Can't have a survey enabled without a survey if($scope.survey_enabled === true && $scope.survey_exists!==true){ - // $scope.$emit("PromptForSurvey"); - - // The original design for this was a pop up that would prompt the user if they wanted to create a - // survey, because they had enabled one but not created it yet. We switched this for now so that - // an error message would be displayed by the survey buttons that tells the user to add a survey or disabled - // surveys. - $scope.invalid_survey = true; - return; - } else { - $scope.$emit("GatherFormFields"); + $scope.survey_enabled = false; } + $scope.$emit("GatherFormFields"); }; diff --git a/awx/ui/client/src/job-templates/add/job-templates-add.partial.html b/awx/ui/client/src/job-templates/add/job-templates-add.partial.html index 6c3956cfb8..67b5ac942f 100644 --- a/awx/ui/client/src/job-templates/add/job-templates-add.partial.html +++ b/awx/ui/client/src/job-templates/add/job-templates-add.partial.html @@ -1,5 +1,5 @@
-
+
diff --git a/awx/ui/client/src/job-templates/edit/job-templates-edit.controller.js b/awx/ui/client/src/job-templates/edit/job-templates-edit.controller.js index 0083262f19..93cb5d2bb9 100644 --- a/awx/ui/client/src/job-templates/edit/job-templates-edit.controller.js +++ b/awx/ui/client/src/job-templates/edit/job-templates-edit.controller.js @@ -307,27 +307,6 @@ export default Wait('start'); - if ($scope.removeEnableSurvey) { - $scope.removeEnableSurvey(); - } - $scope.removeEnableSurvey = $scope.$on('EnableSurvey', function(fld) { - - $('#job_templates_survey_enabled_chbox').attr('checked', $scope[fld]); - Rest.setUrl(defaultUrl + id+ '/survey_spec/'); - Rest.get() - .success(function (data) { - if(data && data.name){ - $scope.survey_exists = true; - } - }) - .error(function (data, status) { - ProcessErrors($scope, data, status, form, { - hdr: 'Error!', - msg: 'Failed to retrieve job template: ' + $stateParams.template_id + '. GET status: ' + status - }); - }); - }); - if ($scope.removeSurveySaved) { $scope.rmoveSurveySaved(); } @@ -506,7 +485,7 @@ export default .error(function(res, status){ ProcessErrors($rootScope, res, status, null, {hdr: 'Error!', msg: 'Call to '+ defaultUrl + ' failed. Return status: '+ status}); - }); + }); } else { $state.go('jobTemplates'); diff --git a/awx/ui/client/src/job-templates/edit/job-templates-edit.partial.html b/awx/ui/client/src/job-templates/edit/job-templates-edit.partial.html index cb55a8a700..c02e2188df 100644 --- a/awx/ui/client/src/job-templates/edit/job-templates-edit.partial.html +++ b/awx/ui/client/src/job-templates/edit/job-templates-edit.partial.html @@ -1,5 +1,5 @@
-
+
diff --git a/awx/ui/client/src/job-templates/survey-maker/questions/edit.factory.js b/awx/ui/client/src/job-templates/survey-maker/questions/edit.factory.js index 2b6ceb420c..25e25c3b2e 100644 --- a/awx/ui/client/src/job-templates/survey-maker/questions/edit.factory.js +++ b/awx/ui/client/src/job-templates/survey-maker/questions/edit.factory.js @@ -1,5 +1,5 @@ export default - function EditQuestion(GetBasePath, Rest, Wait, ProcessErrors, $compile, GenerateForm, SurveyQuestionForm) { + function EditQuestion(GetBasePath, Rest, Wait, ProcessErrors, $compile, GenerateForm, SurveyQuestionForm, CreateSelect2) { return function(params) { var scope = params.scope, @@ -7,16 +7,12 @@ export default element, tmpVar, i, - question = params.question, //scope.survey_questions[index], + question = params.question, form = SurveyQuestionForm; - $('#survey-save-button').attr('disabled', 'disabled'); - angular.element('#survey_question_question_cancel_btn').trigger('click'); - $('#add_question_btn').hide(); - // $('#new_question .aw-form-well').remove(); - element = $('.question_final:eq('+index+')'); - element.css('opacity', 1.0); - element.empty(); + // Update the index so that we know which question is being edited. + scope.editQuestionIndex = index; + scope.text_min = null; scope.text_max = null; scope.int_min = null; @@ -70,6 +66,16 @@ export default else if ( question.type === 'multiselect'){ scope.default_multiselect = question.default; } + + // After we populate the form with data, need to call CreateSelect2 again + // to get the dropdown to show the selected item. + CreateSelect2({ + element:'#survey_question_type', + multiple: false + }); + + // Set the form to dirty. This lets the cancel button know that it should become enabled. + scope.survey_question_form.$setDirty(); }); if (scope.removeGenerateForm) { @@ -77,7 +83,7 @@ export default } scope.removeGenerateForm = scope.$on('GenerateForm', function() { tmpVar = scope.mode; - GenerateForm.inject(form, { id: 'question_'+index, mode: 'edit' , related: false, scope:scope }); + GenerateForm.inject(form, { id: 'survey_maker_question_form', mode: 'edit', related: false, scope:scope }); scope.mode = tmpVar; scope.$emit('FillQuestionForm'); }); @@ -95,5 +101,6 @@ EditQuestion.$inject = 'ProcessErrors', '$compile', 'GenerateForm', - 'questionDefinitionForm' + 'questionDefinitionForm', + 'CreateSelect2' ]; diff --git a/awx/ui/client/src/job-templates/survey-maker/questions/finalize.factory.js b/awx/ui/client/src/job-templates/survey-maker/questions/finalize.factory.js deleted file mode 100644 index f17f477682..0000000000 --- a/awx/ui/client/src/job-templates/survey-maker/questions/finalize.factory.js +++ /dev/null @@ -1,193 +0,0 @@ -/** - * Takes a finalized question and displays it on the survey maker page - * - * FinalizeQuestion({ - * scope: $scope containing list of survey form fields - * question: question object that was submitted by the question form - * id: id of job template that survey is attached to - * callback: $scope.$emit label to call when delete is completed - * }) - * - */ - -export default - function FinalizeQuestion(GetBasePath, Rest, Wait, ProcessErrors, $compile, Empty, $filter, questionScope) { - return function(params) { - - var question = params.question, - scope = questionScope(question, params.scope), - index = params.index, - required, - element, - max, - min, - defaultValue, - html = ""; - - question.index = index; - question.question_name = $filter('sanitize')(question.question_name); - question.question_description = (question.question_description) ? $filter('sanitize')(question.question_description) : undefined; - - - if(!$('#question_'+question.index+':eq(0)').is('div')){ - html+='
'; - $('#finalized_questions').append(html); - } - - required = (question.required===true) ? "prepend-asterisk" : ""; - html = '
'; - html += ''; - html += '
'; - - if(!Empty(question.question_description)){ - html += '
'+question.question_description+'
\n'; - } - - if(question.type === 'text' ){ - defaultValue = (question.default) ? question.default : ""; - defaultValue = $filter('sanitize')(defaultValue); - defaultValue = scope.serialize(defaultValue); - html+='
'+ - '
'+ - ''+ - '
'; - } - if(question.type === "textarea"){ - defaultValue = (question.default) ? question.default : (question.default_textarea) ? question.default_textarea: "" ; - defaultValue = $filter('sanitize')(defaultValue); - defaultValue = scope.serialize(defaultValue); - html+='
'+ - '
'+ - ''+ - '
'; - } - if(question.type === 'multiplechoice' || question.type === "multiselect"){ - - question.default = question.default_multiselect || question.default; - - var defaultScopePropertyName = - question.variable + '_default'; - - if (question.default) { - if (question.type === 'multiselect' && typeof question.default.split === 'function') { - scope[defaultScopePropertyName] = question.default.split('\n'); - } else if (question.type !== 'multiselect') { - scope[defaultScopePropertyName] = question.default; - } - } else { - scope[defaultScopePropertyName] = ''; - } - - html += '
'; - html += '
'; - html += '
'; - html += ''; - html += '
'; - html += '
'; - html += '
'; - } - - if(question.type === 'password'){ - defaultValue = (question.default) ? question.default : ""; - defaultValue = $filter('sanitize')(defaultValue); - defaultValue = scope.serialize(defaultValue); - html+='
'+ - '
'+ - ''+ - ''+ - ''+ - ''+ - '
'+ - '
'; - } - - 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+='
'+ - '
'+ - ''+ - '
'; - - } - html += '
'; - html += ' '; - html += ' '; - html += ' '; - html += ' '; - html+='
'; - - $('#question_'+question.index).append(html); - - element = angular.element(document.getElementById('question_'+question.index)); - // // element.html(html); - //element.css('opacity', 0.7); - - $compile(element)(scope); - - $('#add_question_btn').show(); - $('#add_question_btn').removeAttr('disabled'); - $('#add_question_btn').focus(); - $('#survey_maker_save_btn').removeAttr('disabled'); - - // Sometimes the $event.target returns the anchor element that wraps the icon, and sometimes the icon itself - // is returned. So for each icon click event we check to see which target the user clicked, and depending no which one - // they clicked, we move up the dom hierarchy to get the index on the question. Ultimatley the object that is passed to - // each one of these functions should be the index of the question that the user is trying to perform an action on. - $('#delete-question_'+question.index+'').on('click', function($event){ - if($event.target.nodeName==="A"){ - scope.deleteQuestion($event.target.parentElement.parentElement.id.split('_')[1]); - } - else if($event.target.nodeName === "I"){ - scope.deleteQuestion($event.target.parentElement.parentElement.parentElement.id.split('_')[1]); - } - }); - $('#edit-question_'+question.index+'').on('click', function($event){ - if($event.target.nodeName==="A"){ - scope.editQuestion($event.target.parentElement.parentElement.id.split('_')[1]); - } - else if($event.target.nodeName === "I"){ - scope.editQuestion($event.target.parentElement.parentElement.parentElement.id.split('_')[1]); - } - }); - $('#question-up_'+question.index+'').on('click', function($event){ - if($event.target.nodeName==="A"){ - scope.questionUp($event.target.parentElement.parentElement.id.split('_')[1]); - } - else if($event.target.nodeName === "I"){ - scope.questionUp($event.target.parentElement.parentElement.parentElement.id.split('_')[1]); - } - }); - $('#question-down_'+question.index+'').on('click', function($event){ - if($event.target.nodeName==="A"){ - scope.questionDown($event.target.parentElement.parentElement.id.split('_')[1]); - } - else if($event.target.nodeName === "I"){ - scope.questionDown($event.target.parentElement.parentElement.parentElement.id.split('_')[1]); - } - - }); - }; - } - -FinalizeQuestion.$inject = - [ 'GetBasePath', - 'Rest', - 'Wait', - 'ProcessErrors', - '$compile', - 'Empty', - '$filter', - 'questionScope' - ]; diff --git a/awx/ui/client/src/job-templates/survey-maker/questions/main.js b/awx/ui/client/src/job-templates/survey-maker/questions/main.js index 346e6e9bff..957c066386 100644 --- a/awx/ui/client/src/job-templates/survey-maker/questions/main.js +++ b/awx/ui/client/src/job-templates/survey-maker/questions/main.js @@ -1,9 +1,7 @@ import questionScope from './question-scope.factory'; -import finalize from './finalize.factory'; import edit from './edit.factory'; export default angular.module('jobTemplates.surveyMaker.questions', []) - .factory('finalizeQuestion', finalize) .factory('questionScope', questionScope) .factory('editQuestion', edit); diff --git a/awx/ui/client/src/job-templates/survey-maker/render/multiple-choice.directive.js b/awx/ui/client/src/job-templates/survey-maker/render/multiple-choice.directive.js index 9dd272d27e..556d78ad9a 100644 --- a/awx/ui/client/src/job-templates/survey-maker/render/multiple-choice.directive.js +++ b/awx/ui/client/src/job-templates/survey-maker/render/multiple-choice.directive.js @@ -1,43 +1,31 @@ /* jshint unused: vars */ import {templateUrl} from '../../../shared/template-url/template-url.factory'; -function link($timeout, scope, element, attrs, ngModel) { - attrs.width = attrs.width || '100%'; +function link($timeout, CreateSelect2, scope, element, attrs, ngModel) { $timeout(function() { - $.fn.select2.amd.require( - [ 'select2/utils', - 'select2/dropdown', - 'select2/dropdown/search', - 'select2/dropdown/attachContainer', - 'select2/dropdown/closeOnSelect', - 'select2/dropdown/minimumResultsForSearch' - ], - function(Utils, Dropdown, Search, AttachContainer, CloseOnSelect, MinimumResultsForSearch) { - - var CustomAdapter = - _.reduce([Search, AttachContainer, CloseOnSelect, MinimumResultsForSearch], - function(Adapter, Decorator) { - return Utils.Decorate(Adapter, Decorator); - }, Dropdown); - - element.find('select').select2( - { multiple: scope.isMultipleSelect(), - minimumResultsForSearch: Infinity, - theme: 'bootstrap', - width: attrs.width, - dropdownAdapter: CustomAdapter - }); - }); + // select2-ify the dropdown. If the preview flag is passed here + // and it's true then we don't want to use a custom dropdown adapter. + // The reason for this is that the custom dropdown adapter breaks + // the draggability of this element. We're able to get away with this + // in preview mode (survey create/edit) because the element is disabled + // and we don't actually need the dropdown portion. Note that the custom + // dropdown adapter is used to get the dropdown contents to show up in + // a modal. + CreateSelect2({ + element: element.find('select'), + multiple: scope.isMultipleSelect(), + customDropdownAdapter: scope.preview ? false : true + }); }); } export default - [ '$timeout', - function($timeout) { + [ '$timeout', 'CreateSelect2', + function($timeout, CreateSelect2) { var directive = { restrict: 'E', require: 'ngModel', @@ -47,10 +35,11 @@ export default question: '=', isRequired: '=ngRequired', selectedValue: '=ngModel', - isDisabled: '=ngDisabled' + isDisabled: '=ngDisabled', + preview: '=' }, templateUrl: templateUrl('job-templates/survey-maker/render/multiple-choice'), - link: _.partial(link, $timeout) + link: _.partial(link, $timeout, CreateSelect2) }; return directive; } diff --git a/awx/ui/client/src/job-templates/survey-maker/render/multiple-choice.partial.html b/awx/ui/client/src/job-templates/survey-maker/render/multiple-choice.partial.html index 33bc78c2e5..e5a7a090ac 100644 --- a/awx/ui/client/src/job-templates/survey-maker/render/multiple-choice.partial.html +++ b/awx/ui/client/src/job-templates/survey-maker/render/multiple-choice.partial.html @@ -1,5 +1,5 @@
-
diff --git a/awx/ui/client/src/job-templates/survey-maker/render/survey-question.directive.js b/awx/ui/client/src/job-templates/survey-maker/render/survey-question.directive.js index 3bd240187d..4af8a3ca31 100644 --- a/awx/ui/client/src/job-templates/survey-maker/render/survey-question.directive.js +++ b/awx/ui/client/src/job-templates/survey-maker/render/survey-question.directive.js @@ -23,31 +23,104 @@ function findQuestionByIndex(questions, index) { }); } -function link(scope, element, attrs) { +function link($sce, $filter, Empty, scope, element, attrs) { + + function serialize(expression) { + return $sce.getTrustedHtml(expression); + } + + function sanitizeDefault() { + + var defaultValue = ""; + + if(scope.question.type === 'text'|| scope.question.type === "password" ){ + defaultValue = (scope.question.default) ? scope.question.default : ""; + defaultValue = $filter('sanitize')(defaultValue); + defaultValue = serialize(defaultValue); + } + + if(scope.question.type === "textarea"){ + defaultValue = (scope.question.default) ? scope.question.default : (scope.question.default_textarea) ? scope.question.default_textarea: "" ; + defaultValue = $filter('sanitize')(defaultValue); + defaultValue = serialize(defaultValue); + } + + if(scope.question.type === 'multiplechoice' || scope.question.type === "multiselect"){ + + scope.question.default = scope.question.default_multiselect || scope.question.default; + + if (scope.question.default) { + if (scope.question.type === 'multiselect' && typeof scope.question.default.split === 'function') { + defaultValue = scope.question.default.split('\n'); + } else if (scope.question.type !== 'multiselect') { + defaultValue = scope.question.default; + } + } else { + defaultValue = ''; + } + } + + if(scope.question.type === 'integer'){ + var min = (!Empty(scope.question.min)) ? scope.question.min : ""; + var max = (!Empty(scope.question.max)) ? scope.question.max : "" ; + defaultValue = (!Empty(scope.question.default)) ? scope.question.default : (!Empty(scope.question.default_int)) ? scope.question.default_int : "" ; + + } + if(scope.question.type === "float"){ + var min = (!Empty(scope.question.min)) ? scope.question.min : ""; + var max = (!Empty(scope.question.max)) ? scope.question.max : "" ; + defaultValue = (!Empty(scope.question.default)) ? scope.question.default : (!Empty(scope.question.default_float)) ? scope.question.default_float : "" ; + + } + + scope.defaultValue = defaultValue; + + } + + //for toggling the input on password inputs + scope.toggleInput = function(id) { + var buttonId = id + "_show_input_button", + inputId = id, + buttonInnerHTML = $(buttonId).html(); + if (buttonInnerHTML.indexOf("SHOW") > -1) { + $(buttonId).html("HIDE"); + $(inputId).attr("type", "text"); + } else { + $(buttonId).html("SHOW"); + $(inputId).attr("type", "password"); + } + }; if (!scope.question) { scope.question = findQuestionByIndex(scope.surveyQuestions, Number(attrs.index)); } + // Split out choices to be consumed by the multiple-choice directive if (!_.isUndefined(scope.question.choices)) { scope.choices = scope.question.choices.split('\n'); } + + sanitizeDefault(); + } export default - function() { - var directive = - { restrict: 'E', - scope: - { question: '=', - selectedValue: '=ngModel', - surveyQuestions: '=', - isRequired: '@ngRequired', - isDisabled: '@ngDisabled' - }, - templateUrl: templateUrl('job-templates/survey-maker/render/survey-question'), - link: link - }; + [ + '$sce', '$filter', 'Empty', + function($sce, $filter, Empty) { + var directive = + { restrict: 'E', + scope: + { question: '=', + surveyQuestions: '=', + isRequired: '@ngRequired', + isDisabled: '@ngDisabled', + preview: '=' + }, + templateUrl: templateUrl('job-templates/survey-maker/render/survey-question'), + link: _.partial(link, $sce, $filter, Empty) + }; - return directive; - } + return directive; + } + ]; diff --git a/awx/ui/client/src/job-templates/survey-maker/render/survey-question.partial.html b/awx/ui/client/src/job-templates/survey-maker/render/survey-question.partial.html index 24b95bfd43..441c9d9d51 100644 --- a/awx/ui/client/src/job-templates/survey-maker/render/survey-question.partial.html +++ b/awx/ui/client/src/job-templates/survey-maker/render/survey-question.partial.html @@ -1,8 +1,30 @@ - - +
+ +
+
+ +
+
+ + +
+
+ + + + +
+ +
+ +
+
+ +
diff --git a/awx/ui/client/src/job-templates/survey-maker/shared/question-definition.form.js b/awx/ui/client/src/job-templates/survey-maker/shared/question-definition.form.js index fa416b1768..30c441ae1a 100644 --- a/awx/ui/client/src/job-templates/survey-maker/shared/question-definition.form.js +++ b/awx/ui/client/src/job-templates/survey-maker/shared/question-definition.form.js @@ -15,10 +15,11 @@ export default addTitle: 'Add Question', editTitle: 'Edit Question', + titleClass: 'Form-secondaryTitle', base: 'survey_question', name: 'survey_question', well: true, - twoColumns: true, + cancelButton: false, fields: { question_name: { @@ -28,7 +29,8 @@ export default addRequired: true, editRequired: true, column: 1, - awSurveyQuestion: true + awSurveyQuestion: true, + class: 'Form-formGroup--singleColumn' }, question_description: { realName: 'question_description', @@ -36,16 +38,17 @@ export default type: 'text', addRequired: false, editRequired: false, - column: 1 + column: 1, + class: 'Form-formGroup--singleColumn' }, variable: { ealName: 'variable', type: 'custom', - control:'