Can add answers to a multiple-choices question.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 18 Jan 2011 20:48:11 +0000 (21:48 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 18 Jan 2011 20:48:52 +0000 (21:48 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
core
htdocs/javascript/survey.js
templates/survey/edit.questions.tpl

diff --git a/core b/core
index 4836f91..ad884e3 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 4836f918dd6180f92e10722f9a01b9013f42da64
+Subproject commit ad884e358383200846eef6db76c97f67283fdaea
index 884da41..9b3bfee 100644 (file)
@@ -80,7 +80,6 @@
             for (var q in questions) {
                 var q = questions[q];
                 var child = this.addQuestion(q);
-                console.log("New question added in " + child.get(0).id);
                 if ($.isArray(q.children)) {
                     child.prepareQuestions(q.children);
                 }
             return this.isQuestion() ? this : this.parentQuestion();
         },
 
+        questionForm: function() {
+            return this.question().children('.q_edit_form');
+        },
+
         qid: function() {
             var question = this.question();
             if (question.get(0) == undefined) {
 
         childrenContainer: function() {
             var question = this.question();
-            return question.isRootSection() ? question : question.children('.q_edit_form').children();
+            return question.isRootSection() ? question : question.questionForm().children();
         },
 
         childrenQuestion: function() {
                     var type = $(this).val();
                     var form = question.children('.q_edit_form');
                     form.empty();
-                    $("#q_edit_base").tmpl([ { qid: id, type: type } ]).appendTo(form);
+                    if (type != '') {
+                        $("#q_edit_base").tmpl({ qid: id, type: type })
+                            .bindQuestion(type)
+                            .appendTo(form);
+                    }
                     return true;
                 });
             var dest = this.question();
             return question;
         },
 
+        bindQuestion: function(type) {
+            var name = type + '_bindQuestion';
+            if ($.isFunction(this[name])) {
+                this[name]();
+            }
+            return this;
+        },
+
         removeQuestion: function(force) {
             var question = this.parentQuestion();
             if (!force && question.children('.q_edit_form').children().children('.q_edit').length > 0) {
                 }
             });
             return $this;
+        },
+
+        /* Multiple choices questions */
+        multiple_bindQuestion: function() {
+            return this;
+        },
+
+        multiple_addAnswer: function() {
+            var answer = $("#q_edit_multiple_answer").tmpl({ qid: this.qid() });
+            this.childrenContainer().children('.add_answer').before(answer);
+            return answer;
         }
     });
 })(jQuery);
index fc8bb97..492a5b4 100644 (file)
@@ -59,7 +59,7 @@
 </script>
 
 <script id="q_edit_section" type="text/x-jquery-tmpl">
-  <div id="section_${qid}" style="padding-left: 4ex; border-left: 1px solid white">
+  <div id="q_edit[${qid}][section]" style="padding-left: 4ex; border-left: 1px solid white">
     <div class="add_question">
       <a onclick="$(this).addQuestion()" style="text-decoration: none">
         {/literal}{icon name="add"}{literal} Ajouter une question
@@ -71,7 +71,7 @@
 <script id="q_edit_multiple" type="text/x-jquery-tmpl">
   <div id="q_edit[${qid}][answers]">
     <div class="add_answer">
-      <a onclick="$(this).multipleAddAnswer()">
+      <a onclick="$(this).multiple_addAnswer()">
         {/literal}{icon name="add"}{literal} Ajouter une rĂ©ponse
       </a>
     </div>
     </div>
   </div>
 </script>
+
+<script id="q_edit_multiple_answer" type="text/x-jquery-tmpl">
+  <div><input type="text" name="q_edit[${qid}][answer][]" /></div>
+</script>
+
 {/literal}
 
 {* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}