diff --git a/addons/survey/__openerp__.py b/addons/survey/__openerp__.py index 603f2ed142b..6c135a87da5 100644 --- a/addons/survey/__openerp__.py +++ b/addons/survey/__openerp__.py @@ -38,6 +38,7 @@ sent mails with user name and password for the invitation of the survey. 'website': 'https://www.openerp.com/', 'depends': ['email_template', 'mail', 'website'], 'data': [ + 'survey_cron.xml', 'security/survey_security.xml', 'security/ir.model.access.csv', 'survey_view.xml', diff --git a/addons/survey/controllers/main.py b/addons/survey/controllers/main.py index 2b64dd0e6e3..aa15188bdd2 100644 --- a/addons/survey/controllers/main.py +++ b/addons/survey/controllers/main.py @@ -84,8 +84,12 @@ class WebsiteSurvey(http.Controller): else: # An user cannot open hidden surveys without token return request.website.render("website.403") else: - user_input_id = user_input_obj.search(cr, uid, [('token', '=', token)])[0] - user_input = user_input_obj.browse(cr, uid, [user_input_id], context=context)[0] + 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] _logger.debug('Incoming data: %s', post) diff --git a/addons/survey/static/src/js/survey.js b/addons/survey/static/src/js/survey.js index a50bd16797a..2edadeddf1d 100644 --- a/addons/survey/static/src/js/survey.js +++ b/addons/survey/static/src/js/survey.js @@ -15,13 +15,24 @@ $(document).ready(function () { // Custom code for right behavior of dropdown menu with comments $('.js_drop input[data-oe-survey-othert="1"]').hide(); $('.js_drop select').change(function(){ - if($(this).val() === "Other..."){ + var other_val = $(this).find('.js_other_option').val(); + if($(this).val() === other_val){ $(this).closest('.js_drop').find('input[data-oe-survey-othert="1"]').show().focus(); } else{ $(this).closest('.js_drop').find('input[data-oe-survey-othert="1"]').val("").hide(); } }); + // Custom code for right behavior of checkboxes with comments box + $('.js_ck_comments>input[type="text"]').focusin(function(){ + $(this).prev().find('>input').attr("checked","checked"); + }); + $('.js_ck_comments input[type="checkbox"]').change(function(){ + if (! $(this).prop("checked")){ + $(this).closest('.js_ck_comments').find('input[type="text"]').val(""); + } + }); + var the_form = $('.js_surveyform'); var prefill_controller = the_form.attr("data-prefill"); @@ -67,7 +78,7 @@ $(document).ready(function () { }); // Handles the event when a question is focused out - $('.question-wrapper').focusout( + $('.js_question-wrapper').focusout( function(){ console.debug("[survey] Focus lost on question " + $(this).attr("id")); }); diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 02edb7f6c70..a75339cdf68 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -556,7 +556,7 @@ class survey_label(osv.osv): 'question_id': fields.many2one('survey.question', 'Question', required=True, ondelete='cascade'), 'sequence': fields.integer('Page number'), - 'value': fields.char("Suggested value", length=128, translate=True, + 'value': fields.char("Suggested value", translate=True, required=True) } @@ -580,14 +580,13 @@ class survey_user_input(osv.osv): 'state': fields.selection([('new', 'Not started yet'), ('skip', 'Partially completed'), ('done', 'Completed'), - ('cancel', 'Cancelled'), ('test', 'Test')], 'Status', readonly=True), # Optional Identification data - 'token': fields.char("Identification token", readonly=1, size=36), + 'token': fields.char("Identification token", readonly=1), 'partner_id': fields.many2one('res.partner', 'Partner', readonly=1), - 'email': fields.char("E-mail", size=64, readonly=1), + 'email': fields.char("E-mail", readonly=1), # The answers ! 'user_input_line_ids': fields.one2many('survey.user_input.line', @@ -604,6 +603,13 @@ class survey_user_input(osv.osv): ('unique_token', 'UNIQUE (token)', 'A token must be unique!') ] + 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, + [('type', '=', 'manually'), ('state', '=', 'new')], context=context) + if empty_user_input_ids: + self.unlink(cr, uid, empty_user_input_ids, context=context) + def action_survey_resent(self, cr, uid, ids, context=None): record = self.browse(cr, uid, ids[0], context=context) context = context or {} @@ -684,10 +690,11 @@ class survey_user_input_line(osv.osv): _description = 'Survey User Input Line' _rec_name = 'date_create' _columns = { - 'survey_id': fields.many2one('survey.survey', 'Survey', required=1, - readonly=1, ondelete='cascade'), 'user_input_id': fields.many2one('survey.user_input', 'User Input', ondelete='cascade', required=1), + 'survey_id': fields.many2one('survey.survey', 'Survey', required=1, + readonly=1, ondelete='cascade'), + 'date_create': fields.datetime('Create Date', required=1), # drop 'skipped': fields.boolean('Skipped'), 'question_id': fields.many2one('survey.question', 'Question', diff --git a/addons/survey/survey_cron.xml b/addons/survey/survey_cron.xml new file mode 100644 index 00000000000..c9ecb339f4a --- /dev/null +++ b/addons/survey/survey_cron.xml @@ -0,0 +1,20 @@ + + + + + + + Run Clean empty surveys + + + 1 + hours + -1 + + + + + + + diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index cbf6a2565d7..6c557851ece 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -135,7 +135,7 @@ - + diff --git a/addons/survey/views/survey_templates.xml b/addons/survey/views/survey_templates.xml index 35bd4976802..c3ee0ce27e2 100644 --- a/addons/survey/views/survey_templates.xml +++ b/addons/survey/views/survey_templates.xml @@ -115,7 +115,7 @@