(function() { var ReviewsNavigate, TimeslotAPI; jQuery(function() { $(document).on('click', '#appointments-calendar table caption a, .appointments #header caption a', TimeslotAPI.update_doctor_available_timeslots); $(document).on('click', 'a.calShowMore', TimeslotAPI.show_more); $(document).on('click', '.timeslots a.button', TimeslotAPI.select_date); $('.timeslots a.blue').focus(); $("form[id*='appointment_']").each(function() { var date, id, start; id = $(this).attr("id").split("_")[1]; start = $(this).find("#appointment_start_time").val(); date = $(this).find("#appointment_appointment_date").val(); return $(".timeslots_" + id + " a[data-start-time='" + start + "'][data-appointment-date='" + date + "']").removeClass("gray").addClass("blue").closest("tr").removeClass("hiddenSlot"); }); $("#user-reviews-navigation .dots a").click(ReviewsNavigate.goToPage); $("#user-reviews-navigation .prev").click(ReviewsNavigate.clickPrevious); $("#user-reviews-navigation .next").click(ReviewsNavigate.clickNext); return $("a.favorite-toggle").on("ajax:success", function() { return $(this).toggleClass("blue"); }); }); ReviewsNavigate = { container: function() { return $("#user-reviews-navigation"); }, currentPage: function() { return parseInt(ReviewsNavigate.container().data("current")); }, setCurrentPage: function(val) { ReviewsNavigate.container().data("current", val); ReviewsNavigate.container().find(".dot-blue").removeClass("dot-blue").addClass("dot"); return ReviewsNavigate.container().find(".icon[data-page=" + val + "]").removeClass("dot").addClass("dot-blue"); }, totalPages: function() { return parseInt(this.container().data("total")); }, goToPage: function(ev) { var page; ev.preventDefault(); page = parseInt($(this).find("span").data("page")); if (ReviewsNavigate.currentPage() !== page) { ReviewsNavigate.setCurrentPage(page); return ReviewsNavigate.fetchPage(page); } }, clickNext: function(ev) { ev.preventDefault(); if (ReviewsNavigate.currentPage() < ReviewsNavigate.totalPages()) { ReviewsNavigate.setCurrentPage(ReviewsNavigate.currentPage() + 1); return ReviewsNavigate.fetchPage(ReviewsNavigate.currentPage()); } }, clickPrevious: function(ev) { ev.preventDefault(); if (ReviewsNavigate.currentPage() > 1) { ReviewsNavigate.setCurrentPage(ReviewsNavigate.currentPage() - 1); return ReviewsNavigate.fetchPage(ReviewsNavigate.currentPage()); } }, fetchPage: function(page) { var callOptions; callOptions = { type: 'GET', success: ReviewsNavigate.success, data: { page: ReviewsNavigate.currentPage() } }; return $.ajax(ReviewsNavigate.container().data("url"), callOptions); }, success: function(response) { return $("#reviews-wrapper").html(response); } }; TimeslotAPI = { show_more: function(ev) { ev.preventDefault(); $(this).closest("table").find("tr.hiddenSlot").removeClass("hiddenSlot"); return $(this).closest("tr").hide(); }, select_date: function(ev) { var form_id, timeslots_class; form_id = "#appointment_" + ($(this).data('id')); timeslots_class = ".timeslots_" + ($(this).data('id')); ev.preventDefault(); if ($(this).hasClass("blue")) { $(this).removeClass("blue").addClass("gray"); $("#selectedSlot").text($("#selectedSlot").data("hint")); $(form_id + " #appointment_start_time").val(null); $(form_id + " #appointment_end_time").val(null); $(form_id + " #appointment_appointment_date").val(null); } else { $(timeslots_class + " a.blue").removeClass("blue").addClass("gray"); $(this).addClass("blue").removeClass("gray"); $(form_id + " #appointment_start_time").val($(this).data("start-time")); $(form_id + " #appointment_end_time").val($(this).data("end-time")); $(form_id + " #appointment_appointment_date").val($(this).data("appointment-date")); $("#selectedSlot").text($(this).attr("title")).effect("highlight", {}, 700); $(form_id + " textarea").focus(); } return $("#appointments-table").trigger("date-selected"); }, update_doctor_available_timeslots: function(obj) { var callOptions; obj.preventDefault(); callOptions = { type: 'GET', success: TimeslotAPI.success, error: TimeslotAPI.error, complete: TimeslotAPI.complete }; return $.ajax($(this).attr('href'), callOptions); }, success: function(response) { var doctor_id; doctor_id = $('#doctor_id', $(response)).val(); if ($("#appointments-calendar").length > 0) { $("#appointments-calendar").replaceWith(response); } else { $("#content.appointments table#header").remove(); $("#content.appointments #search-table").replaceWith(response); } if ($("#search-table").length > 0) { return checkHeaderFix(); } }, showAnimation: function(selector, response) { $(selector).replaceWith(response); return $(selector).fadeIn("slow"); }, error: function(response) {}, complete: function(response) {} }; }).call(this);