From eb9bea425529e79fc3d00691517d374bcf27abe5 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Mon, 17 Jan 2011 21:41:49 +0100 Subject: [PATCH] Bind JS to reloaded questions. Signed-off-by: Florent Bruneau --- htdocs/javascript/survey.js | 19 ++++++++++++++----- templates/survey/edit.questions.tpl | 5 +---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/htdocs/javascript/survey.js b/htdocs/javascript/survey.js index a0ef4e2..884da41 100644 --- a/htdocs/javascript/survey.js +++ b/htdocs/javascript/survey.js @@ -77,8 +77,14 @@ /* 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; }, @@ -123,14 +129,17 @@ 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 () { @@ -143,7 +152,7 @@ var dest = this.question(); var res = this.childrenContainer().children('.add_question').before(question); $.renumberQuestions(); - return res; + return question; }, removeQuestion: function(force) { diff --git a/templates/survey/edit.questions.tpl b/templates/survey/edit.questions.tpl index a8a9646..fc8bb97 100644 --- a/templates/survey/edit.questions.tpl +++ b/templates/survey/edit.questions.tpl @@ -60,9 +60,6 @@ -