Subversion Repositories SmartDukaan

Rev

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

$(function() {
        $(".create-scheme").live('click', function() {
                loadScheme("main-content");
        });

        $("#schemes-paginated .next").live(
                        'click',
                        function() {
                                var searchText = $("#scheme-item-search-text").val();
                                // var searchTxt=$("#scheme-search-text").val();
                                console.log(searchText);
                                if (typeof (searchText) == "undefined" || !searchText) {
                                        searchText = "";
                                }

                                if ((searchText)) {
                                        var params = {};
                                        params['searchItem'] = searchText;
                                        loadPaginatedNextItems('/searchItemSchemePanigated',
                                                        params, 'schemes-paginated', 'schemes-table',
                                                        'scheme-details-container');
                                } else {
                                        loadPaginatedNextItems('/getPaginatedSchemes', null,
                                                        'schemes-paginated', 'schemes-table',
                                                        'scheme-details-container');
                                }
                                $(this).blur();
                        });

        $("#schemes-paginated .previous").live(
                        'click',
                        function() {
                                var searchText = $("#scheme-item-search-text").val();
                                // var searchTxt=$("#scheme-search-text").val();
                                console.log(searchText);
                                if (typeof (searchText) == "undefined" || !searchText) {
                                        searchText = "";
                                }

                                if ((searchText)) {
                                        var params = {};
                                        params['searchItem'] = searchText;
                                        loadPaginatedPreviousItems('/searchItemSchemePanigated',
                                                        params, 'schemes-paginated', 'schemes-table',
                                                        'scheme-details-container');
                                } else {
                                        loadPaginatedPreviousItems('/getPaginatedSchemes', null,
                                                        'schemes-paginated', 'schemes-table',
                                                        'scheme-details-container');
                                }
                                $(this).blur();
                        });

        $(".scheme-details").live('click', function() {
                var schemeId = $(this).attr('data');
                console.log("schemeId = " + schemeId);
                loadSchemeDetails(schemeId, "scheme-details-container");
        });

        $(".active-scheme").live('click', function() {
                var schemeId = $(this).attr('data');
                console.log("active-scheme id : " + schemeId);
                var start = $("#schemes-paginated .start").text();
                // var end = $( "#schemes-paginated .end" ).text();
                var offset = start - 1;
                if (confirm("Are you sure you want to Active Scheme!") == true) {
                        activeScheme(schemeId, offset, "schemes-table");
                }
        });

        $(".expire-scheme").live('click', function() {
                var schemeId = $(this).attr('data');
                console.log("expire-scheme id : " + schemeId);
                var start = $("#schemes-paginated .start").text();
                // var end = $( "#schemes-paginated .end" ).text();
                var offset = start - 1;
                if (confirm("Are you sure you want to Expire Scheme!") == true) {
                        expireScheme(schemeId, offset, "schemes-table");
                }
        });
        $("#extendDatetime-button")
                        .live(
                                        'click',
                                        function() {
                                                console.log("extendAll button click");
                                                var extendDatetime = $('input[name="extendDatetime"]')
                                                                .val();
                                                console.log("extendDatetime : " + extendDatetime);
                                                if (extendDatetime) {
                                                        if (confirm("Are you sure you want to Extend expireDateTime for All Scheme!") == true) {
                                                                extendAllScheme(extendDatetime, "schemes-table")
                                                        }
                                                } else {
                                                        alert("feild can't be blank");
                                                }
                                        });
        $("#extendScheme-button")
                        .live(
                                        'click',
                                        function() {
                                                console.log("extend button click");
                                                var extendDatetime = $('input[name="extendScheme"]')
                                                                .val();
                                                var schemeId = $('#schemeId').val()
                                                console.log("extendDatetime : " + extendDatetime);
                                                console.log(schemeId);
                                                if (extendDatetime) {
                                                        if (confirm("Are you sure you want to Extend expireDateTime for Scheme!") == true) {
                                                                extendSchemeById(schemeId)
                                                        }
                                                } else {
                                                        alert("feild can't be blank");
                                                }
                                        });

        $(".schemes").live('click', function() {
                console.log("Active Schemes Button Clicked...")
                schemes("main-content");
        });

        $(".schemes-download-page").live('click', function() {
                console.log("Schemes Download Clicked...")
                loadSchemesDownloadPage("main-content");
        });

        $(".schemes-update").live('click', function() {
                loadSchemeUpdatePage("main-content");
        });

        $(".add-item").live('click', function() {

                schemeIds = $("#schemeids").val();
                itemIds = $("#itemids").val();
                console.log(schemeIds);
                console.log(itemIds);
                if (confirm("Are you sure you want to Add Item to Scheme!") == true) {
                if (itemIds.trim().length === 0 || schemeIds.trim().length === 0) {
                        alert("fields shouldn't be blank");
                        return;
                }
                updateSingleScheme(schemeIds, itemIds);
                }
        });
        $(".add-schemes").live('click', function() {

                schemeIds = $("#schemeids").val();
                itemIds = $("#itemids").val();
                console.log(schemeIds);
                console.log(itemIds);
                if (confirm("Are you sure you want to Add Item to Scheme!") == true) {
                if (itemIds.trim().length === 0 || schemeIds.trim().length === 0) {
                        alert("fields shouldn't be blank");
                        return;
                }
                updateSchemes(schemeIds, itemIds);
                }
        });
        $(".delete-schemes").live('click', function() {
                if (confirm("Are you sure you want to delete Scheme!") == true) {
                        schemeId = $(this).data('schemeid');
                        itemId = $(this).data('itemid');
                        console.log(schemeId);
                        console.log(itemId);
                        deleteScheme(schemeId, itemId);
                }
        });
        $("#scheme-search-button").live('click', function() {
                var searchText = $("#scheme-search-text").val();
                if (typeof (searchText) == "undefined" || !searchText) {
                        searchText = "";
                }
                loadSchemeSearchInfo(searchText);
        });

        $("#scheme-search-text").live("keyup", function(e) {
                var keyCode = e.keyCode || e.which;
                if (keyCode == 13) {
                        $("#scheme-search-button").click();
                }
        });
        $("#scheme-item-search-button").live('click', function() {
                var searchText = $("#scheme-item-search-text").val();
                if (typeof (searchText) == "undefined" || !searchText) {
                        searchText = "";
                }
                loadSchemeItemSearchInfo(searchText);
        });

        $("#scheme-item-search-text").live("keyup", function(e) {
                var keyCode = e.keyCode || e.which;
                if (keyCode == 13) {
                        $("#scheme-item-search-button").click();
                }
        });
});

function configureTagListingItemsDescriptionDropDown() {
        $(document).ready(function() {
                $('#tagListingItemsDescription').multiselect({
                        includeSelectAllOption : true,
                        maxHeight : 200,
                        buttonWidth : '180px',
                        numberDisplayed : 1,
                        nonSelectedText : 'Items',
                        nSelectedText : ' - Items Selected',
                        allSelectedText : 'All Items Selected',
                        enableFiltering : true,
                        enableCaseInsensitiveFiltering : true

                });
        });
}

function schemesDownload() {
        console.log("downloadItemLedgerReport Button clicked")
        var startDateTime = $('input[name="startDateTime"]').val();
        console.log("startDateTime : " + startDateTime);
        var endDateTime = $('input[name="endDateTime"]').val();
        console.log("endDateTime : " + endDateTime);
        doAjaxGetDownload(context + "/schemes/download?startDateTime="
                        + startDateTime + "&endDateTime=" + endDateTime,
                        "SchemesReport.xlsx");
}
function selectedbrand() {
        var brands = $('#tag-listing-brands').val();
        console.log(brands);
        if (brands) {
                loadTagListingItemsDescriptionByBrand(
                                "tag-listing-items-description-container", brands);
        }
}
function loadSchemeDetails(schemeId, domId) {
        doGetAjaxRequestHandler(context + "/getSchemeById?schemeId=" + schemeId,
                        function(response) {
                                $('#' + domId).html(response);
                                window.dispatchEvent(new Event('resize'));
                        });
}

function activeScheme(schemeId, offset, domId) {
        doPutAjaxRequestHandler(context + "/activeSchemeById?schemeId=" + schemeId
                        + "&offset=" + offset, function(response) {
                $('#' + domId).html(response);
                $('#scheme-details-container').html('');
        });

}

function expireScheme(schemeId, offset, domId) {
        doPutAjaxRequestHandler(context + "/expireSchemeById?schemeId=" + schemeId
                        + "&offset=" + offset, function(response) {
                $('#' + domId).html(response);
                $('#scheme-details-container').html('');
        });
}
function extendAllScheme(domId) {
        doPostAjaxRequestWithJsonHandler(context + "/extendAllSchemes",
                        JSON.stringify(startDate), function(response) {
                if (response == 'true') {
                        alert("Scheme All Extended successfully");
                        schemes("main-content");
                } else {
                        alert("No scheme Activated Currently");
                        schemes("main-content");
                }
        });

}
function extendSchemeById(schemeId) {
        doPostAjaxRequestWithJsonHandler(context + "/extendSchemeById?schemeId="+ schemeId,JSON.stringify(startDate), function(response) {
                if (response == 'true') {
                        alert("Scheme extended successfully");
                        schemes("main-content");
                } else {
                        alert("Scheme already Expired");
                        schemes("main-content");
                }
        });

}

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

}

// function loadTagListingItemsDescriptionByBrand(domId, brand) {
// doGetAjaxRequestHandler(context + "/getTagListingItemsByBrand?brand="
// + brand, function(response) {
// $('#' + domId).html(response);
// configureTagListingItemsDescriptionDropDown();
// });
//
// }
function loadTagListingItemsDescriptionByBrand(domId, brands) {
        doPostAjaxRequestWithJsonHandler(context + '/getTagListingItemsByBrand',
                        JSON.stringify(brands), function(response) {
                                $('#' + domId).html(response);
                                configureTagListingItemsDescriptionDropDown();
                        });

}

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

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

function loadSchemeUpdatePage(domId) {
        doGetAjaxRequestHandler(context + "/schemes/update-schemes-page", function(
                        response) {
                $('#' + domId).html(response);
        });
}

function updateSingleScheme(shcemeIds, itemIds) {
        doPostAjaxRequestWithJsonHandler(context + '/addItemToScheme', JSON
                        .stringify({
                                "itemIds" : itemIds.split(",").map(Number),
                                "schemeIds" : schemeIds.split(",").map(Number)
                        }), function(response) {
        if (response == 'true') {
                        alert("Item Added to scheme successfully");
                        // $('#newItemToSchemeModal').modal('hide');
                        loadSchemeDetails(shcemeIds, "scheme-details-container");
                } else {
                        alert("Item already present");
                        loadSchemeDetails(shcemeIds, "scheme-details-container");
                }
        });
}
function updateSchemes(shcemeIds, itemIds) {
        doPostAjaxRequestWithJsonHandler(context + '/schemes/update', JSON
                        .stringify({
                                "itemIds" : itemIds.split(",").map(Number),
                                "schemeIds" : schemeIds.split(",").map(Number)
                        }), function(response) {
                if (response == 'true') {
                        alert("Item Added to scheme successfully");
                        // $('#newItemToSchemeModal').modal('hide');
                        loadSchemeUpdatePage("main-content");
                } 
        });
}
function deleteScheme(shcemeId, itemId) {
        doDeleteAjaxRequestHandler(context + "/schemes/delete?schemeId=" + shcemeId
                        + "&itemId=" + itemId, function(response) {
                if (response == 'true') {
                        alert("ItemId Deleted successfully from Scheme");
                        loadSchemeDetails(shcemeId, "scheme-details-container");
                }
        });
}
function loadSearchScheme(domId, search_text) {
        doGetAjaxRequestHandler(context + "/searchScheme/?searchTerm="
                        + search_text, function(response) {
                $('#' + domId).html(response);
        });
}
function loadSearchItemScheme(domId, search_text) {
        doGetAjaxRequestHandler(context + "/searchScheme/?searchItem="
                        + search_text, function(response) {
                $('#' + domId).html(response);
        });
}
function loadSchemeSearchInfo(search_text) {
        loadSearchScheme("main-content", search_text);
}
function loadSchemeItemSearchInfo(search_text) {
        loadSearchItemScheme("main-content", search_text);
}