- mailing bugs

- radio buttons/checkbox bugs
- cronjob to remove empty user inputs

bzr revid: rim@openerp.com-20131121110457-rbpbltdk1n9es37l
This commit is contained in:
Richard Mathot (OpenERP) 2013-11-21 12:04:57 +01:00
parent dbb0a2b8fe
commit 72e33b8cfe
8 changed files with 74 additions and 25 deletions

View File

@ -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',

View File

@ -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)

View File

@ -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"));
});

View File

@ -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',

View File

@ -0,0 +1,20 @@
<?xml version="1.0"?>
<openerp>
<data noupdate="1">
<!-- Remove unused user inputs -->
<record forcecreate="True" id="ir_cron_clean_empty_surveys"
model="ir.cron">
<field name="name">Run Clean empty surveys</field>
<field eval="True" name="active" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall" />
<field eval="'survey.user_input'" name="model" />
<field eval="'do_clean_emptys'" name="function" />
<field eval="'(False,)'" name="args" />
</record>
</data>
</openerp>

View File

@ -135,7 +135,7 @@
</div>
<field name="description" attrs="{'readonly': True}"/>
</page>
<page string="Pages">
<page string="Pages and questions">
<field name="page_ids" colspan="4" mode="tree" attrs="{'readonly':[('state','=','close')]}" context="{'default_survey_id': active_id}" nolabel="1">
<tree>
<field name="sequence" widget="handle"/>

View File

@ -115,7 +115,7 @@
<!-- A question -->
<template id='question' name='Question'>
<div class="question-wrapper container" t-att-id="prefix">
<div class="js_question-wrapper" t-att-id="prefix">
<t t-if="question.type in ['free_text']"><t t-call="survey.free_text"/></t>
<t t-if="question.type in ['textbox']"><t t-call="survey.textbox"/></t>
<t t-if="question.type in ['numerical_box']"><t t-call="survey.numerical_box"/></t>
@ -165,7 +165,7 @@
<option><t t-esc='label.value'/></option>
</t>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<option>Other...</option>
<option class="js_other_option"><span t-esc="question.children_ids[0].question" /></option>
</t>
</select>
</div>
@ -175,6 +175,7 @@
</t>
<t t-if='question.comments_allowed and not question.comment_count_as_answer'>
<div>
<span t-field="question.children_ids[0].question" />
<input type="text" class="form-control" t-att-name="prefix+'_comments'"/>
</div>
</t>
@ -191,12 +192,13 @@
</t>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<div class="input-group input-group-sm js_comments">
<span class="input-group-addon"><input type="radio" t-att-name="prefix" data-oe-survey-otherr="1"/></span>
<span class="input-group-addon"><input type="radio" t-att-name="prefix" data-oe-survey-otherr="1"/><span t-field="question.children_ids[0].question" /></span>
<input type="text" class="form-control" t-att-name="prefix" data-oe-survey-othert="1"/>
</div>
</t>
<t t-if='question.comments_allowed and not question.comment_count_as_answer'>
<div>
<span t-field="question.children_ids[0].question" />
<input type="text" class="form-control" t-att-name="prefix+'_comments'" data-oe-survey-othert="1"/>
</div>
</t>
@ -214,12 +216,13 @@
</t>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<div class="input-group input-group-sm js_comments">
<span class="input-group-addon"><input type="radio" t-att-name="prefix" data-oe-survey-otherr="1"/></span>
<span class="input-group-addon"><input type="radio" t-att-name="prefix" data-oe-survey-otherr="1"/><span t-field="question.children_ids[0].question" /></span>
<input type="text" class="form-control" t-att-name="prefix" data-oe-survey-othert="1"/>
</div>
</t>
<t t-if='question.comments_allowed and not question.comment_count_as_answer'>
<div>
<span t-field="question.children_ids[0].question" />
<input type="text" class="form-control" t-att-name="prefix+'_comments'" data-oe-survey-othert="1"/>
</div>
</t>
@ -240,12 +243,13 @@
<div class="row">
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<div class="input-group input-group-sm js_comments col-md-6">
<span class="input-group-addon"><input type="radio" t-att-name="prefix" data-oe-survey-otherr="1"/></span>
<span class="input-group-addon"><input type="radio" t-att-name="prefix" data-oe-survey-otherr="1"/><span t-field="question.children_ids[0].question" /></span>
<input type="text" class="form-control" t-att-name="prefix" data-oe-survey-othert="1"/>
</div>
</t>
<t t-if='question.comments_allowed and not question.comment_count_as_answer'>
<div class="col-md-6">
<span t-field="question.children_ids[0].question" />
<input type="text" class="form-control" t-att-name="prefix+'_comments'" data-oe-survey-othert="1"/>
</div>
</t>
@ -267,12 +271,13 @@
<div class="row">
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<div class="input-group input-group-sm js_comments col-md-4">
<span class="input-group-addon"><input type="radio" t-att-name="prefix" data-oe-survey-otherr="1"/></span>
<span class="input-group-addon"><input type="radio" t-att-name="prefix" data-oe-survey-otherr="1"/><span t-field="question.children_ids[0].question" /></span>
<input type="text" class="form-control" t-att-name="prefix" data-oe-survey-othert="1"/>
</div>
</t>
<t t-if='question.comments_allowed and not question.comment_count_as_answer'>
<div class="col-md-4">
<span t-field="question.children_ids[0].question" />
<input type="text" class="form-control" t-att-name="prefix+'_comments'" data-oe-survey-othert="1"/>
</div>
</t>
@ -293,7 +298,7 @@
</t>
<div>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<div class="input-group input-group-sm col-md-4">
<div class="input-group input-group-sm col-md-4 js_ck_comments">
<span class="input-group-addon"><input type="checkbox" t-att-name="prefix + '_other'" /> <span t-field="question.children_ids[0].question" /></span>
<input type="text" class="form-control" t-att-name="prefix + '_' + question.children_ids[0].id.__str__()"/>
</div>
@ -319,7 +324,7 @@
</t>
<div>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<div class="input-group input-group-sm col-md-4">
<div class="input-group input-group-sm js_ck_comments">
<span class="input-group-addon"><input type="checkbox" t-att-name="prefix + '_other'" /> <span t-field="question.children_ids[0].question" /></span>
<input type="text" class="form-control" t-att-name="prefix + '_' + question.children_ids[0].id.__str__()"/>
</div>
@ -345,7 +350,7 @@
</t>
<div>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<div class="input-group input-group-sm col-md-4">
<div class="input-group input-group-sm col-md-6 js_ck_comments">
<span class="input-group-addon"><input type="checkbox" t-att-name="prefix + '_other'" /> <span t-field="question.children_ids[0].question" /></span>
<input type="text" class="form-control" t-att-name="prefix + '_' + question.children_ids[0].id.__str__()"/>
</div>
@ -372,7 +377,7 @@
</t>
<div>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<div class="input-group input-group-sm col-md-4">
<div class="input-group input-group-sm col-md-4 js_ck_comments">
<span class="input-group-addon"><input type="checkbox" t-att-name="prefix + '_other'" /> <span t-field="question.children_ids[0].question" /></span>
<input type="text" class="form-control" t-att-name="prefix + '_' + question.children_ids[0].id.__str__()"/>
</div>

View File

@ -134,10 +134,11 @@ class survey_mail_compose_message(osv.TransientModel):
anonymous_id = None
def create_response_and_send_mail(wizard, token, partner_id, email):
""" Create one mail by recipients and replace __URL__ by link with identification token
"""
""" Create one mail by recipients and replace __URL__ by link with identification token """
#set url
url = token and re.sub(r'params=[^&]+', 'params=%s' % token, wizard.survey_id.public_url) or wizard.survey_id.public_url
url = wizard.survey_id.public_url
if token:
url = url + token
# post the message
values = {
'model': None,
@ -163,7 +164,7 @@ class survey_mail_compose_message(osv.TransientModel):
if wizard.public != 'email_private':
return None
else:
token = uuid.uuid4()
token = uuid.uuid4().__str__()
# create response with token
survey_response_obj.create(cr, uid, {
'survey_id': wizard.survey_id.id,