Added time editing to calendar.

This commit is contained in:
Michal Čihař
2004-04-20 11:54:51 +00:00
parent 8c9f9a1d3b
commit 67285d7263
3 changed files with 86 additions and 18 deletions

View File

@@ -5,6 +5,10 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2004-04-20 Michal Cihar <michal@cihar.com>
* libraries/tbl_change.js, css/phpmyadmin.css.php: Added time editing to
calendar.
2004-04-19 Alexander M. Turek <me@derrabus.de> 2004-04-19 Alexander M. Turek <me@derrabus.de>
* lang/german-*.inc.php: Clarification. * lang/german-*.inc.php: Clarification.
* config.inc.php, Documentation.html, libraries/config_import.lib.php: * config.inc.php, Documentation.html, libraries/config_import.lib.php:

View File

@@ -273,3 +273,7 @@ table.calendar td.selected {
img.calendar { img.calendar {
border: none; border: none;
} }
form.clock {
text-align: center;
}

View File

@@ -115,6 +115,9 @@ function onKeyDownArrowsHandler(e) {
var day; var day;
var month; var month;
var year; var year;
var hour;
var minute;
var second;
/** /**
* Opens calendar window. * Opens calendar window.
@@ -130,6 +133,24 @@ function openCalendar(params, form, field, type) {
dateType = type; dateType = type;
} }
/**
* Formats number to two digits.
*
* @param int number to format.
*/
function formatNum2(i) {
return (i < 10 ? '0' : '') + i;
}
/**
* Formats number to four digits.
*
* @param int number to format.
*/
function formatNum4(i) {
return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
}
/** /**
* Initializes calendar window. * Initializes calendar window.
*/ */
@@ -139,6 +160,17 @@ function initCalendar() {
if (window.opener.dateField.value) { if (window.opener.dateField.value) {
value = window.opener.dateField.value; value = window.opener.dateField.value;
if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') { if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
if (window.opener.dateType == 'datetime') {
parts = value.split(' ');
value = parts[0];
if (parts[1]) {
time = parts[1].split(':');
hour = parseInt(time[0]);
minute = parseInt(time[1]);
second = parseInt(time[2]);
}
}
date = value.split("-"); date = value.split("-");
day = parseInt(date[2]); day = parseInt(date[2]);
month = parseInt(date[1]) - 1; month = parseInt(date[1]) - 1;
@@ -147,6 +179,9 @@ function initCalendar() {
year = parseInt(value.substr(0,4)); year = parseInt(value.substr(0,4));
month = parseInt(value.substr(4,2)) - 1; month = parseInt(value.substr(4,2)) - 1;
day = parseInt(value.substr(6,2)); day = parseInt(value.substr(6,2));
hour = parseInt(value.substr(8,2));
minute = parseInt(value.substr(10,2));
second = parseInt(value.substr(12,2));
} }
} }
if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) { if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
@@ -155,6 +190,12 @@ function initCalendar() {
month = dt.getMonth(); month = dt.getMonth();
day = dt.getDate(); day = dt.getDate();
} }
if (isNaN(hour) || isNaN(minute) || isNaN(second)) {
dt = new Date();
hour = dt.getHours();
minute = dt.getMinutes();
second = dt.getSeconds();
}
} else { } else {
/* Moving in calendar */ /* Moving in calendar */
if (month > 11) { if (month > 11) {
@@ -212,14 +253,10 @@ function initCalendar() {
dispmonth = 1 + month; dispmonth = 1 + month;
yearstring = (year < 1000 ? year < 100 ? year < 10 ? '000' : '00' : '0' : '') + year;
monthstring = (dispmonth < 10 ? '0' : '') + dispmonth;
daystring = (i < 10 ? '0' : '') + i;
if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') { if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
actVal = yearstring + "-" + monthstring + "-" + daystring; actVal = formatNum4(year) + "-" + formatNum2(dispmonth) + "-" + formatNum2(day);
} else { } else {
actVal = "" + yearstring + monthstring + daystring; actVal = "" + formatNum4(year) + formatNum2(dispmonth) + formatNum2(day);
} }
if (i == day) { if (i == day) {
style = ' class="selected"'; style = ' class="selected"';
@@ -235,6 +272,15 @@ function initCalendar() {
str += "</tr></table>"; str += "</tr></table>";
// Should we handle time also?
if (window.opener.dateType != 'date') {
str += '<form class="clock">';
str += '<input id="hour" type="text" size="2" maxlength="2" value="' + formatNum2(hour) + '" />:';
str += '<input id="minute" type="text" size="2" maxlength="2" value="' + formatNum2(minute) + '" />:';
str += '<input id="second" type="text" size="2" maxlength="2" value="' + formatNum2(second) + '" />';
str += '</form>';
}
cnt.innerHTML = str; cnt.innerHTML = str;
} }
@@ -244,6 +290,20 @@ function initCalendar() {
* @param string date text * @param string date text
*/ */
function returnDate(d) { function returnDate(d) {
window.opener.dateField.value = d; txt = d;
if (window.opener.dateType != 'date') {
// need to get time
h = parseInt(document.getElementById('hour').value);
m = parseInt(document.getElementById('minute').value);
s = parseInt(document.getElementById('second').value);
if (window.opener.dateType == 'datetime') {
txt += ' ' + formatNum2(h) + ':' + formatNum2(m) + ':' + formatNum2(s);
} else {
// timestamp
txt += formatNum2(h) + formatNum2(m) + formatNum2(s);
}
}
window.opener.dateField.value = txt;
window.close(); window.close();
} }