From 832dcc770134c13d916c6745f49e207a0ab32f9a Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Fri, 26 Sep 2014 09:15:00 -0400 Subject: [PATCH] completed 'edit question' for survey maker --- awx/ui/static/js/helpers/Survey.js | 136 +++++++++++++------- awx/ui/static/less/survey-maker.less | 20 +-- awx/ui/static/lib/ansible/form-generator.js | 3 + 3 files changed, 102 insertions(+), 57 deletions(-) diff --git a/awx/ui/static/js/helpers/Survey.js b/awx/ui/static/js/helpers/Survey.js index 5dc24008a5..b3bebf0b8e 100644 --- a/awx/ui/static/js/helpers/Survey.js +++ b/awx/ui/static/js/helpers/Survey.js @@ -81,17 +81,17 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', 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" - }, + // 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) { @@ -114,7 +114,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', scope.survey_description = tempSurv.survey_description; // scope.survey_questions = data.spec; for(i=0; i\n'; + html = ""; + + question.index = index; + + if(!$('#question_'+question.index+':eq(0)').is('div')){ + html+='
'; + $('#finalized_questions').append(html); + } + + + + html = '
'+question.question_name+'
\n'; if(!Empty(question.question_description)){ - html += '
'+question.question_description+'
\n'; + html += '
'+question.question_description+'
\n'; } defaultValue = (question.default) ? question.default : ""; if(question.type === 'text' ){ - html+='
'+ '
'+ - ''+ + ''+ '
'; } if(question.type === "textarea"){ html+='
'+ '
'+ - ''+ + ''+ '
'; } if(question.type === 'multiplechoice' || question.type === "multiselect"){ @@ -296,7 +305,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', for( i = 0; i'+ + html+=''; } @@ -307,23 +316,20 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', max = (question.max) ? question.max : "" ; html+='
'+ '
'+ - ''+ + ''+ '
'; - } - if(question.type === "json"){ - } html += '
'; - html += ' '; + html += ' '; html += ' '; html += ' '; - html += ' '; + html += ' '; html+='
'; - $('#finalized_questions').append(html); + $('#question_'+question.index).append(html); - element = angular.element(document.getElementById('finalized_questions')); + element = angular.element(document.getElementById('question_'+question.index)); // element.html(html); $compile(element)(scope); // var questionScope = scope.$new; @@ -335,14 +341,44 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', }]) + .factory('EditQuestion', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', '$compile', 'GenerateForm', 'SurveyQuestionForm', + function(GetBasePath, Rest, Wait, ProcessErrors, $compile, GenerateForm, SurveyQuestionForm) { + return function(params) { + + var scope = params.scope, + index = params.index, + element, fld, i, + form = SurveyQuestionForm; + + + element = $('.question_final:eq('+index+')'); + element.attr('id', 'question_'+index); + element.empty(); + // $('#new_question .aw-form-well').remove(); + GenerateForm.inject(form, { id: 'question_'+index, mode: 'edit' , scope:scope, breadCrumbs: false}); + for(fld in form.fields){ + if(form.fields[fld].type === 'select'){ + for (i = 0; i < scope.answer_types.length; i++) { + if (scope.survey_questions[index][fld] === scope.answer_types[i].type) { + scope[fld] = scope.answer_types[i]; + } + } + } else { + scope[fld] = scope.survey_questions[index][fld]; + } + } + }; + }]) + .factory('SurveyControllerInit', ['$location', 'DeleteSurvey', 'EditSurvey', 'AddSurvey', 'GenerateForm', 'SurveyQuestionForm', 'Wait', 'Alert', - 'GetBasePath', 'Rest', 'ProcessErrors' , '$compile', 'FinalizeQuestion', + 'GetBasePath', 'Rest', 'ProcessErrors' , '$compile', 'FinalizeQuestion', 'EditQuestion', function($location, DeleteSurvey, EditSurvey, AddSurvey, GenerateForm, SurveyQuestionForm, Wait, Alert, - GetBasePath, Rest, ProcessErrors, $compile, FinalizeQuestion) { + GetBasePath, Rest, ProcessErrors, $compile, FinalizeQuestion, EditQuestion) { return function(params) { var scope = params.scope, // parent_scope = params.parent_scope, id = params.id, + // element, i, url; // iterator = (params.iterator) ? params.iterator : scope.iterator, // base = $location.path().replace(/^\//, '').split('/')[0]; @@ -353,7 +389,6 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', {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: 'float'} ]; @@ -384,15 +419,19 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', GenerateForm.inject(SurveyQuestionForm, { id:'new_question', mode: 'add' , scope:scope, breadCrumbs: false}); scope.required = true; //set the required checkbox to true via the ngmodel attached to scope.required. }; - scope.editQuestion = function(question){ - alert('success : ' + question); + scope.editQuestion = function(index){ + EditQuestion({ + index: index, + scope: scope + }); }; - scope.finalizeQuestion= function(data){ + scope.finalizeQuestion= function(data, index){ FinalizeQuestion({ scope: scope, question: data, id: id, + index: index //callback? }); }; @@ -410,7 +449,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', labels={}, min= "min", max = "max", - fld; + fld, key, elementID; //generator.clearApiErrors(); Wait('start'); @@ -433,14 +472,23 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', } } Wait('stop'); - scope.survey_questions.push(data); - $('#new_question .aw-form-well').remove(); - // scope.addQuestion() - $('#add_question_btn').show(); - // for(fld in form.fields){ - // $scope[fld] = ''; - // } - scope.finalizeQuestion(data , labels); + + if(GenerateForm.mode === 'add'){ + scope.survey_questions.push(data); + $('#new_question .aw-form-well').remove(); + // scope.addQuestion() + $('#add_question_btn').show(); + scope.finalizeQuestion(data , scope.survey_questions.length-1); + } + if(GenerateForm.mode === 'edit'){ + elementID = event.target.parentElement.parentElement.parentElement.parentElement.parentElement.id; + key = elementID.split('_')[1]; + scope.survey_questions[key] = data; + $('#'+elementID).empty(); + scope.finalizeQuestion(data , key); + } + + } catch (err) { Wait('stop'); diff --git a/awx/ui/static/less/survey-maker.less b/awx/ui/static/less/survey-maker.less index 20a6a0ac8b..045dcab670 100644 --- a/awx/ui/static/less/survey-maker.less +++ b/awx/ui/static/less/survey-maker.less @@ -34,26 +34,20 @@ } .question_final{ - /*border: 1px dashed; - *border-color: rgb(204,204,204); - *border-radius: 4px; + border-top: 1px dashed; + border-color: rgb(204,204,204); + border-radius: 4px; + /* opacity: 0.7; + */ padding: 5px; - opacity: 0.7; - - textarea{ + .final{ margin-left: 15px; } - input{ - margin-left: 15px; - } - - label{ - margin-left: 15px; - } } + #new_question{ margin-top: 5px; } diff --git a/awx/ui/static/lib/ansible/form-generator.js b/awx/ui/static/lib/ansible/form-generator.js index 357d6b57de..07e6a722a4 100644 --- a/awx/ui/static/lib/ansible/form-generator.js +++ b/awx/ui/static/lib/ansible/form-generator.js @@ -1439,6 +1439,9 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'Utilities', 'ListGenerator html += "\" "; html += "id=\"" + this.form.name + "_" + btn + "_btn\" "; + if(button.ngShow){ + html += this.attr(button, 'ngShow'); + } if (button.ngClick) { html += this.attr(button, 'ngClick'); }