From e82a20a5455b82a67b506d566bce68d3704ae45b Mon Sep 17 00:00:00 2001 From: "Richard Mathot (OpenERP)" Date: Fri, 8 Nov 2013 17:14:14 +0100 Subject: [PATCH] bzr revid: rim@openerp.com-20131108161414-nd908nzsr44n7u1e --- addons/survey/controllers/main.py | 33 ++++++++++++++---------- addons/survey/static/src/js/survey.js | 9 +++++++ addons/survey/views/survey_templates.xml | 32 ++++++++++++----------- 3 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 addons/survey/static/src/js/survey.js diff --git a/addons/survey/controllers/main.py b/addons/survey/controllers/main.py index f9022dbef48..88f4718b2a6 100644 --- a/addons/survey/controllers/main.py +++ b/addons/survey/controllers/main.py @@ -119,21 +119,21 @@ class WebsiteSurvey(http.Controller): 'pagination': pagination}) def validate_free_text(self, survey_id, page_nr, question, post): - answer_tag = survey_id.__str__() + '*' + page_nr + '*' + question.id.__str__() + answer_tag = survey_id.__str__() + '--' + page_nr + '--' + question.id.__str__() problems = [] if question.constr_mandatory: problems = problems + self.__has_empty_input(question, post, answer_tag) return problems def validate_textbox(self, survey_id, page_nr, question, post): - answer_tag = survey_id.__str__() + '*' + page_nr + '*' + question.id.__str__() + answer_tag = survey_id.__str__() + '--' + page_nr + '--' + question.id.__str__() problems = [] if question.constr_mandatory: problems = problems + self.__has_empty_input(question, post, answer_tag) return problems def validate_numerical_box(self, survey_id, page_nr, question, post): - answer_tag = survey_id.__str__() + '*' + page_nr + '*' + question.id.__str__() + answer_tag = survey_id.__str__() + '--' + page_nr + '--' + question.id.__str__() # Check for an empty input problems = [] if question.constr_mandatory: @@ -149,7 +149,7 @@ class WebsiteSurvey(http.Controller): return problems def validate_datetime(self, survey_id, page_nr, question, post): - answer_tag = survey_id.__str__() + '*' + page_nr + '*' + question.id.__str__() + answer_tag = survey_id.__str__() + '--' + page_nr + '--' + question.id.__str__() problems = [] if question.constr_mandatory: problems = problems + self.__has_empty_input(question, post, answer_tag) @@ -159,37 +159,42 @@ class WebsiteSurvey(http.Controller): return problems def validate_simple_choice_scale(self, survey_id, page_nr, question, post): - answer_tag = survey_id.__str__() + '*' + page_nr + '*' + question.id.__str__() + answer_tag = survey_id.__str__() + '--' + page_nr + '--' + question.id.__str__() problems = [] if question.constr_mandatory: problems = problems + self.__has_empty_input(question, post, answer_tag) return problems def validate_simple_choice_dropdown(self, survey_id, page_nr, question, post): - answer_tag = survey_id.__str__() + '*' + page_nr + '*' + question.id.__str__() + answer_tag = survey_id.__str__() + '--' + page_nr + '--' + question.id.__str__() problems = [] if question.constr_mandatory: problems = problems + self.__has_empty_input(question, post, answer_tag) return problems - # def validate_multiple_choice(self, survey_id, page_nr, question, post): - # answer_tag = survey_id.__str__() + '*' + page_nr + '*' + question.id.__str__() - # problems = [] - # return problems + def validate_multiple_choice(self, survey_id, page_nr, question, post): + answer_tag = survey_id.__str__() + '--' + page_nr + '--' + question.id.__str__() + problems = [] + if question.constr_mandatory: + answers = dict_keys_startswith(post, answer_tag) + print(answers) + if not answers: + return [{'qlabel': question.question, + 'errmsg': "This question is mandatory"}] + return problems # def validate_vector(self, survey_id, page_nr, question, post): - # answer_tag = survey_id.__str__() + '*' + page_nr + '*' + question.id.__str__() + # answer_tag = survey_id.__str__() + '--' + page_nr + '--' + question.id.__str__() # problems = [] # return problems # def validate_matrix(self, survey_id, page_nr, question, post): - # answer_tag = survey_id.__str__() + '*' + page_nr + '*' + question.id.__str__() + # answer_tag = survey_id.__str__() + '--' + page_nr + '--' + question.id.__str__() # problems = [] # return problems def __has_empty_input(self, question, post, answer_tag): ''' Check for an empty input ''' - print(answer_tag) if answer_tag not in post or post[answer_tag].strip() == "": return [{'qlabel': question.question, 'errmsg': "This question is mandatory"}] @@ -197,7 +202,7 @@ class WebsiteSurvey(http.Controller): return [] -def __dict_keys_startswith(self, dictionary, string): +def dict_keys_startswith(dictionary, string): '''Returns a dictionary containing the elements of whose keys start with . diff --git a/addons/survey/static/src/js/survey.js b/addons/survey/static/src/js/survey.js new file mode 100644 index 00000000000..e24bda38079 --- /dev/null +++ b/addons/survey/static/src/js/survey.js @@ -0,0 +1,9 @@ +$(document).ready(function () { + console.debug("[survey] Custom JS for survey loaded"); + $('.survey-btn').click( + function(){ + console.debug("[survey] Page button clicked"); + } + ); + +}); \ No newline at end of file diff --git a/addons/survey/views/survey_templates.xml b/addons/survey/views/survey_templates.xml index c448c7041d3..be635b90c25 100644 --- a/addons/survey/views/survey_templates.xml +++ b/addons/survey/views/survey_templates.xml @@ -42,6 +42,9 @@