From b46de52d000ee3dd77726bff9236d8f624160458 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sat, 8 Jan 2011 16:18:11 +0100 Subject: [PATCH] Rewrite form generation. Signed-off-by: Florent Bruneau --- modules/survey.php | 1 + modules/survey/survey.inc.php | 15 +++++++++-- templates/survey/index.tpl | 2 +- templates/survey/question.text.tpl | 28 --------------------- .../survey/{question.section.tpl => questions.tpl} | 29 +++++++++++++++++----- templates/survey/vote.tpl | 21 ++++++++++++---- 6 files changed, 54 insertions(+), 42 deletions(-) delete mode 100644 templates/survey/question.text.tpl rename templates/survey/{question.section.tpl => questions.tpl} (75%) diff --git a/modules/survey.php b/modules/survey.php index a3bd012..f40ce5b 100644 --- a/modules/survey.php +++ b/modules/survey.php @@ -77,6 +77,7 @@ class SurveyModule extends PLModule 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)) { diff --git a/modules/survey/survey.inc.php b/modules/survey/survey.inc.php index df0a9f9..865a148 100644 --- a/modules/survey/survey.inc.php +++ b/modules/survey/survey.inc.php @@ -156,13 +156,24 @@ class Survey extends PlDBTableEntry implements SurveyQuestionContainer 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' diff --git a/templates/survey/index.tpl b/templates/survey/index.tpl index 503f372..0291a3a 100644 --- a/templates/survey/index.tpl +++ b/templates/survey/index.tpl @@ -23,7 +23,7 @@

Sondages

{if $active->total() > 0} - +
Sondages en cours diff --git a/templates/survey/question.text.tpl b/templates/survey/question.text.tpl deleted file mode 100644 index 5e0d231..0000000 --- a/templates/survey/question.text.tpl +++ /dev/null @@ -1,28 +0,0 @@ -{**************************************************************************} -{* *} -{* 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 *} -{* *} -{**************************************************************************} - -
-
{$question->label}
- -
- -{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *} diff --git a/templates/survey/question.section.tpl b/templates/survey/questions.tpl similarity index 75% rename from templates/survey/question.section.tpl rename to templates/survey/questions.tpl index cb4d2af..e7c8709 100644 --- a/templates/survey/question.section.tpl +++ b/templates/survey/questions.tpl @@ -20,12 +20,29 @@ {* *} {**************************************************************************} -
- {$question->label} +{literal} + -{foreach from=$question->children item=child} - {include file=$child->voteTemplate() question=$child} -{/foreach} -
+ + + +{/literal} {* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *} diff --git a/templates/survey/vote.tpl b/templates/survey/vote.tpl index 2dbe32e..5b91735 100644 --- a/templates/survey/vote.tpl +++ b/templates/survey/vote.tpl @@ -24,17 +24,28 @@

{$survey->description|miniwiki}

-
- {foreach from=$survey->questions item=question} - {include file=$question->voteTemplate() question=$question} - {/foreach} +
+
{xsrf_token_field}
-
+ +{include file="survey/questions.tpl"} + + {* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *} -- 2.1.4