Can save multiple choice questions.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 23 Jan 2011 22:07:29 +0000 (23:07 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 23 Jan 2011 22:07:29 +0000 (23:07 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
htdocs/javascript/survey.js
templates/survey/edit.questions.tpl

index aad469f..17ffcb7 100644 (file)
  ***************************************************************************/
 
 (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;
         };
             }
             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;
         },
 
         /* 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($('<input>', {
+                            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;
         }
     });
index 492a5b4..393ebc4 100644 (file)
@@ -39,7 +39,7 @@
       <option value="text" {{if type}}{{if type == 'text'}}selected="selected"{{/if}}{{/if}}>
         Texte
       </option>
-      <option value="multiple" {{if type}}{{if type == 'multiple'}}selection="selected"{{/if}}{{/if}}>
+      <option value="multiple" {{if type}}{{if type == 'multiple'}}selected="selected"{{/if}}{{/if}}>
         Question à choix multiples
       </option>
     </select>
         {/literal}{icon name="add"}{literal} Ajouter une réponse
       </a>
     </div>
+    {{if parameters}}{{if parameters.answer}}
+      {{tmpl(parameters.answer) "#q_edit_multiple_answer"}}
+    {{/if}}{{/if}}
+    <div>
+      Permettre la sélection de plusieurs réponses ?
+      <select name="q_edit[${qid}][subtype]">
+        <option value="checkbox">Oui</option>
+        <option value="radio" selected="selected">Non</option>
+      </select>
+    </div>
     <div>
       Ajouter une case Autre ?
       <select name="q_edit[${qid}][allow_other]">
-        <option name="1">Oui</option>
-        <option name="" selected="selected">Non</option>
+        <option value="1">Oui</option>
+        <option value="" selected="selected">Non</option>
       </select>
     </div>
   </div>
 </script>
 
 <script id="q_edit_multiple_answer" type="text/x-jquery-tmpl">
-  <div><input type="text" name="q_edit[${qid}][answer][]" /></div>
+  <div>
+    <span class="q_edit_answer_box">
+    </span>
+    Réponse&nbsp;: <input type="text" name="q_edit[${qid}][answer][][value]" value="${value}" />
+  </div>
 </script>
 
 {/literal}