[IMP] Prefilling and saving for scalar types, views improvements and typos
bzr revid: rim@openerp.com-20131216153244-y8ctabjwipr0infc
This commit is contained in:
parent
28d2e77c77
commit
3989d19205
|
@ -177,9 +177,45 @@ class WebsiteSurvey(http.Controller):
|
|||
return request.website.render("website.403")
|
||||
|
||||
# AJAX prefilling of a survey
|
||||
# @website.route(['/survey/prefill/<model("survey.survey"):survey>'],
|
||||
# type='json', auth='public', multilang=True):
|
||||
# def prefill(self, survey, **post):
|
||||
@website.route(['/survey/prefill/<model("survey.survey"):survey>/<string:token>',
|
||||
'/survey/prefill/<model("survey.survey"):survey>/<string:token>/<model("survey.page"):page>'],
|
||||
type='http', auth='public', multilang=True)
|
||||
def prefill(self, survey, token, page=None, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
user_input_line_obj = request.registry['survey.user_input_line']
|
||||
ret = {}
|
||||
|
||||
# Fetch previous answers
|
||||
if page:
|
||||
ids = user_input_line_obj.search(cr, uid, [('user_input_id.token', '=', token), ('page_id', '=', page.id)], context=context)
|
||||
else:
|
||||
ids = user_input_line_obj.search(cr, uid, [('user_input_id.token', '=', token)], context=context)
|
||||
previous_answers = user_input_line_obj.browse(cr, uid, ids, context=context)
|
||||
|
||||
# Return non empty answers in a JSON compatible format
|
||||
for answer in previous_answers:
|
||||
if not answer.skipped:
|
||||
answer_tag = '%s_%s_%s' % (answer.survey_id.id, answer.page_id.id, answer.question_id.id)
|
||||
answer_value = None
|
||||
if answer.answer_type == 'free_text':
|
||||
answer_value = answer.value_free_text
|
||||
elif answer.answer_type == 'text':
|
||||
answer_value = answer.value_text
|
||||
elif answer.answer_type == 'number':
|
||||
answer_value = answer.value_number
|
||||
elif answer.answer_type == 'date':
|
||||
answer_value = answer.value_date
|
||||
# TODO mettre les QCM ici
|
||||
if answer_value:
|
||||
ret.update({answer_tag: answer_value})
|
||||
else:
|
||||
_logger.warning("[survey] Fetching None answer for question %s" % answer_tag)
|
||||
|
||||
return json.dumps(ret)
|
||||
|
||||
# load all the user input lines corresponding to token & page (or survey)
|
||||
# format them into a json dict
|
||||
# return them to JS
|
||||
|
||||
# AJAX validation of some questions
|
||||
# @website.route(['/survey/validate/<model("survey.survey"):survey>'],
|
||||
|
|
|
@ -60,9 +60,19 @@ $(document).ready(function () {
|
|||
var validate_controller = the_form.attr("data-validate");
|
||||
var submit_controller = the_form.attr("data-submit");
|
||||
|
||||
// function prefill(form){
|
||||
// return false;
|
||||
// }
|
||||
// Pre-filling of the form with previous answers
|
||||
function prefill(){
|
||||
var prefill_def = $.ajax(prefill_controller, {dataType: "json"})
|
||||
.done(function(json_data){
|
||||
console.log(json_data)
|
||||
_.each(json_data, function(value, key){
|
||||
the_form.find(".form-control[name=" + key + "]").val(value);
|
||||
});
|
||||
})
|
||||
.fail(function(){
|
||||
console.warn("[survey] Unable to load prefill data");
|
||||
});
|
||||
};
|
||||
|
||||
// function validate(form){
|
||||
// return false;
|
||||
|
@ -105,4 +115,6 @@ $(document).ready(function () {
|
|||
});
|
||||
|
||||
console.debug("[survey] Custom JS for survey loaded!");
|
||||
|
||||
prefill();
|
||||
});
|
||||
|
|
|
@ -745,7 +745,7 @@ class survey_label(osv.osv):
|
|||
required=True)
|
||||
}
|
||||
defaults = {
|
||||
'sequence': 10
|
||||
'sequence': 100
|
||||
}
|
||||
|
||||
|
||||
|
@ -934,7 +934,8 @@ class survey_user_input_line(osv.osv):
|
|||
'value_number': fields.float("Numerical answer"),
|
||||
'value_date': fields.datetime("Date answer"),
|
||||
'value_free_text': fields.text("Free Text answer"),
|
||||
'value_suggested': fields.many2one('survey.label'),
|
||||
'value_suggested': fields.many2one('survey.label', "Suggested answer"),
|
||||
'value_suggested_row': fields.many2one('survey.label', "Row answer"),
|
||||
}
|
||||
_defaults = {
|
||||
'skipped': False,
|
||||
|
@ -965,7 +966,7 @@ class survey_user_input_line(osv.osv):
|
|||
if answer_tag in post and post[answer_tag].strip() != '':
|
||||
vals.update({'answer_type': 'free_text', 'value_free_text': post[answer_tag]})
|
||||
else:
|
||||
vals.update({'skipped': True})
|
||||
vals.update({'answer_type': None, 'skipped': True})
|
||||
old_uil = self.search(cr, uid, [('user_input_id', '=', user_input_id),
|
||||
('survey_id', '=', question.survey_id.id),
|
||||
('question_id', '=', question.id)],
|
||||
|
@ -986,7 +987,7 @@ class survey_user_input_line(osv.osv):
|
|||
if answer_tag in post and post[answer_tag].strip() != '':
|
||||
vals.update({'answer_type': 'text', 'value_text': post[answer_tag]})
|
||||
else:
|
||||
vals.update({'skipped': True})
|
||||
vals.update({'answer_type': None, 'skipped': True})
|
||||
old_uil = self.search(cr, uid, [('user_input_id', '=', user_input_id),
|
||||
('survey_id', '=', question.survey_id.id),
|
||||
('question_id', '=', question.id)],
|
||||
|
@ -1007,7 +1008,7 @@ class survey_user_input_line(osv.osv):
|
|||
if answer_tag in post and post[answer_tag].strip() != '':
|
||||
vals.update({'answer_type': 'number', 'value_number': float(post[answer_tag])})
|
||||
else:
|
||||
vals.update({'skipped': True, 'answer_type': None})
|
||||
vals.update({'answer_type': None, 'skipped': True})
|
||||
old_uil = self.search(cr, uid, [('user_input_id', '=', user_input_id),
|
||||
('survey_id', '=', question.survey_id.id),
|
||||
('question_id', '=', question.id)],
|
||||
|
@ -1028,7 +1029,7 @@ class survey_user_input_line(osv.osv):
|
|||
if answer_tag in post and post[answer_tag].strip() != '':
|
||||
vals.update({'answer_type': 'date', 'value_date': post[answer_tag]})
|
||||
else:
|
||||
vals.update({'skipped': True})
|
||||
vals.update({'answer_type': None, 'skipped': True})
|
||||
old_uil = self.search(cr, uid, [('user_input_id', '=', user_input_id),
|
||||
('survey_id', '=', question.survey_id.id),
|
||||
('question_id', '=', question.id)],
|
||||
|
@ -1047,9 +1048,9 @@ class survey_user_input_line(osv.osv):
|
|||
'survey_id': question.survey_id.id,
|
||||
}
|
||||
if answer_tag in post and post[answer_tag].strip() != '':
|
||||
vals.update({'answer_type': 'date', 'value_date': post[answer_tag]})
|
||||
vals.update({'answer_type': 'suggestion', 'value_suggested': post[answer_tag]})
|
||||
else:
|
||||
vals.update({'skipped': True})
|
||||
vals.update({'answer_type': None, 'skipped': True})
|
||||
old_uil = self.search(cr, uid, [('user_input_id', '=', user_input_id),
|
||||
('survey_id', '=', question.survey_id.id),
|
||||
('question_id', '=', question.id)],
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
</t>
|
||||
</template>
|
||||
|
||||
<!-- Thank you message when the survey is completed -->
|
||||
<!-- "Thank you" message when the survey is completed -->
|
||||
<template id="finished" name="Survey Finished">
|
||||
<t t-call="website.layout">
|
||||
<div class="wrap">
|
||||
|
@ -93,7 +93,7 @@
|
|||
<div t-field='page.description'/>
|
||||
</div>
|
||||
|
||||
<form role="form" method="post" class="js_surveyform" t-att-name="'%s_%s' % (survey.id, page.id)" t-att-action="'/survey/fill/%s/%s' % (survey.id, token)" t-att-data-prefill="'/survey/prefill/%s' % (survey.id)" t-att-data-validate="'/survey/validate/%s' % (survey.id)" t-att-data-submit="'/survey/submit/%s' % (survey.id)">
|
||||
<form role="form" method="post" class="js_surveyform" t-att-name="'%s_%s' % (survey.id, page.id)" t-att-action="'/survey/fill/%s/%s' % (survey.id, token)" t-att-data-prefill="'/survey/prefill/%s/%s/%s' % (survey.id, token, page.id)" t-att-data-validate="'/survey/validate/%s' % (survey.id)" t-att-data-submit="'/survey/submit/%s' % (survey.id)">
|
||||
<input type="hidden" name="page_id" t-att-value="page.id" />
|
||||
<input type="hidden" name="token" t-att-value="token" />
|
||||
<t t-foreach='page.question_ids' t-as='question'>
|
||||
|
|
|
@ -516,12 +516,26 @@
|
|||
<field name="context">{'search_default_group_by_survey': True, 'search_default_group_by_page': True}</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record model="ir.ui.view" id="survey_label_tree">
|
||||
<field name="name">survey_label_tree</field>
|
||||
<field name="model">survey.label</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Survey Label">
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="question_id"/>
|
||||
<field name="question_id_2"/>
|
||||
<field name="value"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="action_survey_label_form">
|
||||
<field name="name">Survey Labels</field>
|
||||
<field name="res_model">survey.label</field>
|
||||
<field name="view_type">tree</field>
|
||||
<field name="view_mode">tree</field>
|
||||
<field name="context">{'default_group_by_question': True}</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="survey_label_tree"></field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="survey_question_wizard_test">
|
||||
|
@ -561,7 +575,8 @@
|
|||
<field name="value_number" colspan='2' attrs="{'invisible': [('answer_type','!=','number')]}"/>
|
||||
<field name="value_date" colspan='2' attrs="{'invisible': [('answer_type','!=','date')]}"/>
|
||||
<field name="value_free_text" colspan='2' attrs="{'invisible': [('answer_type','!=','free_text')]}"/>
|
||||
<field name="value_suggested" colspan='2' attrs="{'invisible': [('answer_type','!=','suggested')]}"/>
|
||||
<field name="value_suggested_row" colspan='2' attrs="{'invisible': [('value_suggested_row','is','None')]}"/>
|
||||
<field name="value_suggested" colspan='2' attrs="{'invisible': [('answer_type','!=','suggestion')]}"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue