<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyGroupAlbum.ascx.cs" Inherits="AVA.ResourcesPlatform.WebUI.Control.My.MyGroupAlbum" %>
<div class="well">
    <div class="p_title">
        <span class="title">小组专辑:</span>我的<%= this.Query.RecordCount %>个小组专辑
    </div>
    <div class="dataControl box">
        <form id="frmGroupAlbumSearch" method="post" action="<%= WebUrl.Proxy() %>">
        名称:
        <%= new HtmlText("Name", this.Name) { Width = 120 }%>
        锁:
        <%= new HtmlSelect("LockAlbum", "Value", "Key", "Key") { Option = typeof(AVA.ResourcesPlatform.Model.Pub.VideoLockVideoEnum) }.InsertOption("::选择::", "", 0).SelectValue(this.LockAlbum)%>
        审核:
        <%= new HtmlSelect("Examine", "Value", "Key", "Key") { Option = typeof(AVA.ResourcesPlatform.Model.Pub.VideoExamineEnum) }.InsertOption("::选择::", "", 0).SelectValue(this.Examine)%>
        日期从
        <%= new HtmlText("CreateTimeBegin", this.CreateTimeBegin.ToShortDate()) { Width = 80 }%>
        至
        <%= new HtmlText("CreateTimeEnd", this.CreateTimeEnd.ToShortDate()) { Width = 80 }%>
        <%= new HtmlHidden("Key","MyGroupAlbum") %>
        <%= new HtmlSubmit("查询") %>
        <%= new HtmlReset("清除") { Class="btn"}%>
        </form>
        <script type="text/javascript">
            $(function () {
                $("#frmGroupAlbumSearch [name=CreateTimeBegin]").datepicker({
                    maxDate: new Date($("#frmGroupAlbumSearch [name=CreateTimeEnd]").val()),
                    onClose: function () {
                        $("#frmGroupAlbumSearch [name=CreateTimeEnd]").datepicker("option", "minDate", new Date(this.value));
                    }
                });
                $("#frmGroupAlbumSearch [name=CreateTimeEnd]").datepicker({
                    minDate: new Date($("#frmGroupAlbumSearch [name=CreateTimeBegin]").val()),
                    onClose: function () {
                        $("#frmGroupAlbumSearch [name=CreateTimeBegin]").datepicker("option", "maxDate", new Date(this.value));
                    }
                });
            });
        </script>
    </div>
    <div id="MyGroupAlbumData" class="data">
        <table cellspacing="0" cellpadding="0" width="100%">
            <tbody>
                <tr id="dataHead" class="dataHead">
                    <td valign="middle" class="sel" style="width: 20px;">
                        <input type="checkbox" class="trselall" />
                    </td>
                    <td valign="middle">专辑 </td>
                    <td valign="middle" class="disabled">创建日期 </td>
                    <td valign="middle" class="disabled">视频个数 </td>
                </tr>
                <!--注意 数据行 第一行 和 最后一行 有样式  请加判断添加 当只有一行时 class="firstLine lastLine"-->
                <%
                    for (int i = 0; i <= this.ListAlbum.Count - 1; i++)
                    {
                        var album = this.ListAlbum[i];
                %>
                <tr class='<%= i == 0 ? "firstLine" : ""  %> <%= i == this.ListAlbum.Count - 1 ? "lastLine" : ""  %>'>
                    <td class="sel">
                        <%= new HtmlCheckBox() { Value = SetKey(album.Guid, album.Version), Class = "trsel", Title = DefineEnum.选择_不选.Define() }%>
                    </td>
                    <td class="v">
                        <ul>
                            <li>
                                <%= new HtmlAnchor(
                                new HtmlImg(SettingGroup.AlbumCover(album), album.Name) { Width=100, Height=62, OnErrorImg=SettingGroup.DefaultImg}
                                ) { Title = album.Name, Href = WebUrl.MyAlbumVideo(album.Guid), Target = "_blank" }%>
                            </li>
                            <li>
                                <p>
                                    <%= new HtmlAnchor(album.Name) { Href = WebUrl.MyAlbumVideo(album.Guid), Target = "_blank" }%>
                                    <br />
                                    <%
                        var classStatus = "";
                        if (album.Status == (int)AVA.ResourcesPlatform.Model.Pub.AlbumStatusEnum.有效)
                        {
                            classStatus = "pass";
                        }
                        else
                        {
                            classStatus = "";
                        }
                                    %>
                                    <span class="<%=classStatus  %>">
                                        <%= ((AVA.ResourcesPlatform.Model.Pub.AlbumStatusEnum)album.Status).Define() %>
                                    </span>
                                    <%
                    var classExamine = "";
                    if (album.Examine == (int)AVA.ResourcesPlatform.Model.Pub.AlbumExamineEnum.审核通过)
                    {
                        classExamine = "pass";
                    }
                    else if (album.Examine == (int)AVA.ResourcesPlatform.Model.Pub.AlbumExamineEnum.审核不通过)
                    { }
                    else
                    {
                        classExamine = "";
                    }
                                    %>
                                    <span class="<%=classExamine  %>">
                                        <%= ((AVA.ResourcesPlatform.Model.Pub.AlbumExamineEnum)album.Examine).Define() %>
                                    </span>
                                    <%
                        if (album.LockAlbum == (int)AVA.ResourcesPlatform.Model.Pub.AlbumLockAlbumEnum.锁定)
                        {
                                    %>
                                    <%= new HtmlSpan("锁定") { Title = album.ParentLockUser.UserName + " " + album.LockDateTime + " " + album.LockDescription }.Style(new { Color = "Red" })%>
                                    <% 
                    }
                                    %>
                                    <br />
                                    播放:<%= album.VideoView%>
                                    评论:<%= album.CommentCount%>
                                </p>
                            </li>
                        </ul>
                    </td>
                    <td>
                        <%= album.CreateTime.ToDateTimeN().ToShortDate() %>
                    </td>
                    <td>
                        <%= CreateInstance.AlbumVideoDao.Count(l=>l.ParentAlbum== album) %>
                    </td>
                </tr>
                <% 
                    }
                %>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
        $("#MyGroupAlbumData .trselall").click(function () {
            if (this.checked == true) {
                $("#MyGroupAlbumData .trsel").attr("checked", "checked");
            }
            else {
                $("#MyGroupAlbumData .trsel").removeAttr("checked");
            }
        })
        function SelectMyGroupAlbumAll() {
            var bool = $("#MyGroupAlbumData .trselall").attr("checked");
            bool = !bool;
            if (bool == true) {
                $("#MyGroupAlbumData .trsel").attr("checked", "checked");
                $("#MyGroupAlbumData .trselall").attr("checked", "checked");
            }
            else {
                $("#MyGroupAlbumData .trsel").removeAttr("checked");
                $("#MyGroupAlbumData .trselall").removeAttr("checked");
            }
        }
    </script>
    <div>
        <a onclick="SelectMyGroupAlbumAll(); return false;" href="#">全选 - 取消</a>
    </div>
    <%= new PagerAjaxInstance(this) { RecordCount = this.Query.RecordCount, PageRecordSize = this.Query.PageSize, PageIndex = this.Query.PageIndex, PageJsFn = WebUrl.MyGroupAlbum(int.MaxValue, this.Name, this.CreateTimeBegin.ToString(null), this.CreateTimeEnd.ToString(null), this.LockAlbum.ToString(null), this.Examine.ToString(null)) }.ToHtml()%>
    <div class="dataControl box">
        <%= new HtmlButton("加锁", "AlbumBatchLock(this);")%>
        <%= new HtmlButton("解锁", "AlbumBatchUnLock(this);")%>
        <%= new HtmlButton("审核通过", "AlbumBatchExamine(this);")%>
        <%= new HtmlButton("审核不通过", "AlbumBatchUnExamine(this);")%>
        <%= new HtmlButton("删除", "AlbumBatchDelete(this);")%>
    </div>
</div>
<script type="text/javascript">
    //批量删除
    function AlbumBatchDelete(send) {
        var items = $("#MyGroupAlbumData .trsel:checked");
        var key = "";
        for (var i = 0; i <= items.length - 1; i++) {
            key += "pkid=" + encodeURIComponent(items[i].value);
            if (i != items.length - 1) {
                key += "&";
            }
        }
        if (key != "") {
            if (confirm("确认删除勾选的专辑吗?") == true) {
                $.ajax(
                    {
                        cache: false,
                        type: "POST",
                        url: Global.Site + "/Ajax.aspx?AVA.ResourcesPlatform.Ajax.ClientAjax.AlbumBatchDelete",
                        data: key,
                        async: true,
                        dataType: 'json',
                        success: function (result) {
                            $(send).val("删除");
                            alert("专辑删除成功")
                            Global.Disabled(send, false);
                            $("#frmGroupAlbumSearch").submit();
                        },
                        beforeSend: function () {
                            $(send).val("提交删除...");
                            Global.Disabled(send, true);
                        },
                        complete: function () {
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            $(send).val("删除");
                            Global.Disabled(send, false);
                            var message = XMLHttpRequest.responseText;
                            Global.Error(message);
                        }
                    });
            }
        }
        else {
            alert("请勾选要删除的专辑!");
        }
    };

    //批量加锁
    function AlbumBatchLock(send) {
        var items = $("#MyGroupAlbumData .trsel:checked");
        var key = "";
        for (var i = 0; i <= items.length - 1; i++) {
            key += "pkid=" + encodeURIComponent(items[i].value);
            if (i != items.length - 1) {
                key += "&";
            }
        }
        if (key != "") {
            if (confirm("确认加锁勾选的专辑吗?") == true) {
                var lockDescription = window.prompt("要输入锁定说明吗?", "");
                $.ajax(
                    {
                        cache: false,
                        type: "POST",
                        url: Global.Site + "/Ajax.aspx?AVA.ResourcesPlatform.Ajax.ClientAjax.AlbumBatchLock",
                        data: key + "&LockDescription=" + encodeURIComponent(lockDescription),
                        async: true,
                        dataType: 'json',
                        success: function (result) {
                            $(send).val("加锁");
                            alert("专辑加锁成功")
                            Global.Disabled(send, false);
                            $("#frmGroupAlbumSearch").submit();
                        },
                        beforeSend: function () {
                            $(send).val("提交加锁...");
                            Global.Disabled(send, true);
                        },
                        complete: function () {
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            $(send).val("加锁");
                            Global.Disabled(send, false);
                            var message = XMLHttpRequest.responseText;
                            Global.Error(message);
                        }
                    });
            }
        }
        else {
            alert("请勾选要加锁的专辑!");
        }
    };

    //批量解锁
    function AlbumBatchUnLock(send) {
        var items = $("#MyGroupAlbumData .trsel:checked");
        var key = "";
        for (var i = 0; i <= items.length - 1; i++) {
            key += "pkid=" + encodeURIComponent(items[i].value);
            if (i != items.length - 1) {
                key += "&";
            }
        }
        if (key != "") {
            if (confirm("确认解锁勾选的专辑吗?") == true) {
                $.ajax(
                    {
                        cache: false,
                        type: "POST",
                        url: Global.Site + "/Ajax.aspx?AVA.ResourcesPlatform.Ajax.ClientAjax.AlbumBatchUnLock",
                        data: key,
                        async: true,
                        dataType: 'json',
                        success: function (result) {
                            $(send).val("解锁");
                            alert("专辑解锁成功")
                            Global.Disabled(send, false);
                            $("#frmGroupAlbumSearch").submit();
                        },
                        beforeSend: function () {
                            $(send).val("提交解锁通过...");
                            Global.Disabled(send, true);
                        },
                        complete: function () {
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            $(send).val("解锁");
                            Global.Disabled(send, false);
                            var message = XMLHttpRequest.responseText;
                            Global.Error(message);
                        }
                    });
            }
        }
        else {
            alert("请勾选要审核通过的专辑!");
        }
    };

    //批量审核通过
    function AlbumBatchExamine(send) {
        var items = $("#MyGroupAlbumData .trsel:checked");
        var key = "";
        for (var i = 0; i <= items.length - 1; i++) {
            key += "pkid=" + encodeURIComponent(items[i].value);
            if (i != items.length - 1) {
                key += "&";
            }
        }
        if (key != "") {
            if (confirm("确认审核通过勾选的专辑吗?") == true) {
                $.ajax(
                    {
                        cache: false,
                        type: "POST",
                        url: Global.Site + "/Ajax.aspx?AVA.ResourcesPlatform.Ajax.ClientAjax.AlbumBatchExamine",
                        data: key,
                        async: true,
                        dataType: 'json',
                        success: function (result) {
                            $(send).val("审核通过");
                            alert("专辑审核通过成功")
                            Global.Disabled(send, false);
                            $("#frmGroupAlbumSearch").submit();
                        },
                        beforeSend: function () {
                            $(send).val("提交审核通过...");
                            Global.Disabled(send, true);
                        },
                        complete: function () {
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            $(send).val("审核通过");
                            Global.Disabled(send, false);
                            var message = XMLHttpRequest.responseText;
                            Global.Error(message);
                        }
                    });
            }
        }
        else {
            alert("请勾选要审核通过的专辑!");
        }
    };

    //批量审核不通过
    function AlbumBatchUnExamine(send) {
        var items = $("#MyGroupAlbumData .trsel:checked");
        var key = "";
        for (var i = 0; i <= items.length - 1; i++) {
            key += "pkid=" + encodeURIComponent(items[i].value);
            if (i != items.length - 1) {
                key += "&";
            }
        }
        if (key != "") {
            if (confirm("确认审核不通过勾选的专辑吗?") == true) {
                $.ajax(
                    {
                        cache: false,
                        type: "POST",
                        url: Global.Site + "/Ajax.aspx?AVA.ResourcesPlatform.Ajax.ClientAjax.AlbumBatchUnExamine",
                        data: key,
                        async: true,
                        dataType: 'json',
                        success: function (result) {
                            $(send).val("审核不通过");
                            alert("专辑审核不通过成功")
                            Global.Disabled(send, false);
                            $("#frmGroupAlbumSearch").submit();
                        },
                        beforeSend: function () {
                            $(send).val("提交审核不通过...");
                            Global.Disabled(send, true);
                        },
                        complete: function () {
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            $(send).val("审核不通过");
                            Global.Disabled(send, false);
                            var message = XMLHttpRequest.responseText;
                            Global.Error(message);
                        }
                    });
            }
        }
        else {
            alert("请勾选要审核不通过的专辑!");
        }
    };
</script>