<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <base href="#springUrl('/assets/adminlte/')"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工作台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="plugins/ionicons/css/ionicons.min.css">

    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">

    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <!--validate css-->
    <link rel="stylesheet" href="plugins/jquery-validation/css/validate.css">
    <!--fileinput css-->
    <link rel="stylesheet" href="plugins/bootstrap-fileinput/bootstrap-fileinput.css">
    <link rel="stylesheet" type="text/css" media="all" href="plugins/daterangepicker-master/daterangepicker.css"/>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>

    <![endif]-->
</head>
<!-- END HEAD -->
<body class="hold-transition skin-blue sidebar-mini">

<div class="wrapper">
    <div class="content-wrapper" style="margin-left:0;">

        <section class="content-header">
            <h1>
                研讨会模板消息管理
                <small>研讨会模板消息</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>首页</a></li>
                <li><a class="active">研讨会模板消息</a></li>
            </ol>
        </section>


        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-9">
                    <!-- general form elements disabled -->
                    <div class="box box-primary">
                        <form role="form" id="myForm">
                            <input name="id" value="$!{data.id}" hidden="true"/>
                            <input name="meetingId" value="$!{meetingId}" hidden="true"/>
                            <input name="templateId" value="$!{data.templateId}" hidden="ture">
                            <div class="box-body">
                                <div class="form-group form-md-line-input">
                                    <label>模板类型</label>
                                    <select class="form-control" name="type">
                                        <option value="">请选择消息类型</option>
                                        <option value="0">参加会议通知(所有没有提接机送机信息的客户)</option>
                                        <option value="1">参加会议通知(所有需要接机安排的客户)</option>
                                        <option value="2">会议通知(所有报名客户+内部人)</option>
                                        <option value="3">参加会议通知(所有报名客户+内部人)</option>
                                    </select>
                                </div>
                                <div class="form-group form-md-line-input" id="sendTimeStrDiv">
                                    <label>消息推送时间</label>
                                    <input type="text"
                                           class="form-control datepicker" name="sendTimeStr"
                                           id="explain"
                                           maxlength="200" placeholder="消息推送时间"
                                           value="$!{data.sendTimeStr}" readonly
                                           required="required"
                                    >
                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>短信内容(无需加短信签名)</label>
                                    <textarea name="sendMessage" class="form-control" cols="50" rows="10"></textarea>
                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>链接</label>
                                    <input type="text"
                                           class="form-control" name="url"
                                           id="url"
                                           maxlength="500" placeholder="链接"
                                           value="$!{data.url}"

                                    >
                                </div>
                                <input type="text" style="display: none" name="_csrf" value="${_csrf.token}"/>
                                <input type="text" style="display: none" name="_csrf_header"
                                       value="${_csrf.headerName}"/>
                            </div>

                            <div class="box-footer">
                                #if($shiro.hasPermission("qy:templateMessage:edit"))
                                <input class="btn btn-primary" id="save" value="保存" type="submit">
                                #end
                                <a href="#springUrl('/a/templateMessage/list?meetingId=')${meetingId}" class="btn btn-default">取消</a>
                            </div>
                        </form>
                        <!-- /.box-body -->
                    </div><!-- /.box -->
                </div>
                <div class="col-xs-3">
                    <div class="box box-primary" style="line-height: 10px;padding: 15px 10px;display: none;"
                         id="templateTest">
                        <p style="font-size: 18px;" class="templateTitle"></p>
                        <p style="font-size: 12px;color: #666" class="templateDate">6月8日</p>
                        <p style="margin: 15px 0 20px 0;" class="templateFirst"></p>
                        <p class="remarks"></p>
                    </div>
                </div>
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->


    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div><!-- ./wrapper -->

<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/extensions/i18n/lanauage_ch.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!--fileinput js-->
<script src="plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script src="plugins/bootstrap-maxlength/bootstrap-maxlength.min.js" type="text/javascript"></script>
<script src="plugins/security/sha256.js" type="text/javascript"></script>
<script src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<script src="js/jquery.form.min.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/lang/zh-cn/zh-cn.js"></script>
<script src="common/js/cfapp.js"></script>

<script type="text/javascript" src="plugins/daterangepicker-master/moment.min.js"></script>
<script type="text/javascript" src="plugins/daterangepicker-master/daterangepicker.js"></script>
<script src="js/jquery.serializejson.js"></script>
<!-- END PAGE LEVEL PLUGINS -->
<script>
    var locale = {
        "format": 'YYYY-MM-DD HH:mm',
        "separator": " -222 ",
        "applyLabel": "确定",
        "cancelLabel": "取消",
        "fromLabel": "起始时间",
        "toLabel": "结束时间'",
        "customRangeLabel": "自定义",
        "weekLabel": "W",
        "daysOfWeek": ["日", "一", "二", "三", "四", "五", "六"],
        "monthNames": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        "firstDay": 1
    };
    $().ready(function () {
        Cfapp.init();
        recdTypeAdd.init();


        $('.datepicker').daterangepicker({
            'locale': locale,
            "singleDatePicker": true,
            "timePicker": true,
            "timePicker24Hour": true,
            "showCustomRangeLabel": false
        }, function (start, end, label) {
            console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
        });


        var id = $("input[name='id']").val();
        if (id != null && id != "") {
            $("#templateTest").show();
        }

        $("select[name='type']").change(function () {
            var type = $(this).val();
            $(".templateAdd").remove();
            $("#templateTest .remarks").text("");
            $("#templateTest .templateFirst").text("");
            $.getJSON("#springUrl('/assets/adminlte/json/template.json')", "", function (data) {
                for (var k = 0; k < data.length; k++) {
                    if (data[k]["type"] == type) {
                        $("input[name='templateId']").val(data[k].templateId);
                        data = data[k].data;
                        $("#templateTest .templateTitle").text(data.title);
                        var first = data.first;
                        if (first != null && first != "") {
                            var firstHtml = "<div class=\"form-group form-md-line-input templateAdd\" class='templateAdd'><label>消息头(若存在人员姓名请用{{}}占位)</label>" +
                                    "<input type=\"text\" class=\"form-control\" data-title='" + first + "' name=\"first\" placeholder=\"消息头\"" +
                                    "value=\"$!{data.sendTimeStr}\"></div>";
                            $(".box-body").append(firstHtml);
                        }
                        $("#templateTest .templateFirst").text(first);
                        var keywords = data.keywords;
                        if (keywords) {
                            var html = "";
                            var Htmls = "";
                            for (var key in keywords) {
                                html += "<p class='templateAdd'>" + keywords[key] + "</p>";
                                Htmls+= "<div class=\"form-group form-md-line-input templateAdd\" class=''><label>"+keywords[key]+"</label>" +
                                        "<input type=\"text\" data-title='" + key + "' class=\"form-control\" name=\"keyword\" placeholder=\"" + keywords[key] + "\"" +
                                        "value=\"$!{data.sendTimeStr}\"></div>";
                            }
                            $(".box-body").append(Htmls);
                            $("#templateTest .remarks").before(html);
                        }
                        var remark = data.remark;
                        if (remark != null && remark != "") {
                            var remarkHtml = "<div class=\"form-group form-md-line-input templateAdd\" class='templateAdd'><label>消息尾</label>" +
                                    "<input type=\"text\" class=\"form-control\" data-title='" + remark + "' name=\"remark\" placeholder=\"消息头\"" +
                                    "value=\"\"></div>";
                            $(".box-body").append(remarkHtml);
                            $("#templateTest .remarks").text(remark);
                        }
                    }
                }
                $("#templateTest").show();
            })
        })
    });

    function mcalert(obj){
        Cfapp.alert({
            message: obj,
            btntext: "确定",
            success: function () {

            }
        });
    }


    var recdTypeAdd = function () {
        var initForm = function () {
            var initFormCtrl = function () {
                bindEvent();
            };
            var bindEvent = function () {

                $("#myForm").validate({
                    rules: {},
                    messages: {},
                    submitHandler: function (form) {
                        $("#save").attr("disabled", true);
                        var formJson = $("#myForm").serializeJSON();
                        var content = {};
                        content.template_id=$("input[name='templateId']").val();
                        var data={};
                        var first={};
                        var firstValue=$("input[name='first']").val();
                        if(firstValue && firstValue!=null){
                            first.value=$("input[name='first']").val();
                        }else{
                            first.value="";
                        }
                        data.first=first;
                        var remarks={};
                        var remarksValue=$("input[name='remark']").val();
                        if(remarksValue && remarksValue!=null){
                            remarks.value=$("input[name='remark']").val();
                        }else{
                            remarks.value="";
                        }
                        data.remark=remarks;
                        var keywords = $("input[name='keyword']");
                        for(var k = 0;k<keywords.length;k++){
                            var obj = {};
                            var keywordTitle = $(keywords[k]).attr("data-title");
                            var keywordValue = $(keywords[k]).val();
                            obj.value=keywordValue;
                            data[keywordTitle]=obj;
                        }
                        content.data=data;
                        console.log(content);
                        formJson.content=JSON.stringify(content);
                        formJson.jobname=$("select[name='type'] option:selected").text();
                        $.post("#springUrl('/a/templateMessage/formData')",formJson, function (returnobj) {
                            $("#save").attr("disabled", false);
                            if (returnobj.errorNo == 2) {  //保存成功
                                Cfapp.confirm({
                                    message: "添加成功",
                                    btnoktext: "继续添加",
                                    btncanceltext: "关闭",
                                    success: function () {
                                        location.href = "#springUrl('/a/templateMessage/form?meetingId=')${meetingId}";
                                    },
                                    cancel: function () {
                                        location.href = "#springUrl('/a/templateMessage/list?meetingId=')${meetingId}";
                                    }
                                });
                            } else if (returnobj.errorNo == 0) {  //修改成功
                                Cfapp.alert({
                                    message: "更新成功",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/templateMessage/list')";
                                    }
                                });
                            } else {
                                Cfapp.alert({
                                    message: "创建失败",
                                    btntext: "确定",
                                    success: function () {

                                    }
                                });
                            }
                        });
                    }
                })
            }
            initFormCtrl();
        }
        return {

            //main function to initiate the module
            init: function () {
                initForm();
            }

        };
    }();
</script>
</body>
<!-- END BODY -->
</html>