Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. <!-- Jelly -->
  2. </style>
  3. <g:ui_form>
  4. <!-- Note the var="jvar_future_date" -->
  5. <g2:evaluate var="jvar_future_date">
  6.  
  7.  
  8. var max_days = gs.getProperty('max.days.defer.vul'); //Optional get from sys_proprities
  9. var gdt = new GlideDateTime();
  10. gdt.getLocalDate();
  11. //gdt.addYearsLocalTime(1)
  12. //gdt.addDaysLocalTime(90);
  13. gdt.addDaysLocalTime(max_days);
  14. gdt.getDisplayValueInternal();
  15. </g2:evaluate>
  16. <!-- Lets pass then number of days for the error message -->
  17. <g2:evaluate var="jvar_max_days">
  18. var maxx_days = gs.getProperty('max.days.defer.vul');
  19. maxx_days;
  20. </g2:evaluate>
  21.  
  22.  
  23. <!-- Insert the value of jvar_future_date" into the page -->
  24. <input type="hidden" id="future_date" name='future_date' value="$[jvar_future_date]" />
  25.  
  26.  
  27. <!-- Pass the number of days for the error message -->
  28. <input type="hidden" id="max_days" name='max_days' value="$[jvar_max_days]" />
  29.  
  30.  
  31. <!-- Attach the JavaScript Function to the onchange event -->
  32. <g:ui_date_time name="date" id="date" class="form-control" onchange="verifyDate()"/>
  33.  
  34.  
  35. <!-- end Jelly -->
  36.  
  37.  
  38. //start Client Script / Javascript
  39. function verifyDate() {
  40. $j('#bulk_error_messages').click(function(e){removeErrorMessage(e);});
  41.  
  42. var maxDays = jQuery('#max_days').val();
  43. var providedDate = jQuery('#date').val();//Get Value Set
  44. var futureDate = jQuery('#future_date').val();//Get from input/hidden data
  45.  
  46. // can not exceed one yr in the future
  47. if (providedDate > futureDate) {
  48. jQuery('#date').val(futureDate);
  49. var msg2 = getMessage('Exception duration may not exceed ' + maxDays + ' days. Setting Until Date to match.');
  50. showErrorMessage(msg2);
  51. return false;
  52. }
  53. }
  54.  
  55.  
  56. //********************************************************************************************************
  57. //Does *NOT* work in IE
  58. //UI Page: 'review_request'
  59. //Modify HTML to implement -- 'checkDate()'
  60. //<g:ui_date_time name="date" id="date" class="form-control" onChange="checkDate()"/>
  61. //v2 to-do Pass the number of days from a sys_property to UI page to Client script
  62. // called in html: onchange="checkDate()"
  63. function checkDate(){
  64.  
  65. var today = new Date(); //Todays Date
  66.  
  67. var maxDays = addDays(today, 90); //Set the date in the future
  68. //Requested Date
  69. //var varDate = document.getElementById("date").value; //2019-08-07 14:20:53
  70. var reqDate = gel('date').value; //String
  71. var dateRequested = Date.parse(reqDate); //Turn String into a Date Type
  72.  
  73. var results = CompareDate(dateRequested, maxDays);
  74.  
  75. //alert("wtf " + reqDate);
  76. if(results == 2 ){
  77. //alert("Go ahead!");
  78. removeErrorMessage(false);
  79. }else{
  80. //alert("NOPE!");
  81. showErrorMessage("The date must be less then 90 Days from now.");
  82. //document.getElementById("date").value = "";
  83. gel('date').value = '';
  84. }
  85. }
  86.  
  87. function addDays(date, days) {
  88. /* Testing
  89. var date = new Date();
  90. var newDate = addDays(date, 10);
  91. */
  92. var copy = new Date(Number(date));
  93. copy.setDate(date.getDate() + days);
  94. return copy;
  95. }
  96.  
  97. function CompareDate(firstDate, SecondDate) {
  98. /* Testing
  99. var date = new Date();
  100. var newDate = addDays(date, 10);
  101. CompareDate(newDate, date);
  102. */
  103. var dateOne = firstDate;
  104. var dateTwo = SecondDate;
  105. if (dateOne > dateTwo) {
  106. //alert("Date One is greater than Date Two.");
  107. return 1;
  108. }else if(dateOne === dateTwo) {
  109. //alert("Date one and two are the same.");
  110. return 0;
  111. } else{
  112. //alert("Date Two is greater than Date One.");
  113. return 2;
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement