Subversion Repositories SmartDukaan

Rev

Rev 26218 | 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
                                                                                        },
                                                                                        typeaheaditem : {
                                                                                                required : true
                                                                                        },
                                                                                        placementPolicy : {
                                                                                                required : true
                                                                                        },
                                                                                        activationPolicy : {
                                                                                                required : true
                                                                                        },
                                                                                        startDate : {
                                                                                                required : true
                                                                                        },
                                                                                        endDate : {
                                                                                                required : true
                                                                                        },

                                                                                },
                                                                                messages : {
                                                                                        advanceAmount : {
                                                                                                required : "Please enter advance amount"
                                                                                        },
                                                                                        tentativeAmount : {
                                                                                                required : "Please enter the tentative amount"
                                                                                        },

                                                                                        typeaheaditem : {
                                                                                                required : "Please enter the item"
                                                                                        },
                                                                                        placementPolicy : {
                                                                                                required : "Please enter the Placement Policy"
                                                                                        },
                                                                                        activationPolicy : {
                                                                                                required : "Please enter the Activation Policy"
                                                                                        },
                                                                                        startDate : {
                                                                                                require : "Please choose start date"
                                                                                        },
                                                                                        endDate : {
                                                                                                require : "Please choose end date"
                                                                                        },

                                                                                },
                                                                                submitHandler : function(form, event) {
                                                                                        event.preventDefault();
                                                                                        if (validatePrebookingListingDetails()) {
                                                                                                alert("Please fix errors");
                                                                                                return false;
                                                                                        }
                                                                                        let 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();
         * console.log(itemIdsString); if(itemIdsString == null){ alert("Please
         * choose item"); $("#catalogDescription").addClass("border-highlight");
         * error = true; return error; }
         */

        var catalogId = itemCatalogId;
        if (catalogId == null) {
                alert("Please choose item");
                $("#typeaheaditem").addClass("border-highlight");
                error = true;
                return error;
        }

        console.log("validation prebooking listing error = " + error);
        return error;
}

function prebookingListingDetailsJson() {
        var prebookingListingObject = {};
        prebookingListingObject['advanceAmount'] = $("#advanceAmount").val();
        prebookingListingObject['tentativeAmount'] = $('#tentativeAmount').val();
        prebookingListingObject['catalogId'] = itemCatalogId;
        prebookingListingObject['placementPolicy'] = $('#placementPolicy').val();
        prebookingListingObject['activationPolicy'] = $('#activationPolicy').val();
        prebookingListingObject['activeTimestamp'] = getDatesFromPicker($('input[name="duration"]')).startDate;
        prebookingListingObject['expireTimestamp'] = getDatesFromPicker($('input[name="duration"]')).endDate;
        return JSON.stringify(prebookingListingObject);
}