@extends('layouts.master')
  @section('page_title')
      @if(isset($page_title))
          {{ $page_title }}
      @endif
  @endsection
@section('css')
<link href="{!! url('public/assets/vendors/tabulator/css/bootstrap/tabulator_bootstrap.css') !!}" type="text/css" rel="stylesheet">
@endsection
@section('content')
  <div class="">
      <div class="page-title">
        <div class="title_left">
          <div class="title_left">
            <ol class="breadcrumb">
              <li><a href="{!! url('dashboard') !!}">Dashboard</a></li>
              <li class="active">Credentials</li>
            </ol>
          </div>
        </div>
        <div class="title_right">
          <div class="row">

          </div>
          <div class="row">
              <div class="col-sm-12">
              <div class="pull-right">
                  <!-- <a href="{!! url('clients') !!}" class="btn btn-warning btn-xs"><i class="fa fa-refresh"></i> Reset Filter</a> -->
              </div>
              </div>
          </div>
        </div>


      </div>

      <div class="clearfix"></div>
      <div class="row">
        @include('commons.notifications')
        <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
          <div class="x_title">
            <h2> Credentials </h2>
            <div class="clearfix"></div>
            <div class="pull-left">
              <button id="credentials-download-xlsx" class="btn btn-success btn-sm"><i class="fa fa-file-excel-o"></i> Download XLSX</button>
              <button id="credentials-download-pdf" class="btn btn-danger btn-sm"><i class="fa fa-file-pdf-o"></i> Download PDF</button>
                              <a class="btn btn-primary btn-sm" href="{!! url('systemcreds/create') !!}"><i class="fa fa-plus-square"></i> Add Credentials</a>
            </div>
            <div class="pull-right">
              <form method="GET" action="{!! url('systemcreds') !!}">
                <input type="hidden" name="code_type" value="sms">
                <div class="col-md-5 col-sm-5 col-xs-12 form-group">
                  <div style="margin-top:1px; margin-right:-90px;" class="top_search">
                  </div>
                </div>
                <div class="col-md-12 form-group pull-left top_search" style="margin-top: -2px;">
                  <div class="input-group">
                    <input type="text" name="keyword" class="form-control" id="keywordField" placeholder="Keyword here...">
                    <span class="input-group-btn">
                      <!-- <button type="submit" class="btn btn-primary" style="color: #fff;" type="button">Go!</button> -->
                    </span>
                  </div>
                </div>
              </form>
            </div>
            <div class="clearfix"></div>
            <div class="pull-right">

            </div>
            <div class="clearfix"></div>
          </div>

          <div class="x_content">
            <div id="systemCredentialsTable"></div>
          </div>
        </div>
      </div>
    </div>
</div>

@endsection

@section('javascript')
<script src="{!! url('public/assets/vendors/tabulator/js/tabulator.js') !!}"></script>
<script type="text/javascript" src="{!! url('public/assets/vendors/tabulator/js/xlsx.full.min.js') !!}"></script>
<script type="text/javascript" src="{!! url('public/assets/vendors/tabulator/js/jspdf.min.js') !!}"></script>
<script type="text/javascript" src="{!! url('public/assets/vendors/tabulator/js/jspdf.plugin.autotable.js') !!}"></script>

  <script type="text/javascript">
  $(document).ready(function(){
    function link(cell, formatterParams){
      var url = cell.getValue();
      var rowID = cell.getData().id
      return "<a href='"+ base_url + "/systemcreds/edit/"+rowID+"' class='btn btn-link'>"+url+"</a>";
    }
    var table = new Tabulator("#systemCredentialsTable", {
        ajaxURL: "systemcreds/all",
        paginationSize: 15,
        layout: "fitColumns",
        rowFormatter:function(row){
            if(row.getData().connection_status == "active"){
                //row.getElement().style.backgroundColor = "#1e3b20";
                row.getElement().style.backgroundColor = "red";
            }
        },
        pagination: "remote",
        selectable: false,
        printAsHtml: true,
        ajaxLoaderLoading: $('#logo_spinner').html(),
        columns: [
            {
              title: "Service Name",
              field: "service",
              sorter: "string",
              // formatter:link,
            },
            {
              title: "Client",
              field: "clientName",
              sorter: "string",
            },
            {
              title: "Network Operator",
              field: "networkOpsName",
              sorter: "string",
            },
            {
              title: "URL/Endpoint",
              field: "url_endpoint",
              sorter: "string",
            },
            {
              title: "Expiry Date",
              field: "expiry_date",
              sorter: "string",
            },
            {
              title: "Created By",
              field: "created_by_user",
              sorter: "string",
            },
            {
              title: "Last Modified By",
              field: "modified_by_user",
              sorter: "string",
            },
            {
              title: "Created At",
              field: "created_at",
              sorter: "string",
            },
            {
              title: "Remarks",
              field: "remarks",
              sorter: "string",
            }
        ],

        rowClick:function(e, row){
        var userID = row.getData().id;
        console.log(userID);
        //$('#userEditModal').modal('show');
        },
    });
    document.getElementById("credentials-download-xlsx").addEventListener("click", function(){
      table.download("xlsx", "click_credentials-list.xlsx", {sheetName:"CredentialsList"});
    });
        //trigger download of data.pdf file
    document.getElementById("credentials-download-pdf").addEventListener("click", function(){
      table.download("pdf", "click_credentials-list.pdf", {
          orientation:"portrait", //set page orientation to portrait
          title:"Click Mobile - Credentials List", //add title to report
      });
    });
    $('#keywordField').on('keyup', function(){
      console.log('up');
      var keyword = $(this).val();
      table.setData("systemcreds/all?keyword=" + keyword);

    });
  });
  </script>


@endsection
