Add survey edition form (lost a lot of time theming datepicker).
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 8 Jan 2011 22:19:55 +0000 (23:19 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 8 Jan 2011 22:19:55 +0000 (23:19 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
Makefile
htdocs/css/base.css
htdocs/javascript/survey.js [new file with mode: 0644]
modules/survey.php
templates/survey/edit.tpl [new file with mode: 0644]
templates/survey/vote.tpl

index 509ab88..2418710 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -181,7 +181,7 @@ JQUERY_PLUGINS=color form
 JQUERY_PLUGINS_PATHES=$(addprefix htdocs/javascript/jquery.,$(addsuffix .js,$(JQUERY_PLUGINS)))
 
 JQUERY_UI_VERSION=1.8.7
-JQUERY_UI=core tabs widget
+JQUERY_UI=core tabs datepicker widget
 JQUERY_UI_PATHES=$(addprefix htdocs/javascript/jquery.ui.,$(addsuffix .js,$(JQUERY_UI)))
 
 JQUERY_TMPL_VERSION=vBeta1.0.0
index 669c239..a38d408 100644 (file)
 
 .ui-tabs-hide { display: none; }
 
+.ui-icon {
+    width: 16px;
+    height: 16px;
+}
+
+.ui-datepicker {
+    background: #ffffff;
+    color: #000000;
+    position: absolute;
+}
+
+.ui-datepicker a {
+    color: black;
+    text-decoration: none;
+    text-align: center;
+}
+
+.ui-datepicker-header {
+    padding: 2px;
+    margin: 1px;
+    background: #777;
+    border: 1px solid;
+    border-color: #333;
+}
+
+.ui-datepicker-title {
+    text-align: center;
+    height: 19px;
+}
+
+.ui-datepicker-prev {
+    background: #777 url('/images/icons/resultset_previous.gif');
+    position: absolute;
+    width: 16px;
+    height: 16px;
+    top: 4px;
+    left: 4px;
+    outline: none;
+    display: block;
+}
+
+.ui-datepicker-next {
+    background: #777 url('/images/icons/resultset_next.gif');
+    position: absolute;
+    width: 16px;
+    height: 16px;
+    top: 4px;
+    right: 4px;
+    outline: none;
+    display: block;
+}
+
+.ui-datepicker-next span, .ui-datepicker-prev span {
+    display: block;
+    position: absolute;
+    text-indent: -99999px;
+    overflow: hidden;
+}
+
+.ui-datepicker-week-end {
+    background-color: #eee;
+}
+
+.ui-datepicker-unselectable {
+    color: #777;
+}
+
 /* vim: set et ts=4 sts=4 sw=4: */
diff --git a/htdocs/javascript/survey.js b/htdocs/javascript/survey.js
new file mode 100644 (file)
index 0000000..abd6aca
--- /dev/null
@@ -0,0 +1,33 @@
+/***************************************************************************
+ *  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                *
+ ***************************************************************************/
+
+(function($) {
+    $.fn.extend({
+        surveyQuestions: function(questions) {
+            var data = $('#question_base').tmpl(questions);
+            this.children().remove();
+            data.appendTo(this);
+            return this;
+        }
+    });
+})(jQuery);
+
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
index f40ce5b..c6a3914 100644 (file)
@@ -26,8 +26,9 @@ class SurveyModule extends PLModule
         return array(
             'survey'              => $this->make_hook('index',         AUTH_COOKIE),
             'survey/vote'         => $this->make_hook('vote',          AUTH_COOKIE),
-    /*        'survey/result'       => $this->make_hook('result',        AUTH_COOKIE),
             'survey/edit'         => $this->make_hook('edit',          AUTH_COOKIE),
+            /*
+            'survey/result'       => $this->make_hook('result',        AUTH_COOKIE),
             'survey/ajax'         => $this->make_hook('ajax',          AUTH_COOKIE),
             'survey/admin'        => $this->make_hook('admin',         AUTH_MDP, 'admin'),
             'survey/admin/edit'   => $this->make_hook('adminEdit',     AUTH_MDP, 'admin'),
@@ -78,6 +79,7 @@ class SurveyModule extends PLModule
     {
         $this->load('survey.inc.php');
         $page->addJsLink('jquery.tmpl.js');
+        $page->addJsLink('survey.js');
         $page->changeTpl('survey/vote.tpl');
         $survey = Survey::get($name);
         if (is_null($survey)) {
@@ -100,6 +102,28 @@ class SurveyModule extends PLModule
         }
         $page->assign('survey', $survey);
     }
+
+    function handler_edit(PlPage $page, $name = null)
+    {
+        $this->load('survey.inc.php');
+        $page->addJsLink('jquery.ui.core.js');
+        $page->addJsLink('jquery.ui.widget.js');
+        $page->addJsLink('jquery.ui.datepicker.js');
+        $page->addJsLink('jquery.tmpl.js');
+        $page->addJsLink('survey.js');
+        $page->changeTpl('survey/edit.tpl');
+
+        if (!is_null($name)) {
+            $survey = Survey::get($name);
+        } else {
+            $survey = new Survey();
+            $survey->id = null;
+            $survey->uid = S::user()->id();
+        }
+        if (Post::has('save')) {
+        }
+        $page->assign('survey', $survey);
+    }
 }
 
 // vim:set et sw=4 sts=4 ts=4 foldmethod=marker enc=utf-8:
diff --git a/templates/survey/edit.tpl b/templates/survey/edit.tpl
new file mode 100644 (file)
index 0000000..9c6145d
--- /dev/null
@@ -0,0 +1,50 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  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               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<h1>Edition de sondage</h1>
+
+<form action="survey/edit/{$survey->shortname}" method="post">
+  <fieldset>
+    <legend>Description du sondage</legend>
+
+    Titre&nbsp;: <input type="text" name="title" /><br />
+    Nom&nbsp;: <input type="text" name="shortname" /><br />
+
+    Premier jour&nbsp;: <input type="text" class="datepicker" name="begin" /><br />
+    Dernier jour&nbsp;: <input type="text" class="datepicker" name="end" /><br />
+  </fieldset>
+</form>
+
+{literal}
+<script type="text/javascript">
+  //<![CDATA[
+  $($(".datepicker").datepicker({
+    dateFormat: 'dd/mm/yyyy',
+    firstDay: 1,
+    hideIfNoPrevNext: true,
+    minDate: new Date()
+  }));
+  //]]>
+</script>
+{/literal}
+
+{* vim:set et sw=2 sts=2 ts=8 enc=utf-8: *}
index 5b91735..ad20cc7 100644 (file)
   //<![CDATA[
   var questions = {$survey->exportQuestionsToJSON()|smarty:nodefaults};
 
-  {literal}
-  $(function() {
-    $("#question_base").tmpl(questions).appendTo("#questions");
-  });
-  {/literal}
+  $($("#questions").surveyQuestions(questions));
   //]]>
 </script>