API Docs for:
Show:

File: Shared\common.js


function activeSidebaarLink() {
    $(".sideMenuLink a").click(function () {
        $(".sideMenuLink a").removeClass("activeSideLink");
        $(this).addClass("activeSideLink");
    });
}

$.prototype.levydatepicker = function (options) {
    var dateObject = $(this).datepicker({
        dateFormat: options.dateFormat,
        maxDate: +options.maxDate,
        minDate: options.minDate,
        beforeShowDay: options.beforeShowDay,
        onSelect: options.onSelect,
        changeMonth: options.changeMonth,
        changeYear: options.changeYear,
        yearRange: options.yearRange
    });
    $(this).attr("readonly", "readonly");
    if (options.defaultDate) { dateObject.val(options.defaultDate); }
    $("#ui-datepicker-div").hide();
}

$(document).ajaxStart(function (e) {
    // console.log("ajax request start");
    showLoadingMessage("Loading...");
});

$(document).ajaxStop(function () {
    ////console.log("ajax request end.");
    hideLoadingMessage();
});

function showLoadingMessage(message) {
    if (!message) { message = "Loading.." }
    message = "<div>" + message + "</div>";
    $("#divLoadingElement").html(message).show();
}

function hideLoadingMessage() {
    $("#divLoadingElement").hide();
}

function getCurrentTime() {
    var currDate = new Date();
    return currDate.getDay() + '' + currDate.getMonth() + '' + currDate.getYear() + '' + currDate.getHours() + '' + currDate.getMinutes() + '' + currDate.getSeconds() + '' + currDate.getMilliseconds();
}

/* ================================Call for alive session================================*/
function aliveSession() { var currtime = getCurrentTime(); $.get("/Home/SessionTimeout/", { currtime: currtime }, function (result) { }); }

//setInterval(function () { aliveSession(); }, 1000 * 60 * 10);

/*========================================End============================================*/

/*==================================Time Picker==========================================*/
function timePicker(startTimeId, endTimeId) {
    var id = "#" + startTimeId + ", #" + endTimeId;
    // Use default settings
    $(id).timePicker();

    // Store time used by duration.
    var oldTime = $.timePicker("#" + startTimeId).getTime();

    // Keep the duration between the two inputs.
    $("#" + startTimeId).change(function () {
        if ($("#" + endTimeId).val()) { // Only update when second input has a value.
            // Calculate duration.
            var duration = ($.timePicker("#" + endTimeId).getTime() - oldTime);
            var time = $.timePicker("#" + startTimeId).getTime();
            // Calculate and update the time in the second input.
            $.timePicker("#" + endTimeId).setTime(new Date(new Date(time.getTime() + duration)));
            oldTime = time;
        }

    });
    // Validate.
    $("#" + endTimeId).change(function () {
        if ($.timePicker("#" + startTimeId).getTime() > $.timePicker(this).getTime()) {
            $(this).addClass("error").removeClass('valid');
        }
        else {
            $(this).removeClass("error");
        }
        //changeSliderValue(); //call for slider  value update
    });
}
/*=====================================End===============================================*/

// Show title on kendo grid header
function addTitleAttribute() {
    $.each($(".k-grid-header").find('tr th'), function (idx, th) {
        var a = $(th).attr('data-title');
        if ($(th).attr('data-title')) {
            $(th).attr('title', $(th).attr('data-title'));
        } else {
            $(th).attr('title', $(th).attr('data-field'));
        }
    });
}

// Call when data bound on the grid 
function onDataBound() {

    addTitleAttribute();
}
//
function setPagerAndGroupBarWidth() {
    //console.log($('.k-grid-header tr'));
    var headersWidth = $('.k-grid-header tr').width();
    // alert(headersWidth);
    $(".k-grid-pager").width(headersWidth);
    $(".k-grouping-header").width(headersWidth);
    addTitleAttribute();
}


function fitPagerToGrid() {
    var headersWidth = $('.k-grid-header tr').width();
    //console.log(headersWidth);
    $(".k-grid-pager").width(headersWidth);
}

// open and close Right slider.
function rightSlider() {
    /* right silder for text */
    $(".button").click(function () {
        if ($(this).hasClass('open DD_close')) {
            $(".container").animate({
                right: "-187px"
            }, 250, "linear", function () {
                $('.button').removeClass('open DD_close');
            });
        }
        else {
            $(".container").animate({
                right: "0px"
            }, 250, "linear", function () {
                $('.button').addClass('open DD_close');
            });
        }

    });
}


/**
* Function to add kendo window
* @method addKendoWindow
* @param {String} divId The id of div
* @param {String} titleText The name of window title
* @param {String} width width of window
* @param {String} left margin from left
*/
function addKendoWindow(divId, titleText, width, left, top) {
    $(divId).kendoWindow({
        width: width,
        title: titleText,
        modal: true,
        resizable: false,
        draggable: true,
        position: {
            top: top,
            left: left
        }
    });
}


//============================== query String functionality========================

// Get query string parameter
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

/**
* Add Attributes (Href,target) to given anchor element.
* @method addLinkValue
*/
function addLinkValue($eleParentHref, linkValue) {
    $eleParentHref.attr({
        'href': linkValue,
        'target': '_blank'
    }).css("cursor", "pointer");

}

/**
* function which dynamically add Query parameter on given uri.
* @method updateQueryStringParameter
*/
function updateQueryStringParameter(uri, key, value) {
    var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
    var separator = uri.indexOf('?') !== -1 ? "&" : "?";
    if (uri.match(re)) {
        return uri.replace(re, '$1' + key + "=" + value + '$2');
    }
    else {
        return uri + separator + key + "=" + value;
    }
}
//============================== End of query String functionality========================
/**
* Refresh kendo grid when resize coloum.
* @method onColumnResize
*/
function onColumnResize(e) {
    var activeGridId = e.sender._cellId;
    var replaceString = "_active_cell";
    var updatedId = (activeGridId.replace(replaceString, '')).trim();
    $("#" + updatedId).data("kendoGrid").refresh();
}

/**
* Set numeric filter values as intger.
* @method NumericFilter
*/
function NumericFilter(control) {
    $(control).kendoNumericTextBox({ "format": "n0", "decimals": 0 });

}

// update grid with message if no result found.
function displayNoResult(e) {
    var grid = e.sender;

    if (grid.dataSource.total() == 0) {
        var colCount = grid.columns.length;
        $(e.sender.wrapper)
            .find('tbody')
            .append('<tr class="kendo-data-row"><td colspan="' + colCount + '" style="text-align:center"><b>No data available!</b></td></tr>');
    }
}


//function to decode html text
function stringToDecode(encodedString, id) {
    var stringtodecode = encodedString;
    document.getElementById(id).innerHTML = stringtodecode;
    stringtodecode = document.getElementById(id).innerText;
    return stringtodecode;
}

function AllowSpecialCharacterForOwner(e, t) {

    var key;
    var keychar;

    if (window.event)
        key = window.event.keyCode;
    else if (e)
        key = e.which;
    else
        return true;
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
    // control keys
    if ((key == null) || (key == 0) || (key == 8) ||
        (key == 9) || (key == 13) || (key == 27))
        return true;
    else if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1))
        return true;
    else
        return true;


}


/**
* Function call on row bound of close tickets table
* @param {String} divId The id of div
* @method openKendoWindowInCenter
*/
function openKendoWindowInCenter(divId) {
    var window = $(divId).data("kendoWindow");
    window.center();
    //window.open();
}