TimePicker.js
资源名称:oa.rar [点击查看]
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:15k
源码类别:
OA系统
开发平台:
Java
- /*
- Copyright (c) 2004-2006, The Dojo Foundation
- All Rights Reserved.
- Licensed under the Academic Free License version 2.1 or above OR the
- modified BSD license. For more information on Dojo licensing, see:
- http://dojotoolkit.org/community/licensing.shtml
- */
- dojo.provide("dojo.widget.TimePicker");
- dojo.require("dojo.widget.*");
- dojo.require("dojo.widget.HtmlWidget");
- dojo.require("dojo.event.*");
- dojo.require("dojo.date.serialize");
- dojo.require("dojo.date.format");
- dojo.require("dojo.dom");
- dojo.require("dojo.html.style");
- dojo.requireLocalization("dojo.i18n.calendar", "gregorian", null, "ko,zh-cn,zh,sv,ja,en,zh-tw,it,hu,nl,fi,zh-hk,fr,pt,ROOT,es,de,pt-br");
- dojo.requireLocalization("dojo.widget", "TimePicker", null, "ROOT");
- dojo.widget.defineWidget("dojo.widget.TimePicker", dojo.widget.HtmlWidget, function () {
- this.time = "";
- this.useDefaultTime = false;
- this.useDefaultMinutes = false;
- this.storedTime = "";
- this.currentTime = {};
- this.classNames = {selectedTime:"selectedItem"};
- this.any = "any";
- this.selectedTime = {hour:"", minute:"", amPm:"", anyTime:false};
- this.hourIndexMap = ["", 2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 11, 0];
- this.minuteIndexMap = [0, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 11];
- }, {isContainer:false, templateString:"<div class="timePickerContainer" dojoAttachPoint="timePickerContainerNode">nt<table class="timeContainer" cellspacing="0" >ntt<thead>nttt<tr>ntttt<td class="timeCorner cornerTopLeft" valign="top"> </td>ntttt<td class="timeLabelContainer hourSelector">${this.calendar.field-hour}</td>ntttt<td class="timeLabelContainer minutesHeading">${this.calendar.field-minute}</td>ntttt<td class="timeCorner cornerTopRight" valign="top"> </td>nttt</tr>ntt</thead>ntt<tbody>nttt<tr>ntttt<td valign="top" colspan="2" class="hours">nttttt<table align="center">ntttttt<tbody dojoAttachPoint="hourContainerNode" ntttttttdojoAttachEvent="onClick: onSetSelectedHour;">nttttttt<tr>ntttttttt<td>12</td>ntttttttt<td>6</td>nttttttt</tr>nttttttt<tr>ntttttttt<td>1</td>ntttttttt<td>7</td>nttttttt</tr>nttttttt<tr>ntttttttt<td>2</td>ntttttttt<td>8</td>nttttttt</tr>nttttttt<tr>ntttttttt<td>3</td>ntttttttt<td>9</td>nttttttt</tr>nttttttt<tr>ntttttttt<td>4</td>ntttttttt<td>10</td>nttttttt</tr>nttttttt<tr>ntttttttt<td>5</td>ntttttttt<td>11</td>nttttttt</tr>ntttttt</tbody>nttttt</table>ntttt</td>ntttt<td valign="top" class="minutes" colspan="2">nttttt<table align="center">ntttttt<tbody dojoAttachPoint="minuteContainerNode" ntttttttdojoAttachEvent="onClick: onSetSelectedMinute;">nttttttt<tr>ntttttttt<td>00</td>ntttttttt<td>30</td>nttttttt</tr>nttttttt<tr>ntttttttt<td>05</td>ntttttttt<td>35</td>nttttttt</tr>nttttttt<tr>ntttttttt<td>10</td>ntttttttt<td>40</td>nttttttt</tr>nttttttt<tr>ntttttttt<td>15</td>ntttttttt<td>45</td>nttttttt</tr>nttttttt<tr>ntttttttt<td>20</td>ntttttttt<td>50</td>nttttttt</tr>nttttttt<tr>ntttttttt<td>25</td>ntttttttt<td>55</td>nttttttt</tr>ntttttt</tbody>nttttt</table>ntttt</td>nttt</tr>nttt<tr>ntttt<td class="cornerBottomLeft"> </td>ntttt<td valign="top" class="timeOptions">nttttt<table class="amPmContainer">ntttttt<tbody dojoAttachPoint="amPmContainerNode" ntttttttdojoAttachEvent="onClick: onSetSelectedAmPm;">nttttttt<tr>ntttttttt<td id="am">${this.calendar.am}</td>ntttttttt<td id="pm">${this.calendar.pm}</td>nttttttt</tr>ntttttt</tbody>nttttt</table>ntttt</td>ntttt<td class="timeOptions">nttttt<div dojoAttachPoint="anyTimeContainerNode" nttttttdojoAttachEvent="onClick: onSetSelectedAnyTime;" nttttttclass="anyTimeContainer">${this.widgetStrings.any}</div>ntttt</td>ntttt<td class="cornerBottomRight"> </td>nttt</tr>ntt</tbody>nt</table>n</div>n", templateCssString:"/*Time Picker */n.timePickerContainer {ntwidth:122px;ntfont-family:Tahoma, Myriad, Helvetica, Arial, Verdana, sans-serif;ntfont-size:16px;n}nn.timeContainer {ntborder-collapse:collapse;ntborder-spacing:0;n}nn.timeContainer thead {ntcolor:#293a4b;ntfont-size:0.9em;ntfont-weight:700;n}nn.timeContainer thead td {ntpadding:0.25em;ntfont-size:0.80em;ntborder-bottom:1px solid #6782A8;n}nn.timeCorner {ntwidth:10px;n}nn.cornerTopLeft {ntbackground: url("images/dpCurveTL.png") top left no-repeat;n}nn.cornerTopRight {ntbackground: url("images/dpCurveTR.png") top right no-repeat;n}nn.timeLabelContainer {ntbackground: url("images/dpMonthBg.png") top left repeat-x;n}nn.hours, .minutes, .timeBorder {ntbackground: #7591bc url("images/dpBg.gif") top left repeat-x;nn}nn.hours td, .minutes td {ntpadding:0.2em;nttext-align:center;ntfont-size:0.7em;ntfont-weight:bold;ntcursor:pointer;ntcursor:hand;ntcolor:#fff;n}nn.minutes {ntborder-left:1px solid #f5d1db;n}nn.hours {ntborder-right:1px solid #6782A8;n}nn.hourSelector {ntborder-right:1px solid #6782A8;ntpadding:5px;ntpadding-right:10px;n}nn.minutesSelector {ntpadding:5px;ntborder-left:1px solid #f5c7d4;nttext-align:center;n}nn.minutesHeading {ntpadding-left:9px !important;n}nn.timeOptions {ntbackground-color:#F9C9D7;n}nn.timeContainer .cornerBottomLeft, .timeContainer .cornerBottomRight, .timeContainer .timeOptions {ntborder-top:1px solid #6782A8;n}nn.timeContainer .cornerBottomLeft {ntbackground: url("images/dpCurveBL.png") bottom left no-repeat !important;ntwidth:9px !important;ntpadding:0;ntmargin:0;n}nn.timeContainer .cornerBottomRight {ntbackground: url("images/dpCurveBR.png") bottom right no-repeat !important;ntwidth:9px !important;ntpadding:0;ntmargin:0;n}nn.timeOptions {ntcolor:#fff;ntbackground:url("images/dpYearBg.png") top left repeat-x;nn}nn.selectedItem {ntbackground-color:#fff;ntcolor:#6782a8 !important;n}nn.timeOptions .selectedItem {ntcolor:#fff !important;ntbackground-color:#9ec3fb !important;n}nn.anyTimeContainer {nttext-align:center;ntfont-weight:bold;ntfont-size:0.7em;ntpadding:0.1em;ntcursor:pointer;ntcursor:hand;ntcolor:#fff !important;n}nn.amPmContainer {ntwidth:100%;n}nn.amPmContainer td {nttext-align:center;ntfont-size:0.7em;ntfont-weight:bold;ntcursor:pointer;ntcursor:hand;ntcolor:#fff;n}nnnn/*.timePickerContainer {ntmargin:1.75em 0 0.5em 0;ntwidth:10em;ntfloat:left;n}nn.timeContainer {ntborder-collapse:collapse;ntborder-spacing:0;n}nn.timeContainer thead td{ntborder-bottom:1px solid #e6e6e6;ntpadding:0 0.4em 0.2em 0.4em;n}nn.timeContainer td {ntfont-size:0.9em;ntpadding:0 0.25em 0 0.25em;nttext-align:left;ntcursor:pointer;cursor:hand;n}nn.timeContainer td.minutesHeading {ntborder-left:1px solid #e6e6e6;ntborder-right:1px solid #e6e6e6;tn}nn.timeContainer .minutes {ntborder-left:1px solid #e6e6e6;ntborder-right:1px solid #e6e6e6;n}nn.selectedItem {ntbackground-color:#3a3a3a;ntcolor:#ffffff;n}*/n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/TimePicker.css"), postMixInProperties:function (localProperties, frag) {
- dojo.widget.TimePicker.superclass.postMixInProperties.apply(this, arguments);
- this.calendar = dojo.i18n.getLocalization("dojo.i18n.calendar", "gregorian", this.lang);
- this.widgetStrings = dojo.i18n.getLocalization("dojo.widget", "TimePicker", this.lang);
- }, fillInTemplate:function (args, frag) {
- var source = this.getFragNodeRef(frag);
- dojo.html.copyStyle(this.domNode, source);
- if (args.value) {
- if (args.value instanceof Date) {
- this.storedTime = dojo.date.toRfc3339(args.value);
- } else {
- this.storedTime = args.value;
- }
- }
- this.initData();
- this.initUI();
- }, initData:function () {
- if (this.storedTime.indexOf("T") != -1 && this.storedTime.split("T")[1] && this.storedTime != " " && this.storedTime.split("T")[1] != "any") {
- this.time = dojo.widget.TimePicker.util.fromRfcDateTime(this.storedTime, this.useDefaultMinutes, this.selectedTime.anyTime);
- } else {
- if (this.useDefaultTime) {
- this.time = dojo.widget.TimePicker.util.fromRfcDateTime("", this.useDefaultMinutes, this.selectedTime.anyTime);
- } else {
- this.selectedTime.anyTime = true;
- this.time = dojo.widget.TimePicker.util.fromRfcDateTime("", 0, 1);
- }
- }
- }, initUI:function () {
- if (!this.selectedTime.anyTime && this.time) {
- var amPmHour = dojo.widget.TimePicker.util.toAmPmHour(this.time.getHours());
- var hour = amPmHour[0];
- var isAm = amPmHour[1];
- var minute = this.time.getMinutes();
- var minuteIndex = parseInt(minute / 5);
- this.onSetSelectedHour(this.hourIndexMap[hour]);
- this.onSetSelectedMinute(this.minuteIndexMap[minuteIndex]);
- this.onSetSelectedAmPm(isAm);
- } else {
- this.onSetSelectedAnyTime();
- }
- }, setTime:function (date) {
- if (date) {
- this.selectedTime.anyTime = false;
- this.setDateTime(dojo.date.toRfc3339(date));
- } else {
- this.selectedTime.anyTime = true;
- }
- this.initData();
- this.initUI();
- }, setDateTime:function (rfcDate) {
- this.storedTime = rfcDate;
- }, onClearSelectedHour:function (evt) {
- this.clearSelectedHour();
- }, onClearSelectedMinute:function (evt) {
- this.clearSelectedMinute();
- }, onClearSelectedAmPm:function (evt) {
- this.clearSelectedAmPm();
- }, onClearSelectedAnyTime:function (evt) {
- this.clearSelectedAnyTime();
- if (this.selectedTime.anyTime) {
- this.selectedTime.anyTime = false;
- this.time = dojo.widget.TimePicker.util.fromRfcDateTime("", this.useDefaultMinutes);
- this.initUI();
- }
- }, clearSelectedHour:function () {
- var hourNodes = this.hourContainerNode.getElementsByTagName("td");
- for (var i = 0; i < hourNodes.length; i++) {
- dojo.html.setClass(hourNodes.item(i), "");
- }
- }, clearSelectedMinute:function () {
- var minuteNodes = this.minuteContainerNode.getElementsByTagName("td");
- for (var i = 0; i < minuteNodes.length; i++) {
- dojo.html.setClass(minuteNodes.item(i), "");
- }
- }, clearSelectedAmPm:function () {
- var amPmNodes = this.amPmContainerNode.getElementsByTagName("td");
- for (var i = 0; i < amPmNodes.length; i++) {
- dojo.html.setClass(amPmNodes.item(i), "");
- }
- }, clearSelectedAnyTime:function () {
- dojo.html.setClass(this.anyTimeContainerNode, "anyTimeContainer");
- }, onSetSelectedHour:function (evt) {
- this.onClearSelectedAnyTime();
- this.onClearSelectedHour();
- this.setSelectedHour(evt);
- this.onSetTime();
- }, setSelectedHour:function (evt) {
- if (evt && evt.target) {
- if (evt.target.nodeType == dojo.dom.ELEMENT_NODE) {
- var eventTarget = evt.target;
- } else {
- var eventTarget = evt.target.parentNode;
- }
- dojo.event.browser.stopEvent(evt);
- dojo.html.setClass(eventTarget, this.classNames.selectedTime);
- this.selectedTime["hour"] = eventTarget.innerHTML;
- } else {
- if (!isNaN(evt)) {
- var hourNodes = this.hourContainerNode.getElementsByTagName("td");
- if (hourNodes.item(evt)) {
- dojo.html.setClass(hourNodes.item(evt), this.classNames.selectedTime);
- this.selectedTime["hour"] = hourNodes.item(evt).innerHTML;
- }
- }
- }
- this.selectedTime.anyTime = false;
- }, onSetSelectedMinute:function (evt) {
- this.onClearSelectedAnyTime();
- this.onClearSelectedMinute();
- this.setSelectedMinute(evt);
- this.selectedTime.anyTime = false;
- this.onSetTime();
- }, setSelectedMinute:function (evt) {
- if (evt && evt.target) {
- if (evt.target.nodeType == dojo.dom.ELEMENT_NODE) {
- var eventTarget = evt.target;
- } else {
- var eventTarget = evt.target.parentNode;
- }
- dojo.event.browser.stopEvent(evt);
- dojo.html.setClass(eventTarget, this.classNames.selectedTime);
- this.selectedTime["minute"] = eventTarget.innerHTML;
- } else {
- if (!isNaN(evt)) {
- var minuteNodes = this.minuteContainerNode.getElementsByTagName("td");
- if (minuteNodes.item(evt)) {
- dojo.html.setClass(minuteNodes.item(evt), this.classNames.selectedTime);
- this.selectedTime["minute"] = minuteNodes.item(evt).innerHTML;
- }
- }
- }
- }, onSetSelectedAmPm:function (evt) {
- this.onClearSelectedAnyTime();
- this.onClearSelectedAmPm();
- this.setSelectedAmPm(evt);
- this.selectedTime.anyTime = false;
- this.onSetTime();
- }, setSelectedAmPm:function (evt) {
- var eventTarget = evt.target;
- if (evt && eventTarget) {
- if (eventTarget.nodeType != dojo.dom.ELEMENT_NODE) {
- eventTarget = eventTarget.parentNode;
- }
- dojo.event.browser.stopEvent(evt);
- this.selectedTime.amPm = eventTarget.id;
- dojo.html.setClass(eventTarget, this.classNames.selectedTime);
- } else {
- evt = evt ? 0 : 1;
- var amPmNodes = this.amPmContainerNode.getElementsByTagName("td");
- if (amPmNodes.item(evt)) {
- this.selectedTime.amPm = amPmNodes.item(evt).id;
- dojo.html.setClass(amPmNodes.item(evt), this.classNames.selectedTime);
- }
- }
- }, onSetSelectedAnyTime:function (evt) {
- this.onClearSelectedHour();
- this.onClearSelectedMinute();
- this.onClearSelectedAmPm();
- this.setSelectedAnyTime();
- this.onSetTime();
- }, setSelectedAnyTime:function (evt) {
- this.selectedTime.anyTime = true;
- dojo.html.setClass(this.anyTimeContainerNode, this.classNames.selectedTime + " " + "anyTimeContainer");
- }, onClick:function (evt) {
- dojo.event.browser.stopEvent(evt);
- }, onSetTime:function () {
- if (this.selectedTime.anyTime) {
- this.time = new Date();
- var tempDateTime = dojo.widget.TimePicker.util.toRfcDateTime(this.time);
- this.setDateTime(tempDateTime.split("T")[0]);
- } else {
- var hour = 12;
- var minute = 0;
- var isAm = false;
- if (this.selectedTime["hour"]) {
- hour = parseInt(this.selectedTime["hour"], 10);
- }
- if (this.selectedTime["minute"]) {
- minute = parseInt(this.selectedTime["minute"], 10);
- }
- if (this.selectedTime["amPm"]) {
- isAm = (this.selectedTime["amPm"].toLowerCase() == "am");
- }
- this.time = new Date();
- this.time.setHours(dojo.widget.TimePicker.util.fromAmPmHour(hour, isAm));
- this.time.setMinutes(minute);
- this.setDateTime(dojo.widget.TimePicker.util.toRfcDateTime(this.time));
- }
- this.onValueChanged(this.time);
- }, onValueChanged:function (date) {
- }});
- dojo.widget.TimePicker.util = new function () {
- this.toRfcDateTime = function (jsDate) {
- if (!jsDate) {
- jsDate = new Date();
- }
- jsDate.setSeconds(0);
- return dojo.date.strftime(jsDate, "%Y-%m-%dT%H:%M:00%z");
- };
- this.fromRfcDateTime = function (rfcDate, useDefaultMinutes, isAnyTime) {
- var tempDate = new Date();
- if (!rfcDate || rfcDate.indexOf("T") == -1) {
- if (useDefaultMinutes) {
- tempDate.setMinutes(Math.floor(tempDate.getMinutes() / 5) * 5);
- } else {
- tempDate.setMinutes(0);
- }
- } else {
- var tempTime = rfcDate.split("T")[1].split(":");
- var tempDate = new Date();
- tempDate.setHours(tempTime[0]);
- tempDate.setMinutes(tempTime[1]);
- }
- return tempDate;
- };
- this.toAmPmHour = function (hour) {
- var amPmHour = hour;
- var isAm = true;
- if (amPmHour == 0) {
- amPmHour = 12;
- } else {
- if (amPmHour > 12) {
- amPmHour = amPmHour - 12;
- isAm = false;
- } else {
- if (amPmHour == 12) {
- isAm = false;
- }
- }
- }
- return [amPmHour, isAm];
- };
- this.fromAmPmHour = function (amPmHour, isAm) {
- var hour = parseInt(amPmHour, 10);
- if (isAm && hour == 12) {
- hour = 0;
- } else {
- if (!isAm && hour < 12) {
- hour = hour + 12;
- }
- }
- return hour;
- };
- };