123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- define( function() {
- "use strict";
- function DateRangePrompt()
- {
- };
- function strDateToDateObj (dateValue){
- var dateYear = dateValue.substr(0,4);
- var dateMonth=dateValue.substr(5,2);
- var dateDay=dateValue.substr(8,2);
- var result = new Date(dateYear, dateMonth-1, dateDay);
- return result;
- }
- function substractDate(endDate, startDate) {
- var startDateObj = strDateToDateObj(startDate);
- var endDateObj = strDateToDateObj(endDate);
- var diffInMS = endDateObj.getTime() - startDateObj.getTime();
- return Math.round(diffInMS != 0? diffInMS/(24 * 3600 * 1000) : 0);
- }
- DateRangePrompt.prototype.draw = function( oControlHost )
- {
- var e1=oControlHost.container;
- e1.innerHTML =
- '<style>' +
- '.MyPromptButton' +
- '{' +
- 'background-color: white;' +
- 'border: 2px solid #4178BE;' +
- 'color: #4178be;' +
- 'font-size: 14px;' +
- 'height: 35px;' +
- 'width: 120px;' +
- 'margin-left: 20px;' +
- 'cursor: pointer;' +
- '} ' +
- '.MyPromptButton:hover' +
- '{' +
- 'background-color: #4178BE;' +
- 'color: white;' +
- '}' +
- '</style>' +
- '<button class="MyPromptButton btn1">Run Report</button>';
- e1.querySelector(".btn1").onclick = this.MyPromptButtonFinishClick.bind(this, oControlHost);
- };
- DateRangePrompt.prototype.MyPromptButtonFinishClick = function (oControlHost)
- {
- var dateRangePrompt = oControlHost.page.getControlByName("myDateRange");
-
- var rangeLimit = 10;
- if (dateRangePrompt)
- {
- // Create an array of date prompt values
- var aDatePromptValues = dateRangePrompt.getValues();
- //Get the first value from the array
- var rangeValue = aDatePromptValues[0];
- //Initialize a variable to hold the number of days between the two dates
- var rangeDaysDiff = 0;
- // If the range start and end date set, then validate it
- if (rangeValue.start && rangeValue.end) {
- // Get the start and end dates as strings
- var startDate = rangeValue.start.use;
- var endDate = rangeValue.end.use;
- // Convert string prompt values to proper dates
- var startDateObj = strDateToDateObj(startDate);
- var endDateObj = strDateToDateObj(endDate);
-
- // Calculate the difference in days between the dates
- rangeDaysDiff = substractDate(endDate,startDate);
- // The .getTime method, calculates the time in milliseconds between date and 01 January 1970.
- // Determine the difference between the dates in milliseconds
- var diffInMS = endDateObj.getTime() - startDateObj.getTime();
-
- // If (milliseconds time difference is not zero)
- // then result = (the difference in days)
- // else 0.
- rangeDaysDiff = Math.round(diffInMS != 0? diffInMS/(24 * 3600 * 1000) : 0);
-
- if (rangeDaysDiff >= 0 && rangeDaysDiff <= rangeLimit)
- {
- oControlHost.finish()
- } else
- {
- alert ("The dates selected cannot be more than " + rangeLimit + " days apart. Please select a shorter date range.");
- }
- }
- }
- };
- return DateRangePrompt;
- });
|