/Quản lý website bán vé máy bay PHP/public/style/js/dialog.js

https://gitlab.com/phamngsinh/baitaplon_sinhvien · JavaScript · 244 lines · 118 code · 4 blank · 122 comment · 23 complexity · 236e7035fd1ecbfc13489e0f2ec25279 MD5 · raw file

  1. function isEmpty(obj) {
  2. if (typeof obj == 'undefined' || obj === null || obj === '') return true;
  3. if (typeof obj == 'number' && isNaN(obj)) return true;
  4. if (obj instanceof Date && isNaN(Number(obj))) return true;
  5. return false;
  6. }
  7. $(document).ready(function () {
  8. /*if ($('.one-wave-new input:checked').length > 0)
  9. $(".enddate").hide();
  10. $(".one-wave-new input").click(function () {
  11. $(".enddate").hide();
  12. });
  13. $(".round-trip-new input").click(function () {
  14. $(".enddate").show();
  15. });
  16. minDate = new Date();
  17. maxDate = null;
  18. $(".startdate").datepicker({
  19. minDate: minDate,
  20. numberOfMonths: 2,
  21. onClose: function () {
  22. $('#book-form input').removeClass('focus-input');
  23. $('.endplace').removeClass('choosen');
  24. }
  25. });
  26. $('.startdate').change(function () {
  27. var d = $(".startdate").datepicker("getDate");
  28. $(".enddate").datepicker("option", "minDate", $(".startdate").datepicker("getDate"));
  29. d.setDate(d.getDate() + 3);
  30. $(".enddate").datepicker("setDate", d);
  31. $(this).datepicker('hide');
  32. if ($('.round-trip-new input[type=radio]:checked').length > 0)
  33. $(".enddate").focus();
  34. });
  35. $(".enddate").datepicker({
  36. minDate: minDate,
  37. numberOfMonths: 2,
  38. onClose: function () {
  39. $('#book-form input').removeClass('focus-input');
  40. $('.endplace').removeClass('choosen');
  41. }
  42. });
  43. // enable/disable return date if roundtrip/oneway
  44. if ($("#ContentPlaceHolderMainColumn_UsrSearchForm1_radioOneWay").attr("checked") == "checked") {
  45. $(".enddate").addClass('disabled');
  46. $(".enddate").attr("disabled", "disabled");
  47. $(".enddate").datepicker('disable');
  48. }
  49. $('#ContentPlaceHolderMainColumn_UsrSearchForm1_radioOneWay').click(function () {
  50. $(".enddate").addClass('disabled');
  51. $(".enddate").attr("disabled", "disabled");
  52. $(".enddate").datepicker('disable');
  53. });
  54. $('#ContentPlaceHolderMainColumn_UsrSearchForm1_radioRoundTrip').click(function () {
  55. $(".enddate").removeClass('disabled');
  56. $(".enddate").removeAttr("disabled");
  57. $(".enddate").datepicker('enable');
  58. });
  59. // hide all window when click one
  60. $(".startplace").click(function () {
  61. $('#list-arrival').dialog("close");
  62. $(".startdate").datepicker('hide');
  63. $(".enddate").datepicker('hide');
  64. });
  65. $(".endplace").click(function () {
  66. $('#list-departure').dialog("close");
  67. $(".startdate").datepicker('hide');
  68. $(".enddate").datepicker('hide');
  69. });
  70. $('.startdate,.enddate').focus(function () {
  71. $('.dialog').dialog("close");
  72. $('#book-form input').removeClass('focus-input');
  73. if ($(this).hasClass('disabled')) {
  74. $(this).removeClass('focus-input');
  75. }
  76. else
  77. $(this).addClass('focus-input');
  78. });
  79. $('.select-op select,.select-op-lastItem select,.cbo-return-day').each(function (index, value) {
  80. if ($(this).val() > 0) $(this).addClass('focus-input');
  81. });
  82. $('.select-op select,.select-op-lastItem select,.cbo-return-day').change(function () {
  83. if ($(this).val() > 0) $(this).addClass('focus-input');
  84. else $(this).removeClass('focus-input');
  85. });
  86. $('.startplace,.endplace').each(function (index, value) {
  87. if ($(this).val() != '') $(this).addClass('focus-input');
  88. });
  89. $('.cbo-return-month').each(function (index, value) {
  90. if ($(this).val() != '0') $(this).addClass('focus-input');
  91. });
  92. $('.cbo-return-month').change(function () {
  93. if ($(this).val() != '0') $(this).addClass('focus-input');
  94. else $(this).removeClass('focus-input');
  95. });
  96. // Select waytype hightlight
  97. $('.waytype').click(function () {
  98. $('.waytype-l').removeClass('selected');
  99. $(this).next().addClass('selected');
  100. });
  101. $('input.waytype:checked').each(function (index, value) {
  102. $(this).next().addClass('selected');
  103. });
  104. //*/
  105. $(".startplace").click(function (event) {
  106. $('#list-arrival').dialog("close");
  107. event.stopPropagation();
  108. //return false;
  109. //$(".startdate").datepicker('hide');
  110. //$(".enddate").datepicker('hide');
  111. });
  112. $(".endplace").click(function (event) {
  113. $('#list-departure').dialog("close");
  114. event.stopPropagation();
  115. //return false;
  116. //$(".startdate").datepicker('hide');
  117. //$(".enddate").datepicker('hide');
  118. });
  119. $(".startplace,.endplace").focus(function () {
  120. //alert('sfs');
  121. //$(this).addClass('focus-input');
  122. dateType = $(this).attr('datetype');
  123. var deOffset = $('.startplace').offset();
  124. var arrOffset = $('.endplace').offset();
  125. var inputHeight = $('.endplace').height() + 15 - $(window).scrollTop();
  126. $("#list-departure").dialog({
  127. autoOpen: false,
  128. width: 580,
  129. //modal: true,
  130. position: [deOffset.left, deOffset.top + inputHeight]
  131. });
  132. $("#list-arrival").dialog({
  133. autoOpen: false,
  134. width: 580,
  135. //modal: true,
  136. position: [arrOffset.left, deOffset.top + inputHeight]
  137. });
  138. // $("#inter-city-" + dateType).focus();
  139. $("#list-" + dateType).dialog("open");
  140. if ($("#list-departure").dialog("isOpen")) {
  141. $("#inter-city-departure").focus();
  142. }
  143. if ($("#list-arrival").dialog("isOpen")) {
  144. $("#inter-city-arrival").focus();
  145. }
  146. var interCityInput = '';
  147. $("#inter-city-" + dateType).keyup(function () {
  148. interCityInput = $(this).val();
  149. });
  150. var depCity = $('.startplace').val();
  151. var arrCity = $('.endplace').val();
  152. if (isEmpty(interCityInput)) {
  153. $("#submit-departure").click(function () {
  154. var val = $("#inter-city-departure").val().trim();
  155. if (val == '') {
  156. $('.error-departure').text('Xin hãy nhập tên thành phố hoặc sân bay để tiếp tục.');
  157. $("#inter-city-departure").val(val);
  158. return;
  159. }
  160. $('.error-departure').text(' ');
  161. $('.startplace').attr('value', val);
  162. $('.dialog').dialog("close");
  163. if ($('.endplace').hasClass('choosen'))
  164. $(".startdate").focus();
  165. else
  166. $('.endplace').focus();
  167. });
  168. $("#submit-arrival").click(function () {
  169. var val = $("#inter-city-arrival").val().trim();
  170. if (val == '') {
  171. $('.error-arrival').text('Xin hãy nhập tên thành phố hoặc sân bay để tiếp tục.');
  172. $("#inter-city-arrival").val(val);
  173. return;
  174. }
  175. $('.error-arrival').text(' ');
  176. $('.endplace').addClass('choosen');
  177. $('.endplace').attr('value', val);
  178. $('.dialog').dialog("close");
  179. if (isEmpty(depCity))
  180. $('.startplace').focus();
  181. else {
  182. $('.dialog').dialog("close");
  183. $(".startdate").focus();
  184. }
  185. });
  186. }
  187. // close dialog when click outside dialog
  188. $('body').click(function () {
  189. $('.dialog').dialog("close");
  190. });
  191. $('#book-form input, .dialog').click(function (event) {
  192. event.stopPropagation();
  193. });
  194. $('.ui-widget-overlay').live('click', function () {
  195. $('#book-form input').removeClass('focus-input');
  196. $('.dialog').dialog("close");
  197. });
  198. // get data from dialog when click
  199. $('#list-departure a').click(function () {
  200. //$('.startplace').attr('value', $(this).value());
  201. $('.startplace').attr('value', $(this).text());
  202. $('#list-departure').dialog("close");
  203. if ($('.endplace').hasClass('choosen') && !isEmpty(arrCity)) {
  204. $(".startdate").focus();
  205. }
  206. else
  207. $(".endplace").focus();
  208. return false;
  209. });
  210. $('.startplace').focus(function () {
  211. $("#inter-city-departure").focus();
  212. });
  213. $('.endplace').focus(function () {
  214. $("#inter-city-arrival").focus();
  215. });
  216. $('#list-arrival a').click(function () {
  217. $('.endplace').addClass('choosen');
  218. $('.endplace').attr('value', $(this).text());
  219. $('#list-arrival').dialog("close");
  220. if (isEmpty(depCity))
  221. $('.startplace').focus();
  222. else {
  223. $('.dialog').dialog("close");
  224. $(".startdate").focus();
  225. }
  226. return false;
  227. });
  228. });
  229. });