Allow reordering the delivery list.
[readifood.git] / lib / forms.php
index 7b707d7..c71c11f 100644 (file)
   }
 
   function textarea($name, $value = null) {
-    echo "<textarea name=\"$name\">";
+    $id = "textarea_$name";
+    echo "<textarea id=\"$id\" name=\"$name\" cols=30>";
     if (isset($value)) echo $value;
     else echo $_POST[$name];
     echo "</textarea>";
+    echo "<script>\n  $(function() {\n";
+    echo "    $(\"#$id\").autosize();\n";
+    echo "  });</script>";
   }
 
   function option($select, $value, $text, $selected = null) {
     echo ">$text\n";
   }
 
+  function datepicker($name, $value = null, $past = true, $past_picker = null, $future = true, $future_picker = null) {
+    $id = "datepicker_$name";
+    echo "<script>\n  $(function() {\n";
+    echo "    $(\"#$id\").datepicker({\n";
+    /*
+      If this is the "to" picker in a date range, restrict the end date of the
+      "from" picker to be the date selected by this picker.
+    */
+    if (isset($past_picker)) {
+      echo "      onClose: function(selectedDate) {\n";
+      echo "        $(\"#datepicker_$past_picker\").datepicker(\"option\", \"maxDate\", selectedDate);\n";
+      echo "      },\n";
+    }
+    /*
+      If this is the "from" picker in a date range, restrict the start date of
+      the "to" picker to be the date selected by this picker.
+    */
+    if (isset($future_picker)) {
+      echo "      onClose: function(selectedDate) {\n";
+      echo "        $(\"#datepicker_$future_picker\").datepicker(\"option\", \"minDate\", selectedDate);\n";
+      echo "      },\n";
+    }
+    echo "      changeMonth: true,\n";
+    echo "      changeYear: true,\n";
+    echo "      dateFormat: 'yy-mm-dd',\n";
+    /* Are we allowed to show dates earlier than today? */
+    if (! $past) echo "      minDate: 0,\n";
+    /* Are we allowed to show dates later than today? */
+    if (! $future) echo "      maxDate: 0,\n";
+    echo "      showButtonPanel: true\n";
+    echo "    });\n  });</script>";
+    echo "<input name=\"$name\" id=\"$id\"";
+    echo " maxlength=10 size=10";
+    if (isset($value)) echo " value=\"$value\"";
+    else echo " value=\"" . $_POST[$name] . "\"";
+    echo "><em class=\"small\">(Y-m-d)</em>";
+  }
+
 ?>