<?php $__env->startSection('content'); ?>
    <ol class="breadcrumb bc-3">
        <li>
            <a href="<?php echo URL::to('dashboard'); ?>"><i class="entypo-home"></i>Home</a>
        </li>
        <li class="active">
            <strong>Server Monitor</strong>
        </li>
    </ol>
    <h3>Server Monitor</h3>

    <?php echo $__env->make('includes.errors', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <?php echo $__env->make('includes.success', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

    <p style="text-align: right;">

        <?php if( User::checkCategoryPermission('ServerInfo','Add') ): ?>
            <a href="javascript:void(0)" id="add-new-server" class="btn btn-primary ">
                <i class="entypo-plus"></i>
                Add New Server
            </a>
        <?php endif; ?>
    </p>
    <table class="table tab-content table-bordered datatable" id="table-4">
        <thead>
        <tr>
            <th width="20%">Server Name</th>
            <th width="15%">Server Link</th>
            <th width="15%">Action</th>
        </tr>
        </thead>
        <tbody>


        </tbody>
    </table>

    <style>

        #ServerInfoTab{
            margin-left: 0px;
        }
        #ServerInfoTab li a{
            padding: 10px;
        }
        #ServerInfoTab .btn-xs{
            margin-left:0px;
            padding: 0px;;
            cursor: pointer;
        }
        #ServerInfoTabContent .tab-pane{
            height: 1024px;
        }
        #Serverview{
            width: 10%;
            margin-top: 50px;
            margin-left: 45%;
            font-size: x-large;
        }

    </style>
    <!-- Nav tabs from Bootstrap 3 -->


    <!-- Redirect to server monitor -->
    <div id="ServerInfoTabContent" class="tab-content" >
    </div>





    <script type="text/javascript">
        var $searchFilter = {};
        var update_new_url;
        var postdata;
        jQuery(document).ready(function ($) {
            public_vars.$body = $("body");
            //show_loading_bar(40);

            data_table = $("#table-4").dataTable({
                "bDestroy": true,
                "bProcessing":true,
                "bServerSide":true,
                "sAjaxSource": baseurl + "/serverinfo/ajax_datagrid",
                "iDisplayLength": parseInt('<?php echo CompanyConfiguration::get('PAGE_SIZE'); ?>'),
                "sPaginationType": "bootstrap",
                "aaSorting": [],
                "aoColumns":
                    [
                        {  "bSortable": true },  //0  ServerInfoTitle', '', '', '
                        {  "bSortable": true,
                            mRender: function ( id, type, full ) {
                                action = '<a target="_blank" href="' + full[1] + '" > ' + full[1] + '<a / >';
                                    return action;
                            } },                //1   ServerInfoURL
                        {                       //3  ServerInfoID
                            "bSortable": true,
                            mRender: function ( id, type, full ) {
                                var action , edit_ , show_ , delete_;
                                action = '<div class = "hiddenRowData" >';
                                action += '<input type = "hidden"  name = "ServerInfoTitle" value = "' + full[0] + '" / >';
                                action += '<input type = "hidden"  name = "ServerInfoUrl" value = "' + full[1] + '" / >';
                                action += '</div>';

                                <?php if(User::checkCategoryPermission('ServerInfo','Edit')){ ?>
                                    action += ' <a data-name = "'+full[0]+'" data-id="'+ id +'" title="Edit" class="edit-serverinfo btn btn-default btn-sm"><i class="entypo-pencil"></i>&nbsp;</a>';
                                <?php } ?>
                                    <?php if(User::checkCategoryPermission('ServerInfo','show')){ ?>
                                    action += ' <a href = "'+full[1]+'" title="" target="_blank" title="View" class="btn btn-primary btn-sm"><i class="entypo-eye"></i>&nbsp;</a>';
                                <?php } ?>
                                    <?php if(User::checkCategoryPermission('ServerInfo','Delete')){ ?>
                                    action += ' <a data-id="'+ id +'" title="Delete" class="delete-serverinfo btn delete btn-danger btn-sm"><i class="entypo-trash"></i></a>';
                                <?php } ?>

                                    return action;
                            }
                        },
                    ],

                "fnDrawCallback": function() {
                    //After Delete done
                    FnDeleteServerInfoSuccess = function(response){

                        if (response.status == 'success') {
                            $("#Note"+response.NoteID).parent().parent().fadeOut('fast');
                            ShowToastr("success",response.message);
                            data_table.fnFilter('', 0);
                        }else{
                            ShowToastr("error",response.message);
                        }
                    }
                    //onDelete Click
                    FnDeleteServerInfo = function(e){
                        result = confirm("Are you Sure?");
                        if(result){
                            var id  = $(this).attr("data-id");
                            showAjaxScript( baseurl + "/serverinfo/"+id+"/delete" ,"",FnDeleteServerInfoSuccess );
                        }
                        return false;
                    }
                    $(".delete-serverinfo").click(FnDeleteServerInfo); // Delete Note
                    $(".dataTables_wrapper select").select2({
                        minimumResultsForSearch: -1
                    });
                }
            });
            // Replace Checboxes
            $(".pagination a").click(function (ev) {
                replaceCheckboxes();
            });




            $('#add-new-server').click(function(ev){
                ev.preventDefault();
                $('#serverinfo-form').trigger("reset");
                $("#serverinfo-form [name='ServerInfoID']").val('')
                $('#modal-serverinfo h4').html('Add Server');
                $('#modal-serverinfo').modal('show');
            });
            $('table tbody').on('click','.edit-serverinfo',function(ev){
                ev.preventDefault();
                ev.stopPropagation();
                $('#serverinfo-form').trigger("reset");
                var prevrow = $(this).prev("div.hiddenRowData");

                ServerInfoTitle = prevrow.find("input[name='ServerInfoTitle']").val();
                ServerInfoUrl = prevrow.find("input[name='ServerInfoUrl']").val();

                $("#serverinfo-form [name='ServerInfoTitle']").val(ServerInfoTitle);
                $("#serverinfo-form [name='ServerInfoUrl']").val(ServerInfoUrl);

                $("#serverinfo-form [name='ServerInfoID']").val($(this).attr('data-id'));
                $('#modal-serverinfo h4').html('Edit Server');
                $('#modal-serverinfo').modal('show');

            })

            $('#serverinfo-form').submit(function(e){
                e.preventDefault();
                var ServerInfoID = $("#serverinfo-form [name='ServerInfoID']").val()
                if( typeof ServerInfoID != 'undefined' && ServerInfoID != ''){
                    update_new_url = baseurl + '/serverinfo/'+ServerInfoID+'/update';
                }else{
                    update_new_url = baseurl + '/serverinfo/store';
                }
                ajax_update(update_new_url,$('#serverinfo-form').serialize());
            });

        });

        function ajax_update(fullurl,data){
//alert(data)
            $.ajax({
                url:fullurl, //Server script to process data
                type: 'POST',
                dataType: 'json',
                success: function(response) {
                    $("#serverinfo-update").button('reset');
                    $(".btn").button('reset');
                    $('#modal-serverinfo').modal('hide');

                    if (response.status == 'success') {
                        $('#modal-serverinfo').modal('hide');
                        toastr.success(response.message, "Success", toastr_opts);
                        if( typeof data_table !=  'undefined'){
                            data_table.fnFilter('', 0);
                        }
                    } else {
                        toastr.error(response.message, "Error", toastr_opts);
                    }
                },
                data: data,
                //Options to tell jQuery not to process data or worry about content-type.
                cache: false
            });

        }

    </script>

    <?php echo $__env->make('includes.errors', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <?php echo $__env->make('includes.success', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('footer_ext'); ?>
    @parent

    <div class="modal fade in" id="modal-serverinfo">
        <div class="modal-dialog">
            <div class="modal-content">
                <form id="serverinfo-form" method="post">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">Add Server</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="field-5" class="control-label">Name</label>
                                    <input type="text" name="ServerInfoTitle" class="form-control" value="" />
                                    <input type="hidden" name="ServerInfoID" />
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="field-5" class="control-label">Server URL</label>
                                    <input type="text" name="ServerInfoUrl" class="form-control" value="" />

                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" id="serverinfo-update" class="btn btn-primary print btn-sm btn-icon icon-left" data-loading-text="Loading...">
                            <i class="entypo-floppy"></i>
                            Save
                        </button>
                        <button  type="button" class="btn btn-danger btn-sm btn-icon icon-left" data-dismiss="modal">
                            <i class="entypo-cancel"></i>
                            Close
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout.main', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>