<!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">

    <style type="text/css">
        .thumbnail {
            margin:10px;
        }

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

        .upimg {
            cursor: pointer;
        }

    </style>
</head>
<body>
<div id="msg-tip">

</div>
<div class="content_wrapper">
    <div class="container-fluid">
        <aside>
            <header><i class="fa fa-fw fa-file"></i>语言配置</header>
            <section>
                <div class="container-fluid">
                    <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  action="#" style="margin-top: 20px">
                        <div class="form-group">
                            <div class="col-sm-2">
                                <select class="form-control typeControl" name="lang" id="lang">
                                    <?php foreach ($lang as $key => $vl) { ?>
                                        <option value="<?php echo $key;?>" <?php if($curLang == $key) echo 'selected';?>><?php echo $vl;?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <div class="col-sm-2">
                                <select class="form-control" name="class" id="class" >
                                    <?php foreach ($class as $key => $vl) { ?>
                                        <option value="<?php echo $vl['path'];?>" <?php if($curClass == $vl['path']) echo 'selected';?>><?php echo $vl['name'];?></option>
                                    <?php } ?>
                                </select>
                            </div>
                            <button type="button" class="btn btn-primary" id="submit">确定</button>
                        </div>
                    </form>
                </div>
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-sm-12">
                            <button type="button" class="btn btn-success" id="configsubmitBtn">提交</button>
                        </div>
                    </div>
                </div>
                <div class="container-fluid" style="border: 1px solid #CCC;margin: 20px 15px;padding: 10px 0;"">
                    <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" id="configForm" action="#" style="margin-top: 20px">
                        <input type="hidden" name="lang" value="<?php echo $curLang;?>">
                        <input type="hidden" name="class" value="<?php echo $curClass;?>">
                        <div id="addDiv">
                            <?php foreach ($data as $key => $vl) { ?>
                                <div class="row">
                                    <?php if($key !=0 ){ echo "<label class=\"col-sm-1 control-label\"></label>";}else{ echo '<label class="col-sm-1 control-label" style="text-align: right;">翻译数据*: </label>'; }?>
                                    <div class="col-sm-10">
                                        <div class="col-sm-4">
                                            <span style="display: inline-block">名称:</span>
                                            <input type="text" class="form-control" readonly name="name[]" value="<?php echo $vl['name'];?>" style="display: inline-block;width: 85%;">
                                        </div>
                                        <div class="col-sm-4">
                                            <span style="display: inline-block">唯一键:</span>
                                            <input type="text" class="form-control" name="path[]" value="<?php echo $vl['path'];?>" style="display: inline-block;width: 85%;">
                                        </div>
                                        <div class="col-sm-4">
                                            <span style="display: inline-block">值:</span>
                                            <input type="text" class="form-control" name="value[]" value="<?php echo $vl['value'];?>" style="display: inline-block;width: 85%;">
                                        </div>
                                    </div>
                                    <div class="col-sm-1">
                                        <button type="button" class="btn btn-danger delButton">删除</button>
                                    </div>
                                </div>
                            <?php } ?>
                        </div>
                        <button type="button" class="btn btn-success" style="margin-left: 1%;" id="addButton">新增</button>
                    </form>
                </div>
            </section>
        </aside>
    </div>
</div>
</body>

<script>
    $(function () {
        $('#submit').click(function () {
            var lang  = $('#lang').val();
            var classs = $('#class').val();
            window.location.href = "#lang/index/"+lang+'/'+classs;
        });
        $('#addButton').click(function () {
            var sHtml = '<div class="row"><label class="col-sm-1 control-label"></label><div class="col-sm-10"><div class="col-sm-4"><span style="display: inline-block">名称:</span><input type="text" class="form-control" name="name[]" value="" style="display: inline-block;width: 85%">'
                        +'</div><div class="col-sm-4"><span style="display: inline-block">唯一键:</span><input type="text" class="form-control" name="path[]" value="" style="display: inline-block;width: 85%">\</div><div class="col-sm-4"><span style="display: inline-block">值:</span>'
                        +'<input type="text" class="form-control" name="value[]" value="" style="display: inline-block;width: 85%"></div></div><div class="col-sm-1"><button type="button" class="btn btn-danger delButton">删除</button></div></div>';
            $('#addDiv').append(sHtml);

        });
        $('#addDiv').on("click",'.delButton',function(){
            $(this).parent().parent().remove();
        });

        $('#configsubmitBtn').click(function () {
            var data = new FormData(document.getElementById("configForm"));
            $.ajax({
                url: rootPath + 'Lang/actionLang',
                type: 'POST',
                data: data,
                dataType: 'json',
                contentType: false, //必须
                processData: false, //必须
                success: function (data) {
                    alert(data.msg);
                    window.location.reload();
                },
                error: function (msg) {
                    alert(data.msg);
                }
            });
        });
    });
</script>
</html>
