From b09bfb149957a4e523fdfa99fa85491001fb39ae Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 23 Jan 2011 23:07:29 +0100 Subject: [PATCH] Can save multiple choice questions. Signed-off-by: Florent Bruneau --- htdocs/javascript/survey.js | 34 +++++++++++++++++++++++++--------- templates/survey/edit.questions.tpl | 22 ++++++++++++++++++---- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/htdocs/javascript/survey.js b/htdocs/javascript/survey.js index aad469f..17ffcb7 100644 --- a/htdocs/javascript/survey.js +++ b/htdocs/javascript/survey.js @@ -19,11 +19,11 @@ ***************************************************************************/ (function($) { - var dispatchType(method) { - return function(type) { + var dispatchType = function(method) { + return function(type, id) { var name = type + '_' + method; if ($.isFunction(this[name])) { - return this[name](); + return this[name](id); } return this; }; @@ -153,14 +153,15 @@ } var question = $("#q_edit_new").tmpl(q); question - .children('select') + .children('select[name$="[type]"]') .change(function () { var type = $(this).val(); var form = question.children('.q_edit_form'); + var qid = $(this).qid(); form.empty(); if (type) { - $("#q_edit_base").tmpl({ qid: id, type: type }) - .bindQuestion(type) + $("#q_edit_base").tmpl({ qid: qid, type: type }) + .bindQuestion(type, qid) .appendTo(form); } return true; @@ -206,13 +207,28 @@ }, /* Multiple choices questions */ - multiple_bindQuestion: function() { + multiple_selectSubtype: function() { + return this.find('select[name$="[subtype]"]'); + }, + + multiple_bindQuestion: function(id) { + var $question = this; + this.multiple_selectSubtype() + .change(function() { + $question.find('.q_edit_answer_box') + .empty() + .append($('', { + type: $(this).val(), + disabled: "disabled" + })); + }); return this; }, multiple_addAnswer: function() { - var answer = $("#q_edit_multiple_answer").tmpl({ qid: this.qid() }); - this.childrenContainer().children('.add_answer').before(answer); + var question = this.question(); + var answer = $("#q_edit_multiple_answer").tmpl({ qid: question.qid() }); + question.childrenContainer().children('.add_answer').after(answer); return answer; } }); diff --git a/templates/survey/edit.questions.tpl b/templates/survey/edit.questions.tpl index 492a5b4..393ebc4 100644 --- a/templates/survey/edit.questions.tpl +++ b/templates/survey/edit.questions.tpl @@ -39,7 +39,7 @@ - @@ -75,18 +75,32 @@ {/literal}{icon name="add"}{literal} Ajouter une réponse + {{if parameters}}{{if parameters.answer}} + {{tmpl(parameters.answer) "#q_edit_multiple_answer"}} + {{/if}}{{/if}} +
+ Permettre la sélection de plusieurs réponses ? + +
Ajouter une case Autre ?
{/literal} -- 2.1.4