functions.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. ;(function($, window, document, undefined) {
  2. var $win = $(window);
  3. $win.on('load', function() {
  4. var ajaxRequests = [];
  5. // Add Pending Count to Tab
  6. $('.booked-tabs').find('li a div.counter').each(function(){
  7. var thisCounter = $(this),
  8. thisTabName = $(this).parent().attr('href');
  9. thisTabName = thisTabName.split('#');
  10. thisTabName = thisTabName[1];
  11. totalAppointments = $('#profile-'+thisTabName).find('.appt-block').length;
  12. if (totalAppointments > 0){
  13. thisCounter.html(totalAppointments).fadeIn('fast');
  14. }
  15. });
  16. // User Info Click
  17. $('.booked-fea-appt-list').on('click', '.user', function(e) {
  18. e.preventDefault();
  19. var $thisLink = $(this),
  20. user_id = $thisLink.attr('data-user-id'),
  21. appt_id = $thisLink.parent().attr('data-appt-id'),
  22. booked_ajaxURL = booked_fea_vars.ajax_url;
  23. create_booked_modal();
  24. $.ajax({
  25. url: booked_ajaxURL,
  26. type: 'post',
  27. data: {
  28. action: 'booked_fea_user_info_modal',
  29. user_id: user_id,
  30. appt_id: appt_id
  31. },
  32. success: function( html ) {
  33. $('.bm-window').html( html );
  34. var bookedModal = $('.booked-modal');
  35. var bmWindow = bookedModal.find('.bm-window');
  36. bmWindow.css({'visibility':'hidden'});
  37. bookedModal.removeClass('bm-loading');
  38. resize_booked_modal();
  39. bmWindow.hide();
  40. setTimeout(function(){
  41. bmWindow.css({'visibility':'visible'});
  42. bmWindow.show();
  43. },50);
  44. }
  45. });
  46. return false;
  47. });
  48. // Show Additional Information
  49. $('.booked-fea-appt-list').on('click', '.booked-show-cf', function(e) {
  50. e.preventDefault();
  51. var hiddenBlock = $(this).parent().find('.cf-meta-values-hidden');
  52. if(hiddenBlock.is(':visible')){
  53. hiddenBlock.hide();
  54. } else {
  55. hiddenBlock.show();
  56. }
  57. return false;
  58. });
  59. // Approve Appointment from Appointment List
  60. $('.booked-fea-appt-list').on('click', '.appt-block .approve', function(e) {
  61. e.preventDefault();
  62. var $button = $(this),
  63. $thisParent = $button.parents('.appt-block'),
  64. appt_id = $thisParent.attr('data-appt-id'),
  65. booked_ajaxURL = booked_fea_vars.ajax_url;
  66. confirm_appt_approve = confirm(booked_fea_vars.i18n_confirm_appt_approve);
  67. if (confirm_appt_approve == true){
  68. var currentApptCount = parseInt($button.parents('.booked-fea-appt-list').find('h4 span.count').html());
  69. currentApptCount = parseInt(currentApptCount - 1);
  70. $button.parents('.booked-fea-appt-list').find('h4 span.count').html(currentApptCount);
  71. if ($button.parents('#profile-fea_pending').length){
  72. if (currentApptCount < 1){
  73. $('.booked-tabs').find('li a[href="#fea_pending"] .counter').remove();
  74. } else {
  75. $('.booked-tabs').find('li a[href="#fea_pending"] .counter').html(currentApptCount);
  76. }
  77. }
  78. $('.appt-block').animate({'opacity':0.4},0);
  79. $button.remove();
  80. $.ajax({
  81. 'method' : 'post',
  82. 'url' : booked_ajaxURL,
  83. 'data': {
  84. 'action' : 'booked_fea_approve_appt',
  85. 'appt_id' : appt_id
  86. },
  87. success: function(data) {
  88. $('.appt-block').animate({'opacity':1},150);
  89. }
  90. });
  91. }
  92. return false;
  93. });
  94. // Delete Appointment from Appointment List
  95. $('.booked-fea-appt-list').on('click', '.appt-block .delete', function(e) {
  96. e.preventDefault();
  97. var $button = $(this),
  98. $thisParent = $button.parents('.appt-block'),
  99. appt_id = $thisParent.attr('data-appt-id'),
  100. booked_ajaxURL = booked_fea_vars.ajax_url;
  101. confirm_appt_delete = confirm(booked_fea_vars.i18n_confirm_appt_delete);
  102. if (confirm_appt_delete == true){
  103. var currentApptCount = parseInt($button.parents('.booked-fea-appt-list').find('h4 span.count').html());
  104. currentApptCount = parseInt(currentApptCount - 1);
  105. $button.parents('.booked-fea-appt-list').find('h4 span.count').html(currentApptCount);
  106. if ($button.parents('#profile-fea_pending').length){
  107. if (currentApptCount < 1){
  108. $('.booked-tabs').find('li a[href="#fea_pending"] .counter').remove();
  109. } else {
  110. $('.booked-tabs').find('li a[href="#fea_pending"] .counter').html(currentApptCount);
  111. }
  112. }
  113. $('.appt-block').animate({'opacity':0.4},0);
  114. $thisParent.slideUp('fast',function(){
  115. $(this).remove();
  116. });
  117. $.ajax({
  118. 'method' : 'post',
  119. 'url' : booked_ajaxURL,
  120. 'data': {
  121. 'action' : 'booked_fea_delete_appt',
  122. 'appt_id' : appt_id
  123. },
  124. success: function(data) {
  125. $('.appt-block').animate({'opacity':1},150);
  126. }
  127. });
  128. }
  129. return false;
  130. });
  131. });
  132. })(jQuery, window, document);