From 3e067585138cf08ea838b086eb7f43b5576a5b71 Mon Sep 17 00:00:00 2001 From: "Richard Mathot (OpenERP)" Date: Tue, 28 Jan 2014 13:47:07 +0100 Subject: [PATCH] [IMP] corrections on web client actions (all the links and buttons should work now) [IMP] views enhancements [REM] outdated code bzr revid: rim@openerp.com-20140128124707-qlytna4nceoklw52 --- addons/survey/__openerp__.py | 1 - addons/survey/static/src/css/survey.css | 8 - addons/survey/static/src/js/survey.js | 62 ++++---- addons/survey/survey.py | 186 ++++++++++++++++-------- addons/survey/views/survey_views.xml | 115 ++++++++------- 5 files changed, 226 insertions(+), 146 deletions(-) diff --git a/addons/survey/__openerp__.py b/addons/survey/__openerp__.py index 2c4b0560612..d4922833085 100644 --- a/addons/survey/__openerp__.py +++ b/addons/survey/__openerp__.py @@ -58,7 +58,6 @@ sent mails with personal token for the invitation of the survey. 'sequence': 10, 'images': [], '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/static/src/css/survey.css b/addons/survey/static/src/css/survey.css index 8feb0c7fc9e..95cd27ed098 100644 --- a/addons/survey/static/src/css/survey.css +++ b/addons/survey/static/src/css/survey.css @@ -35,11 +35,3 @@ .openerp .oe_kanban_survey .oe_inactive { color: #aaaaaa; } - -.openerp .oe_kanban_survey .oe_stats_box { - width: 96px; - display: inline-block; - margin: 2px 2px 0px 0px; - text-align: center; - border: 1px solid rgba(0, 0, 0, 0.16); -} \ No newline at end of file diff --git a/addons/survey/static/src/js/survey.js b/addons/survey/static/src/js/survey.js index ebf80b2a3fa..3ff47795a56 100644 --- a/addons/survey/static/src/js/survey.js +++ b/addons/survey/static/src/js/survey.js @@ -1,20 +1,25 @@ /* -* OpenERP, Open Source Management Solution -* Copyright (C) 2004-TODAY OpenERP S.A. -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Affero General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with this program. If not, see . -*/ + * OpenERP, Open Source Management Solution + * Copyright (C) 2004-TODAY OpenERP S.A. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +/* + * This file is intended to add interactivity to survey forms rendered by + * the website engine. + */ $(document).ready(function () { 'use strict'; @@ -25,10 +30,12 @@ $(document).ready(function () { var prefill_controller = the_form.attr("data-prefill"); var validate_controller = the_form.attr("data-validate"); var submit_controller = the_form.attr("data-submit"); + var print_mode = false; // Printing mode: will disable all the controls in the form if (_.isUndefined(submit_controller)) { $('.js_surveyform :input').prop('disabled', true); + print_mode = true } // Custom code for right behavior of radio buttons with comments box @@ -81,10 +88,6 @@ $(document).ready(function () { return prefill_def; }; - // function validate(form){ - // return false; - // } - // Parameters for form submission $('.js_surveyform').ajaxForm({ url: submit_controller, @@ -115,14 +118,19 @@ $(document).ready(function () { } }); - // Handles the event when a question is focused out - $('.js_question-wrapper').focusout( - function(){ - console.debug("[survey] Focus lost on question " + $(this).attr("id")); + // // Handles the event when a question is focused out + // $('.js_question-wrapper').focusout( + // function(){ + // console.debug("[survey] Focus lost on question " + $(this).attr("id")); + // }); + + // Launch prefilling + prefill().then(function(){ + // Activate the print dialog if needed + if (print_mode){ + window.print(); + }; }); console.debug("[survey] Custom JS for survey loaded!"); - - // Launch prefilling - prefill(); }); diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 1ad557c3760..b02cac0d72e 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -90,13 +90,21 @@ class survey_survey(osv.Model): def _get_public_url(self, cr, uid, ids, name, arg, context=None): """ Computes a public URL for the survey """ - res = dict((id, 0) for id in ids) base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url') - for survey_browse in self.browse(cr, uid, ids, context=context): - res[survey_browse.id] = urljoin(base_url, "survey/start/%s/" - % survey_browse.id) - return res + return {id: urljoin(base_url, "survey/start/%s/" % id) for id in ids} + + def _get_print_url(self, cr, uid, ids, name, arg, context=None): + """ Computes a printing URL for the survey """ + base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, + 'web.base.url') + return {id: urljoin(base_url, "survey/print/%s/" % id) for id in ids} + + def _get_result_url(self, cr, uid, ids, name, arg, context=None): + """ Computes an URL for the survey results """ + base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, + 'web.base.url') + return {id: urljoin(base_url, "survey/result/%s/" % id) for id in ids} # Model fields # @@ -104,8 +112,8 @@ class survey_survey(osv.Model): 'title': fields.char('Title', required=1, translate=True), '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'), + 'date_open': fields.datetime('Opening date', readonly=True), + 'date_close': fields.datetime('Closing date', readonly=True), 'user_input_limit': fields.integer('Automatic closing limit', help="Limits the number of instances of this survey that can be completed (if set to 0, no limit is applied)", oldname='max_response_limit'), @@ -132,6 +140,10 @@ class survey_survey(osv.Model): 'User responses', readonly=1), 'public_url': fields.function(_get_public_url, string="Public link", type="char"), + 'print_url': fields.function(_get_print_url, + string="Print link", type="char"), + 'result_url': fields.function(_get_result_url, + string="Results link", type="char"), 'email_template_id': fields.many2one('email.template', 'Email Template', ondelete='set null'), 'thank_you_message': fields.html('Thank you message', translate=True, @@ -153,6 +165,25 @@ class survey_survey(osv.Model): # Public methods # + def write(self, cr, uid, ids, vals, context=None): + new_state = vals.get('state') + if new_state == 'draft': + vals.update({'date_open': None}) + vals.update({'date_close': None}) + self.message_post(cr, uid, ids, body="""

Survey drafted

""", context=context) + elif new_state == 'open': + if self._has_questions(cr, uid, ids, context=None): + vals.update({'date_open': fields.datetime.now(), 'date_close': None}) + self.message_post(cr, uid, ids, body="""

Survey opened

""", context=context) + else: + raise osv.except_osv(_('Error!'), _('You can not open a survey that has no questions.')) + elif new_state == 'close': + vals.update({'date_close': fields.datetime.now()}) + self.message_post(cr, uid, ids, body="""

Survey closed

""", context=context) + elif new_state == 'cancel': + self.message_post(cr, uid, ids, body="""

Survey cancelled

""", context=context) + return super(survey_survey, self).write(cr, uid, ids, vals, context=context) + def copy(self, cr, uid, ids, default=None, context=None): vals = {} current_rec = self.read(cr, uid, ids, context=context) @@ -201,35 +232,41 @@ class survey_survey(osv.Model): else: return (pages[current_page_index + 1][1], current_page_index + 1, False) - def action_edit_survey(self, cr, uid, ids, context=None): - ''' Open a survey in edition view ''' - id = ids[0] - context.update({ - 'survey_id': id, - 'edit': True, - 'ir_actions_act_window_target': 'new', - }) + # Web client actions + + def action_kanban_update_state(self, cr, uid, ids, context=None): + ''' Change the state from the kanban ball ''' + for survey in self.read(cr, uid, ids, ['state'], context=context): + if survey['state'] == 'draft': + self.write(cr, uid, [survey['id']], {'state': 'open'}, context=context) + elif survey['state'] == 'open': + self.write(cr, uid, [survey['id']], {'state': 'close'}, context=context) + elif survey['state'] == 'close': + self.write(cr, uid, [survey['id']], {'state': 'cancel'}, context=context) + elif survey['state'] == 'cancel': + self.write(cr, uid, [survey['id']], {'state': 'draft'}, context=context) + return {} + + def action_start_survey(self, cr, uid, ids, context=None): + ''' Open the website page with the survey form ''' return { - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'survey.question.wiz', - 'type': 'ir.actions.act_window', - 'target': 'new', - 'name': self.browse(cr, uid, id, context=context).title, - 'context': context + 'type': 'ir.actions.act_url', + 'name': "Start Survey", + 'target': 'self', + 'url': self.read(cr, uid, ids, ['public_url'], context=context)[0]['public_url'] } def action_send_survey(self, cr, uid, ids, context=None): ''' Open a window to compose an email, pre-filled with the survey message ''' if not self._has_questions(cr, uid, ids, context=None): - raise osv.except_osv(_('Error!'), _('You can not send a survey that has no questions.')) + raise osv.except_osv(_('Error!'), _('You cannot send an invitation for a survey that has no questions.')) survey_browse = self.pool.get('survey.survey').browse(cr, uid, ids, context=context)[0] if survey_browse.state != "open": raise osv.except_osv(_('Warning!'), - _("You cannot send invitations since the survey is not open.")) + _("You cannot send invitations unless the survey is open.")) assert len(ids) == 1, 'This option should only be used for a single \ survey at a time.' @@ -239,15 +276,14 @@ class survey_survey(osv.Model): template_id = templates[1] if len(templates) > 0 else False ctx = dict(context) - ctx.update({ - 'default_model': 'survey.survey', - 'default_res_id': ids[0], - 'default_survey_id': ids[0], - 'default_use_template': bool(template_id), - 'default_template_id': template_id, - 'default_composition_mode': 'comment', - 'survey_state': survey_browse.state - }) + ctx.update({'default_model': 'survey.survey', + 'default_res_id': ids[0], + 'default_survey_id': ids[0], + 'default_use_template': bool(template_id), + 'default_template_id': template_id, + 'default_composition_mode': 'comment', + 'survey_state': survey_browse.state} + ) return { 'type': 'ir.actions.act_window', 'view_type': 'form', @@ -257,24 +293,32 @@ class survey_survey(osv.Model): 'context': ctx, } - def write(self, cr, uid, ids, vals, context=None): - new_state = vals.get('state') - if new_state == 'draft': - vals.update({'date_open': None}) - vals.update({'date_close': None}) - self.message_post(cr, uid, ids, body="""

Survey drafted

""", context=context) - elif new_state == 'open': - if self._has_questions(cr, uid, ids, context=None): - vals.update({'date_open': fields.datetime.now(), 'date_close': None}) - self.message_post(cr, uid, ids, body="""

Survey opened

""", context=context) - else: - raise osv.except_osv(_('Error!'), _('You can not open a survey that has no questions.')) - elif new_state == 'close': - vals.update({'date_close': fields.datetime.now()}) - self.message_post(cr, uid, ids, body="""

Survey closed

""", context=context) - elif new_state == 'cancel': - self.message_post(cr, uid, ids, body="""

Survey cancelled

""", context=context) - return super(survey_survey, self).write(cr, uid, ids, vals, context=context) + def action_print_survey(self, cr, uid, ids, context=None): + ''' Open the website page with the survey printable view ''' + return { + 'type': 'ir.actions.act_url', + 'name': "Print Survey", + 'target': 'self', + 'url': self.read(cr, uid, ids, ['print_url'], context=context)[0]['print_url'] + } + + def action_result_survey(self, cr, uid, ids, context=None): + ''' Open the website page with the survey results view ''' + return { + 'type': 'ir.actions.act_url', + 'name': "Results of the Survey", + 'target': 'self', + 'url': self.read(cr, uid, ids, ['result_url'], context=context)[0]['result_url'] + } + + def action_test_survey(self, cr, uid, ids, context=None): + ''' Open the website page with the survey form into test mode''' + return { + 'type': 'ir.actions.act_url', + 'name': "Results of the Survey", + 'target': 'self', + 'url': self.read(cr, uid, ids, ['public_url'], context=context)[0]['public_url'] + "phantom/" + } class survey_page(osv.Model): @@ -679,6 +723,10 @@ class survey_user_input(osv.Model): 'user_input_line_ids': fields.one2many('survey.user_input_line', 'user_input_id', 'Answers'), + # URLs used to display the answers + 'result_url': fields.related('survey_id', 'result_url', string="Public link to the survey results"), + 'print_url': fields.related('survey_id', 'print_url', string="Public link to the empty survey"), + #'quizz_score': fields.function() } _defaults = { @@ -692,12 +740,12 @@ class survey_user_input(osv.Model): ('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 + def copy(self, cr, uid, id, default=None, context=None): + raise osv.except_osv(_('Warning!'), _('You cannot duplicate this \ + element!')) - .. note: - This function does not remove - ''' + def do_clean_emptys(self, cr, uid, automatic=False, context=None): + ''' Remove empty user inputs that have been created manually (cronjob) ''' empty_user_input_ids = self.search(cr, uid, [('type', '=', 'manually'), ('state', '=', 'new'), ('date_create', '<', (datetime.datetime.now() - datetime.timedelta(hours=1)).strftime(DF))], @@ -706,6 +754,7 @@ class survey_user_input(osv.Model): self.unlink(cr, uid, empty_user_input_ids, context=context) def action_survey_resent(self, cr, uid, ids, context=None): + ''' Sent again the invitation ''' record = self.browse(cr, uid, ids[0], context=context) context = context or {} context.update({ @@ -714,12 +763,27 @@ class survey_user_input(osv.Model): 'default_multi_email': record.email or "", 'default_public': 'email_private', }) - return self.pool.get('survey.survey').action_survey_sent(cr, uid, + return self.pool.get('survey.survey').action_send_survey(cr, uid, [record.survey_id.id], context=context) - def copy(self, cr, uid, id, default=None, context=None): - raise osv.except_osv(_('Warning!'), _('You cannot duplicate this \ - element!')) + def action_view_answers(self, cr, uid, ids, context=None): + ''' Open the website page with the survey form ''' + user_input = self.read(cr, uid, ids, ['print_url', 'token'], context=context)[0] + return { + 'type': 'ir.actions.act_url', + 'name': "View Answers", + 'target': 'self', + 'url': '%s%s/' % (user_input['print_url'], user_input['token']) + } + + def action_survey_results(self, cr, uid, ids, context=None): + ''' Open the website page with the survey results ''' + return { + 'type': 'ir.actions.act_url', + 'name': "Survey Results", + 'target': 'self', + 'url': self.read(cr, uid, ids, ['result_url'], context=context)[0]['result_url'] + } class survey_user_input_line(osv.Model): @@ -735,7 +799,7 @@ class survey_user_input_line(osv.Model): relation='survey.page', string="Page"), 'survey_id': fields.related('user_input_id', 'survey_id', type="many2one", relation="survey.survey", - string='Survey'), + string='Survey', store=True), 'date_create': fields.datetime('Create Date', required=1), 'skipped': fields.boolean('Skipped'), 'answer_type': fields.selection([('text', 'Text'), diff --git a/addons/survey/views/survey_views.xml b/addons/survey/views/survey_views.xml index fd75746d793..4d4cdefb008 100644 --- a/addons/survey/views/survey_views.xml +++ b/addons/survey/views/survey_views.xml @@ -11,14 +11,14 @@ - - - + + + - - - + + + @@ -27,10 +27,11 @@ survey_user_input_form survey.user_input -
+
-
@@ -67,7 +68,7 @@ survey_user_input_tree survey.user_input - + @@ -75,8 +76,6 @@ -