Subversion Repositories SmartDukaan

Rev

View as "text/plain" | Blame | Last modification | View Log | RSS feed

$(function() {
        $(document).on('click', ".brand-region-mapping", function() {
                loadBrandRegionMapping("main-content");
        });


        $(document).on('click', ".region-brand-mapping", function() {

                var brand = $('#regionBrand').val();

                var accessory = $('#accessory').is(':checked');



                doGetAjaxRequestHandler(context + "/getBrandRegionMapping?brand=" + brand + "&accessory=" + accessory, function(response) {

                        $('.brandRegionMappingContainer').html(response);
                });
        });

        $(document).on('click', ".remove-mapping", function() {
                var brand = $(this).data('brand');
                var fromWarehouse = $(this).data('fromwarehouse');
                var toWarehouse = $(this).data('towarehouse');
                var accessory = $(this).data('isaccessory');
                var row = $(this).closest("tr");

                var brandRegionModel = {};
                brandRegionModel['brand'] = brand;
                brandRegionModel['fromWarehouse'] = fromWarehouse
                brandRegionModel['toWarehouse'] = toWarehouse
                brandRegionModel['accessory'] = accessory



                doPostAjaxRequestWithJsonHandler(context + "/removeBrandRegionMapping", JSON
                        .stringify(brandRegionModel), function(response) {
                                if (response == "true") {
                                        alert("Mapping removed successfully");

                                        doGetAjaxRequestHandler(context + "/getBrandRegionMapping?brand=" + brand + "&accessory=" + accessory, function(response) {

                                                $('.brandRegionMappingContainer').html(response);
                                        });
                                }
                        });
        });




        $(document).on('click', ".mapping-submit", function() {

                var brand = $('#regionBrand').val();
                var fromWarehouse = $('#fromWarehouse').val();

                var toWarehouse = $('#toWarehouse').val();

                var accessory = $('#accessory').is(':checked');



                if (brand == "" || brand == null
                        || brand == undefined) {
                        alert("please select brand");
                        return false;
                }
                if (fromWarehouse == "" || fromWarehouse == null
                        || fromWarehouse == undefined) {
                        alert("please select from warehouse");
                        return false;
                }

                if (toWarehouse == "" || toWarehouse == null
                        || toWarehouse == undefined) {
                        alert("please select toWarehouse");
                        return false;
                }



                var brandRegionMappingModel = {};
                brandRegionMappingModel['accessory'] = accessory

                brandRegionMappingModel['brand'] = brand
                brandRegionMappingModel['fromWarehouse'] = fromWarehouse
                brandRegionMappingModel['toWarehouse'] = toWarehouse


                console.log(brandRegionMappingModel);

                console.log(JSON
                        .stringify(brandRegionMappingModel));
                doPostAjaxRequestWithJsonHandler(context + "/brandRegionMapped", JSON
                        .stringify(brandRegionMappingModel), function(response) {
                                if (response == "true") {
                                        alert("Mapping created successfully");

                                        doGetAjaxRequestHandler(context + "/getBrandRegionMapping?brand=" + brand + "&accessory=" + accessory, function(response) {

                                                $('.brandRegionMappingContainer').html(response);
                                        });
                                }
                        });
        });

});

function loadBrandRegionMapping(domId) {

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