Subversion Repositories SmartDukaan

Rev

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

var walletHistory = walletHistory || {};
walletHistory.startTime="";
walletHistory.endTime="";

$(function() {
        $(".wallet_icon_header").live('click', function() {
                loadWallet("main-content", "", "");
        });
        
        $("#wallet-history-paginated .next").live('click', function() {
                var start = $( "#wallet-history-paginated .start" ).text();
                var end = $( "#wallet-history-paginated .end" ).text();
                getWalletHistoryNextItems(start, end, walletHistory.startTime, walletHistory.endTime);
                $("#wallet-history-paginated .next").blur();
    });
        
        $("#wallet-history-paginated .previous").live('click', function() {
                var start = $( "#wallet-history-paginated .start" ).text();
                var end =  $( "#wallet-history-paginated .end" ).text();
                var size = $("#wallet-history-paginated .size").text();
                if(parseInt(end) == parseInt(size)){
                        var mod = parseInt(end) % 10;
                        end = parseInt(end) + (10 - mod); 
                }
                var pre = end - 20;
                getWalletHistoryPreviousItems(start, end, pre, walletHistory.startTime, walletHistory.endTime);
                $("#wallet-history-paginated .previous").blur();
    });
});


function getWalletHistoryNextItems(start, end, startTime, endTime){
        console.log(start);
        console.log(end);
        console.log(+end + +10);
        console.log(+start + +10);
        doAjaxRequestHandler(context+"/getPaginatedWalletHistory?startTime="+startTime
                +"&endTime="+endTime+"&offset="+end, "GET", function(response){
                var size = $("#wallet-history-paginated .size").text();
                if((parseInt(end) + 10) > parseInt(size)){
                        console.log("(end + 10) > size == true");
                        $( "#wallet-history-paginated .end" ).text(size);
                }else{
                        console.log("(end + 10) > size == false");
                        $( "#wallet-history-paginated .end" ).text(+end + +10);
                }
                
                $( "#wallet-history-paginated .start" ).text(+start + +10);
                var last = $( "#wallet-history-paginated .end" ).text();
                var temp = $( "#wallet-history-paginated .size" ).text();
                if (parseInt(last) >= parseInt(temp)){
                        $("#wallet-history-paginated .next").prop('disabled', true);
                        //$( "#good-inventory-paginated .end" ).text(temp);
                }
            $('#wallet-history-table').html(response);
            $("#wallet-history-paginated .previous").prop('disabled', false);
        });
        
}

function getWalletHistoryPreviousItems(start, end, pre, startTime, endTime){
        console.log(start);
        console.log(end);
        console.log(pre);
        console.log(+end - +10);
        console.log(+start - +10);
        doAjaxRequestHandler(context+"/getPaginatedWalletHistory?startTime="+startTime
                +"&endTime="+endTime+"&offset="+pre, "GET", function(response){
                $( "#wallet-history-paginated .end" ).text(+end - +10);
                $( "#wallet-history-paginated .start" ).text(+start - +10);
                $('#wallet-history-table').html(response);
                $("#wallet-history-paginated .next").prop('disabled', false);
                if (parseInt(pre)==0)
                {
                        $("#wallet-history-paginated .previous").prop('disabled', true);
                }
        });
        
}

function loadWallet(domId, startTime, endTime){
        doAjaxRequestHandler(context+"/walletDetails?startTime="+startTime
                +"&endTime="+endTime, "GET", function(response){
                $('#' + domId).html(response);
        });
}