Subversion Repositories SmartDukaan

Rev

Rev 23434 | Rev 24882 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

$().ready(function() {
        // validate the comment form when it is submitted
        $('#create-prebooking-listing-form').validate({
                rules:{
                        advanceAmount:{
                                required:true
                        },
                        tentativeAmount:{
                                required:true
                        }
                },
                messages:{
                        advanceAmount:{
                                required: "Please enter advance amount"
                        },
                        tentativeAmount:{
                                required: "Please enter the tentative amount"
                        }
                },
                submitHandler: function (form, event) {
                        event.preventDefault();
                        if(validatePrebookingListingDetails()){
                                alert("Please fix errors");
                                return false;
                        }
                        var json = prebookingListingDetailsJson();
                        console.log("prebookingListingJson = " + json);
                        if(confirm("Are you sure you want to create Prebooking Listing!") == true){
                                doAjaxRequestWithJsonHandler(context+"/createPrebookingListing", "POST", json, function(response){
                                        $('#main-content').html(response);
                                });
                     return false; // required to block normal submit since you used ajax
                        }
         }
        });
  
});


function validatePrebookingListingDetails(){
        console.log("validating prebooking listing Details...");
        var error = false;
        
        var advanceAmount = $("form#create-prebooking-listing-form input[name=advanceAmount]").val();
        console.log("advanceAmount = " + advanceAmount);
        $("#advanceAmount").removeClass("border-highlight");
        if(advanceAmount == ""){
                $("form#create-prebooking-listing-form input[name=advanceAmount]").val(0);
        }else if(advanceAmount <= 0){
                alert("Tentative Amount should be greater than 0");
                $("#advanceAmount").addClass("border-highlight");
                error = true;
                return error;
        }
        
        var tentativeAmount = $("form#create-prebooking-listing-form input[name=tentativeAmount]").val();
        console.log("tentativeAmount = " + tentativeAmount);
        $("#tentativeAmount").removeClass("border-highlight");
        if (tentativeAmount == ""){
                $("form#create-scheme-form input[name=tentativeAmount]").val(0);
        }else if(tentativeAmount <= 0){
                alert("Tentative Amount should be greater than 0");
                $("#tentativeAmount").addClass("border-highlight");
                error = true;
                return error;
        }
        
        //$('#brand-value').text($(this).text());
        $("#brand-value").removeClass("border-highlight");
        if($("#brand-value").text() == "Brands"){
                alert("Please choose Brand");
                $("#brand-value").addClass("border-highlight");
                error = true;
                return error;
        }
        
        $("#catalogDescription").removeClass("border-hightlight");
        var itemIdsString = $("#catalogDescription").val();
        if(itemIdsString == null){
                alert("Please choose item");
                $("#catalogDescription").addClass("border-highlight");
                error = true;
                return error;
        }
        
        console.log("validation prebooking listing error = " + error);
        return error;
}

function prebookingListingDetailsJson(){
        console.log("prebookingListingDetailsJson")
        var prebookingListingObject = {};
        prebookingListingObject['advanceAmount'] = $("#advanceAmount").val();
        prebookingListingObject['tentativeAmount'] = $('#tentativeAmount').val();
        prebookingListingObject['catalogId'] = parseInt($("#catalogDescription").val());
        return JSON.stringify(prebookingListingObject);
}