]> git.joonet.de Git - adminer.git/commitdiff
New plugin: Edit calendar
authorJakub Vrana <jakub@vrana.cz>
Fri, 18 Feb 2011 15:16:36 +0000 (16:16 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 18 Feb 2011 15:16:36 +0000 (16:16 +0100)
.gitmodules
adminer/plugin.php
externals/jquery-timepicker [new submodule]
externals/jquery-ui [new submodule]
plugins/edit-calendar.php [new file with mode: 0644]

index 56ec0fc573519005c98f6d3cd4c3f03d719312ff..127b40b9944fe98ff00d1e81c5860f230cc5fe98 100644 (file)
@@ -7,3 +7,9 @@
 [submodule "tinymce"]
        path = externals/tinymce
        url = git://github.com/tinymce/tinymce.git
+[submodule "jquery-ui"]
+       path = externals/jquery-ui
+       url = git://github.com/jquery/jquery-ui.git
+[submodule "jquery-timepicker"]
+       path = externals/jquery-timepicker
+       url = git://github.com/trentrichardson/jQuery-Timepicker-Addon.git
index 0cad4c3e23694b4ea1efb1c7b39eb502bb64a527..3afcf12fd9488a08095a2455768c8d3772ddd70d 100644 (file)
@@ -18,6 +18,7 @@ function adminer_object() {
                // specify enabled plugins here
                new AdminerDumpZip,
                new AdminerDumpXml,
+               new AdminerEditCalendar("<script type='text/javascript' src='../externals/jquery-ui/jquery-1.4.4.js'></script>\n<script type='text/javascript' src='../externals/jquery-ui/ui/jquery.ui.core.js'></script>\n<script type='text/javascript' src='../externals/jquery-ui/ui/jquery.ui.widget.js'></script>\n<script type='text/javascript' src='../externals/jquery-ui/ui/jquery.ui.datepicker.js'></script>\n<script type='text/javascript' src='../externals/jquery-ui/ui/jquery.ui.mouse.js'></script>\n<script type='text/javascript' src='../externals/jquery-ui/ui/jquery.ui.slider.js'></script>\n<script type='text/javascript' src='../externals/jquery-timepicker/jquery-ui-timepicker-addon.js'></script>\n<link rel='stylesheet' href='../externals/jquery-ui/themes/base/jquery.ui.all.css'>\n<style type='text/css'>\n.ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }\n.ui-timepicker-div dl { text-align: left; }\n.ui-timepicker-div dl dt { height: 25px; }\n.ui-timepicker-div dl dd { margin: -25px 0 10px 65px; }\n.ui-timepicker-div td { font-size: 90%; }\n</style>\n", "../externals/jquery-ui/ui/i18n/jquery.ui.datepicker-%s.js"),
                new AdminerTinymce("../externals/tinymce/jscripts/tiny_mce/tiny_mce_dev.js"),
                new AdminerFileUpload(""),
                new AdminerSlugify,
diff --git a/externals/jquery-timepicker b/externals/jquery-timepicker
new file mode 160000 (submodule)
index 0000000..ec1a143
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit ec1a143b5c56578aab05d8975b3663fa9bcba72b
diff --git a/externals/jquery-ui b/externals/jquery-ui
new file mode 160000 (submodule)
index 0000000..c44818f
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit c44818fccaeb4f41fdb8b8a00662169a4258b78c
diff --git a/plugins/edit-calendar.php b/plugins/edit-calendar.php
new file mode 100644 (file)
index 0000000..1565119
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+/** Display jQuery UI Timepicker for each date and datetime field
+* @uses jQuery-Timepicker, http://trentrichardson.com/examples/timepicker/
+* @uses jQuery UI: core, widget, mouse, slider, datepicker
+* @author Jakub Vrana, http://www.vrana.cz/
+* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
+*/
+class AdminerEditCalendar {
+       var $prepend;
+       var $langPath;
+       
+       /**
+       * @param string text to append before first calendar usage
+       * @param string path to language file, %s stands for language code
+       */
+       function AdminerEditCalendar($prepend = "<script type='text/javascript' src='jquery-ui/jquery.js'></script>\n<script type='text/javascript' src='jquery-ui/jquery-ui.js'></script>\n<script type='text/javascript' src='jquery-ui/jquery-ui-timepicker-addon.js'></script>\n<link rel='stylesheet' type='text/css' href='jquery-ui/jquery-ui.css'>\n", $langPath = "jquery-ui/i18n/jquery.ui.datepicker-%s.js") { //! insert <link> by JavaScript to achieve HTML validity
+               $this->prepend = $prepend;
+               $this->langPath = $langPath;
+       }
+       
+       function editInput($table, $field, $attrs, $value) {
+               static $calendar = false;
+               if (ereg("date|time", $field["type"])) {
+                       if (!$calendar) {
+                               $calendar = true;
+                               echo $this->prepend;
+                               if ($this->langPath && function_exists('get_lang')) { // since Adminer 3.2.0
+                                       $lang = get_lang();
+                                       $lang = ($lang == "zh" ? "zh-CN" : ($lang == "zh-tw" ? "zh-TW" : $lang));
+                                       if ($lang != "en" && file_exists(sprintf($this->langPath, $lang))) {
+                                               printf("<script type='text/javascript' src='$this->langPath'></script>\n", $lang);
+                                               echo "<script type='text/javascript'>jQuery(function () { jQuery.timepicker.setDefaults(jQuery.datepicker.regional['$lang']); });</script>\n";
+                                       }
+                               }
+                       }
+                       $dateFormat = "changeYear: true, dateFormat: 'yy-mm-dd'"; //! yy-mm-dd regional
+                       $timeFormat = "showSecond: true, timeFormat: 'hh:mm:ss'";
+                       return "<input id='fields-" . h($field["field"]) . "' value='" . h($value) . "'" . ($maxlength ? " maxlength='$maxlength'" : "") . "$attrs><script type='text/javascript'>jQuery(function () { jQuery('#fields-" . js_escape($field["field"]) . "')."
+                               . ($field["type"] == "time" ? "timepicker({ $timeFormat })"
+                               : (ereg("time", $field["type"]) ? "datetimepicker({ $dateFormat, $timeFormat })"
+                               : "datepicker({ $dateFormat })"
+                       )) . "; });</script>";
+               }
+       }
+       
+}