<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改广告</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="<?php echo base_url();?>public/js/bootstrap/bootstrap.min.css" >
    <link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
    <link rel="stylesheet" href="<?php echo base_url();?>public/css/jquery.timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/select2/select2.min.css">
    <link rel="stylesheet" href="<?php echo base_url();?>public/js/date/datedropper.min.css">
    <script src="<?php echo base_url();?>public/js/date/datedropper.min.js"></script>
    <style type="text/css">
        .thumbnail {
            margin:10px;
        }

        .lang-name {
            margin-left:42px;
        }

        .upimg {
            cursor: pointer;
        }

    </style>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-12">
            <aside>
                <hr>
                <section>
                    <div class="container-fluid">
                        <div class="row">
                            <label class="col-sm-3 control-label"><i class="fa fa-fw fa-file"></i>等級推送范围值</label>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="downLevel" value="<?php echo $downLevel;?>" name="downLevel"/>
                            </div>
                            <div class="col-sm-1">
                                <button type="button" class="btn btn-success" onclick="setModel()">提交</button>
                            </div>
                        </div>
                    </div>
                </section>
            </aside>
        </div>
    </div>
</div>
<hr>

<div class="container-fluid" style="margin-top: 2rem">
    <div class="row">
        <div class="col-sm-12">
            <aside>
                <header><i class="fa fa-fw fa-file"></i>新增等級推送文案</header>
                <hr>
                <section>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <form class="form-horizontal J_ajaxForm" role="form" method="post" action="push/actionUpdateLevel" data-callBack="message" id="actionUpdateLevel">
                                    <div class="modal-body">
                                        <style>
                                            .time{
                                                height: 34px;
                                                padding: 6px 12px;
                                                font-size: 14px;
                                                line-height: 1.42857143;
                                                color: #555;
                                                background-color: #fff;
                                                background-image: none;
                                                border: 1px solid #ccc;
                                                border-radius: 4px;
                                            }

                                        </style>
                                        <div id="langDiv" >
                                            <?php foreach ($lang as $key=>$row) { ?>
                                                <div class="form-group">
                                                    <label class="col-sm-3 control-label"><?php echo $row;?></label>
                                                    <div class="col-sm-6">
                                                        <input type="text" class="form-control" value="<?php echo $content[$key]['title'];?>" name="title[<?php echo $key;?>]"/>
                                                        <textarea  rows="7" cols="50" class="form-control" name="content[<?php echo $key;?>]"><?php echo $content[$key]['content'];?></textarea>
                                                    </div>
                                                </div>
                                            <?php }?>
                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                        <button type="button" class="btn btn-primary" id="submit">提交</button>
                                        <button type="button" class="J_ajaxSubmitBtn" style="display:none;" ></button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </section>
            </aside>
        </div>
    </div>
</div>

</body>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script src="<?php echo base_url();?>public/js/common.js"></script>
<script>
    function message(returnData, $from) {
        if(returnData.ret == 0){
            console.log(1);
            // window.location.reload();
        }
    }

    function  setModel() {
        var downLevel = $('#downLevel').val();
        $.post('push/actionDownLevel',{
            downLevel : downLevel
        },function (data) {
            alert('修改成功')
        });
    }



    $(document).on("click","#submit",function(){
        $(this).parent().find(".J_ajaxSubmitBtn").click();
    });

    //添加更新内容
    $('#langContentPri').change(function () {
        var langContent, contentMatch;
        langContent = $('#langContentPri').val();

        //英文更新
        contentMatch = langContent.match(/<en-US>([\s\S]*?)<\/en-US>/);
        showContent(contentMatch, $('#langDiv .en_title'), $('#langDiv  .en_content'));

        //德語更新
        contentMatch = langContent.match(/<de-DE>([\s\S]*?)<\/de-DE>/);
        showContent(contentMatch, $('#langDiv .de_title'), $('#langDiv  .de_content'));

        //西班牙更新
        contentMatch = langContent.match(/<es-ES>([\s\S]*?)<\/es-ES>/);
        showContent(contentMatch, $('#langDiv .es_title'), $('#langDiv  .es_content'));

        //法語更新
        contentMatch = langContent.match(/<fr-FR>([\s\S]*?)<\/fr-FR>/);
        showContent(contentMatch, $('#langDiv .fr_title'), $('#langDiv  .fr_content'));

        //法語更新
        contentMatch = langContent.match(/<pt-PT>([\s\S]*?)<\/pt-PT>/);
        showContent(contentMatch, $('#langDiv .pt_title'), $('#langDiv  .pt_content'));

        //泰文更新
        contentMatch = langContent.match(/<th>([\s\S]*?)<\/th>/);
        console.log(contentMatch);
        showContent(contentMatch, $('#langDiv .th_title'), $('#langDiv  .th_content'));

        //中文更新
        contentMatch = langContent.match(/<zh-CN>([\s\S]*?)<\/zh-CN>/);
        showContent(contentMatch, $('#langDiv .zh_title'), $('#langDiv  .zh_content'));

        //台湾更新
        contentMatch = langContent.match(/<zh-TW>([\s\S]*?)<\/zh-TW>/);
        showContent(contentMatch, $('#langDiv .tw_title'), $('#langDiv  .tw_content'));

        //印地语更新
        contentMatch = langContent.match(/<hi>([\s\S]*?)<\/hi>/);
        showContent(contentMatch, $('#langDiv .hi_title'), $('#langDiv  .hi_content'));

        //俄语更新
        contentMatch = langContent.match(/<ru>([\s\S]*?)<\/ru>/);
        showContent(contentMatch, $('#langDiv .ru_title'), $('#langDiv  .ru_content'));

    });

    /**
     * 更加输入内容截取显示标题和内容
     * @param contentMatch
     * @param titleElement
     * @param contentElement
     */
    function showContent(contentMatch, titleElement, contentElement) {
        var content = '', contentArr = [];
        if(!isEmpty(contentMatch)) {
            content = contentMatch[1];
            contentArr = content.trim().split(/[\n]/);
            if(contentArr.length > 0) {//如果截取的数组不为空，则取第一个为标题，其他的为内容
                content = contentArr[0]
            }
        }
        contentElement.val(content);
    }
</script>
</html>