function handler_vote(PlPage $page, $name)
{
$this->load('survey.inc.php');
+ $page->addJsLink('jquery.tmpl.js');
$page->changeTpl('survey/vote.tpl');
$survey = Survey::get($name);
if (is_null($survey)) {
public function export()
{
$export = parent::export();
- $export['questions'] = array();
+ $export['questions'] = $this->exportQuestions();
+ return $export;
+ }
+
+ public function exportQuestions()
+ {
+ $export = array();
foreach ($this->questions as $question) {
- $export['questions'][] = $question->export();
+ $export[] = $question->export();
}
return $export;
}
+ public function exportQuestionsToJSON()
+ {
+ return json_encode($this->exportQuestions());
+ }
+
/* Return an indicator of the progression of the survey:
* negative values means 'the survey is not started'
* 0 means 'the survey is in progress'
<h1>Sondages</h1>
{if $active->total() > 0}
-<table class="bicol">
+<table class="bicol" id="surveyList">
<tr>
<th>
Sondages en cours
+++ /dev/null
-{**************************************************************************}
-{* *}
-{* Copyright (C) 2003-2011 Polytechnique.org *}
-{* http://opensource.polytechnique.org/ *}
-{* *}
-{* This program is free software; you can redistribute it and/or modify *}
-{* it under the terms of the GNU General Public License as published by *}
-{* the Free Software Foundation; either version 2 of the License, or *}
-{* (at your option) any later version. *}
-{* *}
-{* This program is distributed in the hope that it will be useful, *}
-{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
-{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
-{* GNU General Public License for more details. *}
-{* *}
-{* You should have received a copy of the GNU General Public License *}
-{* along with this program; if not, write to the Free Software *}
-{* Foundation, Inc., *}
-{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
-{* *}
-{**************************************************************************}
-
-<div>
- <div>{$question->label}</div>
- <input type="text" name="qid[{$question->qid}]" value="" />
-</div>
-
-{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
{* *}
{**************************************************************************}
-<fieldset>
- <legend>{$question->label}</legend>
+{literal}
+<script id="question_base" type="text/x-jquery-tmpl">
+ {{if type == 'text'}}
+ {{tmpl "#question_text"}}
+ {{else type == 'section'}}
+ {{tmpl "#question_section"}}
+ {{/if}}
+</script>
-{foreach from=$question->children item=child}
- {include file=$child->voteTemplate() question=$child}
-{/foreach}
-</fieldset>
+<script id="question_section" type="text/x-jquery-tmpl">
+ <fieldset>
+ <legend>${label}</legend>
+
+ {{tmpl(children) "#question_base"}}
+ </fieldset>
+</script>
+
+<script id="question_text" type="text/x-jquery-tmpl">
+ <div>
+ <div>${label}</div>
+ <input type="text" name="qid[${qid}]" value="" />
+ </div>
+</script>
+{/literal}
{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
<p>{$survey->description|miniwiki}</p>
-<div>
<form action="survey/vote/{$survey->shortname}" method="post">
- {foreach from=$survey->questions item=question}
- {include file=$question->voteTemplate() question=$question}
- {/foreach}
+ <div id="questions">
+ </div>
<div class="center">
{xsrf_token_field}
<input type="submit" name="vote" value="Enregister mon vote" />
</div>
</form>
-</div>
+
+{include file="survey/questions.tpl"}
+
+<script type="text/javascript">
+ //<![CDATA[
+ var questions = {$survey->exportQuestionsToJSON()|smarty:nodefaults};
+
+ {literal}
+ $(function() {
+ $("#question_base").tmpl(questions).appendTo("#questions");
+ });
+ {/literal}
+ //]]>
+</script>
{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}