2012-10-31 26 views
2

我在尋找編碼方面的幫助。我有一個類似airbnb的預訂系統。我的問題與預訂日期有關。爲了更具體的我就會給你一個例子javascript保留系統,簽入簽出日期並已預訂日期

一個公寓房已經預定爲那些以下日期2012年12月2日起至2012年12月5日:

如果一個新客戶從4選擇以下日期2012年12月直到6它顯示消息說「這些日期已經預訂」。

但是,如果客戶選擇這樣的日期1 dec dec 6 dec或29 nov和10 dec。如果日期可用,系統讓客戶繼續進行。

總結:如果他選擇的時間段包括已經預訂的日期,我想確保客戶將有消息「這些日期已經預訂」。

我不是編碼方面的專家,根本不是。但我很確定問題來自顯示可用Flats的JavaScript。

我會把整個Js。

消息「這些日期已經預訂」對應於#book_it_disabled_message。

預先感謝您的時間和技能。

function check_inputs(b, c, a) { 
b = typeof (b) != "undefined" ? b : true; 
c = typeof (c) != "undefined" ? c : "checkin"; 
a = typeof (a) != "undefined" ? a : "checkout"; 
if (calendar_is_not_set_date(c)) { 
    if (b) { 
     calendar_show_cal(c) 
    } 
    return false 
} 
if (calendar_is_not_set_date(a)) { 
    if (b) { 
     calendar_show_cal(a) 
    } 
    return false 
} 
return true 
} 

function copy_checkin_checkout_fields() { 
var a = check_inputs(false); 
if (a) { 
    jQuery("#message_checkin").val(jQuery("#checkin").val()); 
    jQuery("#message_checkout").val(jQuery("#checkout").val()); 
    jQuery("#message_number_of_guests").val(jQuery("#number_of_guests").val()); 
    check_availability_of_dates() 
} 
} 

function copy_message_fields_to_book_it() { 
jQuery("#checkin").val(jQuery("#message_checkin").val()); 
jQuery("#checkout").val(jQuery("#message_checkout").val()); 
jQuery("#number_of_guests").val(jQuery("#message_number_of_guests").val()) 
} 

function refresh_subtotal() { 
var a = function (c, e, d) { 
     var b; 
     if (c.available) { 
      jQuery("#book_it_disabled").hide(); 
      jQuery("#book_it_enabled").show(); 
      b = jQuery("#price_amount").html(c.price_per_night).data("nightly-price", c.price_per_night); 
      jQuery("#service_fee").html(c.service_fee); 
      CogzidelRooms.staggered = c.staggered; 
      if (CogzidelRooms.staggered === true) { 
       if (CogzidelRooms.stayOffered !== 0) { 
        jQuery("#payment_period").hide(); 
        jQuery("#per_month").show(); 
        CogzidelRooms.$cancellationVal.text(Translations.long_term); 
        jQuery("#includesFees").show(); 
        jQuery("#book_it_default").addClass("monthly") 
       } 
       jQuery("#subtotal_area").hide(); 
       jQuery("#show_more_subtotal_info").hide(); 
       jQuery("#price_amount").text(Cogzidel.Utils.decode(c.staggered_price)); 
       b.data("monthly-price", c.staggered_price); 
       CogzidelRooms.hideMonthlyPriceDetails() 
      } else { 
       if (CogzidelRooms.stayOffered === 2) { 
        jQuery("#per_month").hide(); 
        CogzidelRooms.$cancellationVal.text(CogzidelRooms.originalCancellationPolicy); 
        jQuery("#includesFees").hide(); 
        jQuery("#book_it_default").removeClass("monthly"); 
        jQuery("#payment_period").show() 
       } 
       jQuery("#subtotal_area ").show(); 
       jQuery("#subtotal_area").find("p").show(); 
       jQuery("#show_more_subtotal_info").show(); 
       jQuery("#subtotal").html(c.total_price); 
       jQuery("#payment_period").val("per_night"); 
       b.removeAttr("data-monthly-price"); 
       CogzidelRooms.showMonthlyPriceDetails() 
      } 
      if (c.can_instant_book) { 
       Page3.showInstantBookButton() 
      } else { 
       Page3.showBookItButton() 
      } 
     } else { 
      if (CogzidelRooms.stayOffered === 1) { 
       jQuery("#payment_period").hide(); 
       jQuery("#per_month").show(); 
       CogzidelRooms.$cancellationVal.text(Translations.long_term); 
       jQuery("#includesFees").show(); 
       CogzidelRooms.hideMonthlyPriceDetails() 
      } else { 
       jQuery("#book_it_default").removeClass("monthly"); 
       jQuery("#payment_period").show(); 
       jQuery("#per_month").hide(); 
        CogzidelRooms.$cancellationVal.text(CogzidelRooms.originalCancellationPolicy); 
       jQuery("#includesFees").hide(); 
       jQuery("#price_amount").html(jQuery("#price_amount").data("nightly-price")); 
       CogzidelRooms.showMonthlyPriceDetails() 
      } 
      jQuery("#book_it_disabled_message").html(c.reason_message); 
      jQuery("#book_it_enabled").hide(); 
      jQuery("#book_it_disabled").show(); 
      jQuery("#show_more_subtotal_info").hide() 
     } 
     jQuery("#book_it_status").pulsate(1, 600) 
    }; 
jQuery("#book_it_button").removeAttr("disabled"); 
jQuery("#subtotal_area").find("p").hide(); 
jQuery("#subtotal_area").show(); 
if (calendar_is_not_set_date("checkin") || calendar_is_not_set_date("checkout")) { 
    a = function() {}; 
    jQuery("#book_it_disabled").hide(); 
    jQuery("#book_it_enabled").show(); 
    jQuery("#subtotal_area").hide(); 
    jQuery("#show_more_subtotal_info").hide() 
} else { 
    jQuery("#subtotal, #book_it_disabled_message").html('<img src="'+base_url+'images/spinner.gif" alt="" height="16" width="16" />') 
} 
jQuery.getJSON(base_url+"rooms/ajax_refresh_subtotal", jQuery("#book_it_form").serialize(), a) 
} 

回答

1

從這一行:

if (calendar_is_not_set_date("checkin") || calendar_is_not_set_date("checkout")) { 

看來你是在互相排斥的功能測試日期1和日期2。如果您每次只測試1天,您還需要在(簽到)和(簽出)之間每天進行測試。

也許你需要一個接受checkin和checkout日期的函數作爲2個參數,然後測試看看這個日期塊是否可用。

+0

謝謝詹姆斯,我在想,但我真的不知道如何實現這一點。問題是,如果選擇的日期在已經預訂的日期內,或者如果有一個日期(checkin或chekout),它會顯示消息「不可用日期」,這很好。但是,如果所選日期包括預訂日期,則顯示可用日期。如果在預訂的時間段內包含日期(checkin或ckeout)之一,但是如果預訂的時間段已包含在Checkin和checkout選定日期之間,系統將授權預訂,那麼選擇的時間段會被測試就會很奇怪。 –

+0

我瞭解您的問題,並可以看到它發生的原因。你將不得不檢查我害怕的整個日期範圍。 – James