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 = '' + ''; 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; });