diff --git a/addons/survey/__openerp__.py b/addons/survey/__openerp__.py index 6c135a87da5..4afb83530ad 100644 --- a/addons/survey/__openerp__.py +++ b/addons/survey/__openerp__.py @@ -41,7 +41,7 @@ sent mails with user name and password for the invitation of the survey. 'survey_cron.xml', 'security/survey_security.xml', 'security/ir.model.access.csv', - 'survey_view.xml', + 'views/survey_views.xml', 'views/survey_templates.xml', #'wizard/survey_answer.xml', #'wizard/survey_print_statistics.xml', @@ -62,4 +62,5 @@ sent mails with user name and password for the invitation of the survey. 'css': ['static/src/css/survey.css'], 'js': ['static/src/js/survey.js'], } + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/survey/controllers/main.py b/addons/survey/controllers/main.py index 56f3e14d16f..d9166aad4c4 100644 --- a/addons/survey/controllers/main.py +++ b/addons/survey/controllers/main.py @@ -49,7 +49,6 @@ class WebsiteSurvey(http.Controller): surveys = survey_obj.browse(cr, uid, survey_ids, context=context) return request.website.render('survey.list', {'surveys': surveys}) - # Survey displaying @website.route(['/survey/fill//'], type='http', auth='public', multilang=True) @@ -127,10 +126,6 @@ class WebsiteSurvey(http.Controller): # @website.route(['/survey/validate/'], # type='json', auth='public', multilang=True) - # def validate(self, survey=None, **post): - # # for each {K:V} in post, check - # _logger.debug("Incoming json data: " + post.__str__()) - # return {'valid': True, 'errors': None} @website.route(['/survey/submit/'], type='http', auth='public', multilang=True) @@ -167,10 +162,8 @@ class WebsiteSurvey(http.Controller): type='http', auth='public', multilang=True) def print_empty_survey(self, survey=None, **post): '''Display an empty survey in printable view''' - pagination = {'current': -1, 'next': 0} return request.website.render('survey.survey_print', - {'survey': survey, - 'pagination': pagination}) + {'survey': survey, 'page_nr': 0}) # Pagination @@ -289,11 +282,28 @@ class WebsiteSurvey(http.Controller): # TODO when datepicker will be available return errors - # def validate_simple_choice(self, question, post, answer_tag): - # problems = [] - # if question.constr_mandatory: - # problems = problems + self.__has_empty_input(question, post, answer_tag) - # return problems + def validate_simple_choice(self, question, post, answer_tag): + errors = {} + comment_tag = "%s_%s" % (answer_tag, question.comment_children_ids[0].id) + # Empty answer to mandatory question + if question.constr_mandatory and not answer_tag in post: + errors.update({answer_tag: question.constr_error_msg}) + # Answer is a comment and is empty + if question.constr_mandatory and answer_tag in post and post[answer_tag] == "-1" and question.comment_count_as_answer and comment_tag in post and not post[comment_tag].strip(): + errors.update({answer_tag: question.constr_error_msg}) + # There is a comment and it should be validated + # if question.comment_allowed and comment_tag in post and post[comment_tag].strip(): + + + ### if comments_allowed: + ### if validation des comments required + ### + ### if comment_count_as answer and question mandatory + ### + ### else: + ### if question mandatory: + + return errors # def validate_multiple_choice(self, question, post, answer_tag): # problems = [] diff --git a/addons/survey/docs/changelog.rst b/addons/survey/docs/changelog.rst new file mode 100644 index 00000000000..e69de29bb2d diff --git a/addons/survey/static/src/js/survey.js b/addons/survey/static/src/js/survey.js index 2edadeddf1d..13892173ea3 100644 --- a/addons/survey/static/src/js/survey.js +++ b/addons/survey/static/src/js/survey.js @@ -17,9 +17,11 @@ $(document).ready(function () { $('.js_drop select').change(function(){ var other_val = $(this).find('.js_other_option').val(); if($(this).val() === other_val){ + $(this).parent().removeClass('col-md-12').addClass('col-md-6'); $(this).closest('.js_drop').find('input[data-oe-survey-othert="1"]').show().focus(); } else{ + $(this).parent().removeClass('col-md-6').addClass('col-md-12'); $(this).closest('.js_drop').find('input[data-oe-survey-othert="1"]').val("").hide(); } }); diff --git a/addons/survey/survey.py b/addons/survey/survey.py index c4f06110300..7010eaca995 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -85,7 +85,7 @@ class survey_survey(osv.osv): _columns = { 'title': fields.char('Title', size=128, required=1, translate=True), - 'category': fields.char('Category'), + 'res_model': fields.char('Category'), 'page_ids': fields.one2many('survey.page', 'survey_id', 'Pages'), 'date_open': fields.datetime('Opening date'), 'date_close': fields.datetime('Closing date'), @@ -121,7 +121,6 @@ class survey_survey(osv.osv): } _defaults = { - 'category': lambda s, cr, uid, c: _('Uncategorized'), 'user_input_limit': 0, 'state': 'draft', 'visible_to_user': True, @@ -360,25 +359,30 @@ class survey_question(osv.osv): ('simple_choice', 'Multiple choice (one answer)'), ('multiple_choice', 'Multiple choice (multiple answers)'), ('matrix', 'Matrix')], 'Question Type', required=1), + 'matrix_subtype': fields.selection([('simple', 'One choice per line'), + ('multiple', 'Several choices per line')], 'Matrix Type'), 'labels_ids': fields.one2many('survey.label', 'question_id', 'Suggested answers', oldname='answer_choice_ids'), + 'labels_ids_2': fields.one2many('survey.label', + 'question_id_2', 'Suggested answers'), # Display options 'column_nb': fields.selection([('12', '1 column choices'), - ('6', '2 columns choices'), - ('4', '3 columns choices'), - ('3', '4 columns choices'), - ('2', '6 columns choices') - ], 'Number of columns'), + ('6', '2 columns choices'), + ('4', '3 columns choices'), + ('3', '4 columns choices'), + ('2', '6 columns choices')], + 'Number of columns'), 'display_mode': fields.selection([('columns', 'Columns'), - ('dropdown', 'Dropdown menu') - ], 'Display mode'), + ('dropdown', 'Dropdown menu')], + 'Display mode'), # Comments 'comments_allowed': fields.boolean('Allow comments', oldname="allow_comment"), - 'comment_children_ids': fields.one2many('survey.question', - 'parent_id', 'Comment question'), # one2one in fact + 'comment_children_ids': fields.many2many('survey.question', + 'question_comment_children_ids', 'comment_id', 'parent_id', + 'Comment question'), # one2one in fact 'comment_count_as_answer': fields.boolean('Comment field is an answer choice', oldname='make_comment_field'), @@ -421,6 +425,7 @@ class survey_question(osv.osv): _defaults = { 'page_id': lambda s, cr, uid, c: c.get('page_id'), 'type': 'free_text', + 'matrix_subtype': 'simple', 'column_nb': '12', 'display_mode': 'dropdown', 'constr_type': 'at least', @@ -559,8 +564,10 @@ class survey_label(osv.osv): _columns = { 'question_id': fields.many2one('survey.question', 'Question', - required=True, ondelete='cascade'), - 'sequence': fields.integer('Page number'), + ondelete='cascade'), + 'question_id_2': fields.many2one('survey.question', 'Question', + ondelete='cascade'), + 'sequence': fields.integer('Label Sequence order'), 'value': fields.char("Suggested value", translate=True, required=True) } @@ -608,6 +615,45 @@ class survey_user_input(osv.osv): ('unique_token', 'UNIQUE (token)', 'A token must be unique!') ] + def create(self, cr, uid, vals, context=None): + #if not vals['test_entry']: + # if survey_obj.exists(cr, uid, survey.id, context=context) == []: + # return werkzeug.utils.redirect("/survey/") + + # # In case of auth required, block public user + # if survey.auth_required and uid == request.registry['website'].get_public_user(request.cr, SUPERUSER_ID, request.context).id: + # return request.website.render("website.401") + + # # In case of non open surveys + # if survey.state != 'open': + # return request.website.render("survey.notopen") + + # # If enough surveys completed + # if survey.user_input_limit > 0: + # completed = user_input_obj.search(cr, uid, [('state', '=', 'done')], count=True) + # if completed >= survey.user_input_limit: + # return request.website.render("survey.notopen") + + # # Manual surveying + # if not token: + # if survey.visible_to_user: + # user_input_id = user_input_obj.create(cr, uid, {'survey_id': survey.id}) + # user_input = user_input_obj.browse(cr, uid, [user_input_id], context=context)[0] + # else: # An user cannot open hidden surveys without token + # return request.website.render("website.403") + # else: + # try: + # user_input_id = user_input_obj.search(cr, uid, [('token', '=', token)])[0] + # except IndexError: # Invalid token + # return request.website.render("website.403") + # else: + # user_input = user_input_obj.browse(cr, uid, [user_input_id], context=context)[0] + + return super(survey_user_input, self).create(cr, uid, vals, context) + + # raise osv.except_osv(_('Warning!'), _('You must enter one or more answers for question "%s" of page %s .') % (vals['question'], page.title)) + + def do_clean_emptys(self, cr, uid, automatic=False, context=None): ''' Remove empty user inputs that have been created manually ''' empty_user_input_ids = self.search(cr, uid, diff --git a/addons/survey/survey_cron.xml b/addons/survey/survey_cron.xml index c9ecb339f4a..7f22bbcb5ff 100644 --- a/addons/survey/survey_cron.xml +++ b/addons/survey/survey_cron.xml @@ -1,20 +1,19 @@ - Run Clean empty surveys - - + + 1 hours -1 - - - - + + + + diff --git a/addons/survey/views/survey_templates.xml b/addons/survey/views/survey_templates.xml index 62090a6e0c7..ce18466ea86 100644 --- a/addons/survey/views/survey_templates.xml +++ b/addons/survey/views/survey_templates.xml @@ -9,11 +9,10 @@

Open surveys

- + -
TitleCategory
Title
@@ -28,7 +27,7 @@
-
+

Thank you!

@@ -42,7 +41,7 @@
-
+

Not open

This survey is not open. Thank you for your interest!

@@ -89,9 +88,7 @@