<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>工作日历管理</title>
	<meta name="decorator" content="default"/>
    <link href="${ctxStatic}/bootstrap-select-1.12.4/css/bootstrap-select.min.css" rel="stylesheet" />
    <script src="${ctxStatic}/bootstrap-select-1.12.4/js/bootstrap-select.min.js"></script>
	<script type="text/javascript">
		function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            $("#inputForm").submit();
		  return true;
		}

        Date.prototype.format = function(fmt) {
            var o = {
                "M+" : this.getMonth()+1,                 //月份
                "d+" : this.getDate(),                    //日
                "h+" : this.getHours(),                   //小时
                "m+" : this.getMinutes(),                 //分
                "s+" : this.getSeconds(),                 //秒
                "q+" : Math.floor((this.getMonth()+3)/3), //季度
                "S"  : this.getMilliseconds()             //毫秒
            };
            if(/(y+)/.test(fmt)) {
                fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
            }
            for(var k in o) {
                if(new RegExp("("+ k +")").test(fmt)){
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
                }
            }
            return fmt;
        }
		$(document).ready(function() {
            repeatChg();
            {
                var val = $("#repeatType").val();
                if(val==1){
                    var arr="${workCalendar.repeatDate}".split(',');
                    $('#repeatDate').selectpicker('val',arr);
                }
            }
		});
		function repeatChg() {
            var val = $("#repeatType").val();
            if(val==''||val==0){
                $('.month').show();
                $('.selectpicker').selectpicker('hide');
                $('.selectpicker').selectpicker('deselectAll');
                $(".month").val("");
                $(".month").attr("disabled","disabled");
            }else {
                if(val==1){
                    $('.selectpicker').selectpicker('show');
                    $('.month').hide();
                }else {
                    $('.selectpicker').selectpicker('hide');
                    $('.selectpicker').selectpicker('deselectAll');
                    $('.month').show();
                }
            }
        }
	</script>
</head>
<body>
<div class="single-form">
    <div class="container view-form">
		<form:form id="inputForm" modelAttribute="workCalendar" action="${ctx}/workcalendar/workCalendar/delete" method="post" class="form-horizontal">
		<form:hidden path="id"/>
            <div class="form-group layui-row first">
                <div class="form-group-label"><h2>基本信息</h2></div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label"><span class="require-item">*</span>主    题：</label>
                    <div class="layui-input-block">
                        <form:input path="subject" htmlEscape="false" readonly="true" class="form-control required layui-input"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label"><span class="require-item">*</span>地    点：</label>
                    <div class="layui-input-block">
                        <form:input path="address" htmlEscape="false" readonly="true" class="form-control required layui-input"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm12 with-textarea">
                    <label class="layui-form-label">内    容：</label>
                    <div class="layui-input-block">
                        <form:textarea path="content" htmlEscape="false" readonly="true" rows="3" class="form-control"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label"><span class="require-item">*</span>开始日期：</label>
                    <div class="layui-input-block">
                        <input id="startDate" name="startDate" type="text" maxlength="20" readonly="true" class="form-control layui-input"
                               value="<fmt:formatDate value="${workCalendar.startDate}" pattern="yyyy-MM-dd"/>"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label">结束日期：</label>
                    <div class="layui-input-block">
                        <input id="endDate" name="endDate" type="text" maxlength="20" readonly="true" class="form-control layui-input"
                               value="<fmt:formatDate value="${workCalendar.endDate}" pattern="yyyy-MM-dd"/>"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label"><span class="require-item">*</span>重复类型：</label>
                    <div class="layui-input-block">
                            <form:select path="repeatType" disabled="true" class="form-control simple-select required query-group" onchange="repeatChg();">
                                <form:option value="" label=""/>
                                <form:options items="${fns:getDictList('calender_repeat_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                            </form:select>
                            <span class="group-sep"></span>
                            <select name="repeatDate" id="repeatDate" disabled="true" class="form-control selectpicker required layui-input query-group" multiple="true" >
                                <c:forEach items="${fns:getDictList('week_day')}" var="item">
                                    <option value="${item.label}">${item.label}</option>
                                </c:forEach>
                            </select>
                            <form:select path="repeatDate" disabled="true" class="form-control required month query-group simple-select">
                                <form:option value="" label=""/>
                                <form:options items="${fns:getDictList('month_day')}" itemLabel="label" itemValue="label" htmlEscape="false"/>
                            </form:select>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label"><span class="require-item">*</span>提醒时间：</label>
                    <div class="layui-input-block">
                            <input id="remind" readonly value="${fns:getDictLabel(workCalendar.remind,'calender_remind_type','')}" class="form-control layui-input query-group"/>
                            <span class="group-sep"></span>
                            <input name="remindTime" id="remindTime" htmlEscape="false" readonly="readonly" class="form-control layui-input query-group"
                                        value="<fmt:formatDate value="${workCalendar.remindTime}" pattern="HH:mm"/>"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label double-line"><span class="require-item">*</span>发送日常事务：</label>
                    <div class="layui-input-block">&nbsp;&nbsp;
                        <form:radiobutton class="usccClass i-checks" disabled="true" path="sendDaily" value="1" label="是"></form:radiobutton>
                        &nbsp;&nbsp;
                        <form:radiobutton class="usccClass i-checks" disabled="true" path="sendDaily" value="2" label="否"></form:radiobutton>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label">创 建 人：</label>
                    <div class="layui-input-block">
                        <form:input path="createBy.name" htmlEscape="false" readonly="true" class="form-control layui-input"/>
                        <form:hidden path="createBy.id" htmlEscape="false" readonly="true" class="form-control layui-input"/>
                    </div>
                </div>
            </div>
            <div class="form-group layui-row">
                <div class="form-group-label"><h2>日历共享人</h2></div>
                <table id="userTable" class="table table-bordered table-condensed details">
                    <thead>
                    <tr>
                        <th class="hide"></th>
                        <th>姓名</th>
                        <th>部门</th>
                        <th>职级</th>
                    </tr>
                    </thead>
                    <tbody id="userTableList">
                    </tbody>
                </table>
                <script type="text/template" id="userTpl">//<!--
                    <tr id="userList{{idx}}">
                        <td class="hide">
                            <input id="userList{{idx}}_id" name="userList[{{idx}}].id" readonly="true" value="{{row.id}}" type="hidden" class="form-control userId"/>
                        </td>
                        <td>
                        {{row.name}}
                        </td>
                        <td>
                        {{row.officeName}}
                        </td>
                        <td>
                        </td>
                    </tr>//-->
                </script>
                <script type="text/javascript">
                    var userIdx = 0, userTpl = $("#userTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");

                    $(document).ready(function() {
                        var dataBank = ${fns:toJson(workCalendar.userList)};
                        if (dataBank!=null) {
                            for (var i = 0; i < dataBank.length; i++) {
                                addRow('#userTableList', userIdx, userTpl, dataBank[i]);
                                userIdx = userIdx + 1;
                            }
                        }
                    });

                    function addRow(list, idx, tpl, row){
                        var idx1 = $("#userTableList tr").length
                        bornTemplete(list, idx, tpl, row, idx1);
                    }
                    function bornTemplete(list, idx, tpl, row, idx1){
                        $(list).append(Mustache.render(tpl, {
                            idx: idx, delBtn: true, row: row,
                            order:idx1 + 1, idx1:idx1
                        }));
                        $(list+idx).find("select").each(function(){
                            $(this).val($(this).attr("data-value"));
                        });
                        $(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
                            var ss = $(this).attr("data-value").split(',');
                            for (var i=0; i<ss.length; i++){
                                if($(this).val() == ss[i]){
                                    $(this).attr("checked","checked");
                                }
                            }
                        });
                    }
                    function delRow(obj, prefix,idx){
                        $(obj).parent().parent().remove();
                    }

                    function changeUser(ids,names,parents) {
                        var split = ids.split(',');
                        var split2 = names.split(',');
                        $("#userTableList").html("");
                        userIdx=0;
                        for(var i=0;i<split.length;i++){
                            var id = split[i];
                            if(id==''||id==null){
                                continue;
                            }
                            var obj = {'id':id,'name':split2[i],'officeName':parents[i]};
                            addRow('#userTableList',userIdx,userTpl,obj);
                            userIdx+=1;
                        }
                    }

                    function getSelectUserIds() {
                        var selectedIds = "";
                        var pidArr = $("#userTableList tr .userId");
                        for(var i=0;i<pidArr.length;i++){
                            selectedIds+=$(pidArr[i]).val();
                            selectedIds+=",";
                        }
                        return selectedIds;
                    }
                </script>
            </div>
	</form:form>
    </div>
</div>
</body>
</html>