mirror of https://github.com/apache/archiva.git
[MRM-84]
-fixed optionstransferselect box in pick report -updated datepicker to jquery datepicker but it's not working :-( git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@707811 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
08d84aff96
commit
8ea1037a29
|
@ -145,7 +145,8 @@ public class GenerateReportAction
|
|||
private DataLimits limits = new DataLimits();
|
||||
|
||||
private String[] datePatterns = new String[] { "MM/dd/yy", "MM/dd/yyyy", "MMMMM/dd/yyyy", "MMMMM/dd/yy",
|
||||
"dd MMMMM yyyy", "dd/MM/yy", "dd/MM/yyyy", "yyyy/MM/dd" };
|
||||
"dd MMMMM yyyy", "dd/MM/yy", "dd/MM/yyyy", "yyyy/MM/dd", "yyyy-MM-dd", "yyyy-dd-MM", "MM-dd-yyyy",
|
||||
"MM-dd-yy" };
|
||||
|
||||
public static final String SEND_FILE = "send-file";
|
||||
|
||||
|
|
|
@ -19,13 +19,28 @@
|
|||
|
||||
<%@ taglib prefix="s" uri="/struts-tags" %>
|
||||
|
||||
<link type="text/css" rel="StyleSheet" href="/archiva/css/datepicker.css" />
|
||||
<script type="text/javascript" src="/archiva/js/datepicker/datepicker.js"></script>
|
||||
<!-- jQuery -->
|
||||
<script type="text/javascript" src="/archiva/js/jquery/jquery-1.2.6.packjs"></script>
|
||||
|
||||
<!-- required plugins -->
|
||||
<script type="text/javascript" src="/archiva/js/jquery/date.js"></script>
|
||||
|
||||
<!-- jquery.datePicker.js -->
|
||||
<script type="text/javascript" src="/archiva/js/jquery/jquery.datePicker.js"></script>
|
||||
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Reports</title>
|
||||
<s:head theme="ajax" />
|
||||
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
$(function()
|
||||
{
|
||||
$('#startDate').datePicker({clickInput:true})
|
||||
$('#endDate').datePicker({clickInput:true})
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -38,41 +53,38 @@
|
|||
|
||||
<s:optiontransferselect label="Repositories To Be Compared" name="availableRepositories"
|
||||
list="availableRepositories" doubleName="selectedRepositories"
|
||||
doubleList="selectedRepositories" size="8" doubleSize="8"/>
|
||||
doubleList="selectedRepositories" size="8" doubleSize="8"
|
||||
addAllToRightOnclick="selectAllOptions(document.getElementById('generateStatisticsReport_availableRepositories'));selectAllOptions(document.getElementById('generateStatisticsReport_selectedRepositories'));"
|
||||
addToRightOnclick="selectAllOptions(document.getElementById('generateStatisticsReport_availableRepositories'));selectAllOptions(document.getElementById('generateStatisticsReport_selectedRepositories'));"
|
||||
addAllToLeftOnclick="selectAllOptions(document.getElementById('generateStatisticsReport_availableRepositories'));selectAllOptions(document.getElementById('generateStatisticsReport_selectedRepositories'));"
|
||||
addToLeftOnclick="selectAllOptions(document.getElementById('generateStatisticsReport_availableRepositories'));selectAllOptions(document.getElementById('generateStatisticsReport_selectedRepositories'));"
|
||||
/>
|
||||
|
||||
<s:textfield label="Row Count" name="rowCount" />
|
||||
<s:textfield label="Start Date" name="startDate" disabled="true"/>
|
||||
<script type="text/javascript">
|
||||
var d1 = new Date();
|
||||
var dp1 = new DatePicker(d1);
|
||||
|
||||
var tables = document.forms[0].getElementsByTagName("table");
|
||||
var myRow = tables[0].insertRow(3);
|
||||
var actionsCell = myRow.insertCell(0);
|
||||
var startDateCell = myRow.insertCell(1);
|
||||
startDateCell.appendChild(dp1.create());
|
||||
|
||||
dp1.onchange = function () {
|
||||
document.forms[0].startDate.value = dp1.getDate();
|
||||
};
|
||||
</script>
|
||||
|
||||
<s:textfield label="End Date" name="endDate" disabled="true"/>
|
||||
<script type="text/javascript">
|
||||
var d2 = new Date();
|
||||
var dp2 = new DatePicker(d2);
|
||||
|
||||
var tables = document.forms[0].getElementsByTagName("table");
|
||||
var myRow = tables[0].insertRow(5);
|
||||
var actionsCell = myRow.insertCell(0);
|
||||
var startDateCell = myRow.insertCell(1);
|
||||
startDateCell.appendChild(dp2.create());
|
||||
|
||||
dp2.onchange = function () {
|
||||
document.forms[0].endDate.value = dp2.getDate();
|
||||
};
|
||||
</script>
|
||||
|
||||
<s:textfield label="Row Count" name="rowCount" />
|
||||
|
||||
<s:textfield label="Start Date" id="startDate" name="startDate"/>
|
||||
<%--
|
||||
<script type="text/javascript">
|
||||
Calendar.setup({
|
||||
inputField : "startDate",
|
||||
ifFormat : "%Y-%m-%d",
|
||||
align : "Tl",
|
||||
singleClick : true
|
||||
});
|
||||
</script>
|
||||
--%>
|
||||
|
||||
<s:textfield label="End Date" id="endDate" name="endDate"/>
|
||||
<%--
|
||||
<script type="text/javascript">
|
||||
Calendar.setup({
|
||||
inputField : "endDate",
|
||||
ifFormat : "%Y-%m-%d",
|
||||
align : "Tl",
|
||||
singleClick : true
|
||||
});
|
||||
</script>
|
||||
--%>
|
||||
<s:submit value="View Statistics"/>
|
||||
</s:form>
|
||||
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
table.jCalendar {
|
||||
border: 1px solid #000;
|
||||
background: #aaa;
|
||||
border-collapse: separate;
|
||||
border-spacing: 2px;
|
||||
}
|
||||
table.jCalendar th {
|
||||
background: #333;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
padding: 3px 5px;
|
||||
}
|
||||
table.jCalendar td {
|
||||
background: #ccc;
|
||||
color: #000;
|
||||
padding: 3px 5px;
|
||||
text-align: center;
|
||||
}
|
||||
table.jCalendar td.other-month {
|
||||
background: #ddd;
|
||||
color: #aaa;
|
||||
}
|
||||
table.jCalendar td.today {
|
||||
background: #666;
|
||||
color: #fff;
|
||||
}
|
||||
table.jCalendar td.selected {
|
||||
background: #f66;
|
||||
color: #fff;
|
||||
}
|
||||
table.jCalendar td.selected:hover {
|
||||
background: #f33;
|
||||
color: #fff;
|
||||
}
|
||||
table.jCalendar td:hover, table.jCalendar td.dp-hover {
|
||||
background: #fff;
|
||||
color: #000;
|
||||
}
|
||||
table.jCalendar td.disabled, table.jCalendar td.disabled:hover {
|
||||
background: #bbb;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
/* For the popup */
|
||||
|
||||
/* NOTE - you will probably want to style a.dp-choose-date - see how I did it in demo.css */
|
||||
|
||||
div.dp-popup {
|
||||
position: relative;
|
||||
background: #ccc;
|
||||
font-size: 10px;
|
||||
font-family: arial, sans-serif;
|
||||
padding: 2px;
|
||||
width: 171px;
|
||||
line-height: 1.2em;
|
||||
}
|
||||
div#dp-popup {
|
||||
position: absolute;
|
||||
z-index: 199;
|
||||
}
|
||||
div.dp-popup h2 {
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
margin: 2px 0;
|
||||
padding: 0;
|
||||
}
|
||||
a#dp-close {
|
||||
font-size: 11px;
|
||||
padding: 4px 0;
|
||||
text-align: center;
|
||||
display: block;
|
||||
}
|
||||
a#dp-close:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
div.dp-popup a {
|
||||
color: #000;
|
||||
text-decoration: none;
|
||||
padding: 3px 2px 0;
|
||||
}
|
||||
div.dp-popup div.dp-nav-prev {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 4px;
|
||||
width: 100px;
|
||||
}
|
||||
div.dp-popup div.dp-nav-prev a {
|
||||
float: left;
|
||||
}
|
||||
/* Opera needs the rules to be this specific otherwise it doesn't change the cursor back to pointer after you have disabled and re-enabled a link */
|
||||
div.dp-popup div.dp-nav-prev a, div.dp-popup div.dp-nav-next a {
|
||||
cursor: pointer;
|
||||
}
|
||||
div.dp-popup div.dp-nav-prev a.disabled, div.dp-popup div.dp-nav-next a.disabled {
|
||||
cursor: default;
|
||||
}
|
||||
div.dp-popup div.dp-nav-next {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
right: 4px;
|
||||
width: 100px;
|
||||
}
|
||||
div.dp-popup div.dp-nav-next a {
|
||||
float: right;
|
||||
}
|
||||
div.dp-popup a.disabled {
|
||||
cursor: default;
|
||||
color: #aaa;
|
||||
}
|
||||
div.dp-popup td {
|
||||
cursor: pointer;
|
||||
}
|
||||
div.dp-popup td.disabled {
|
||||
cursor: default;
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
.datePicker {
|
||||
border: 1px solid WindowText;
|
||||
background: Window;
|
||||
width: 170px;
|
||||
padding: 0px;
|
||||
cursor: default;
|
||||
-moz-user-focus: normal;
|
||||
}
|
||||
|
||||
|
||||
.datePicker td {
|
||||
font: smallcaption;
|
||||
font: small-caption;
|
||||
text-align: center;
|
||||
color: WindowText;
|
||||
cursor: default;
|
||||
font-weight: normal !important;
|
||||
-moz-user-select: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.datePicker td.red {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.datePicker .header {
|
||||
background: ActiveCaption;
|
||||
padding: 3px;
|
||||
border-bottom: 1px solid WindowText;
|
||||
}
|
||||
|
||||
.datePicker .headerTable {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.datePicker .footer {
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
.datePicker .footerTable {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.datePicker .grid {
|
||||
padding: 3px;
|
||||
}
|
||||
.datePicker .gridTable {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.datePicker .gridTable td {
|
||||
width: 14.3%;
|
||||
}
|
||||
|
||||
.datePicker .gridTable .daysRow td {
|
||||
font-weight: bold !important;
|
||||
border-bottom: 1px solid ThreeDDarkShadow;
|
||||
}
|
||||
|
||||
.datePicker .grid .gridTable .upperLine {
|
||||
width: 100%;
|
||||
height: 2px;
|
||||
overflow: hidden;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.datePicker td.today {
|
||||
font-weight: bold !important;
|
||||
}
|
||||
|
||||
.datePicker td.selected {
|
||||
background: Highlight;
|
||||
color: HighlightText !important;
|
||||
}
|
||||
|
||||
.datePicker td.labelContainer {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.datePicker td .topLabel {
|
||||
color: CaptionText;
|
||||
display: block;
|
||||
font-weight: bold !important;
|
||||
width: 100%;
|
||||
text-decoration: none;
|
||||
|
||||
}
|
||||
|
||||
.datePicker td.filler {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.datePicker button {
|
||||
border-width: 1px;
|
||||
font: Caption;
|
||||
font-weight: normal !important;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.datePicker .previousButton {
|
||||
background: buttonface url("../images/arrow.left.png") no-repeat center center;
|
||||
}
|
||||
|
||||
.datePicker .nextButton {
|
||||
background: buttonface url("../images/arrow.right.png") no-repeat center center;
|
||||
}
|
||||
.datePicker .previousButton,
|
||||
.datePicker .nextButton {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
|
||||
.datePicker .todayButton,
|
||||
.datePicker .noneButton {
|
||||
width: 50px;
|
||||
}
|
||||
|
||||
|
||||
.datePicker .labelPopup {
|
||||
position: absolute;
|
||||
min-width: 130px;
|
||||
background: Window;
|
||||
border: 1px solid WindowText;
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
.datePicker .labelPopup a {
|
||||
width: 100%;
|
||||
display: block;
|
||||
color: WindowText;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.datePicker .labelPopup a:hover {
|
||||
background: Highlight;
|
||||
color: HighlightText;
|
||||
}
|
||||
|
||||
.datePicker .labelPopup a.selected {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
|
@ -1,618 +0,0 @@
|
|||
/*----------------------------------------------------------------------------\
|
||||
| Date Picker 1.06 |
|
||||
|-----------------------------------------------------------------------------|
|
||||
| Created by Erik Arvidsson |
|
||||
| (http://webfx.eae.net/contact.html#erik) |
|
||||
| For WebFX (http://webfx.eae.net/) |
|
||||
|-----------------------------------------------------------------------------|
|
||||
| A DOM based Date Picker |
|
||||
|-----------------------------------------------------------------------------|
|
||||
| Copyright (c) 1999, 2002, 2002, 2003, 2004, 2006 Erik Arvidsson |
|
||||
|-----------------------------------------------------------------------------|
|
||||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|
||||
| use this file except in compliance with the License. You may obtain a copy |
|
||||
| of the License at http://www.apache.org/licenses/LICENSE-2.0 |
|
||||
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
||||
| Unless required by applicable law or agreed to in writing, software |
|
||||
| distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
||||
| WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
||||
| License for the specific language governing permissions and limitations |
|
||||
| under the License. |
|
||||
|-----------------------------------------------------------------------------|
|
||||
| Dependencies: datepicker.css Date picker style declarations |
|
||||
|-----------------------------------------------------------------------------|
|
||||
| 2002-02-10 | Changed _update method to only update the text nodes instead |
|
||||
| | rewriting the entire table. Also added support for mouse wheel |
|
||||
| | in IE6. |
|
||||
| 2002-01-14 | Cleaned up for 1.0 public version |
|
||||
| 2002-01-15 | Replace all innerHTML calls with DOM1 methods |
|
||||
| 2002-01-18 | Minor IE6 bug that occured when dragging the mouse |
|
||||
| 2002-01-19 | Added a popup that is shown when the user clicks on the month. |
|
||||
| | This allows navigation to 6 adjacent months. |
|
||||
| 2002-04-10 | Fixed a bug that occured in the popup when a date was selected |
|
||||
| | that caused surroundung months to "overflow" |
|
||||
| | This had the effect that one could get two October months |
|
||||
| | listed. |
|
||||
| 2002-09-06 | I had missed one place were window was used instead of |
|
||||
| | doc.parentWindow |
|
||||
| 2003-08-28 | Added support for ensurin no date overflow when changing |
|
||||
| | months. |
|
||||
| 2004-01-10 | Adding type on the buttons to ensure they are not submit |
|
||||
| | buttons. Minor CSS change for CSS2 |
|
||||
| 2006-05-28 | Changed license to Apache Software License 2.0. |
|
||||
|-----------------------------------------------------------------------------|
|
||||
| Created 2001-10-?? | All changes are in the log above. | Updated 2006-05-28 |
|
||||
\----------------------------------------------------------------------------*/
|
||||
|
||||
// The DatePicker constructor
|
||||
// oDate : Date Optional argument representing the date to select
|
||||
function DatePicker( oDate ) {
|
||||
// check arguments
|
||||
if ( arguments.length == 0 ) {
|
||||
this._selectedDate = new Date;
|
||||
this._none = false;
|
||||
}
|
||||
else {
|
||||
this._selectedDate = oDate || new Date();
|
||||
this._none = oDate == null;
|
||||
}
|
||||
|
||||
this._matrix = [[],[],[],[],[],[],[]];
|
||||
this._showNone = true;
|
||||
this._showToday = true;
|
||||
this._firstWeekDay = 0; // start week with monday according to standards
|
||||
this._redWeekDay = 6; // sunday is the default red day.
|
||||
|
||||
this._dontChangeNone = false;
|
||||
}
|
||||
|
||||
// two static fields describing the name of the months abd days
|
||||
DatePicker.months = [
|
||||
"January", "February", "March", "April",
|
||||
"May", "June", "July", "August",
|
||||
"September", "October", "November", "December"];
|
||||
DatePicker.days = ["m", "t", "w", "t", "f", "s", "s"];
|
||||
|
||||
|
||||
DatePicker.prototype.onchange = function () {};
|
||||
|
||||
// create the nodes inside the date picker
|
||||
DatePicker.prototype.create = function ( doc ) {
|
||||
if ( doc == null ) doc = document;
|
||||
|
||||
this._document = doc;
|
||||
|
||||
// create elements
|
||||
this._el = doc.createElement( "div" );
|
||||
this._el.className = "datePicker";
|
||||
|
||||
// header
|
||||
var div = doc.createElement( "div" );
|
||||
div.className = "header";
|
||||
this._el.appendChild( div );
|
||||
|
||||
var headerTable = doc.createElement( "table" );
|
||||
headerTable.className = "headerTable";
|
||||
headerTable.cellSpacing = 0;
|
||||
div.appendChild( headerTable );
|
||||
|
||||
var tBody = doc.createElement( "tbody" );
|
||||
headerTable.appendChild( tBody );
|
||||
|
||||
var tr = doc.createElement( "tr" );
|
||||
tBody.appendChild( tr );
|
||||
|
||||
var td = doc.createElement( "td" );
|
||||
this._previousMonth = doc.createElement( "button" );
|
||||
this._previousMonth.className = "previousButton";
|
||||
this._previousMonth.setAttribute("type", "button");
|
||||
td.appendChild( this._previousMonth );
|
||||
tr.appendChild( td );
|
||||
|
||||
td = doc.createElement( "td" );
|
||||
td.className = "labelContainer";
|
||||
tr.appendChild( td );
|
||||
|
||||
this._topLabel = doc.createElement( "a" );
|
||||
this._topLabel.className = "topLabel";
|
||||
this._topLabel.href = "#";
|
||||
this._topLabel.appendChild( doc.createTextNode( String.fromCharCode( 160 ) ) );
|
||||
td.appendChild( this._topLabel );
|
||||
|
||||
this._labelPopup = doc.createElement( "div" );
|
||||
this._labelPopup.className = "labelPopup";
|
||||
// no insertion
|
||||
|
||||
td = doc.createElement( "td" );
|
||||
this._nextMonth = doc.createElement( "button" );
|
||||
this._nextMonth.className = "nextButton";
|
||||
this._nextMonth.setAttribute("type", "button");
|
||||
td.appendChild( this._nextMonth );
|
||||
tr.appendChild( td );
|
||||
|
||||
// grid
|
||||
div = doc.createElement( "div" );
|
||||
div.className = "grid";
|
||||
this._el.appendChild( div );
|
||||
this._table = div;
|
||||
|
||||
// footer
|
||||
div = doc.createElement( "div" );
|
||||
div.className = "footer";
|
||||
this._el.appendChild( div );
|
||||
|
||||
var footerTable = doc.createElement( "table" );
|
||||
footerTable.className = "footerTable";
|
||||
footerTable.cellSpacing = 0;
|
||||
div.appendChild( footerTable );
|
||||
|
||||
tBody = doc.createElement( "tbody" );
|
||||
footerTable.appendChild( tBody );
|
||||
|
||||
tr = doc.createElement( "tr" );
|
||||
tBody.appendChild( tr );
|
||||
|
||||
td = doc.createElement( "td" );
|
||||
this._todayButton = doc.createElement( "button" );
|
||||
this._todayButton.className = "todayButton";
|
||||
this._todayButton.setAttribute("type", "button");
|
||||
this._todayButton.appendChild( doc.createTextNode( "Today" ) );
|
||||
td.appendChild( this._todayButton );
|
||||
tr.appendChild( td );
|
||||
|
||||
td = doc.createElement( "td" );
|
||||
td.className = "filler";
|
||||
td.appendChild( doc.createTextNode( String.fromCharCode( 160 ) ) );
|
||||
tr.appendChild( td );
|
||||
|
||||
td = doc.createElement( "td" );
|
||||
this._noneButton = doc.createElement( "button" );
|
||||
this._noneButton.className = "noneButton";
|
||||
this._noneButton.setAttribute("type", "button");
|
||||
this._noneButton.appendChild( doc.createTextNode( "None" ) );
|
||||
td.appendChild( this._noneButton );
|
||||
tr.appendChild( td );
|
||||
|
||||
|
||||
|
||||
this._createTable( doc );
|
||||
|
||||
this._updateTable();
|
||||
this._setTopLabel();
|
||||
|
||||
if ( !this._showNone )
|
||||
this._noneButton.style.visibility = "hidden";
|
||||
if ( !this._showToday )
|
||||
this._todayButton.style.visibility = "hidden";
|
||||
|
||||
// IE55+ extension
|
||||
this._previousMonth.hideFocus = true;
|
||||
this._nextMonth.hideFocus = true;
|
||||
this._todayButton.hideFocus = true;
|
||||
this._noneButton.hideFocus = true;
|
||||
// end IE55+ extension
|
||||
|
||||
// hook up events
|
||||
var dp = this;
|
||||
// buttons
|
||||
this._previousMonth.onclick = function () {
|
||||
dp._dontChangeNone = true;
|
||||
dp.goToPreviousMonth();
|
||||
dp._dontChangeNone = false;
|
||||
};
|
||||
this._nextMonth.onclick = function () {
|
||||
dp._dontChangeNone = true;
|
||||
dp.goToNextMonth();
|
||||
dp._dontChangeNone = false;
|
||||
};
|
||||
this._todayButton.onclick = function () {
|
||||
dp.goToToday();
|
||||
};
|
||||
this._noneButton.onclick = function () {
|
||||
dp.setDate( null );
|
||||
};
|
||||
|
||||
this._el.onselectstart = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
this._table.onclick = function ( e ) {
|
||||
// find event
|
||||
if ( e == null ) e = doc.parentWindow.event;
|
||||
|
||||
// find td
|
||||
var el = e.target != null ? e.target : e.srcElement;
|
||||
while ( el.nodeType != 1 )
|
||||
el = el.parentNode;
|
||||
while ( el != null && el.tagName && el.tagName.toLowerCase() != "td" )
|
||||
el = el.parentNode;
|
||||
|
||||
// if no td found, return
|
||||
if ( el == null || el.tagName == null || el.tagName.toLowerCase() != "td" )
|
||||
return;
|
||||
|
||||
var d = new Date( dp._selectedDate );
|
||||
var n = Number( el.firstChild.data );
|
||||
if ( isNaN( n ) || n <= 0 || n == null )
|
||||
return;
|
||||
|
||||
d.setDate( n );
|
||||
dp.setDate( d );
|
||||
};
|
||||
|
||||
// show popup
|
||||
this._topLabel.onclick = function ( e ) {
|
||||
dp._showLabelPopup();
|
||||
return false;
|
||||
};
|
||||
|
||||
this._el.onkeydown = function ( e ) {
|
||||
if ( e == null ) e = doc.parentWindow.event;
|
||||
var kc = e.keyCode != null ? e.keyCode : e.charCode;
|
||||
|
||||
if ( kc < 37 || kc > 40 ) return true;
|
||||
|
||||
var d = new Date( dp._selectedDate ).valueOf();
|
||||
if ( kc == 37 ) // left
|
||||
d -= 24 * 60 * 60 * 1000;
|
||||
else if ( kc == 39 ) // right
|
||||
d += 24 * 60 * 60 * 1000;
|
||||
else if ( kc == 38 ) // up
|
||||
d -= 7 * 24 * 60 * 60 * 1000;
|
||||
else if ( kc == 40 ) // down
|
||||
d += 7 * 24 * 60 * 60 * 1000;
|
||||
|
||||
dp.setDate( new Date( d ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
// ie6 extension
|
||||
this._el.onmousewheel = function ( e ) {
|
||||
if ( e == null ) e = doc.parentWindow.event;
|
||||
var n = - e.wheelDelta / 120;
|
||||
var d = new Date( dp._selectedDate );
|
||||
var m = d.getMonth() + n;
|
||||
d.setMonth( m );
|
||||
|
||||
|
||||
dp._dontChangeNone = true;
|
||||
dp.setDate( d );
|
||||
dp._dontChangeNone = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return this._el;
|
||||
};
|
||||
|
||||
DatePicker.prototype.setDate = function ( oDate ) {
|
||||
|
||||
this._hideLabelPopup();
|
||||
|
||||
// if null then set None
|
||||
if ( oDate == null ) {
|
||||
if ( !this._none ) {
|
||||
this._none = true;
|
||||
this._setTopLabel();
|
||||
this._updateTable();
|
||||
|
||||
if ( typeof this.onchange == "function" )
|
||||
this.onchange();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// if string or number create a Date object
|
||||
if ( typeof oDate == "string" || typeof oDate == "number" ) {
|
||||
oDate = new Date( oDate );
|
||||
}
|
||||
|
||||
|
||||
// do not update if not really changed
|
||||
if ( this._selectedDate.getDate() != oDate.getDate() ||
|
||||
this._selectedDate.getMonth() != oDate.getMonth() ||
|
||||
this._selectedDate.getFullYear() != oDate.getFullYear() ||
|
||||
this._none ) {
|
||||
|
||||
if ( !this._dontChangeNone )
|
||||
this._none = false;
|
||||
|
||||
this._selectedDate = new Date( oDate );
|
||||
|
||||
this._setTopLabel();
|
||||
this._updateTable();
|
||||
|
||||
if ( typeof this.onchange == "function" )
|
||||
this.onchange();
|
||||
}
|
||||
|
||||
if ( !this._dontChangeNone )
|
||||
this._none = false;
|
||||
}
|
||||
|
||||
|
||||
DatePicker.prototype.getDate = function () {
|
||||
if ( this._none ) return null;
|
||||
return new Date( this._selectedDate ); // create a new instance
|
||||
}
|
||||
|
||||
// creates the table elements and inserts them into the date picker
|
||||
DatePicker.prototype._createTable = function ( doc ) {
|
||||
var str, i;
|
||||
var rows = 6;
|
||||
var cols = 7;
|
||||
var currentWeek = 0;
|
||||
|
||||
var table = doc.createElement( "table" );
|
||||
table.className = "gridTable";
|
||||
table.cellSpacing = 0;
|
||||
|
||||
var tBody = doc.createElement( "tbody" );
|
||||
table.appendChild( tBody );
|
||||
|
||||
// days row
|
||||
var tr = doc.createElement( "tr" );
|
||||
tr.className = "daysRow";
|
||||
|
||||
var td, tn;
|
||||
var nbsp = String.fromCharCode( 160 );
|
||||
for ( i = 0; i < cols; i++ ) {
|
||||
td = doc.createElement( "td" );
|
||||
td.appendChild( doc.createTextNode( nbsp ) );
|
||||
tr.appendChild( td );
|
||||
}
|
||||
tBody.appendChild( tr );
|
||||
|
||||
// upper line
|
||||
tr = doc.createElement( "tr" );
|
||||
td = doc.createElement( "td" );
|
||||
td.className = "upperLine";
|
||||
td.colSpan = 7;
|
||||
tr.appendChild( td );
|
||||
tBody.appendChild( tr );
|
||||
|
||||
// rest
|
||||
for ( i = 0; i < rows; i++ ) {
|
||||
tr = doc.createElement( "tr" );
|
||||
for ( var j = 0; j < cols; j++ ) {
|
||||
td = doc.createElement( "td" );
|
||||
td.appendChild( doc.createTextNode( nbsp ) );
|
||||
tr.appendChild( td );
|
||||
}
|
||||
tBody.appendChild( tr );
|
||||
}
|
||||
str += "</table>";
|
||||
|
||||
if ( this._table != null )
|
||||
this._table.appendChild( table )
|
||||
};
|
||||
// this method updates all the text nodes inside the table as well
|
||||
// as all the classNames on the tds
|
||||
DatePicker.prototype._updateTable = function () {
|
||||
// if no element no need to continue
|
||||
if ( this._table == null ) return;
|
||||
|
||||
var i;
|
||||
var str = "";
|
||||
var rows = 6;
|
||||
var cols = 7;
|
||||
var currentWeek = 0;
|
||||
|
||||
var cells = new Array( rows );
|
||||
this._matrix = new Array( rows )
|
||||
for ( i = 0; i < rows; i++ ) {
|
||||
cells[i] = new Array( cols );
|
||||
this._matrix[i] = new Array( cols );
|
||||
}
|
||||
|
||||
// Set the tmpDate to this month
|
||||
var tmpDate = new Date( this._selectedDate.getFullYear(),
|
||||
this._selectedDate.getMonth(), 1 );
|
||||
var today = new Date();
|
||||
// go thorugh all days this month and store the text
|
||||
// and the class name in the cells matrix
|
||||
for ( i = 1; i < 32; i++ ) {
|
||||
tmpDate.setDate( i );
|
||||
// convert to ISO, Monday is 0 and 6 is Sunday
|
||||
var weekDay = ( tmpDate.getDay() + 6 ) % 7;
|
||||
var colIndex = ( weekDay - this._firstWeekDay + 7 ) % 7;
|
||||
if ( tmpDate.getMonth() == this._selectedDate.getMonth() ) {
|
||||
|
||||
var isToday = tmpDate.getDate() == today.getDate() &&
|
||||
tmpDate.getMonth() == today.getMonth() &&
|
||||
tmpDate.getFullYear() == today.getFullYear();
|
||||
|
||||
cells[currentWeek][colIndex] = { text: "", className: "" };
|
||||
|
||||
if ( this._selectedDate.getDate() == tmpDate.getDate() && !this._none )
|
||||
cells[currentWeek][colIndex].className += "selected ";
|
||||
if ( isToday )
|
||||
cells[currentWeek][colIndex].className += "today ";
|
||||
if ( ( tmpDate.getDay() + 6 ) % 7 == this._redWeekDay ) // ISO
|
||||
cells[currentWeek][colIndex].className += "red";
|
||||
|
||||
cells[currentWeek][colIndex].text =
|
||||
this._matrix[currentWeek][colIndex] = tmpDate.getDate();
|
||||
|
||||
if ( colIndex == 6 )
|
||||
currentWeek++;
|
||||
}
|
||||
}
|
||||
|
||||
// fix day letter order if not standard
|
||||
var weekDays = DatePicker.days;
|
||||
if (this._firstWeekDay != 0) {
|
||||
weekDays = new Array(7);
|
||||
for ( i = 0; i < 7; i++)
|
||||
weekDays[i] = DatePicker.days[ (i + this._firstWeekDay) % 7];
|
||||
}
|
||||
|
||||
// update text in days row
|
||||
var tds = this._table.firstChild.tBodies[0].rows[0].cells;
|
||||
for ( i = 0; i < cols; i++ )
|
||||
tds[i].firstChild.data = weekDays[i];
|
||||
|
||||
// update the text nodes and class names
|
||||
var trs = this._table.firstChild.tBodies[0].rows;
|
||||
var tmpCell;
|
||||
var nbsp = String.fromCharCode( 160 );
|
||||
for ( var y = 0; y < rows; y++ ) {
|
||||
for (var x = 0; x < cols; x++) {
|
||||
tmpCell = trs[y + 2].cells[x];
|
||||
if ( typeof cells[y][x] != "undefined" ) {
|
||||
tmpCell.className = cells[y][x].className;
|
||||
tmpCell.firstChild.data = cells[y][x].text;
|
||||
}
|
||||
else {
|
||||
tmpCell.className = "";
|
||||
tmpCell.firstChild.data = nbsp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sets the label showing the year and selected month
|
||||
DatePicker.prototype._setTopLabel = function () {
|
||||
var str = this._selectedDate.getFullYear() + " " + DatePicker.months[ this._selectedDate.getMonth() ];
|
||||
if ( this._topLabel != null )
|
||||
this._topLabel.lastChild.data = str;
|
||||
}
|
||||
|
||||
DatePicker.prototype.goToNextMonth = function () {
|
||||
var d = new Date( this._selectedDate );
|
||||
d.setDate( Math.min(d.getDate(), DatePicker.getDaysPerMonth(d.getMonth() + 1,
|
||||
d.getFullYear())) ); // no need to catch dec -> jan for the year
|
||||
d.setMonth( d.getMonth() + 1 );
|
||||
this.setDate( d );
|
||||
}
|
||||
|
||||
DatePicker.prototype.goToPreviousMonth = function () {
|
||||
var d = new Date( this._selectedDate );
|
||||
d.setDate( Math.min(d.getDate(), DatePicker.getDaysPerMonth(d.getMonth() - 1,
|
||||
d.getFullYear())) ); // no need to catch jan -> dec for the year
|
||||
d.setMonth( d.getMonth() - 1 );
|
||||
this.setDate( d );
|
||||
}
|
||||
|
||||
DatePicker.prototype.goToToday = function () {
|
||||
if ( this._none )
|
||||
// change the selectedDate to force update if none was true
|
||||
this._selectedDate = new Date( this._selectedDate + 10000000000 );
|
||||
this._none = false;
|
||||
this.setDate( new Date() );
|
||||
}
|
||||
|
||||
DatePicker.prototype.setShowToday = function ( bShowToday ) {
|
||||
if ( typeof bShowToday == "string" )
|
||||
bShowToday = !/false|0|no/i.test( bShowToday );
|
||||
|
||||
if ( this._todayButton != null )
|
||||
this._todayButton.style.visibility = bShowToday ? "visible" : "hidden";
|
||||
this._showToday = bShowToday;
|
||||
}
|
||||
|
||||
DatePicker.prototype.getShowToday = function () {
|
||||
return this._showToday;
|
||||
}
|
||||
|
||||
DatePicker.prototype.setShowNone = function ( bShowNone ) {
|
||||
if ( typeof bShowNone == "string" )
|
||||
bShowNone = !/false|0|no/i.test( bShowNone );
|
||||
|
||||
if ( this._noneButton != null )
|
||||
this._noneButton.style.visibility = bShowNone ? "visible" : "hidden";
|
||||
this._showNone = bShowNone;
|
||||
}
|
||||
|
||||
DatePicker.prototype.getShowNone = function () {
|
||||
return this._showNone;
|
||||
}
|
||||
|
||||
// 0 is monday and 6 is sunday as in the ISO standard
|
||||
DatePicker.prototype.setFirstWeekDay = function ( nFirstWeekDay ) {
|
||||
if ( this._firstWeekDay != nFirstWeekDay ) {
|
||||
this._firstWeekDay = nFirstWeekDay;
|
||||
this._updateTable();
|
||||
}
|
||||
}
|
||||
|
||||
DatePicker.prototype.getFirstWeekDay = function () {
|
||||
return this._firstWeekDay;
|
||||
}
|
||||
|
||||
// 0 is monday and 6 is sunday as in the ISO standard
|
||||
DatePicker.prototype.setRedWeekDay = function ( nRedWeekDay ) {
|
||||
if ( this._redWeekDay != nRedWeekDay ) {
|
||||
this._redWeekDay = nRedWeekDay;
|
||||
this._updateTable();
|
||||
}
|
||||
}
|
||||
|
||||
DatePicker.prototype.getRedWeekDay = function () {
|
||||
return this._redWeekDay;
|
||||
}
|
||||
|
||||
|
||||
DatePicker.prototype._showLabelPopup = function () {
|
||||
|
||||
/*
|
||||
this._labelPopup document.createElement( "DIV" );
|
||||
div.className = "month-popup";
|
||||
div.noWrap = true;
|
||||
el.unselectable = div.unselectable = "on";
|
||||
el.onselectstart = div.onselectstart = function () { return false; };
|
||||
*/
|
||||
|
||||
var dateContext = function ( dp, d ) {
|
||||
return function ( e ) {
|
||||
dp._dontChangeNone = true;
|
||||
dp._hideLabelPopup();
|
||||
dp.setDate( d );
|
||||
dp._dontChangeNone = false;
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
var dp = this;
|
||||
|
||||
// clear all old elements in the popup
|
||||
while ( this._labelPopup.hasChildNodes() )
|
||||
this._labelPopup.removeChild( this._labelPopup.firstChild );
|
||||
|
||||
var a, tmp, tmp2;
|
||||
for ( var i = -3; i < 4; i++ ) {
|
||||
tmp = new Date( this._selectedDate );
|
||||
tmp2 = new Date( this._selectedDate ); // need another tmp to catch year change when checking leap
|
||||
tmp2.setDate(1);
|
||||
tmp2.setMonth( tmp2.getMonth() + i );
|
||||
tmp.setDate( Math.min(tmp.getDate(), DatePicker.getDaysPerMonth(tmp.getMonth() + i,
|
||||
tmp2.getFullYear())) );
|
||||
tmp.setMonth( tmp.getMonth() + i );
|
||||
|
||||
a = this._document.createElement( "a" );
|
||||
a.href = "javascript:void 0;";
|
||||
a.onclick = dateContext( dp, tmp );
|
||||
a.appendChild( this._document.createTextNode( tmp.getFullYear() + " " +
|
||||
DatePicker.months[ tmp.getMonth() ] ) );
|
||||
if ( i == 0 )
|
||||
a.className = "selected";
|
||||
this._labelPopup.appendChild( a );
|
||||
}
|
||||
|
||||
this._topLabel.parentNode.insertBefore( this._labelPopup, this._topLabel.parentNode.firstChild );
|
||||
};
|
||||
|
||||
DatePicker.prototype._hideLabelPopup = function () {
|
||||
if ( this._labelPopup.parentNode )
|
||||
this._labelPopup.parentNode.removeChild( this._labelPopup );
|
||||
};
|
||||
|
||||
DatePicker._daysPerMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
|
||||
DatePicker.getDaysPerMonth = function (nMonth, nYear) {
|
||||
nMonth = (nMonth + 12) % 12;
|
||||
var res = DatePicker._daysPerMonth[nMonth];
|
||||
if (nMonth == 1) {
|
||||
res += nYear % 4 == 0 && !(nYear % 400 == 0) ? 1 : 0;
|
||||
}
|
||||
return res;
|
||||
};
|
467
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/jquery/date.js
vendored
Normal file
467
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/jquery/date.js
vendored
Normal file
|
@ -0,0 +1,467 @@
|
|||
/*
|
||||
* Date prototype extensions. Doesn't depend on any
|
||||
* other code. Doens't overwrite existing methods.
|
||||
*
|
||||
* Adds dayNames, abbrDayNames, monthNames and abbrMonthNames static properties and isLeapYear,
|
||||
* isWeekend, isWeekDay, getDaysInMonth, getDayName, getMonthName, getDayOfYear, getWeekOfYear,
|
||||
* setDayOfYear, addYears, addMonths, addDays, addHours, addMinutes, addSeconds methods
|
||||
*
|
||||
* Copyright (c) 2006 Jörn Zaefferer and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
|
||||
*
|
||||
* Additional methods and properties added by Kelvin Luck: firstDayOfWeek, dateFormat, zeroTime, asString, fromString -
|
||||
* I've added my name to these methods so you know who to blame if they are broken!
|
||||
*
|
||||
* Dual licensed under the MIT and GPL licenses:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* An Array of day names starting with Sunday.
|
||||
*
|
||||
* @example dayNames[0]
|
||||
* @result 'Sunday'
|
||||
*
|
||||
* @name dayNames
|
||||
* @type Array
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
Date.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||
|
||||
/**
|
||||
* An Array of abbreviated day names starting with Sun.
|
||||
*
|
||||
* @example abbrDayNames[0]
|
||||
* @result 'Sun'
|
||||
*
|
||||
* @name abbrDayNames
|
||||
* @type Array
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
Date.abbrDayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
|
||||
/**
|
||||
* An Array of month names starting with Janurary.
|
||||
*
|
||||
* @example monthNames[0]
|
||||
* @result 'January'
|
||||
*
|
||||
* @name monthNames
|
||||
* @type Array
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
Date.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
||||
|
||||
/**
|
||||
* An Array of abbreviated month names starting with Jan.
|
||||
*
|
||||
* @example abbrMonthNames[0]
|
||||
* @result 'Jan'
|
||||
*
|
||||
* @name monthNames
|
||||
* @type Array
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
Date.abbrMonthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
|
||||
/**
|
||||
* The first day of the week for this locale.
|
||||
*
|
||||
* @name firstDayOfWeek
|
||||
* @type Number
|
||||
* @cat Plugins/Methods/Date
|
||||
* @author Kelvin Luck
|
||||
*/
|
||||
Date.firstDayOfWeek = 1;
|
||||
|
||||
/**
|
||||
* The format that string dates should be represented as (e.g. 'dd/mm/yyyy' for UK, 'mm/dd/yyyy' for US, 'yyyy-mm-dd' for Unicode etc).
|
||||
*
|
||||
* @name format
|
||||
* @type String
|
||||
* @cat Plugins/Methods/Date
|
||||
* @author Kelvin Luck
|
||||
*/
|
||||
Date.format = 'dd/mm/yyyy';
|
||||
//Date.format = 'mm/dd/yyyy';
|
||||
//Date.format = 'yyyy-mm-dd';
|
||||
//Date.format = 'dd mmm yy';
|
||||
|
||||
/**
|
||||
* The first two numbers in the century to be used when decoding a two digit year. Since a two digit year is ambiguous (and date.setYear
|
||||
* only works with numbers < 99 and so doesn't allow you to set years after 2000) we need to use this to disambiguate the two digit year codes.
|
||||
*
|
||||
* @name format
|
||||
* @type String
|
||||
* @cat Plugins/Methods/Date
|
||||
* @author Kelvin Luck
|
||||
*/
|
||||
Date.fullYearStart = '20';
|
||||
|
||||
(function() {
|
||||
|
||||
/**
|
||||
* Adds a given method under the given name
|
||||
* to the Date prototype if it doesn't
|
||||
* currently exist.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function add(name, method) {
|
||||
if( !Date.prototype[name] ) {
|
||||
Date.prototype[name] = method;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if the year is a leap year.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.isLeapYear();
|
||||
* @result true
|
||||
*
|
||||
* @name isLeapYear
|
||||
* @type Boolean
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("isLeapYear", function() {
|
||||
var y = this.getFullYear();
|
||||
return (y%4==0 && y%100!=0) || y%400==0;
|
||||
});
|
||||
|
||||
/**
|
||||
* Checks if the day is a weekend day (Sat or Sun).
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.isWeekend();
|
||||
* @result false
|
||||
*
|
||||
* @name isWeekend
|
||||
* @type Boolean
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("isWeekend", function() {
|
||||
return this.getDay()==0 || this.getDay()==6;
|
||||
});
|
||||
|
||||
/**
|
||||
* Check if the day is a day of the week (Mon-Fri)
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.isWeekDay();
|
||||
* @result false
|
||||
*
|
||||
* @name isWeekDay
|
||||
* @type Boolean
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("isWeekDay", function() {
|
||||
return !this.isWeekend();
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets the number of days in the month.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.getDaysInMonth();
|
||||
* @result 31
|
||||
*
|
||||
* @name getDaysInMonth
|
||||
* @type Number
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("getDaysInMonth", function() {
|
||||
return [31,(this.isLeapYear() ? 29:28),31,30,31,30,31,31,30,31,30,31][this.getMonth()];
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets the name of the day.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.getDayName();
|
||||
* @result 'Saturday'
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.getDayName(true);
|
||||
* @result 'Sat'
|
||||
*
|
||||
* @param abbreviated Boolean When set to true the name will be abbreviated.
|
||||
* @name getDayName
|
||||
* @type String
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("getDayName", function(abbreviated) {
|
||||
return abbreviated ? Date.abbrDayNames[this.getDay()] : Date.dayNames[this.getDay()];
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets the name of the month.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.getMonthName();
|
||||
* @result 'Janurary'
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.getMonthName(true);
|
||||
* @result 'Jan'
|
||||
*
|
||||
* @param abbreviated Boolean When set to true the name will be abbreviated.
|
||||
* @name getDayName
|
||||
* @type String
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("getMonthName", function(abbreviated) {
|
||||
return abbreviated ? Date.abbrMonthNames[this.getMonth()] : Date.monthNames[this.getMonth()];
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the number of the day of the year.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.getDayOfYear();
|
||||
* @result 11
|
||||
*
|
||||
* @name getDayOfYear
|
||||
* @type Number
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("getDayOfYear", function() {
|
||||
var tmpdtm = new Date("1/1/" + this.getFullYear());
|
||||
return Math.floor((this.getTime() - tmpdtm.getTime()) / 86400000);
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the number of the week of the year.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.getWeekOfYear();
|
||||
* @result 2
|
||||
*
|
||||
* @name getWeekOfYear
|
||||
* @type Number
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("getWeekOfYear", function() {
|
||||
return Math.ceil(this.getDayOfYear() / 7);
|
||||
});
|
||||
|
||||
/**
|
||||
* Set the day of the year.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.setDayOfYear(1);
|
||||
* dtm.toString();
|
||||
* @result 'Tue Jan 01 2008 00:00:00'
|
||||
*
|
||||
* @name setDayOfYear
|
||||
* @type Date
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("setDayOfYear", function(day) {
|
||||
this.setMonth(0);
|
||||
this.setDate(day);
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Add a number of years to the date object.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.addYears(1);
|
||||
* dtm.toString();
|
||||
* @result 'Mon Jan 12 2009 00:00:00'
|
||||
*
|
||||
* @name addYears
|
||||
* @type Date
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("addYears", function(num) {
|
||||
this.setFullYear(this.getFullYear() + num);
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Add a number of months to the date object.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.addMonths(1);
|
||||
* dtm.toString();
|
||||
* @result 'Tue Feb 12 2008 00:00:00'
|
||||
*
|
||||
* @name addMonths
|
||||
* @type Date
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("addMonths", function(num) {
|
||||
var tmpdtm = this.getDate();
|
||||
|
||||
this.setMonth(this.getMonth() + num);
|
||||
|
||||
if (tmpdtm > this.getDate())
|
||||
this.addDays(-this.getDate());
|
||||
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Add a number of days to the date object.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.addDays(1);
|
||||
* dtm.toString();
|
||||
* @result 'Sun Jan 13 2008 00:00:00'
|
||||
*
|
||||
* @name addDays
|
||||
* @type Date
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("addDays", function(num) {
|
||||
this.setDate(this.getDate() + num);
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Add a number of hours to the date object.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.addHours(24);
|
||||
* dtm.toString();
|
||||
* @result 'Sun Jan 13 2008 00:00:00'
|
||||
*
|
||||
* @name addHours
|
||||
* @type Date
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("addHours", function(num) {
|
||||
this.setHours(this.getHours() + num);
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Add a number of minutes to the date object.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.addMinutes(60);
|
||||
* dtm.toString();
|
||||
* @result 'Sat Jan 12 2008 01:00:00'
|
||||
*
|
||||
* @name addMinutes
|
||||
* @type Date
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("addMinutes", function(num) {
|
||||
this.setMinutes(this.getMinutes() + num);
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Add a number of seconds to the date object.
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.addSeconds(60);
|
||||
* dtm.toString();
|
||||
* @result 'Sat Jan 12 2008 00:01:00'
|
||||
*
|
||||
* @name addSeconds
|
||||
* @type Date
|
||||
* @cat Plugins/Methods/Date
|
||||
*/
|
||||
add("addSeconds", function(num) {
|
||||
this.setSeconds(this.getSeconds() + num);
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Sets the time component of this Date to zero for cleaner, easier comparison of dates where time is not relevant.
|
||||
*
|
||||
* @example var dtm = new Date();
|
||||
* dtm.zeroTime();
|
||||
* dtm.toString();
|
||||
* @result 'Sat Jan 12 2008 00:01:00'
|
||||
*
|
||||
* @name zeroTime
|
||||
* @type Date
|
||||
* @cat Plugins/Methods/Date
|
||||
* @author Kelvin Luck
|
||||
*/
|
||||
add("zeroTime", function() {
|
||||
this.setMilliseconds(0);
|
||||
this.setSeconds(0);
|
||||
this.setMinutes(0);
|
||||
this.setHours(0);
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns a string representation of the date object according to Date.format.
|
||||
* (Date.toString may be used in other places so I purposefully didn't overwrite it)
|
||||
*
|
||||
* @example var dtm = new Date("01/12/2008");
|
||||
* dtm.asString();
|
||||
* @result '12/01/2008' // (where Date.format == 'dd/mm/yyyy'
|
||||
*
|
||||
* @name asString
|
||||
* @type Date
|
||||
* @cat Plugins/Methods/Date
|
||||
* @author Kelvin Luck
|
||||
*/
|
||||
add("asString", function() {
|
||||
var r = Date.format;
|
||||
return r
|
||||
.split('yyyy').join(this.getFullYear())
|
||||
.split('yy').join((this.getFullYear() + '').substring(2))
|
||||
.split('mmm').join(this.getMonthName(true))
|
||||
.split('mm').join(_zeroPad(this.getMonth()+1))
|
||||
.split('dd').join(_zeroPad(this.getDate()));
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns a new date object created from the passed String according to Date.format or false if the attempt to do this results in an invalid date object
|
||||
* (We can't simple use Date.parse as it's not aware of locale and I chose not to overwrite it incase it's functionality is being relied on elsewhere)
|
||||
*
|
||||
* @example var dtm = Date.fromString("12/01/2008");
|
||||
* dtm.toString();
|
||||
* @result 'Sat Jan 12 2008 00:00:00' // (where Date.format == 'dd/mm/yyyy'
|
||||
*
|
||||
* @name fromString
|
||||
* @type Date
|
||||
* @cat Plugins/Methods/Date
|
||||
* @author Kelvin Luck
|
||||
*/
|
||||
Date.fromString = function(s)
|
||||
{
|
||||
var f = Date.format;
|
||||
var d = new Date('01/01/1977');
|
||||
var iY = f.indexOf('yyyy');
|
||||
if (iY > -1) {
|
||||
d.setFullYear(Number(s.substr(iY, 4)));
|
||||
} else {
|
||||
// TODO - this doesn't work very well - are there any rules for what is meant by a two digit year?
|
||||
d.setFullYear(Number(Date.fullYearStart + s.substr(f.indexOf('yy'), 2)));
|
||||
}
|
||||
var iM = f.indexOf('mmm');
|
||||
if (iM > -1) {
|
||||
var mStr = s.substr(iM, 3);
|
||||
for (var i=0; i<Date.abbrMonthNames.length; i++) {
|
||||
if (Date.abbrMonthNames[i] == mStr) break;
|
||||
}
|
||||
d.setMonth(i);
|
||||
} else {
|
||||
d.setMonth(Number(s.substr(f.indexOf('mm'), 2)) - 1);
|
||||
}
|
||||
d.setDate(Number(s.substr(f.indexOf('dd'), 2)));
|
||||
if (isNaN(d.getTime())) {
|
||||
return false;
|
||||
}
|
||||
return d;
|
||||
};
|
||||
|
||||
// utility method
|
||||
var _zeroPad = function(num) {
|
||||
var s = '0'+num;
|
||||
return s.substring(s.length-2)
|
||||
//return ('0'+num).substring(-2); // doesn't work on IE :(
|
||||
};
|
||||
|
||||
})();
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue