<%@ page title="" language="C#" masterpagefile="~/lovecenter/LoveCenterMaster.master" autoeventwireup="true" inherits="lovecenter_PersonPlans, App_Web_ubyenibr" enableEventValidation="false" %>
<%@ Import Namespace="System.Collections.Generic" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link href="/css/blitzer/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="/js/data.js"></script>
    <script type="text/javascript" src="/js/jqueryui.js"></script>
    <script type="text/javascript" src="/js/ui.datepicker-zh-CN.js"></script>
    <script type="text/javascript">
        var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
        var mType = "<%= type %>";
        $(function() {
            jQuery.fx.off = true;
            getCnt("all", $(".tabs li").get()[0]);

            $(".addnew").click(function() {
            $(".table").append("<tr class='newrow irow bord'><td class='c1'><input class='chk' type='checkbox' /></td><td class='c2'><input class='txt date' type='text' /> <span></span></td><td class='c3'><input maxlength='50' class='txt desc' type='text' value='请输入内容' /></td><td class='c4'><a href='#'><img src='/images/del.gif' /></a></td></tr>");
                bindEvent();

                $(".table input:last").get()[0].focus();
                $(".table input:last").get()[0].select();
            });
            setInterval(function() {
                $(".loading").css("top", 50 + scrollTop());
            }, 100);
        });

        function getDateByString(str) {
            var spt = str.split('-');
            return new Date(spt[1] + "/" + spt[2] + "/" + spt[0]);
        }

        function getDateString(d) {
            return d.getFullYear().toString() + "-" + d.getMonth() + "-" + d.getDate();
        }

        function getCnt(listVal, sender) {
            $(".tabs li").removeClass("chked");
            $(sender).addClass("chked");
            $(".loading").show();
            $.ajax({
                url: "/inc/aspx/PersonPlanService.aspx",
                data: { act: "get", list: listVal,
                    type: mType
                },
                cache: false,
                success: function(html) {
                    $(".tabcnt").html(html);
                    $(".loading").hide();
                    bindEvent();
                }
            });
        }

        function bindEvent() {
            $(".desc").hover(function() {
                //this.focus();
                $(this).addClass("hover");
            }, function() {
                $(this).removeClass("hover");
            });
            
            $(".date").datepicker({ showOn: 'button', buttonImage: '/images/calendar.gif', buttonImageOnly: true, changeMonth: true, changeYear: true });
            $(".txt").unbind("change");
            $(".date").bind("change", function() {
                var sender = this;
                $(".loading").show();

                $.ajax({
                    url: "/inc/aspx/PersonPlanService.aspx",
                    data: { act: "updatetime", val: $(this).val(),
                        id: $(sender).parent().parent().attr("id"),
                        status: $(sender).parent().parent().find(".chk").attr("checked"),
                        date: $(sender).parent().parent().find(".date").val(),
                        descr: $(sender).parent().parent().find(".desc").val(),
                        type: mType
                    },
                    cache: false,
                    success: function(html) {
                        $(".loading").hide();
                        /*
                        if (html != "1") {
                        alert(html);
                        return;
                        }
                        */
                        if ($(this).parent().parent().attr("id") == "") {
                            $(this).parent().parent().attr("id", html);
                        }

                        // 将当前行移动到目标位置
                        var date = getDateByString($(sender).val());
                        var fullrow = null;
                        $(".fullrow").each(function() {
                            if (date >= getDateByString($(this).attr("start")) &&
                                date <= getDateByString($(this).attr("end"))) {
                                fullrow = this;
                            }
                        });

                        var found = false;
                        $(".irow").each(function() {
                            if (getDateByString($(this).find(".date").val()) < date &&
                                $(this).attr("index") == $(fullrow).attr("index")) {
                                $(this).after($(sender).parent().parent());
                                $(sender).parent().parent().attr("index", $(fullrow).attr("index"));
                                found = true;
                            }
                        });

                        if (!found) {
                            if (fullrow == null) {
                                alert("提示：该项目将移动到其他时间模块中。");
                                $(sender).parent().parent().remove();
                                return;
                            }
                            else {
                                $(fullrow).after($(sender).parent().parent());
                                $(sender).parent().parent().attr("index", $(fullrow).attr("index"));
                            }
                        }

                        $(sender).parent().find("span").html(weeks[date.getDay()]);
                        $(sender).parent().parent().removeClass("newrow");

                        var tick = 0;
                        var handler;
                        $(sender).parent().parent().find(".desc").get()[0].focus();
                        handler = setInterval(function() {
                            $(sender).parent().parent().toggleClass("bord");
                            tick++;

                            if (tick > 8) {
                                $(sender).parent().parent().removeClass("bord");
                                clearInterval(handler);
                            }
                        }, 350);
                    }
                });
            });

            $(".desc").bind("change", function() {
                $(".loading").show();
                $.ajax({
                    url: "/inc/aspx/PersonPlanService.aspx",
                    data: { act: "updatecnt", val: $(this).val(), id: $(this).parent().parent().attr("id"),
                        type: mType
                    },
                    cache: false,
                    success: function(html) {
                        $(".loading").hide();
                        if (html != "1") {
                            alert(html);
                            return;
                        }
                    }
                });
            });

            $(".chk").unbind("change");
            $(".chk").bind("click", function() {
                $(".loading").show();
                $.ajax({
                    url: "/inc/aspx/PersonPlanService.aspx",
                    data: { act: "updatestatus", val: $(this).attr("checked"), id: $(this).parent().parent().attr("id"),
                        type: mType
                    },
                    cache: false,
                    success: function(html) {
                        $(".loading").hide();
                        if (html != "1") {
                            alert(html);
                            return;
                        }
                    }
                });
            });

            $(".c4 a").unbind("change");
            $(".c4 a").bind("click", function() {
                var sender_ = this;
                if (confirm("确实要删除“" + $(this).parent().parent().find(".date").val() + " " + $(this).parent().parent().find(".desc").val() + "”吗？")) {
                    $(".loading").show();
                    $.ajax({
                        url: "/inc/aspx/PersonPlanService.aspx",
                        data: { act: "delete", id: $(this).parent().parent().attr("id"),
                            type: mType
                        },
                        cache: false,
                        success: function(html) {
                            $(".loading").hide();
                            if (html != "1") {
                                alert(html);
                                return;
                            }
                            $(sender_).parent().parent().remove();
                        }
                    });
                }
            });
        }

        function scrollTop() {
            if (document.documentElement && document.documentElement.scrollTop) {   // Explorer 6 Strict
                return document.documentElement.scrollTop;
            } else if (document.body) {// all other Explorers
                return document.body.scrollTop;
            }
        }

        function resetAll() {
            if (confirm('确实要重设所有项吗？'))
                window.location = 'personplans.aspx?act=clear&type=' + mType;
            else
                return;
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="rightbody personplans">
        <div class="menutit">
            代办事项
        </div>
        <div class="bodycotent">
            <div class="menutab">
                <div class="menuitem">
                    <a href="personplans.aspx?type=1" <%= type == "1" ? "class='chk'" : "" %>>订婚计划</a>
                    <a href="personplans.aspx?type=2" <%= type != "1" ? "class='chk'" : "" %>>结婚计划</a>
                </div>
                <div class="menusub">
                    <%if (type == "1")
                      { %>
                    <span>您的订婚日期是：<label><%= pud.engagementdate.ToString("yyyy年MM月dd日")%></label></span>
                    <a href="PersonInfo.aspx">修改订婚日期</a> 
                    <%}
                      else
                      { %>
                    <span>您的结婚日期是：<label>
                    <a href="PersonInfo.aspx">修改结婚日期</a> 
                    <%} %>
                    <%= pud.marrydate.ToString("yyyy年MM月dd日") %></label></span>
                    <a href="javascript:resetAll();">重设所有事项</a> 
                </div>
            </div>
            <div class="body">
                <div class="descr"></div>
                <div class="list inputs">
                    <div class="loading">
                        正在载入..
                    </div>
                    <ul class="tabs">
                        <li class="chked" onclick="javascript:getCnt('all',this);">所有时间</li>
                    <%
                        int i = 0;
                        foreach (object[] item in Utils.GetPersonPlanSysDates(type))
                        {
                         %>
                        <li onclick="javascript:getCnt('<%= i %>',this);"><%= item[2] %></li>
                        <%
                            i++;
                        } %>
                    </ul>
                    <div class="clear"></div>
                    <div class="tabcnt">
                    </div>
                </div>
                <div class="submits">
                    <a class="okbtn addnew" href="javascript:void(0);">新增项</a>
                    <a class="okbtn" href="javascript:window.print();">打印</a>
                </div>
            </div>
        </div>
    </div>
</asp:Content>

