@using JXCMS.CMS.Movie.Entity
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-toolbar clearfix">
                    <form class="pull-right search-bar" method="get" action="#!" role="form">
                        <div class="input-group">
                            <div class="input-group-btn">
                                <input type="hidden" name="search_field" id="search-field" value="title">
                                <button class="btn btn-default dropdown-toggle" id="search-btn" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">
                                    标题 <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a tabindex="-1" href="javascript:void(0)" data-field="title">标题</a>
                                    </li>
                                    <li>
                                        <a tabindex="-1" href="javascript:void(0)" data-field="cat_name">栏目</a>
                                    </li>
                                </ul>
                            </div>
                            <input type="text" class="form-control" value="" name="keyword" placeholder="请输入名称">
                        </div>
                    </form>
                    <div class="toolbar-btn-action">
                        <a data-src="@Url.Action("WebSiteDialog", "Collection", new {id = 0})" class="btn btn-primary m-r-5" id="new" data-toggle="modal" data-target="#exampleModal"><i class="mdi mdi-plus"></i> 新增</a>
                        <a class="btn btn-success m-r-5" onclick="enableWebsiteBatch()"><i class="mdi mdi-check"></i> 启用</a>
                        <a class="btn btn-warning m-r-5" onclick="disableWebsiteBatch()"><i class="mdi mdi-block-helper"></i> 禁用</a>
                        <a class="btn btn-danger" onclick="delWebsiteBatch()"><i class="mdi mdi-window-close"></i> 删除</a>
                    </div>
                </div>
                <div class="card-body">

                    <div class="table-responsive">
                        <form id="batchForm" action="#" method="post">
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th>
                                        <label class="lyear-checkbox checkbox-primary">
                                            <input type="checkbox" id="check-all"><span></span>
                                        </label>
                                    </th>
                                    <th>网站名称</th>
                                    <th>网站url</th>
                                    <th>采集cron</th>
                                    <th>状态</th>
                                    <th>下次执行时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @if (ViewBag.website.Count == 0)
                                {
                                    <tr>
                                        <td colspan="7" style="text-align: center">无数据</td>
                                    </tr>
                                }
                                @foreach (WebSiteEntity webSiteEntity in ViewBag.website)
                                {
                                    <tr>
                                        <td>
                                            <label class="lyear-checkbox checkbox-primary">
                                                <input type="checkbox" name="ids[]" value="@webSiteEntity.Id"><span></span>
                                            </label>
                                        </td>
                                        <td>@webSiteEntity.WebSiteName</td>
                                        <td>@webSiteEntity.ApiUrl</td>
                                        <td>@webSiteEntity.Cron</td>
                                        <td>
                                            <span class="text-success">@(webSiteEntity.IsEnable ? "正常" : "已禁用")</span>
                                        </td>
                                        <td>@webSiteEntity.NextRunTime</td>
                                        <td>
                                            <div class="btn-group">
                                                <a class="btn btn-xs btn-default" data-src="@Url.Action("WebSiteDialog", "Collection", new {id = webSiteEntity.Id})" title="编辑" data-toggle="modal" data-target="#exampleModal">
                                                    <i class="mdi mdi-pencil"></i>
                                                </a>
                                                <a class="btn btn-xs btn-default" data-src="@Url.Action("BindingClassifyDialog", "Collection", new {id = webSiteEntity.Id})" data-toggle="modal" data-target="#exampleModal">
                                                    <i class="mdi mdi-link-variant"></i>
                                                </a>
                                                <a class="btn btn-xs btn-default" href="#" title="删除" onclick="delWebsite(@webSiteEntity.Id, '@webSiteEntity.WebSiteName')">
                                                    <i class="mdi mdi-window-close"></i>
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                }

                                </tbody>
                            </table>
                        </form>
                    </div>
                    <ul class="pagination">
                        @if (ViewBag.pageNumber != 1)
                        {
                            <li>
                                <a href="@Url.Action("Index", "Collection")">&lt;&lt;</a>
                            </li>
                        }
                        @for (int i = ViewBag.pageNumber - 3; i < ViewBag.pageNumber + 3; i++)
                        {
                            if (i < 1 || i > ViewBag.totlePage)
                            {
                                continue;
                            }
                            if (i == ViewBag.pageNumber)
                            {
                                <li class="active">
                                    <span>@i</span>
                                </li>
                            }
                            else
                            {
                                <li>
                                    <a href="@Url.Action("Index", "Collection", new {pageNumber = i})">@i</a>
                                </li>
                            }
                        }
                        @if (ViewBag.pageNumber < ViewBag.totlePage)
                        {
                            <li>
                                <a href="@Url.Action("Index", "Collection", new {pageNumber = ViewBag.totlePage})">&gt;&gt;</a>
                            </li>
                        }

                    </ul>

                </div>
            </div>
        </div>

    </div>
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                正在加载，请稍后...
            </div>
        </div>
    </div>
    <form id="delForm" action="@Url.Action("DeleteWebSite")" method="post">
        <input type="hidden" name="id" id="delId"/>
    </form>
</div>

@section style
{
    <link rel="stylesheet" href="@Url.ContentAdmin("js/jconfirm/jquery-confirm.min.css")">
}

@section script
{
    <script src="@Url.ContentAdmin("js/bootstrap-notify.min.js")"></script>
    <script type="text/javascript" src="@Url.ContentAdmin("js/lightyear.js")"></script>
    <script type="text/javascript" src="@Url.ContentAdmin("js/Validate.js")"></script>
    <script src="@Url.ContentAdmin("js/jconfirm/jquery-confirm.min.js")"></script>
    <script>
    $('#exampleModal').on('show.bs.modal', function(event) {
      var button = $(event.relatedTarget); // Button that triggered the modal
        var recipient = button.data('src'); // Extract info from data-* attributes
        var content = $(this).find(".modal-content");
        content.html("正在加载，请稍后...");
        $.get(recipient, function(data, status) {
          if (status === "success") {
              content.html(data)
          } else{
              content.html("发生错误，请重试")
          }
        })
    });
    function delWebsite(id, name) {
      $.alert({
              title: '删除采集地址' + name,
              content: '是否删除' + name + '?该操作不可恢复',
      		buttons: {
      			confirm: {
      				text: '是',
      				btnClass: 'btn-primary',
      				action: function(){
                          $('#delId').val(id);
                          $('#delForm').submit();
      				}
      			},
      			cancel: {
      				text: '否'
      			}
      		}
          });
    }
    
    function delWebsiteBatch() {
          $.alert({
                  title: '批量删除采集地址',
                  content: '是否要批量删除选中的采集地址?该操作不可恢复',
          		buttons: {
          			confirm: {
          				text: '是',
          				btnClass: 'btn-primary',
          				action: function(){
                              $('#batchForm').attr('action', '@Url.Action("DeleteWebSiteBatch")').submit();
          				}
          			},
          			cancel: {
          				text: '否'
          			}
          		}
              });
        }
        
        function enableWebsiteBatch() {
                  $.alert({
                          title: '批量启用采集地址',
                          content: '是否要批量启用选中的采集地址?',
                  		buttons: {
                  			confirm: {
                  				text: '是',
                  				btnClass: 'btn-primary',
                  				action: function(){
                                      $('#batchForm').attr('action', '@Url.Action("EnableWebSiteBatch")').submit();
                  				}
                  			},
                  			cancel: {
                  				text: '否'
                  			}
                  		}
                      });
                }
                
                function disableWebsiteBatch() {
                          $.alert({
                                  title: '批量禁用采集地址',
                                  content: '是否要禁用删除选中的采集地址?',
                          		buttons: {
                          			confirm: {
                          				text: '是',
                          				btnClass: 'btn-primary',
                          				action: function(){
                                              $('#batchForm').attr('action', '@Url.Action("DisableWebSiteBatch")').submit();
                          				}
                          			},
                          			cancel: {
                          				text: '否'
                          			}
                          		}
                              });
                        }
    </script>
}