Subversion Repositories SmartDukaan

Rev

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

$(function() {
        $(document).on('click', ".create-combo", function() {
                loadCombo("main-content");
        });





        $(document).on('click', ".add-combo", function() {

                var markup = "<tr><td>"
                        + mappedCatalogItemId
                        + "</td><td>"
                        + $('#item-mapping-search-text').val()
                        + "</td><td>"
                        + $('#item-mapping-qty').val()
                        + "</td><td><button type = 'button' class='btnDelete'>Delete</button></td></tr>";
                $('#cm-table > tbody:last-child').append(markup);

                $('#item-mapping-search-text').val(" ");
                $('#item-mapping-qty').val(" ")

                console.log(markup)

        })

        $(document).on('click', ".create-combo-model", function() {
                var catalogId = catalogItemId
                var itemQty = $('#item-qty').val();
                var warehouseMap = ($("select.criteria-warehouseregion").val() || []).map(Number);

                var addComboModel = {}
                addComboModel['catalogId'] = catalogId;
                addComboModel['qty'] = itemQty
                addComboModel['warehouseId'] = warehouseMap

                var coIdsJSon = [];
                var coIds;
                $('#cm-table').find('tr').each(function() {
                        var row = $(this);

                        console.log(row);
                        var currentRow = $(this).closest("tr");

                        var catalogId = currentRow.find("td:eq(0)").html();
                        var qty = currentRow.find("td:eq(2)").html();

                        console.log(catalogId);
                        if (catalogId != undefined) {
                                coIds = {
                                        "catalogId": catalogId,
                                        "qty": qty

                                }
                                console.log(coIds);
                                coIdsJSon.push(coIds);
                        }
                });

                console.log(coIdsJSon)
                if (itemQty == " ") {
                        alert("itemQty is required");
                        return false;
                }

                if (catalogId == null) {
                        alert("catalogId is required");
                        return false;
                }

                if (catalogId == " ") {
                        alert("warehosueId is required");
                        return false;
                }
                if (coIdsJSon.length === 0) {
                        alert("Atleast one Item added");
                        return false;
                }

                addComboModel['mappedComboModel'] = coIdsJSon;

                console.log(JSON.stringify(addComboModel));
                if (confirm("Are you sure you want to Add Combo!") == true) {
                        doPostAjaxRequestWithJsonHandler(context
                                + "/addCombo", JSON
                                        .stringify(addComboModel), function(response) {
                                                if (response == 'true') {
                                                        alert("successfully Add");

                                                        loadCombo("main-content")

                                                }
                                        });

                }


        })

        $(document).on('click', ".btnDelete", function() {
                console.log("Hello");

                $(this).closest("tr").remove();

        });




        $(document).on('click', ".remove-combo", function() {
                var id = $(this).data('requestid');
                if (confirm("Are you sure to remove combo") == true) {
                        doPostAjaxRequestHandler(context + "/combo/remove?id=" + id,
                                function(response) {

                                        console.log(response);
                                        if (response == 'true') {
                                                alert("successfully remove");
                                                loadCombo("main-content")
                                        }
                                });


                }

        });


})

function loadCombo(domId) {
        doGetAjaxRequestHandler(context + "/createCombo", function(response) {
                $('#' + domId).html(response);

        });
}