@model PagedList.IPagedList<PantheonApi.Data.DbModels.Pantheon.tPA_SyncTableStatus>
@using PagedList.Mvc;
@{
    ViewBag.Title = "SyncParameters";
    Layout = null;
}

<div id="SyncParametersList">
    <h2>Sync parameters</h2>

    @using (Ajax.BeginForm("SyncParameters", "SyncManager", new { page = ViewBag.CurrentPage },
                new AjaxOptions
                {
                    UpdateTargetId = "SyncParametersList",
                    OnBegin = "startLoading('SyncParametersList')"
                }))
    {

        <div class="form-group">
            <div class="input-group" style="display:inline-flex">
                <input type="text" 
                       class="form-control" 
                       title="@ViewBag.searchString" 
                       name="searchString" 
                       placeholder="Search..." 
                       value="@ViewBag.searchString"
                       style="margin-right: 15px"
                       autofocus>
                <input type="text" 
                       class="form-control" 
                       title="@ViewBag.deviceId" 
                       name="deviceId" 
                       placeholder="Search by id..." 
                       value="@ViewBag.deviceId">
                <input type="submit" style="display: none" />
            </div>
        </div>
    }

    <div class="table-responsive">
        <table class="table table-hover table-striped">
            <tr>
                <th>
                    ID
                </th>
                <th>
                    Device ID
                </th>
                <th>
                    Table ID
                </th>
                <th>
                    Table name
                </th>
                <th>
                    Sync Enabled
                </th>
                <th>
                    Transfer Direction
                </th>
                <th></th>
            </tr>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.anId)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.anDeviceId)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.anTableId)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.TableName)
                    </td>
                    @if (item.abIsSyncEnabled)
                    {
                        <td class="text-success">
                            <i class="glyphicon glyphicon-ok"></i>
                        </td>
                    }
                    else
                    {
                        <td class="text-danger">
                            <i class="glyphicon glyphicon-remove"></i>
                        </td>
                    }
                    <td>
                        @Html.DisplayFor(modelItem => item.acTransferDirection)
                    </td>
                    <td>
                        @if (User.IsInRole(Constants.DatalabRole))
                        {
                            @Ajax.ActionLink("Edit", "EditSyncParameter", "SyncManager", new { anId = item.anId, page = Model.PageNumber, searchString = ViewBag.searchString },
                            new AjaxOptions
                            {
                                UpdateTargetId = "SyncParametersList",
                                InsertionMode = InsertionMode.Replace,
                                OnBegin = "startLoading('SyncParametersList')"
                            })
                        }
                    </td>
                </tr>
            }
        </table>
    </div>
    <br />
    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount

    <div class="text-center">
        @Html.PagedListPager(Model, page => Url.Action("SyncParameters", "SyncManager", 
         new { page, searchString = ViewBag.searchString, deviceId = ViewBag.deviceId }),
         PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions()
         {
             HttpMethod = "GET",
             UpdateTargetId = "SyncParametersList"
         }))
    </div>
</div>
