Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(document).on('click', ".super-catalog-list", function () {
    doGetAjaxRequestHandler(context + "/super-catalog",
        (response) => {
            $('#' + 'main-content').html(response);
        });
});

$(document).on('click', ".save_super_model", function () {
    let mappingArr = [];
    $('#catalogMapping').find('tr').each(function () {
        const catalogId = $(this).find('select#catalog_id').val();
        const variantName = $(this).find('input#variant_name').val();
        const mappingId = $(this).find('input#mapping_id').val();
        if (catalogId > 0) {
            mappingArr.push({
                catalogId: catalogId,
                variantName: variantName,
                superCatalogId: parseInt($('#super_catalog_name').val()),
                id: mappingId
            })
        }
    });
    const params = {
        id: mappingArr.length ? mappingArr[0].id : 0,
        brandId: parseInt($('#brand_id').val()),
        mappingArr: mappingArr,
        superCatalogName: parseInt($('#super_catalog_name').val()) || $('#super_catalog_name').val(),
    };
    console.log('params',params);
    if (!params.brandId || mappingArr.length === 0 || !params.superCatalogName){
        alert("Please fill all details"); return;
    }
    doAjaxRequestWithJsonHandler(context + "/super-catalog", "POST", JSON.stringify(params), (response) => {
        if (response) {
            $('.super-catalog-list').trigger('click');
            $('#manageSuperCatalogModal').modal('hide');
            alert("Saved successfully");
        } else {
            alert("Something went wrong!");
        }
    });
});

$(document).on('click', ".delete-super-catalog-mapping", function() {
    const id = parseInt($(this).closest('td').data('id')) || 0;
    console.log("id",id);
    if (confirm("Are you sure you want to delete this record")) {
        if (id > 0) {
            doDeleteAjaxRequestHandler(context + "/super-catalog/" + id, (response) => {
                if (response) {
                    $(this).parent('td').closest('tr').remove();
                    $('.super-catalog-list').trigger('click');
                    alert("Deleted successfully");
                } else {
                    alert("Something went wrong!");
                }
            });
        } else {
            $(this).parent('td').closest('tr').remove();
        }
    }
});