functions.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471
  1. // make it a global variable so other scripts can access it
  2. var booked_load_calendar_date_booking_options,
  3. booked_appt_form_options,
  4. bookedNewAppointment;
  5. ;(function($, window, document, undefined) {
  6. var $win = $(window);
  7. $.fn.spin.presets.booked = {
  8. lines: 10, // The number of lines to draw
  9. length: 7, // The length of each line
  10. width: 5, // The line thickness
  11. radius: 11, // The radius of the inner circle
  12. corners: 1, // Corner roundness (0..1)
  13. rotate: 0, // The rotation offset
  14. direction: 1, // 1: clockwise, -1: counterclockwise
  15. color: '#555', // #rgb or #rrggbb or array of colors
  16. speed: 1, // Rounds per second
  17. trail: 60, // Afterglow percentage
  18. shadow: false, // Whether to render a shadow
  19. hwaccel: false, // Whether to use hardware acceleration
  20. className: 'booked-spinner', // The CSS class to assign to the spinner
  21. zIndex: 2e9, // The z-index (defaults to 2000000000)
  22. top: '50%', // Top position relative to parent
  23. left: '50%' // Left position relative to parent
  24. }
  25. $.fn.spin.presets.booked_top = {
  26. lines: 11, // The number of lines to draw
  27. length: 10, // The length of each line
  28. width: 6, // The line thickness
  29. radius: 15, // The radius of the inner circle
  30. corners: 1, // Corner roundness (0..1)
  31. rotate: 0, // The rotation offset
  32. scale: 0.5,
  33. direction: 1, // 1: clockwise, -1: counterclockwise
  34. color: '#aaaaaa', // #rgb or #rrggbb or array of colors
  35. speed: 1, // Rounds per second
  36. trail: 60, // Afterglow percentage
  37. shadow: false, // Whether to render a shadow
  38. hwaccel: false, // Whether to use hardware acceleration
  39. className: 'booked-spinner booked-spinner-top', // The CSS class to assign to the spinner
  40. zIndex: 2e9, // The z-index (defaults to 2000000000)
  41. top: '15px', // Top position relative to parent
  42. left: '50%' // Left position relative to parent
  43. }
  44. $.fn.spin.presets.booked_white = {
  45. lines: 13, // The number of lines to draw
  46. length: 11, // The length of each line
  47. width: 5, // The line thickness
  48. radius: 18, // The radius of the inner circle
  49. scale: 1,
  50. corners: 1, // Corner roundness (0..1)
  51. rotate: 0, // The rotation offset
  52. direction: 1, // 1: clockwise, -1: counterclockwise
  53. color: '#fff', // #rgb or #rrggbb or array of colors
  54. speed: 1, // Rounds per second
  55. trail: 60, // Afterglow percentage
  56. shadow: false, // Whether to render a shadow
  57. hwaccel: false, // Whether to use hardware acceleration
  58. className: 'booked-spinner booked-white', // The CSS class to assign to the spinner
  59. zIndex: 2e9, // The z-index (defaults to 2000000000)
  60. top: '50%', // Top position relative to parent
  61. left: '50%' // Left position relative to parent
  62. }
  63. // Adjust the calendar sizing when resizing the window
  64. $win.on('resize', function(){
  65. adjust_calendar_boxes();
  66. resize_booked_modal();
  67. });
  68. $win.on('load', function() {
  69. BookedTabs.Init();
  70. var ajaxRequests = [];
  71. // Adjust the calendar sizing on load
  72. adjust_calendar_boxes();
  73. $('.booked-calendar-wrap').each(function(){
  74. var thisCalendar = $(this);
  75. var calendar_month = thisCalendar.find('table.booked-calendar').attr('data-calendar-date');
  76. thisCalendar.attr('data-default',calendar_month);
  77. init_tooltips(thisCalendar);
  78. });
  79. $('.booked-list-view').each(function(){
  80. var thisList = $(this);
  81. var list_date = thisList.find('.booked-appt-list').attr('data-list-date');
  82. thisList.attr('data-default',list_date);
  83. });
  84. bookedRemoveEmptyTRs();
  85. init_appt_list_date_picker();
  86. $('.booked_calendar_chooser').change(function(e){
  87. e.preventDefault();
  88. var $selector = $(this),
  89. thisIsCalendar = $selector.parents('.booked-calendarSwitcher').hasClass('calendar');
  90. if (!thisIsCalendar){
  91. var thisCalendarWrap = $selector.parents('.booked-calendar-shortcode-wrap').find('.booked-list-view'),
  92. thisDefaultDate = thisCalendarWrap.attr('data-default'),
  93. thisIsCalendar = $selector.parents('.booked-calendarSwitcher').hasClass('calendar');
  94. if (typeof thisDefaultDate == 'undefined'){ thisDefaultDate = false; }
  95. thisCalendarWrap.addClass('booked-loading');
  96. var args = {
  97. 'action' : 'booked_appointment_list_date',
  98. 'date' : thisDefaultDate,
  99. 'calendar_id' : $selector.val()
  100. };
  101. $(document).trigger("booked-before-loading-appointment-list-booking-options");
  102. thisCalendarWrap.spin('booked_top');
  103. $.ajax({
  104. url: booked_js_vars.ajax_url,
  105. type: 'post',
  106. data: args,
  107. success: function( html ) {
  108. thisCalendarWrap.html( html );
  109. init_appt_list_date_picker();
  110. setTimeout(function(){
  111. thisCalendarWrap.removeClass('booked-loading');
  112. },1);
  113. }
  114. });
  115. } else {
  116. var thisCalendarWrap = $selector.parents('.booked-calendar-shortcode-wrap').find('.booked-calendar-wrap'),
  117. thisDefaultDate = thisCalendarWrap.attr('data-default');
  118. if (typeof thisDefaultDate == 'undefined'){ thisDefaultDate = false; }
  119. var args = {
  120. 'action' : 'booked_calendar_month',
  121. 'gotoMonth' : thisDefaultDate,
  122. 'calendar_id' : $selector.val()
  123. };
  124. savingState(true,thisCalendarWrap);
  125. $.ajax({
  126. url: booked_js_vars.ajax_url,
  127. type: 'post',
  128. data: args,
  129. success: function( html ) {
  130. thisCalendarWrap.html( html );
  131. adjust_calendar_boxes();
  132. bookedRemoveEmptyTRs();
  133. init_tooltips(thisCalendarWrap);
  134. $(window).trigger('booked-load-calendar', args, $selector );
  135. }
  136. });
  137. }
  138. return false;
  139. });
  140. // Calendar Next/Prev Click
  141. $('.booked-calendar-wrap').on('click', '.page-right, .page-left, .monthName a', function(e) {
  142. e.preventDefault();
  143. var $button = $(this),
  144. gotoMonth = $button.attr('data-goto'),
  145. thisCalendarWrap = $button.parents('.booked-calendar-wrap'),
  146. thisCalendarDefault = thisCalendarWrap.attr('data-default'),
  147. calendar_id = $button.parents('table.booked-calendar').attr('data-calendar-id');
  148. if (typeof thisCalendarDefault == 'undefined'){ thisCalendarDefault = false; }
  149. var args = {
  150. 'action' : 'booked_calendar_month',
  151. 'gotoMonth' : gotoMonth,
  152. 'calendar_id' : calendar_id,
  153. 'force_default' : thisCalendarDefault
  154. };
  155. savingState(true,thisCalendarWrap);
  156. $.ajax({
  157. url: booked_js_vars.ajax_url,
  158. type: 'post',
  159. data: args,
  160. success: function( html ) {
  161. thisCalendarWrap.html( html );
  162. adjust_calendar_boxes();
  163. bookedRemoveEmptyTRs();
  164. init_tooltips(thisCalendarWrap);
  165. $(window).trigger('booked-load-calendar', args, $button );
  166. }
  167. });
  168. return false;
  169. });
  170. // Calendar Date Click
  171. $('.booked-calendar-wrap').on('click', 'tr.week td', function(e) {
  172. e.preventDefault();
  173. var $thisDate = $(this),
  174. booked_calendar_table = $thisDate.parents('table.booked-calendar'),
  175. $thisRow = $thisDate.parent(),
  176. date = $thisDate.attr('data-date'),
  177. calendar_id = booked_calendar_table.attr('data-calendar-id'),
  178. colspanSetting = $thisRow.find('td').length;
  179. if (!calendar_id){ calendar_id = 0; }
  180. if ($thisDate.hasClass('blur') || $thisDate.hasClass('booked') && !booked_js_vars.publicAppointments || $thisDate.hasClass('prev-date')){
  181. // Do nothing.
  182. } else if ($thisDate.hasClass('active')){
  183. $thisDate.removeClass('active');
  184. $('tr.entryBlock').remove();
  185. var calendarHeight = booked_calendar_table.height();
  186. booked_calendar_table.parent().height(calendarHeight);
  187. } else {
  188. $('tr.week td').removeClass('active');
  189. $thisDate.addClass('active');
  190. $('tr.entryBlock').remove();
  191. $thisRow.after('<tr class="entryBlock booked-loading"><td colspan="'+colspanSetting+'"></td></tr>');
  192. $('tr.entryBlock').find('td').spin('booked');
  193. booked_load_calendar_date_booking_options = {'action':'booked_calendar_date','date':date,'calendar_id':calendar_id};
  194. $(document).trigger("booked-before-loading-calendar-booking-options");
  195. var calendarHeight = booked_calendar_table.height();
  196. booked_calendar_table.parent().height(calendarHeight);
  197. $.ajax({
  198. url: booked_js_vars.ajax_url,
  199. type: 'post',
  200. data: booked_load_calendar_date_booking_options,
  201. success: function( html ) {
  202. $('tr.entryBlock').find('td').html( html );
  203. $('tr.entryBlock').removeClass('booked-loading');
  204. $('tr.entryBlock').find('.booked-appt-list').fadeIn(300);
  205. $('tr.entryBlock').find('.booked-appt-list').addClass('shown');
  206. adjust_calendar_boxes();
  207. }
  208. });
  209. }
  210. return;
  211. });
  212. // Appointment List Next/Prev Date Click
  213. $('.booked-list-view').on('click', '.booked-list-view-date-prev,.booked-list-view-date-next', function(e) {
  214. e.preventDefault();
  215. var $thisLink = $(this),
  216. date = $thisLink.attr('data-date'),
  217. thisList = $thisLink.parents('.booked-list-view'),
  218. defaultDate = thisList.attr('data-default'),
  219. calendar_id = $thisLink.parents('.booked-list-view-nav').attr('data-calendar-id');
  220. if (typeof defaultDate == 'undefined'){ defaultDate = false; }
  221. if (!calendar_id){ calendar_id = 0; }
  222. thisList.addClass('booked-loading');
  223. var booked_load_list_view_date_booking_options = {
  224. 'action' : 'booked_appointment_list_date',
  225. 'date' : date,
  226. 'calendar_id' : calendar_id,
  227. 'force_default' : defaultDate
  228. };
  229. $(document).trigger("booked-before-loading-appointment-list-booking-options");
  230. thisList.spin('booked_top');
  231. $.ajax({
  232. url: booked_js_vars.ajax_url,
  233. type: 'post',
  234. data: booked_load_list_view_date_booking_options,
  235. success: function( html ) {
  236. thisList.html( html );
  237. init_appt_list_date_picker();
  238. setTimeout(function(){
  239. thisList.removeClass('booked-loading');
  240. },1);
  241. }
  242. });
  243. return false;
  244. });
  245. // New Appointment Click
  246. bookedNewAppointment = function(e) {
  247. e.preventDefault();
  248. var $button = $(this),
  249. title = $button.attr('data-title'),
  250. timeslot = $button.attr('data-timeslot'),
  251. date = $button.attr('data-date'),
  252. calendar_id = $button.attr('data-calendar-id'),
  253. $thisTimeslot = $button.parents('.timeslot'),
  254. is_list_view = $button.parents('.booked-calendar-wrap').hasClass('booked-list-view');
  255. if (typeof is_list_view != 'undefined' && is_list_view){
  256. var new_calendar_id = $button.parents('.booked-list-view').find('.booked-list-view-nav').attr('data-calendar-id');
  257. } else {
  258. var new_calendar_id = $button.parents('table.booked-calendar').attr('data-calendar-id');
  259. }
  260. calendar_id = new_calendar_id ? new_calendar_id : calendar_id;
  261. booked_appt_form_options = {'action':'booked_new_appointment_form','date':date,'timeslot':timeslot,'calendar_id':calendar_id,'title':title};
  262. $(document).trigger("booked-before-loading-booking-form");
  263. create_booked_modal();
  264. setTimeout(function(){
  265. $.ajax({
  266. url: booked_js_vars.ajax_url,
  267. type: 'post',
  268. data: booked_appt_form_options,
  269. success: function( html ) {
  270. $('.bm-window').html( html );
  271. var bookedModal = $('.booked-modal');
  272. var bmWindow = bookedModal.find('.bm-window');
  273. bmWindow.css({'visibility':'hidden'});
  274. bookedModal.removeClass('bm-loading');
  275. $(document).trigger("booked-on-new-app");
  276. resize_booked_modal();
  277. bmWindow.hide();
  278. $('.booked-modal .bm-overlay').find('.booked-spinner').remove();
  279. setTimeout(function(){
  280. bmWindow.css({'visibility':'visible'});
  281. bmWindow.show();
  282. },50);
  283. }
  284. });
  285. },100);
  286. return false;
  287. }
  288. $('.booked-calendar-wrap').on('click', 'button.new-appt', bookedNewAppointment);
  289. // Profile Tabs
  290. var profileTabs = $('.booked-tabs');
  291. if (!profileTabs.find('li.active').length){
  292. profileTabs.find('li:first-child').addClass("active");
  293. }
  294. if (profileTabs.length){
  295. $('.booked-tab-content').hide();
  296. var activeTab = profileTabs.find('.active > a').attr('href');
  297. activeTab = activeTab.split('#');
  298. activeTab = activeTab[1];
  299. $('#profile-'+activeTab).show();
  300. profileTabs.find('li > a').on('click', function(e) {
  301. e.preventDefault();
  302. $('.booked-tab-content').hide();
  303. profileTabs.find('li').removeClass('active');
  304. $(this).parent().addClass('active');
  305. var activeTab = $(this).attr('href');
  306. activeTab = activeTab.split('#');
  307. activeTab = activeTab[1];
  308. $('#profile-'+activeTab).show();
  309. return false;
  310. });
  311. }
  312. // Show Additional Information
  313. $('.booked-profile-appt-list').on('click', '.booked-show-cf', function(e) {
  314. e.preventDefault();
  315. var hiddenBlock = $(this).parent().find('.cf-meta-values-hidden');
  316. if(hiddenBlock.is(':visible')){
  317. hiddenBlock.hide();
  318. $(this).removeClass('booked-cf-active');
  319. } else {
  320. hiddenBlock.show();
  321. $(this).addClass('booked-cf-active');
  322. }
  323. return false;
  324. });
  325. // Check Login/Registration/Forgot Password forms before Submitting
  326. if ($('#loginform').length){
  327. $('#loginform input[type="submit"]').on('click',function(e) {
  328. if ($('#loginform input[name="log"]').val() && $('#loginform input[name="pwd"]').val()){
  329. $('#loginform .booked-custom-error').hide();
  330. } else {
  331. if ( $('#loginform').parents('.booked-form-wrap').length ){
  332. e.preventDefault();
  333. $('#loginform').parents('.booked-form-wrap').find('.booked-custom-error').fadeOut(200).fadeIn(200);
  334. }
  335. }
  336. });
  337. }
  338. if ($('#profile-forgot').length){
  339. $('#profile-forgot input[type="submit"]').on('click',function(e) {
  340. if ($('#profile-forgot input[name="user_login"]').val()){
  341. $('#profile-forgot .booked-custom-error').hide();
  342. } else {
  343. e.preventDefault();
  344. $('#profile-forgot').find('.booked-custom-error').fadeOut(200).fadeIn(200);
  345. }
  346. });
  347. }
  348. // Custom Upload Field
  349. if ($('.booked-upload-wrap').length){
  350. $('.booked-upload-wrap input[type=file]').on('change',function(){
  351. var fileName = $(this).val();
  352. $(this).parent().find('span').html(fileName);
  353. $(this).parent().addClass('hasFile');
  354. });
  355. }
  356. // Delete Appointment
  357. $('.booked-profile-appt-list').on('click', '.appt-block .cancel', function(e) {
  358. e.preventDefault();
  359. var $button = $(this),
  360. $thisParent = $button.parents('.appt-block'),
  361. appt_id = $thisParent.attr('data-appt-id');
  362. confirm_delete = confirm(booked_js_vars.i18n_confirm_appt_delete);
  363. if (confirm_delete == true){
  364. var currentApptCount = parseInt($('.booked-profile-appt-list').find('h4').find('span.count').html());
  365. currentApptCount = parseInt(currentApptCount - 1);
  366. if (currentApptCount < 1){
  367. $('.booked-profile-appt-list').find('h4').find('span.count').html('0');
  368. $('.no-appts-message').slideDown('fast');
  369. } else {
  370. $('.booked-profile-appt-list').find('h4').find('span.count').html(currentApptCount);
  371. }
  372. $('.appt-block').animate({'opacity':0.4},0);
  373. $thisParent.slideUp('fast',function(){
  374. $(this).remove();
  375. });
  376. $.ajax({
  377. 'url' : booked_js_vars.ajax_url,
  378. 'method' : 'post',
  379. 'data' : {
  380. 'action' : 'booked_cancel_appt',
  381. 'appt_id' : appt_id
  382. },
  383. success: function(data) {
  384. $('.appt-block').animate({'opacity':1},150);
  385. }
  386. });
  387. }
  388. return false;
  389. });
  390. $('body').on('touchstart click','.bm-overlay, .bm-window .close, .booked-form .cancel',function(e){
  391. e.preventDefault();
  392. close_booked_modal();
  393. return false;
  394. });
  395. $('body')
  396. .on('focusin', '.booked-form input', function() {
  397. if(this.title==this.value) {
  398. $(this).addClass('hasContent');
  399. this.value = '';
  400. }
  401. }).on('focusout', '.booked-form input', function(){
  402. if(this.value==='') {
  403. $(this).removeClass('hasContent');
  404. this.value = this.title;
  405. }
  406. });
  407. $('body').on('change','.booked-form input',function(){
  408. var condition = $(this).attr('data-condition'),
  409. thisVal = $(this).val();
  410. if (condition && $('.condition-block').length) {
  411. $('.condition-block.'+condition).hide();
  412. $('#condition-'+thisVal).fadeIn(200);
  413. resize_booked_modal();
  414. }
  415. });
  416. // Perform AJAX login on form submit
  417. $('body').on('submit','form#ajaxlogin', function(e){
  418. e.preventDefault();
  419. $('form#ajaxlogin p.status').show().html('<i class="booked-icon booked-icon-spinner-clock booked-icon-spin"></i>&nbsp;&nbsp;&nbsp;' + booked_js_vars.i18n_please_wait);
  420. resize_booked_modal();
  421. var $this = $(this),
  422. date = $this.data('date'),
  423. title = $this.data('title'),
  424. timeslot = $this.data('timeslot'),
  425. calendar_id = $this.data('calendar-id');
  426. $.ajax({
  427. type : 'post',
  428. url : booked_js_vars.ajax_url,
  429. data : $('form#ajaxlogin').serialize(),
  430. success : function(data) {
  431. if (data == 'success'){
  432. // close the modal box
  433. close_booked_modal();
  434. // reopen the modal box
  435. var $button = $( '<button data-title="' + title + '" data-timeslot="' + timeslot + '" data-date="' + date + '" data-calendar-id="' + calendar_id + '"></button>' );
  436. $button.on( 'click', window.bookedNewAppointment );
  437. $button.triggerHandler( 'click' );
  438. $button.unbind( 'click', window.bookedNewAppointment );
  439. $button.detach();
  440. } else {
  441. $('form#ajaxlogin p.status').show().html('<i class="booked-icon booked-icon-alert" style="color:#E35656"></i>&nbsp;&nbsp;&nbsp;' + booked_js_vars.i18n_wrong_username_pass);
  442. resize_booked_modal();
  443. }
  444. }
  445. });
  446. e.preventDefault();
  447. });
  448. $('body').on('click','.booked-forgot-password',function(e){
  449. e.preventDefault();
  450. $('#ajaxlogin').hide();
  451. $('#ajaxforgot').show();
  452. resize_booked_modal();
  453. });
  454. $('body').on('click','.booked-forgot-goback',function(e){
  455. e.preventDefault();
  456. $('#ajaxlogin').show();
  457. $('#ajaxforgot').hide();
  458. resize_booked_modal();
  459. });
  460. // Perform AJAX login on form submit
  461. $('body').on('submit','form#ajaxforgot', function(e){
  462. e.preventDefault();
  463. $('form#ajaxforgot p.status').show().html('<i class="booked-icon booked-icon-spinner-clock booked-icon-spin"></i>&nbsp;&nbsp;&nbsp;' + booked_js_vars.i18n_please_wait);
  464. resize_booked_modal();
  465. var $this = $(this);
  466. $.ajax({
  467. type : 'post',
  468. url : booked_js_vars.ajax_url,
  469. data : $('form#ajaxforgot').serialize(),
  470. success : function(data) {
  471. if (data == 'success'){
  472. e.preventDefault();
  473. $('#ajaxlogin').show();
  474. $('#ajaxforgot').hide();
  475. $('form#ajaxlogin p.status').show().html('<i class="booked-icon booked-icon-check" style="color:#56c477"></i>&nbsp;&nbsp;&nbsp;' + booked_js_vars.i18n_password_reset);
  476. resize_booked_modal();
  477. } else {
  478. //console.log(data);
  479. $('form#ajaxforgot p.status').show().html('<i class="booked-icon booked-icon-alert" style="color:#E35656"></i>&nbsp;&nbsp;&nbsp;' + booked_js_vars.i18n_password_reset_error);
  480. resize_booked_modal();
  481. }
  482. }
  483. });
  484. e.preventDefault();
  485. });
  486. // Submit the "Request Appointment" Form
  487. $('body').on('click','.booked-form input#submit-request-appointment',function(e){
  488. $('form#newAppointmentForm p.status').show().html('<i class="booked-icon booked-icon-spinner-clock booked-icon-spin"></i>&nbsp;&nbsp;&nbsp;' + booked_js_vars.i18n_please_wait);
  489. resize_booked_modal();
  490. e.preventDefault();
  491. var customerType = $('#newAppointmentForm input[name=customer_type]').val(),
  492. customerID = $('#newAppointmentForm input[name=user_id]').val(),
  493. name = $('#newAppointmentForm input[name=booked_appt_name]').val(),
  494. surname = $('#newAppointmentForm input[name=booked_appt_surname]').val(),
  495. surnameActive = $('#newAppointmentForm input[name=booked_appt_surname]').length,
  496. guest_name = $('#newAppointmentForm input[name=guest_name]').val(),
  497. guest_surname = $('#newAppointmentForm input[name=guest_surname]').val(),
  498. guest_surnameActive = $('#newAppointmentForm input[name=guest_surname]').length,
  499. guest_email = $('#newAppointmentForm input[name=guest_email]').val(),
  500. guest_emailActive = $('#newAppointmentForm input[name=guest_email]').length,
  501. email = $('#newAppointmentForm input[name=booked_appt_email]').val(),
  502. password = $('#newAppointmentForm input[name=booked_appt_password]').val(),
  503. showRequiredError = false,
  504. ajaxRequests = [];
  505. $(this).parents('.booked-form').find('input,textarea,select').each(function(i,field){
  506. var required = $(this).attr('required');
  507. if (required && $(field).attr('type') == 'hidden'){
  508. var fieldParts = $(field).attr('name');
  509. fieldParts = fieldParts.split('---');
  510. fieldName = fieldParts[0];
  511. fieldNumber = fieldParts[1].split('___');
  512. fieldNumber = fieldNumber[0];
  513. if (fieldName == 'radio-buttons-label'){
  514. var radioValue = false;
  515. $('input:radio[name="single-radio-button---'+fieldNumber+'[]"]:checked').each(function(){
  516. if ($(this).val()){
  517. radioValue = $(this).val();
  518. }
  519. });
  520. if (!radioValue){
  521. showRequiredError = true;
  522. }
  523. } else if (fieldName == 'checkboxes-label'){
  524. var checkboxValue = false;
  525. $('input:checkbox[name="single-checkbox---'+fieldNumber+'[]"]:checked').each(function(){
  526. if ($(this).val()){
  527. checkboxValue = $(this).val();
  528. }
  529. });
  530. if (!checkboxValue){
  531. showRequiredError = true;
  532. }
  533. }
  534. } else if (required && $(field).attr('type') != 'hidden' && $(field).val() == ''){
  535. showRequiredError = true;
  536. }
  537. });
  538. if (showRequiredError) {
  539. $('form#newAppointmentForm p.status').show().html('<i class="booked-icon booked-icon-alert" style="color:#E35656"></i>&nbsp;&nbsp;&nbsp;' + booked_js_vars.i18n_fill_out_required_fields);
  540. resize_booked_modal();
  541. return false;
  542. }
  543. if ( customerType == 'new' && !name || customerType == 'new' && surnameActive && !surname || customerType == 'new' && !email || customerType == 'new' && !password ) {
  544. $('form#newAppointmentForm p.status').show().html('<i class="booked-icon booked-icon-alert" style="color:#E35656"></i>&nbsp;&nbsp;&nbsp;' + booked_js_vars.i18n_appt_required_fields);
  545. resize_booked_modal();
  546. return false;
  547. }
  548. if ( customerType == 'guest' && !guest_name || customerType == 'guest' && guest_emailActive && !guest_email || customerType == 'guest' && guest_surnameActive && !guest_surname ){
  549. $('form#newAppointmentForm p.status').show().html('<i class="booked-icon booked-icon-alert" style="color:#E35656"></i>&nbsp;&nbsp;&nbsp;' + booked_js_vars.i18n_appt_required_fields_guest);
  550. resize_booked_modal();
  551. return false;
  552. }
  553. if (customerType == 'current' && customerID ||
  554. customerType == 'guest' && guest_name && !guest_surnameActive && !guest_emailActive ||
  555. customerType == 'guest' && guest_name && guest_surnameActive && guest_surname && !guest_emailActive ||
  556. customerType == 'guest' && guest_name && guest_emailActive && guest_email && !guest_surnameActive ||
  557. customerType == 'guest' && guest_name && guest_emailActive && guest_email && guest_surnameActive && guest_surname ) {
  558. SubmitRequestAppointment.currentUserOrGuest();
  559. }
  560. if (customerType == 'new' && name && email && password) {
  561. if ( !surnameActive || surnameActive && surname ){
  562. SubmitRequestAppointment.newUser();
  563. }
  564. }
  565. });
  566. var SubmitRequestAppointment = {
  567. formSelector: '#newAppointmentForm',
  568. formBtnRequestSelector: '.booked-form input#submit-request-appointment',
  569. formStatusSelector: 'p.status',
  570. formSubmitBtnSelector: '#submit-request-appointment',
  571. apptContainerSelector: '.booked-appointment-details',
  572. baseFields: [ 'guest_name','guest_surname','guest_email','action', 'customer_type', 'user_id' ],
  573. apptFields: [ 'appoinment', 'calendar_id', 'title', 'date', 'timestamp', 'timeslot' ],
  574. userFields: [ 'booked_appt_name','booked_appt_surname','booked_appt_email', 'booked_appt_password' ],
  575. captchaFields: [ 'captcha_word', 'captcha_code' ],
  576. currentApptIndex: false,
  577. currentApptCounter: false,
  578. hasAnyErrors: false,
  579. currentUserOrGuest: function() {
  580. var total_appts = SubmitRequestAppointment._totalAppts();
  581. if ( ! total_appts ) {
  582. return;
  583. }
  584. SubmitRequestAppointment._showLoadingMessage();
  585. SubmitRequestAppointment._resetDefaultValues();
  586. var data = SubmitRequestAppointment._getBaseData();
  587. SubmitRequestAppointment.currentApptIndex = 0;
  588. SubmitRequestAppointment.currentApptCounter = 1;
  589. SubmitRequestAppointment._doRequestAppointment( data, total_appts );
  590. },
  591. // pretty much the same as SubmitRequestAppointment.currentUserOrGuest(), however, it include the user name, email and password
  592. newUser: function() {
  593. var total_appts = SubmitRequestAppointment._totalAppts();
  594. if ( ! total_appts ) {
  595. return;
  596. }
  597. SubmitRequestAppointment._showLoadingMessage();
  598. SubmitRequestAppointment._resetDefaultValues();
  599. var data = SubmitRequestAppointment._getBaseData();
  600. // when there are more than one appointment, we need to make the registration request first and then loop the appointments
  601. if ( total_appts > 1 ) {
  602. var data_obj_with_no_reference = null;
  603. data_obj_with_no_reference = $.extend( true, {}, data );
  604. data_obj_with_no_reference = SubmitRequestAppointment._addUserRegistrationData( data_obj_with_no_reference );
  605. SubmitRequestAppointment._requestUserRegistration( data_obj_with_no_reference );
  606. data.customer_type = 'current';
  607. } else {
  608. // add user registration fields values
  609. data = SubmitRequestAppointment._addUserRegistrationData( data );
  610. }
  611. SubmitRequestAppointment.currentApptIndex = 0;
  612. SubmitRequestAppointment._doRequestAppointment( data, total_appts );
  613. },
  614. _doRequestAppointment: function( data, total_appts ) {
  615. var appt_fields = SubmitRequestAppointment.apptFields;
  616. // for the first item only
  617. if ( SubmitRequestAppointment.currentApptIndex === 0 ) {
  618. SubmitRequestAppointment._hideCancelBtn();
  619. SubmitRequestAppointment._disableSubmitBtn();
  620. SubmitRequestAppointment.hasAnyErrors = false;
  621. }
  622. // <------end
  623. var data_obj_with_no_reference = $.extend( true, {}, data );
  624. // add the appointment fields to the data
  625. for (var i = 0; i < appt_fields.length; i++) {
  626. data_obj_with_no_reference[ appt_fields[i] ] = SubmitRequestAppointment._getFieldVal( appt_fields[i], SubmitRequestAppointment.currentApptIndex );
  627. }
  628. var calendar_id = SubmitRequestAppointment._getFieldVal( 'calendar_id', SubmitRequestAppointment.currentApptIndex );
  629. data_obj_with_no_reference = SubmitRequestAppointment._addCustomFieldsData( data_obj_with_no_reference, calendar_id );
  630. var $appt = SubmitRequestAppointment._getApptElement( SubmitRequestAppointment.currentApptIndex );
  631. if ( ! $appt.hasClass('skip') ) {
  632. $.ajax({
  633. type : 'post',
  634. url : booked_js_vars.ajax_url,
  635. data : data_obj_with_no_reference,
  636. success : function( response ) {
  637. //SubmitRequestAppointment._enableSubmitBtn();
  638. //SubmitRequestAppointment._showCancelBtn();
  639. //console.log(response);
  640. //return;
  641. SubmitRequestAppointment._requestAppointmentResponseHandler( response );
  642. SubmitRequestAppointment.currentApptIndex++;
  643. setTimeout( function() {
  644. if ( SubmitRequestAppointment.currentApptCounter === total_appts ) {
  645. // for the last item only
  646. if ( ! SubmitRequestAppointment.hasAnyErrors ) {
  647. SubmitRequestAppointment._onAfterRequestAppointment();
  648. } else {
  649. SubmitRequestAppointment._enableSubmitBtn();
  650. SubmitRequestAppointment._showCancelBtn();
  651. }
  652. // <------end
  653. } else {
  654. SubmitRequestAppointment.currentApptCounter++;
  655. SubmitRequestAppointment._doRequestAppointment( data, total_appts );
  656. }
  657. }, 100 );
  658. }
  659. });
  660. } else {
  661. SubmitRequestAppointment.currentApptIndex++;
  662. SubmitRequestAppointment.currentApptCounter++;
  663. SubmitRequestAppointment._doRequestAppointment( data, total_appts, SubmitRequestAppointment.currentApptIndex );
  664. }
  665. },
  666. _totalAppts: function() {
  667. return $(SubmitRequestAppointment.formSelector + ' input[name="appoinment[]"]').length;
  668. },
  669. _getBaseData: function() {
  670. var data = {},
  671. fields = SubmitRequestAppointment.baseFields;
  672. // set up the base form data
  673. for ( var i = 0; i < fields.length; i++ ) {
  674. data[ fields[i] ] = SubmitRequestAppointment._getFieldVal( fields[i] );
  675. }
  676. data['is_fe_form'] = true;
  677. data['total_appts'] = SubmitRequestAppointment._totalAppts();
  678. return data;
  679. },
  680. _getFieldVal: function( field_name, field_index ) {
  681. var field_name = typeof field_name === 'undefined' ? '' : field_name,
  682. field_index = typeof field_index === 'undefined' ? false : field_index,
  683. selector = SubmitRequestAppointment.formSelector + ' ';
  684. if ( field_index === false ) {
  685. selector += ' [name=' + field_name + ']';
  686. return $( selector ).val();
  687. }
  688. selector += ' [name="' + field_name + '[]"]';
  689. return $( selector ).eq( field_index ).val();
  690. },
  691. _resetDefaultValues: function() {
  692. $('.booked-form input').each(function(){
  693. var thisVal = $(this).val(),
  694. thisDefault = $(this).attr('title');
  695. if ( thisDefault == thisVal ){
  696. $(this).val('');
  697. }
  698. });
  699. },
  700. _resetToDefaultValues: function() {
  701. $('.booked-form input').each(function(){
  702. var thisVal = $(this).val(),
  703. thisDefault = $(this).attr('title');
  704. if ( ! thisVal ){
  705. $(this).val( thisDefault );
  706. }
  707. });
  708. },
  709. _addUserRegistrationData: function( data ) {
  710. // populate the user data
  711. $.each( SubmitRequestAppointment.userFields, function( index, field_name ) {
  712. data[ field_name ] = SubmitRequestAppointment._getFieldVal( field_name );
  713. } );
  714. // populate captcha data if available
  715. $.each( SubmitRequestAppointment.captchaFields, function( index, field_name ) {
  716. var field_value = SubmitRequestAppointment._getFieldVal( field_name );
  717. if ( ! field_value ) {
  718. return;
  719. }
  720. data[ field_name ] = field_value;
  721. } );
  722. return data;
  723. },
  724. _addCustomFieldsData: function( data, calendar_id ) {
  725. var custom_fields_data = $('.cf-block [name]')
  726. .filter( function( index ) {
  727. var $this = $(this);
  728. return parseInt($this.data('calendar-id')) === parseInt(calendar_id) && $this.attr('name').match(/---\d+/g);
  729. } )
  730. .each( function( index ) {
  731. var $this = $(this),
  732. name = $this.attr('name'),
  733. value = $this.val(),
  734. type = $this.attr('type');
  735. if ( ! value ) {
  736. return;
  737. }
  738. if ( ! name.match(/checkbox|radio+/g) ) {
  739. data[ name ] = value;
  740. return;
  741. }
  742. if ( name.match(/radio+/g) && $this.is(':checked') ) {
  743. data[ name ] = value;
  744. return;
  745. }
  746. if ( ! name.match(/radio+/g) && typeof data[ name ] === 'undefined' || ! name.match(/radio+/g) && data[ name ].constructor !== Array ) {
  747. data[ name ] = [];
  748. }
  749. if ( ! $this.is(':checked') ) {
  750. return;
  751. }
  752. data[ name ].push( value );
  753. } );
  754. return data;
  755. },
  756. _requestUserRegistration: function( base_data, appt_index ) {
  757. $.ajax({
  758. type : 'post',
  759. url : booked_js_vars.ajax_url,
  760. data : base_data,
  761. async : false,
  762. success : function( response ) {
  763. SubmitRequestAppointment._requestUserRegistrationResponseHandler( response );
  764. }
  765. });
  766. },
  767. _requestUserRegistrationResponseHandler: function( response ) {
  768. var response_parts = response.split('###'),
  769. data_result = response_parts[0].substr( response_parts[0].length - 5 );
  770. if ( data_result === 'error' ) {
  771. // do something on registration failure
  772. return;
  773. }
  774. // do something on successful registration
  775. },
  776. _requestAppointment: function( response ) {
  777. SubmitRequestAppointment._requestAppointmentResponseHandler( response );
  778. },
  779. _requestAppointmentResponseHandler: function( response ) {
  780. var response_parts = response.split('###'),
  781. data_result = response_parts[0].substr( response_parts[0].length - 5 );
  782. if ( data_result === 'error' ) {
  783. SubmitRequestAppointment._requestAppointmentOnError( response_parts );
  784. return;
  785. }
  786. SubmitRequestAppointment._requestAppointmentOnSuccess( response_parts );
  787. },
  788. _requestAppointmentOnError: function( response_parts ) {
  789. var $apptEl = SubmitRequestAppointment._getApptElement();
  790. $(document).trigger("booked-on-requested-appt-error",[$apptEl]);
  791. SubmitRequestAppointment._highlightAppt();
  792. SubmitRequestAppointment._setStatusMsg( response_parts[1] );
  793. SubmitRequestAppointment.hasAnyErrors = true;
  794. resize_booked_modal();
  795. },
  796. _requestAppointmentOnSuccess: function( response_parts ) {
  797. var $apptEl = SubmitRequestAppointment._getApptElement();
  798. $(document).trigger("booked-on-requested-appt-success",[$apptEl]);
  799. SubmitRequestAppointment._unhighlightAppt();
  800. },
  801. _onAfterRequestAppointment: function() {
  802. var redirectObj = { redirect : false };
  803. var redirect = $(document).trigger("booked-on-requested-appointment",[redirectObj]);
  804. if ( redirectObj.redirect ) {
  805. return;
  806. }
  807. if ( booked_js_vars.profilePage ) {
  808. window.location = booked_js_vars.profilePage;
  809. return;
  810. }
  811. SubmitRequestAppointment._reloadApptsList();
  812. SubmitRequestAppointment._reloadCalendarTable();
  813. },
  814. _setStatusMsg: function( msg ) {
  815. var form_status_selector = SubmitRequestAppointment.formSelector + ' ' + SubmitRequestAppointment.formStatusSelector;
  816. $( form_status_selector ).show().html( '<i class="booked-icon booked-icon-alert" style="color:#E35656"></i>&nbsp;&nbsp;&nbsp;' + msg );
  817. },
  818. _getApptElement: function( appt_index ) {
  819. var appt_index = typeof appt_index === 'undefined' ? SubmitRequestAppointment.currentApptIndex : appt_index,
  820. appt_cnt_selector = SubmitRequestAppointment.formSelector + ' ' + SubmitRequestAppointment.apptContainerSelector;
  821. return $( appt_cnt_selector ).eq( appt_index );
  822. },
  823. _highlightAppt: function( msg ) {
  824. var $apptEl = SubmitRequestAppointment._getApptElement();
  825. if ( ! $apptEl.length ) {
  826. return;
  827. }
  828. $apptEl.addClass('has-error');
  829. },
  830. _unhighlightAppt: function( msg ) {
  831. var $apptEl = SubmitRequestAppointment._getApptElement();
  832. if ( ! $apptEl.length ) {
  833. return;
  834. }
  835. $apptEl.removeClass('has-error').addClass('skip');
  836. },
  837. _enableSubmitBtn: function() {
  838. var btn_selector = SubmitRequestAppointment.formSelector + ' ' + SubmitRequestAppointment.formSubmitBtnSelector;
  839. $( btn_selector ).attr( 'disabled', false );
  840. },
  841. _disableSubmitBtn: function() {
  842. var btn_selector = SubmitRequestAppointment.formSelector + ' ' + SubmitRequestAppointment.formSubmitBtnSelector;
  843. $( btn_selector ).attr( 'disabled', true );
  844. },
  845. _showCancelBtn: function() {
  846. $( SubmitRequestAppointment.formSelector ).find('button.cancel').show();
  847. },
  848. _hideCancelBtn: function() {
  849. $( SubmitRequestAppointment.formSelector ).find('button.cancel').hide();
  850. },
  851. _showLoadingMessage: function() {
  852. $('form#newAppointmentForm p.status').show().html('<i class="booked-icon booked-icon-spinner-clock booked-icon-spin"></i>&nbsp;&nbsp;&nbsp;' + booked_js_vars.i18n_please_wait);
  853. },
  854. _reloadApptsList: function() {
  855. if ( ! $('.booked-appt-list').length ){
  856. return;
  857. }
  858. $('.booked-appt-list').each( function() {
  859. var $thisApptList = $(this),
  860. date = $thisApptList.attr('data-list-date'),
  861. thisList = $thisApptList.parents('.booked-list-view'),
  862. defaultDate = thisList.attr('data-default'),
  863. calendar_id = parseInt($thisApptList.find('.booked-list-view-nav').attr('data-calendar-id')) || 0;
  864. defaultDate = typeof defaultDate === 'undefined' ? false : defaultDate;
  865. calendar_id = calendar_id ? calendar_id : 0;
  866. thisList.addClass('booked-loading');
  867. var booked_load_list_view_date_booking_options = {
  868. 'action' : 'booked_appointment_list_date',
  869. 'date' : date,
  870. 'calendar_id' : calendar_id,
  871. 'force_default' : defaultDate
  872. };
  873. $(document).trigger("booked-before-loading-appointment-list-booking-options");
  874. thisList.spin('booked_top');
  875. $.ajax({
  876. url: booked_js_vars.ajax_url,
  877. type: 'post',
  878. data: booked_load_list_view_date_booking_options,
  879. success: function( html ) {
  880. thisList.html( html );
  881. close_booked_modal();
  882. init_appt_list_date_picker();
  883. setTimeout(function(){
  884. thisList.removeClass('booked-loading');
  885. },1);
  886. }
  887. });
  888. });
  889. },
  890. _reloadCalendarTable: function() {
  891. if ( ! $('td.active').length ) {
  892. return;
  893. }
  894. var $activeTD = $('td.active'),
  895. activeDate = $activeTD.attr('data-date'),
  896. calendar_id = parseInt( $activeTD.parents('table').data('calendar-id') ) || 0;
  897. booked_load_calendar_date_booking_options = { 'action':'booked_calendar_date', 'date':activeDate, 'calendar_id':calendar_id };
  898. $(document).trigger("booked-before-loading-calendar-booking-options");
  899. $.ajax({
  900. url: booked_js_vars.ajax_url,
  901. type: 'post',
  902. data: booked_load_calendar_date_booking_options,
  903. success: function( html ) {
  904. $('tr.entryBlock').find('td').html( html );
  905. close_booked_modal();
  906. $('tr.entryBlock').removeClass('booked-loading');
  907. $('tr.entryBlock').find('.booked-appt-list').hide().fadeIn(300);
  908. $('tr.entryBlock').find('.booked-appt-list').addClass('shown');
  909. adjust_calendar_boxes();
  910. }
  911. });
  912. }
  913. }
  914. });
  915. function bookedRemoveEmptyTRs(){
  916. $('table.booked-calendar').find('tr.week').each(function(){
  917. if ($(this).children().length == 0){
  918. $(this).remove();
  919. }
  920. });
  921. }
  922. // Saving state updater
  923. function savingState(show,limit_to){
  924. show = typeof show !== 'undefined' ? show : true;
  925. limit_to = typeof limit_to !== 'undefined' ? limit_to : false;
  926. if (limit_to){
  927. var $savingStateDIV = limit_to.find('li.active .savingState, .topSavingState.savingState, .calendarSavingState');
  928. var $stuffToHide = limit_to.find('.monthName');
  929. var $stuffToTransparent = limit_to.find('table.booked-calendar tbody');
  930. } else {
  931. var $savingStateDIV = $('li.active .savingState, .topSavingState.savingState, .calendarSavingState');
  932. var $stuffToHide = $('.monthName');
  933. var $stuffToTransparent = $('table.booked-calendar tbody');
  934. }
  935. if (show){
  936. $savingStateDIV.fadeIn(200);
  937. $stuffToHide.hide();
  938. $stuffToTransparent.animate({'opacity':0.2},100);
  939. } else {
  940. $savingStateDIV.hide();
  941. $stuffToHide.show();
  942. $stuffToTransparent.animate({'opacity':1},0);
  943. }
  944. }
  945. $(document).ajaxStop(function() {
  946. savingState(false);
  947. });
  948. function init_appt_list_date_picker(){
  949. $('.booked_list_date_picker').each(function(){
  950. var thisDatePicker = $(this);
  951. var minDateVal = thisDatePicker.parents('.booked-appt-list').attr('data-min-date');
  952. var maxDateVal = thisDatePicker.parents('.booked-appt-list').attr('data-max-date');
  953. if (typeof minDateVal == 'undefined'){ var minDateVal = thisDatePicker.attr('data-min-date'); }
  954. thisDatePicker.datepicker({
  955. dateFormat: 'yy-mm-dd',
  956. minDate: minDateVal,
  957. maxDate: maxDateVal,
  958. showAnim: false,
  959. beforeShow: function(input, inst) {
  960. $('#ui-datepicker-div').removeClass();
  961. $('#ui-datepicker-div').addClass('booked_custom_date_picker');
  962. },
  963. onClose: function(dateText){
  964. $('.booked_list_date_picker_trigger').removeClass('booked-dp-active');
  965. },
  966. onSelect: function(dateText){
  967. var thisInput = $(this),
  968. date = dateText,
  969. thisList = thisInput.parents('.booked-list-view'),
  970. defaultDate = thisList.attr('data-default'),
  971. calendar_id = thisInput.parents('.booked-list-view-nav').attr('data-calendar-id');
  972. if (typeof defaultDate == 'undefined'){ defaultDate = false; }
  973. if (!calendar_id){ calendar_id = 0; }
  974. thisList.addClass('booked-loading');
  975. var booked_load_list_view_date_booking_options = {
  976. 'action' : 'booked_appointment_list_date',
  977. 'date' : date,
  978. 'calendar_id' : calendar_id,
  979. 'force_default' : defaultDate
  980. };
  981. $(document).trigger("booked-before-loading-appointment-list-booking-options");
  982. thisList.spin('booked_top');
  983. $.ajax({
  984. url: booked_js_vars.ajax_url,
  985. type: 'post',
  986. data: booked_load_list_view_date_booking_options,
  987. success: function( html ) {
  988. thisList.html( html );
  989. init_appt_list_date_picker();
  990. setTimeout(function(){
  991. thisList.removeClass('booked-loading');
  992. },1);
  993. }
  994. });
  995. return false;
  996. }
  997. });
  998. });
  999. $('body').on('click','.booked_list_date_picker_trigger',function(e){
  1000. e.preventDefault();
  1001. if (!$(this).hasClass('booked-dp-active')){
  1002. $(this).addClass('booked-dp-active');
  1003. $(this).parents('.booked-appt-list').find('.booked_list_date_picker').datepicker('show');
  1004. }
  1005. });
  1006. }
  1007. var BookedTabs = {
  1008. bookingModalSelector: '.booked-modal',
  1009. tabSelector: '.booked-tabs',
  1010. tabNavSelector: '.booked-tabs-nav span',
  1011. tabCntSelector: '.booked-tabs-cnt',
  1012. Init: function() {
  1013. $(document).on( 'click', this.tabNavSelector, this.tabsNav );
  1014. },
  1015. tabsNav: function( event ) {
  1016. event.preventDefault();
  1017. BookedTabs.switchToTab( $(this) );
  1018. BookedTabs.maybeResizeBookingModal();
  1019. },
  1020. switchToTab: function( tab_nav_item ) {
  1021. var $nav_item = tab_nav_item,
  1022. tab_cnt_class = '.' + $nav_item.data('tab-cnt'),
  1023. $tabs_container = $nav_item.parents( BookedTabs.tabSelector );
  1024. $nav_item
  1025. .addClass( 'active' )
  1026. .siblings()
  1027. .removeClass( 'active' )
  1028. $tabs_container
  1029. .find( BookedTabs.tabCntSelector + ' ' + tab_cnt_class )
  1030. .addClass( 'active' )
  1031. .siblings()
  1032. .removeClass( 'active' );
  1033. },
  1034. maybeResizeBookingModal: function() {
  1035. if ( ! $(BookedTabs.bookingModalSelector).length ) {
  1036. return;
  1037. }
  1038. resize_booked_modal();
  1039. }
  1040. }
  1041. })(jQuery, window, document);
  1042. // Create Booked Modal
  1043. function create_booked_modal(){
  1044. var windowHeight = jQuery(window).height();
  1045. var windowWidth = jQuery(window).width();
  1046. if (windowWidth > 720){
  1047. var maxModalHeight = windowHeight - 295;
  1048. } else {
  1049. var maxModalHeight = windowHeight;
  1050. }
  1051. jQuery('body input, body textarea, body select').blur();
  1052. jQuery('body').addClass('booked-noScroll');
  1053. jQuery('<div class="booked-modal bm-loading"><div class="bm-overlay"></div><div class="bm-window"><div style="height:100px"></div></div></div>').appendTo('body');
  1054. jQuery('.booked-modal .bm-overlay').spin('booked_white');
  1055. jQuery('.booked-modal .bm-window').css({'max-height':maxModalHeight+'px'});
  1056. }
  1057. var previousRealModalHeight = 100;
  1058. function resize_booked_modal(){
  1059. var windowHeight = jQuery(window).height();
  1060. var windowWidth = jQuery(window).width();
  1061. var common43 = 43;
  1062. if (jQuery('.booked-modal .bm-window .booked-scrollable').length){
  1063. var realModalHeight = jQuery('.booked-modal .bm-window .booked-scrollable')[0].scrollHeight;
  1064. if (realModalHeight < 100){
  1065. realModalHeight = previousRealModalHeight;
  1066. } else {
  1067. previousRealModalHeight = realModalHeight;
  1068. }
  1069. } else {
  1070. var realModalHeight = 0;
  1071. }
  1072. var minimumWindowHeight = realModalHeight + common43 + common43;
  1073. var modalScrollableHeight = realModalHeight - common43;
  1074. var maxModalHeight;
  1075. var maxFormHeight;
  1076. if (windowHeight < minimumWindowHeight){
  1077. modalScrollableHeight = windowHeight - common43 - common43;
  1078. } else {
  1079. modalScrollableHeight = realModalHeight;
  1080. }
  1081. if (windowWidth > 720){
  1082. maxModalHeight = modalScrollableHeight - 25;
  1083. maxFormHeight = maxModalHeight - 15;
  1084. var modalNegMargin = (maxModalHeight + 78) / 2;
  1085. } else {
  1086. maxModalHeight = windowHeight - common43;
  1087. maxFormHeight = maxModalHeight - 60;
  1088. var modalNegMargin = (maxModalHeight) / 2;
  1089. }
  1090. jQuery('.booked-modal').css({'margin-top':'-'+modalNegMargin+'px'});
  1091. jQuery('.booked-modal .bm-window').css({'max-height':maxModalHeight+'px'});
  1092. jQuery('.booked-modal .bm-window .booked-scrollable').css({'max-height':maxFormHeight+'px'});
  1093. }
  1094. function close_booked_modal(){
  1095. var modal = jQuery('.booked-modal');
  1096. modal.fadeOut(200);
  1097. modal.addClass('bm-closing');
  1098. jQuery('body').removeClass('booked-noScroll');
  1099. setTimeout(function(){
  1100. modal.remove();
  1101. },300);
  1102. }
  1103. function init_tooltips(container){
  1104. jQuery('.tooltipster').tooltipster({
  1105. theme: 'tooltipster-light',
  1106. animation: 'grow',
  1107. speed: 200,
  1108. delay: 50,
  1109. offsetY: -15
  1110. });
  1111. }
  1112. // Function to adjust calendar sizing
  1113. function adjust_calendar_boxes(){
  1114. jQuery('.booked-calendar').each(function(){
  1115. var windowWidth = jQuery(window).width();
  1116. var smallCalendar = jQuery(this).parents('.booked-calendar-wrap').hasClass('small');
  1117. var boxesWidth = jQuery(this).find('tbody tr.week td').width();
  1118. var calendarHeight = jQuery(this).height();
  1119. boxesHeight = boxesWidth * 1;
  1120. jQuery(this).find('tbody tr.week td').height(boxesHeight);
  1121. jQuery(this).find('tbody tr.week td .date').css('line-height',boxesHeight+'px');
  1122. jQuery(this).find('tbody tr.week td .date .number').css('line-height',boxesHeight+'px');
  1123. if (smallCalendar || windowWidth < 720){
  1124. jQuery(this).find('tbody tr.week td .date .number').css('line-height',boxesHeight+'px');
  1125. } else {
  1126. jQuery(this).find('tbody tr.week td .date .number').css('line-height','');
  1127. }
  1128. var calendarHeight = jQuery(this).height();
  1129. jQuery(this).parent().height(calendarHeight);
  1130. });
  1131. }