[IMP] Multichoice questions admin view and display

bzr revid: rim@openerp.com-20131118161259-5ni4jn3t32n28ln6
This commit is contained in:
Richard Mathot (OpenERP)
2013-11-18 17:12:59 +01:00
parent 0b852849de
commit 233e5c82dc
4 changed files with 246 additions and 81 deletions
+22 -5
View File
@@ -2,6 +2,27 @@ $(document).ready(function () {
console.debug("[survey] Custom JS for survey is loading...");
// Custom code for right behavior of radio buttons with comments box
$('.js_comments>input[type="text"]').focusin(function(){
$(this).prev().find('>input').attr("checked","checked");
});
$('.js_radio input[type="radio"][data-oe-survey-otherr!="1"]').click(function(){
$(this).closest('.js_radio').find('.js_comments>input[type="text"]').val("");
});
$('.js_comments input[type="radio"]').click(function(){
$(this).closest('.js_comments').find('>input[data-oe-survey-othert="1"]').focus();
});
// 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..."){
$(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();
}
});
var the_form = $('.js_surveyform');
var prefill_controller = the_form.attr("data-prefill");
var validate_controller = the_form.attr("data-validate");
@@ -15,10 +36,6 @@ $(document).ready(function () {
// return false;
// }
// function submit(form){
// return false;
// }
// Parameters for form submission
$('.js_surveyform').ajaxForm({
url: submit_controller,
@@ -52,4 +69,4 @@ $(document).ready(function () {
console.debug("[survey] Custom JS for survey loaded!");
});
});
+12 -12
View File
@@ -333,7 +333,8 @@ class survey_question(osv.osv):
ondelete='cascade'),
'survey_id': fields.related('page_id', 'survey_id', type='many2one',
relation='survey.survey', string='Survey', store=True),
'parent_id': fields.many2one('survey.question', 'Parent question'),
'parent_id': fields.many2one('survey.question', 'Parent question',
ondelete='cascade'),
'children_ids': fields.one2many('survey.question', 'parent_id',
'Children questions'),
'sequence': fields.integer(string='Sequence'),
@@ -356,18 +357,17 @@ class survey_question(osv.osv):
'question_id', 'Suggested answers', oldname='answer_choice_ids'),
# Display options
'simple_choice_display' : fields.selection([('1col', 'Buttons (1 column)'),
('2col', 'Buttons (2 columns)'),
('3col', 'Buttons (3 columns)'),
('horizontal', 'Buttons (horizontal)'),
('dropdown', 'Dropdown menu'),],
'Display mode', ),
'simple_choice_display': fields.selection([('1col', '1 column choices'),
('2col', '2 columns choices'),
('3col', '3 columns choices'),
('horizontal', 'Horizontal choices'),
('dropdown', 'Dropdown menu')], 'Display mode'),
# Comments
'comments_allowed': fields.boolean('Allow comments',
oldname="allow_comment"),
#'comment_children_ids': fields.one2many('survey.question_id',
# 'parent_id', 'Comment question'), # one2one in fact
'comment_children_ids': fields.one2many('survey.question',
'parent_id', 'Comment question'), # one2one in fact
'comment_count_as_answer': fields.boolean('Comment field is an answer choice',
oldname='make_comment_field'),
@@ -416,7 +416,7 @@ class survey_question(osv.osv):
'constr_error_msg': lambda s, cr, uid, c:
_('This question requires an answer.'),
'validation_error_msg': lambda s, cr, uid, c: _('The answer you entered has an invalid format.'),
'validation_required': 'False',
'validation_required': False,
}
_sql_constraints = [
('positive_len_min', 'CHECK (validation_length_min >= 0)', 'A length must be positive!'),
@@ -542,12 +542,12 @@ class survey_label(osv.osv):
''' A suggested answer for a question '''
_name = 'survey.label'
_rec_name = 'value'
_order = 'sequence'
_columns = {
#'survey_id': fields.related('page_id', 'survey_id', type='many2one',
# relation='survey.survey', string='Survey', store=True),
'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,
required=True)
}
+12 -7
View File
@@ -397,19 +397,20 @@
<!-- The question -->
<group colspan="2">
<field name="type"/>
<field name="type" readonly="context.get('is_comment_question', False)"/>
<field name="question" />
<field name="description" />
</group>
<!-- Labels -->
<group colspan="2" string="Choice of answers" attrs="{'invisible':[('type','not in',['simple_choice', 'multiple_choice'])]}">
<field colspan="2" name="simple_choice_display" string="Display mode" />
<field colspan="2" name="labels_ids" nolabel="1" context="{'default_question_id': active_id}">
<tree string="Suggested answers" editable="bottom">
<field name="sequence" widget="handle"/>
<field name="value" />
</tree>
</field>
<field colspan="2" name="simple_choice_display" string="Display mode"/>
</group>
<!-- Sub-questions -->
@@ -419,7 +420,7 @@
<!-- Question validation -->
<group colspan="2" string="Question required">
<group colspan="2" string="Question required" invisible="context.get('is_comment_question', False)">
<field name="constr_mandatory" string="Is this question mandatory?"/>
<group attrs="{'invisible':[('constr_mandatory','=',False)]}">
<group attrs="{'invisible':[('type','not in',['matrix'])]}">
@@ -444,15 +445,15 @@
<field name="validation_type" />
<group colspan="2" attrs="{'invisible':[('validation_type','!=','has_length')]}">
<field name="validation_length_min" string="between"/>
<field name="validation_length_max" string="and"/>
<field name="validation_length_max" string="and"/>
</group>
<group colspan="2" attrs="{'invisible':[('validation_type','!=','is_decimal')]}">
<field name="validation_min_float_value" string="between"/>
<field name="validation_max_float_value" string="and"/>
<field name="validation_max_float_value" string="and"/>
</group>
<group colspan="2" attrs="{'invisible':[('validation_type','!=','is_integer')]}">
<field name="validation_min_int_value" string="between"/>
<field name="validation_max_int_value" string="and"/>
<field name="validation_max_int_value" string="and"/>
</group>
<group colspan="2" attrs="{'invisible':[('validation_type','!=','is_date')]}">
<field name="validation_min_date" string="between"/>
@@ -468,9 +469,13 @@
<field name='comments_allowed' />
<group attrs="{'invisible':[('comments_allowed','=',False)]}">
<field name='comment_count_as_answer' />
<field colspan="2" nolabel="1" name="comment_children_ids" context="{'default_parent_id': active_id, 'default_type': 'textbox', 'is_comment_question': True}">
<tree>
<field name="question" string="Comment question (only one question allowed, others will be ignored)"/>
</tree>
</field>
</group>
</group>
</group>
</sheet>
</form>
+200 -57
View File
@@ -107,13 +107,14 @@
<!-- <t t-if="question.parent_id and question.children_ids"><t t-set="is_matrix_vector" t-value="True" /></t>
<t t-if="question.parent_id"><t t-set="is_vector_element" t-value="True" /></t>
-->
<div class="question-wrapper" t-att-id="prefix">
<div class="question-wrapper container" 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>
<t t-if="question.type in ['datetime']"><t t-call="survey.datetime"/></t>
<t t-if="question.type in ['simple_choice']"><t t-call="survey.simple_choice"/></t>
<t t-if="question.type in ['multiple_choice']"><t t-call="survey.multiple_choice"/></t>
<!-- <h2><span t-field='question.question' /> <t t-if="question.constr_mandatory"><abbr title="This question is mandatory." class="text-danger">*</abbr></t></h2>
@@ -122,14 +123,6 @@
<!-- instanciating different types of questions -->
<!--
<t t-if="question.type in ['datetime']" >
TODO: replace html5 datetime widget by OpenERP-CMS datetime widget
</t>
<t t-if="question.type in ['multiple_choice']">
<t t-foreach='question.suggested_answers_ids' t-as='label'>
<div class="checkbox">
@@ -149,12 +142,6 @@
</table>
</t> -->
<!-- Comments -->
<!-- <t t-if="question.comments_allowed">
Other: <input type="text" class="form-control" />
</t> -->
<div class="js_errzone alert alert-danger" style="display:none;"></div>
</div>
@@ -190,29 +177,54 @@
<template id="simple_choice" name="Simple choice">
<h2><span t-field='question.question' /><t t-if="question.constr_mandatory"><abbr title="This question is mandatory." class="text-danger">*</abbr></t></h2>
<p class="text-muted"><t t-if="question.description"><span t-field='question.description'/></t></p>
<t t-if="question.simple_choice_display == 'dropdown'">
<select class="form-control" t-att-name="prefix">
<option disabled="1" selected="1">Choose...</option>
<t t-foreach='question.labels_ids' t-as='label'>
<option><t t-esc='label.value'/></option>
<div class="js_drop row">
<div class="col-md-6">
<select class="form-control" t-att-name="prefix">
<option disabled="1" selected="1">Choose...</option>
<t t-foreach='question.labels_ids' t-as='label'>
<option><t t-esc='label.value'/></option>
</t>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<option>Other...</option>
</t>
</select>
</div>
<div class="col-md-6">
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<input type="text" class="form-control" t-att-name="prefix+'_other'" data-oe-survey-othert="1"/>
</t>
</select>
<t t-if='question.comments_allowed and not question.comment_count_as_answer'>
<div>
<input type="text" class="form-control" t-att-name="prefix+'_comments'"/>
</div>
</t>
</div>
</div>
</t>
<t t-if="question.simple_choice_display == 'horizontal'">
<div>
<t t-foreach='question.labels_ids' t-as='label'>
<div class="radio-inline">
<label>
<input type="radio" t-att-name="prefix" t-att-value='label.value' />
<div class="js_radio">
<t t-foreach='question.labels_ids' t-as='label'>
<label class="radio-inline">
<input type="radio" t-att-name="prefix" t-att-value='label.id' />
<span t-field='label.value'/>
</label>
</div>
</t>
</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>
<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>
<input type="text" class="form-control" t-att-name="prefix+'_comments'" data-oe-survey-othert="1"/>
</div>
</t>
</div>
</t>
<t t-if="question.simple_choice_display == '1col'">
<div>
<div class="js_radio">
<t t-foreach='question.labels_ids' t-as='label'>
<div class="radio">
<label>
@@ -221,21 +233,48 @@
</label>
</div>
</t>
</div>
</t>
<t t-if="question.simple_choice_display == '2col'">
<div class="row">
<t t-foreach='question.labels_ids' t-as='label'>
<div class="radio col-md-6">
<label>
<input type="radio" t-att-name="prefix" t-att-value='label.value' />
<span t-field='label.value'/>
</label>
<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>
<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>
<input type="text" class="form-control" t-att-name="prefix+'_comments'" data-oe-survey-othert="1"/>
</div>
</t>
</div>
</t>
<t t-if="question.simple_choice_display == '2col'">
<div class="js_radio">
<div class="row">
<t t-foreach='question.labels_ids' t-as='label'>
<div class="radio col-md-6">
<label>
<input type="radio" t-att-name="prefix" t-att-value='label.value' />
<span t-field='label.value'/>
</label>
</div>
</t>
</div>
<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>
<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">
<input type="text" class="form-control" t-att-name="prefix+'_comments'" data-oe-survey-othert="1"/>
</div>
</t>
</div>
</div>
</t>
<t t-if="question.simple_choice_display == '3col'">
<div class="js_radio">
<div class="row">
<t t-foreach='question.labels_ids' t-as='label'>
<div class="radio col-md-4">
@@ -246,27 +285,131 @@
</div>
</t>
</div>
</t>
<!--
<t t-if="question.type in ['simple_choice_scale']">
<t t-foreach='question.suggested_answers_ids' t-as='label'>
<div class="radio">
<label>
<input type="radio" t-att-name="prefix" t-att-value='label.value' />
<span t-field='label.value'/>
</label>
<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>
<input type="text" class="form-control" t-att-name="prefix" data-oe-survey-othert="1"/>
</div>
</t>
</t>
<t t-if="question.type in ['simple_choice_dropdown']">
</t>
-->
<t t-if='question.comments_allowed and not question.comment_count_as_answer'>
<div class="col-md-4">
<input type="text" class="form-control" t-att-name="prefix+'_comments'" data-oe-survey-othert="1"/>
</div>
</t>
</div>
</div>
</t>
</template>
<template id="multiple_choice" name="Multiple choice">
<h2><span t-field='question.question' /><t t-if="question.constr_mandatory"><abbr title="This question is mandatory." class="text-danger">*</abbr></t></h2>
<p class="text-muted"><t t-if="question.description"><span t-field='question.description'/></t></p>
<t t-if="question.simple_choice_display == 'horizontal'">
<div>
<t t-foreach='question.labels_ids' t-as='label'>
<label class="checkbox-inline">
<input type="checkbox" t-att-name="prefix + '_' + label.id.__str__()" t-att-value='label.value' />
<span t-field='label.value'/>
</label>
</t>
<div>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<div class="input-group input-group-sm col-md-4">
<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>
</t>
<t t-if='question.comments_allowed and not question.comment_count_as_answer'>
<div class="row">
<span t-field="question.children_ids[0].question" class="col-md-4"/>
<input type="text" class="form-control col-md-4" t-att-name="prefix+'_comments'" data-oe-survey-othert="1"/>
</div>
</t>
</div>
</div>
</t>
<t t-if="question.simple_choice_display == '1col'">
<div>
<t t-foreach='question.labels_ids' t-as='label'>
<div class="checkbox">
<label>
<input type="checkbox" t-att-name="prefix + '_' + label.id.__str__()" t-att-value='label.value' />
<span t-field='label.value'/>
</label>
</div>
</t>
<div>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<div class="input-group input-group-sm col-md-4">
<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>
</t>
<t t-if='question.comments_allowed and not question.comment_count_as_answer'>
<div class="row">
<span t-field="question.children_ids[0].question" class="col-md-4"/>
<input type="text" class="form-control col-md-4" t-att-name="prefix+'_comments'" data-oe-survey-othert="1"/>
</div>
</t>
</div>
</div>
</t>
<t t-if="question.simple_choice_display == '2col'">
<div class="row">
<t t-foreach='question.labels_ids' t-as='label'>
<div class="checkbox col-md-6">
<label>
<input type="checkbox" t-att-name="prefix + '_' + label.id.__str__()" t-att-value='label.value' />
<span t-field='label.value'/>
</label>
</div>
</t>
<div>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<div class="input-group input-group-sm col-md-4">
<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>
</t>
<t t-if='question.comments_allowed and not question.comment_count_as_answer'>
<div class="row">
<span t-field="question.children_ids[0].question" class="col-md-4"/>
<input type="text" class="form-control col-md-4" t-att-name="prefix+'_comments'" data-oe-survey-othert="1"/>
</div>
</t>
</div>
</div>
</t>
<t t-if="question.simple_choice_display == '3col'">
<div class="row">
<t t-foreach='question.labels_ids' t-as='label'>
<div class="checkbox col-md-4">
<label>
<input type="checkbox" t-att-name="prefix + '_' + label.id.__str__()" t-att-value='label.value' />
<span t-field='label.value'/>
</label>
</div>
</t>
<div>
<t t-if='question.comments_allowed and question.comment_count_as_answer'>
<div class="input-group input-group-sm col-md-4">
<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>
</t>
<t t-if='question.comments_allowed and not question.comment_count_as_answer'>
<div class="row">
<span t-field="question.children_ids[0].question" class="col-md-4"/>
<input type="text" class="form-control col-md-4" t-att-name="prefix+'_comments'" data-oe-survey-othert="1"/>
</div>
</t>
</div>
</div>
</t>
</template>
<!-- Printable view of a survey (all pages) -->