Bind JS to reloaded questions.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 17 Jan 2011 20:41:49 +0000 (21:41 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 18 Jan 2011 20:48:51 +0000 (21:48 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
htdocs/javascript/survey.js
templates/survey/edit.questions.tpl

index a0ef4e2..884da41 100644 (file)
 
         /* Edition form */
         prepareQuestions: function(questions) {
-            var data = $('#q_edit_new').tmpl(questions);
-            data.prependTo(this);
+            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;
         },
 
             return this.childrenContainer().children('.q_edit');
         },
 
-        addQuestion: function() {
+        addQuestion: function(q) {
             var id = $.lastQuestion().qid();
             if (id == undefined) {
                 id = 0;
             } else {
                 id++;
             }
-            var question = $("#q_edit_new").tmpl([{ qid: id } ]);
+            if (q == null) {
+                q = { qid: id }
+            }
+            var question = $("#q_edit_new").tmpl(q);
             question
                 .children('select')
                 .change(function () {
             var dest = this.question();
             var res = this.childrenContainer().children('.add_question').before(question);
             $.renumberQuestions();
-            return res;
+            return question;
         },
 
         removeQuestion: function(force) {
index a8a9646..fc8bb97 100644 (file)
@@ -60,9 +60,6 @@
 
 <script id="q_edit_section" type="text/x-jquery-tmpl">
   <div id="section_${qid}" style="padding-left: 4ex; border-left: 1px solid white">
-    {{if children}}
-      {{tmpl(children) "#q_edit_new"}}
-    {{/if}}
     <div class="add_question">
       <a onclick="$(this).addQuestion()" style="text-decoration: none">
         {/literal}{icon name="add"}{literal} Ajouter une question
@@ -71,7 +68,7 @@
   </div>
 </script>
 
-<script id="q_edit_multiple" typex="text/x-jquery-tmpl">
+<script id="q_edit_multiple" type="text/x-jquery-tmpl">
   <div id="q_edit[${qid}][answers]">
     <div class="add_answer">
       <a onclick="$(this).multipleAddAnswer()">