Subversion Repositories SmartDukaan

Rev

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

$(function() {

        $(".punch-in-outs").live('click', function() {
                loadPunchInOuts("main-content");
        });

        $("#punch-in-outs-paginated .next")
                        .live(
                                        'click',
                                        function() {
                                                loadPaginatedNextItems('/getPaginatedPunchInOuts',
                                                                null, 'punch-in-outs-paginated',
                                                                'punch-in-outs-table', null);
                                                $(this).blur();
                                        });

        $("#punch-in-outs-paginated .previous")
                        .live(
                                        'click',
                                        function() {
                                                loadPaginatedPreviousItems('/getPaginatedPunchInOuts',
                                                                null, 'punch-in-outs-paginated',
                                                                'punch-in-outs-table', null);
                                                $(this).blur();
                                        });
});

function createPunchInOut(inOut) {
        if (confirm("Are you sure you want to do punch " + inOut)) {
                distance = undefined;
                if (navigator.geolocation) {
                        navigator.geolocation
                                        .getCurrentPosition(function(position) {
                                                alert("Unable to fetch your device location");
                                                if (typeof latitude == "undefined") {
                                                        distance = getDistance(latitude, longitude,
                                                                        position.coords.latitude,
                                                                        position.coords.longitude);
                                                        if (distance < 500) {
                                                                doPostAjaxRequestWithParamsHandler(context
                                                                                + "/createPunchInOut", {}, function(
                                                                                response) {
                                                                        $('#main-content').html(response);
                                                                        alert("Punch " + inOut
                                                                                        + " done successfully");
                                                                });
                                                        } else {
                                                                alert("Punch " + inOut
                                                                                + " can only be done from store.");
                                                        }
                                                } else {
                                                        alert("Location cant be tracked. Please enable location");
                                                        return;
                                                }
                                        });
                } else {
                        alert("Location cant be tracked. Please enable location");
                }
        }
}

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