New plugin: Edit calendar

This commit is contained in:
Jakub Vrana 2011-02-18 16:16:36 +01:00
parent f9287eef65
commit 6cb8749916
5 changed files with 57 additions and 0 deletions

6
.gitmodules vendored
View 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

View 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,

1
externals/jquery-timepicker vendored Submodule

@ -0,0 +1 @@
Subproject commit ec1a143b5c56578aab05d8975b3663fa9bcba72b

1
externals/jquery-ui vendored Submodule

@ -0,0 +1 @@
Subproject commit c44818fccaeb4f41fdb8b8a00662169a4258b78c

48
plugins/edit-calendar.php Normal file
View file

@ -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>";
}
}
}