Subversion Repositories SmartDukaan

Rev

Rev 32344 | 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-container", function() {
                var $htmlContainer = $('<li>'
                        + '<div class = "row" style="margin-top:12px" >'
                        + '<div class="">'
                        + '<div class="panel panel-default">'
                        + ' <div class="panel-heading">Set <a role="button" href="javascript:void(0)" class="deleteSet" > <i class="fa fa-trash" style="float:right;color:red;margin-top:10px;"></i></a></div>'


                        + '  <div class="panel-content">'
                        + '    <div id="cosummary">'
                        + '   <div class = "row" style="margin-top:12px" >'
                        + '     <div class="col-lg-3">'
                        + '   <label>Combo Item</label>'
                        + '             <input type="text" class="typeahead form-control item-mapping-search-text" name="Item" '
                        + '       data-provide="typeahead" autocomplete="off" value="" placeholder="Search for product..." />'
                        + '  </div>'

                        + ' <div class="col-lg-3">'
                        + '    <label>Combo Qty</label>'
                        + '     <input type="text"  class="typeahead form-control item-mapping-qty" name="item-mapping-qty" value=""  placeholder="Item Qty" />'
                        + '</div>'

                        + '<div class="col-lg-2">'
                        + ' <button class="btn btn-primary add-combo" style = "margin-top:25px" type="button">Add Combo</button>'
                        + ' </div>'
                        + '  </div>'
                        + '    <table class="table table-sm cm-table">'
                        + '       <thead>'
                        + '         <tr>'
                        + '      <th>catalogId</th>'
                        + '           <th>Name</th>'
                        + '      <th>Quantity</th>'

                        + '    </tr>'
                        + '  </thead>'
                        + '    <tbody>'

                        + '   </tbody>'
                        + '</table>'
                        + ' </div>'

                        + ' </div>'
                        + ' </div>'
                        + ' </div>'
                        + ' </li> ');

                $("#list").append($htmlContainer);


                getItemAheadOptions($htmlContainer.find('.item-mapping-search-text'), true, function(
                        selectedItem) {


                        var mappedcatalogitemid = selectedItem.catalogId;
                        console.log(mappedcatalogitemid);


                        $htmlContainer.find('.add-combo').data('mappedcatalogitemid', mappedcatalogitemid)


                });


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

                var $row = $(this).closest("li");

                var mappedCatalogItemId = $(this).data("mappedcatalogitemid");

                console.log(mappedCatalogItemId);

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

                var qty = $row.find('.item-mapping-qty').val();

                var item = $row.find('.item-mapping-search-text').val()

                if (item === " ") {
                        alert("please select items");
                        return false;
                }


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


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

                $row.find('.item-mapping-search-text').val(" ");
                $row.find('.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
                addComboModel['comboOptionModel'] = []


                $('#list').find('>li').each(function() {
                        var coIdsJSon = [];
                        var currentLi = $(this).closest("li");

                        currentLi.find('.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) {
                                        var coIds = {
                                                "catalogId": catalogId,
                                                "qty": qty

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

                        addComboModel.comboOptionModel.push({ mappedComboModel: coIdsJSon });

                });





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

                for (var i = 0; i < addComboModel.comboOptionModel.length; i++) {

                        if (addComboModel.comboOptionModel[i].mappedComboModel.length === 0) {
                                alert("please add combo set");
                                return false;
                        }

                }


                console.log(JSON
                        .stringify(addComboModel))

                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', ".deleteSet", function() {
                console.log("Hello");

                $(this).closest(".panel").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);

        });
}