$(document).ready(function()
{
    $(document).on('click', '#leaveTable td:not(.idTD,.actionTD)', function()
    {
        $.zui.modalTrigger.show({name : 'ajaxModal', url : $(this).parent().attr('url'), backdrop : 'static'});
        return false;
    });

    $(document).on('click', '.deleteLeave', function()
    {
        if(confirm(v.lang.confirmDelete))
        {
            $(this).text(v.lang.deleting);
            $.getJSON($(this).attr('href'), function(data)
            {
                if(data.result == 'success')
                {
                    if(data.locate) return location.href = data.locate;
                    return location.reload();
                }
                else
                {
                    alert(data.message);
                    if(selecter.parents('#ajaxModal').size()) return $.reloadAjaxModal(1200);
                    return location.reload();
                }
            });
        }
        return false;
    });

    $(document).on('click', '.reviewPass', function()
    {
        if(confirm(v.confirmReview.pass))
        {
            var selecter = $(this);

            $.getJSON(selecter.attr('href'), function(data)
            {
                if(data.result == 'success')
                {
                    if(data.locate) return location.href = data.locate;
                    return location.reload();
                }
                else
                {
                    bootbox.alert(data.message, function()
                    {
                        return location.reload();
                    });
                }
            });
        }
        return false;
    });

    $('.batchPass').on('click', function()
    {
        $.setAjaxForm('#batchReviewForm', function(data)
        {
            if(data.result == 'success')
            {
                location.reload();
            }
            else
            {
                bootbox.alert(data.message)
            }
        });
        $('#batchReviewForm').submit();
    });

    /* expand active tree. */
    $('.tree').tree('expandSelect', '.active');
});
