Bases of survey edition interface.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 9 Jan 2011 16:00:31 +0000 (17:00 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 9 Jan 2011 16:00:31 +0000 (17:00 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
htdocs/javascript/survey.js
templates/survey/edit.questions.tpl [new file with mode: 0644]
templates/survey/edit.tpl

index fb944cd..15ae19e 100644 (file)
 
 (function($) {
     $.fn.extend({
-        surveyQuestions: function(questions) {
+        showQuestions: function(questions) {
             var data = $('#question_base').tmpl(questions);
             this.children().remove();
             data.appendTo(this);
             return this;
+        },
+
+        addQuestion: function(id) {
+            var question = $("#q_edit_new").tmpl([{ qid: id } ]);
+            question
+                .children('select')
+                .change(function () {
+                    var type = $(this).val();
+                    var form = question.children('.q_edit_form');
+                    form.empty();
+                    $("#q_edit_base").tmpl([ { qid: id, type: type } ]).appendTo(form);
+                    return true;
+                });
+            question.appendTo(this);
+            return this;
         }
     });
 })(jQuery);
diff --git a/templates/survey/edit.questions.tpl b/templates/survey/edit.questions.tpl
new file mode 100644 (file)
index 0000000..f938971
--- /dev/null
@@ -0,0 +1,57 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  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               *}
+{*                                                                        *}
+{**************************************************************************}
+
+{literal}
+<script id="q_edit_new" type="text/x-jquery-tmpl">
+  <div>
+    <div><strong>Question ${qid + 1}</strong></div>
+    Type de question&nbsp;: <select name="q_edit[${qid}][type]">
+      <option value=""></option>
+      <option value="text">Texte</option>
+      <option value="section">Section</option>
+    </select>
+    <div class="q_edit_form"></div>
+  </div>
+</script>
+
+<script id="q_edit_base" type="text/x-jquery-tmpl">
+  {{if type}}
+    {{tmpl "#q_edit_" + type}}
+  {{/if}}
+</script>
+
+<script id="q_edit_text" type="text/x-jquery-tmpl">
+  Question&nbsp;: <input type="text" name="q_edit[${qid}][label]" /><br />
+</script>
+
+<script id="q_edit_section" type="text/x-jquery-tmpl">
+  <div id="section_${qid}" style="padding-left: 4ex; border-left: 1px solid white">
+    <div class="center">
+      <a href="javascript:$('#section_${qid}').addQuestion(next_qid++)">
+        {/literal}{icon name="add"}{literal} Ajouter une question
+      </a>
+    </div>
+  <div>
+</script>
+{/literal}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
index 6a2d274..04de2a0 100644 (file)
   </fieldset>
 
   <fieldset>
-    <legend>Déroulement du sondage</legend>
+    <legend>Paramètre du sondage</legend>
     Premier jour&nbsp;: <input type="text" class="datepicker" name="begin" /><br />
     Dernier jour&nbsp;: <input type="text" class="datepicker" name="end" /><br />
+    Sondage anonyme&nbsp;: Oui&nbsp;<input type="radio" name="anonymous" value="1" checked="checked" />
+    <input type="radio" name="anonymous" value="0" />&nbsp;Non
   </fieldset>
+
+  <h2>Questions</h2>
+
+  <div id="questions">
+    <div class="center">
+      <a href="javascript:$('#questions').addQuestion(next_qid++)">
+        {icon name="add"} Ajouter une question
+      </a>
+    </div>
+  </div>
+
+  <div class="center">
+    <input type="submit" name="valid" value="Soumettre" />
+  </div>
 </form>
 
+<script type="text/javascript">
+  //<![CDATA[
+  var next_qid = 0;
+  //]]>
+</script>
+
+{include file="survey/vote.questions.tpl"}
+{include file="survey/edit.questions.tpl"}
+
 {* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}