/public/assets/pages/scripts/components-date-time-pickers.js

https://bitbucket.org/nvtechsolutions/temprev · JavaScript · 246 lines · 199 code · 34 blank · 13 comment · 9 complexity · fee800f665e54add8a4f5ee59d5a3d32 MD5 · raw file

  1. var ComponentsDateTimePickers = function () {
  2. var handleDatePickers = function () {
  3. if (jQuery().datepicker) {
  4. $('.date-picker').datepicker({
  5. rtl: App.isRTL(),
  6. orientation: "left",
  7. autoclose: true
  8. });
  9. //$('body').removeClass("modal-open"); // fix bug when inline picker is used in modal
  10. }
  11. /* Workaround to restrict daterange past date select: http://stackoverflow.com/questions/11933173/how-to-restrict-the-selectable-date-ranges-in-bootstrap-datepicker */
  12. // Workaround to fix datepicker position on window scroll
  13. $( document ).scroll(function(){
  14. $('#form_modal2 .date-picker').datepicker('place'); //#modal is the id of the modal
  15. });
  16. }
  17. var handleTimePickers = function () {
  18. if (jQuery().timepicker) {
  19. $('.timepicker-default').timepicker({
  20. autoclose: true,
  21. showSeconds: true,
  22. minuteStep: 1
  23. });
  24. $('.timepicker-no-seconds').timepicker({
  25. autoclose: true,
  26. minuteStep: 5,
  27. defaultTime: false
  28. });
  29. $('.timepicker-24').timepicker({
  30. autoclose: true,
  31. minuteStep: 5,
  32. showSeconds: false,
  33. showMeridian: false
  34. });
  35. // handle input group button click
  36. $('.timepicker').parent('.input-group').on('click', '.input-group-btn', function(e){
  37. e.preventDefault();
  38. $(this).parent('.input-group').find('.timepicker').timepicker('showWidget');
  39. });
  40. // Workaround to fix timepicker position on window scroll
  41. $( document ).scroll(function(){
  42. $('#form_modal4 .timepicker-default, #form_modal4 .timepicker-no-seconds, #form_modal4 .timepicker-24').timepicker('place'); //#modal is the id of the modal
  43. });
  44. }
  45. }
  46. var handleDateRangePickers = function () {
  47. if (!jQuery().daterangepicker) {
  48. return;
  49. }
  50. $('#defaultrange').daterangepicker({
  51. opens: (App.isRTL() ? 'left' : 'right'),
  52. format: 'MM/DD/YYYY',
  53. separator: ' to ',
  54. startDate: moment().subtract('days', 29),
  55. endDate: moment(),
  56. ranges: {
  57. 'Today': [moment(), moment()],
  58. 'Yesterday': [moment().subtract('days', 1), moment().subtract('days', 1)],
  59. 'Last 7 Days': [moment().subtract('days', 6), moment()],
  60. 'Last 30 Days': [moment().subtract('days', 29), moment()],
  61. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  62. 'Last Month': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
  63. },
  64. minDate: '01/01/2012',
  65. maxDate: '12/31/2018',
  66. },
  67. function (start, end) {
  68. $('#defaultrange input').val(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
  69. }
  70. );
  71. $('#defaultrange_modal').daterangepicker({
  72. opens: (App.isRTL() ? 'left' : 'right'),
  73. format: 'MM/DD/YYYY',
  74. separator: ' to ',
  75. startDate: moment().subtract('days', 29),
  76. endDate: moment(),
  77. minDate: '01/01/2012',
  78. maxDate: '12/31/2018',
  79. },
  80. function (start, end) {
  81. $('#defaultrange_modal input').val(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
  82. }
  83. );
  84. // this is very important fix when daterangepicker is used in modal. in modal when daterange picker is opened and mouse clicked anywhere bootstrap modal removes the modal-open class from the body element.
  85. // so the below code will fix this issue.
  86. $('#defaultrange_modal').on('click', function(){
  87. if ($('#daterangepicker_modal').is(":visible") && $('body').hasClass("modal-open") == false) {
  88. $('body').addClass("modal-open");
  89. }
  90. });
  91. $('#reportrange').daterangepicker({
  92. opens: (App.isRTL() ? 'left' : 'right'),
  93. startDate: moment().subtract('days', 29),
  94. endDate: moment(),
  95. //minDate: '01/01/2012',
  96. //maxDate: '12/31/2014',
  97. dateLimit: {
  98. days: 60
  99. },
  100. showDropdowns: true,
  101. showWeekNumbers: true,
  102. timePicker: false,
  103. timePickerIncrement: 1,
  104. timePicker12Hour: true,
  105. ranges: {
  106. 'Today': [moment(), moment()],
  107. 'Yesterday': [moment().subtract('days', 1), moment().subtract('days', 1)],
  108. 'Last 7 Days': [moment().subtract('days', 6), moment()],
  109. 'Last 30 Days': [moment().subtract('days', 29), moment()],
  110. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  111. 'Last Month': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
  112. },
  113. buttonClasses: ['btn'],
  114. applyClass: 'green',
  115. cancelClass: 'default',
  116. format: 'MM/DD/YYYY',
  117. separator: ' to ',
  118. locale: {
  119. applyLabel: 'Apply',
  120. fromLabel: 'From',
  121. toLabel: 'To',
  122. customRangeLabel: 'Custom Range',
  123. daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
  124. monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  125. firstDay: 1
  126. }
  127. },
  128. function (start, end) {
  129. $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
  130. }
  131. );
  132. //Set the initial state of the picker label
  133. $('#reportrange span').html(moment().subtract('days', 29).format('MMMM D, YYYY') + ' - ' + moment().format('MMMM D, YYYY'));
  134. }
  135. var handleDatetimePicker = function () {
  136. if (!jQuery().datetimepicker) {
  137. return;
  138. }
  139. $(".form_datetime").datetimepicker({
  140. autoclose: true,
  141. isRTL: App.isRTL(),
  142. format: "dd MM yyyy - hh:ii",
  143. pickerPosition: (App.isRTL() ? "bottom-right" : "bottom-left")
  144. });
  145. $(".form_advance_datetime").datetimepicker({
  146. isRTL: App.isRTL(),
  147. format: "dd MM yyyy - hh:ii",
  148. autoclose: true,
  149. todayBtn: true,
  150. startDate: "2013-02-14 10:00",
  151. pickerPosition: (App.isRTL() ? "bottom-right" : "bottom-left"),
  152. minuteStep: 10
  153. });
  154. $(".form_meridian_datetime").datetimepicker({
  155. isRTL: App.isRTL(),
  156. format: "dd MM yyyy - HH:ii P",
  157. showMeridian: true,
  158. autoclose: true,
  159. pickerPosition: (App.isRTL() ? "bottom-right" : "bottom-left"),
  160. todayBtn: true
  161. });
  162. $('body').removeClass("modal-open"); // fix bug when inline picker is used in modal
  163. // Workaround to fix datetimepicker position on window scroll
  164. $( document ).scroll(function(){
  165. $('#form_modal1 .form_datetime, #form_modal1 .form_advance_datetime, #form_modal1 .form_meridian_datetime').datetimepicker('place'); //#modal is the id of the modal
  166. });
  167. }
  168. var handleClockfaceTimePickers = function () {
  169. if (!jQuery().clockface) {
  170. return;
  171. }
  172. $('.clockface_1').clockface();
  173. $('#clockface_2').clockface({
  174. format: 'HH:mm',
  175. trigger: 'manual'
  176. });
  177. $('#clockface_2_toggle').click(function (e) {
  178. e.stopPropagation();
  179. $('#clockface_2').clockface('toggle');
  180. });
  181. $('#clockface_2_modal').clockface({
  182. format: 'HH:mm',
  183. trigger: 'manual'
  184. });
  185. $('#clockface_2_modal_toggle').click(function (e) {
  186. e.stopPropagation();
  187. $('#clockface_2_modal').clockface('toggle');
  188. });
  189. $('.clockface_3').clockface({
  190. format: 'H:mm'
  191. }).clockface('show', '14:30');
  192. // Workaround to fix clockface position on window scroll
  193. $( document ).scroll(function(){
  194. $('#form_modal5 .clockface_1, #form_modal5 #clockface_2_modal').clockface('place'); //#modal is the id of the modal
  195. });
  196. }
  197. return {
  198. //main function to initiate the module
  199. init: function () {
  200. handleDatePickers();
  201. handleTimePickers();
  202. handleDatetimePicker();
  203. handleDateRangePickers();
  204. handleClockfaceTimePickers();
  205. }
  206. };
  207. }();
  208. if (App.isAngularJsApp() === false) {
  209. jQuery(document).ready(function() {
  210. ComponentsDateTimePickers.init();
  211. });
  212. }