<div class="row tile">
    <div class="col-md-12 col-md-auto">
        <div class="ibox float-e-margins">
            <h3 class="ibox-title">编辑</h3>
            <div class="ibox-content">
                <form class="form-horizontal">
                    <input type="hidden" name="id" value="{{.t.Id}}">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">mode </label>
                        <div class="col-sm-10">
                            <select class="form-control" name="type" id="type">
                                <option {{if eq "tcp" .t.Mode}}selected{{end}} value="tcp">tcp</option>
                                <option {{if eq "udp" .t.Mode}}selected{{end}} value="udp">udp</option>
                                <option {{if eq "socks5" .t.Mode}}selected{{end}} value="socks5">socks5
                                </option>
                                <option {{if eq "httpProxy" .t.Mode}}selected{{end}} value="httpProxy">http</option>
                                <option {{if eq "secret" .t.Mode}}selected{{end}} value="secret">secret</option>
                                <option {{if eq "p2p" .t.Mode}}selected{{end}} value="p2p">p2p</option>
                                <option {{if eq "file" .t.Mode}}selected{{end}} value="file">file</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">remark</label>
                        <div class="col-sm-10">
                            <input value="{{.t.Remark}}" class="form-control" type="text" name="remark"
                                   placeholder="empty means to be unrestricted">
                        </div>
                    </div>

                    <div class="form-group" id="port">
                        <label class="col-sm-2 control-label">port of server</label>
                        <div class="col-sm-10">
                            <input value="{{.t.Port}}" class="form-control" type="text" name="port"
                                   placeholder="such as 8024">
                        </div>
                    </div>
                    <div class="form-group" id="target">
                        <label class="col-sm-2 control-label">target of Intranet(ip:port)</label>
                        <div class="col-sm-10">
                            <textarea class="form-control" name="target" rows="4" placeholder="10.1.50.203:22
10.1.50.202:22">{{.t.Target}}</textarea>
                            <span class="help-block m-b-none">can only fill in ports if it is local machine proxy, only tcp supports load balancing

</span>                        </div>
                    </div>

                    <div class="form-group" id="client_id">
                        <label class="col-sm-2 control-label">id of client</label>
                        <div class="col-sm-10">
                            <input value="{{.t.Client.Id}}" value="{{.client_id}}" class="form-control" type="text"
                                   name="client_id"
                                   placeholder="id of client">
                        </div>
                    </div>

                    <div class="form-group" id="local_path">
                        <label class="col-sm-2 control-label">local path</label>
                        <div class="col-sm-10">
                            <input value="{{.t.LocalPath}}" class="form-control" type="text" name="local_path"
                                   placeholder="such as /tmp">
                        </div>
                    </div>

                    <div class="form-group" id="strip_pre">
                        <label class="col-sm-2 control-label">strip pre</label>
                        <div class="col-sm-10">
                            <input value="{{.t.StripPre}}" class="form-control" type="text" name="strip_pre"
                                   placeholder="such as static">
                        </div>
                    </div>

                    <div class="form-group" id="password">
                        <label class="col-sm-2 control-label">unique identification key</label>
                        <div class="col-sm-10">
                            <input value="{{.t.Password}}" class="form-control" type="text" name="password"
                                   placeholder="unique identification key">
                            <span class="help-block m-b-none">when p2p or secret</span>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                            <button class="btn btn-success" href="#" id="add"><i
                                    class="fa fa-fw fa-lg fa-eye"></i>save
                            </button>
                        </div>
                    </div>

                </form>
            </div>
        </div>
    </div>
</div>
<script>
    var arr = []
    arr["all"] = ["type", "port", "compress", "u", "p", "target", "password", "local_path", "strip_pre"]
    arr["tcp"] = ["type", "port", "target", "u", "p", "compress"]
    arr["udp"] = ["type", "port", "target", "compress"]
    arr["socks5"] = ["type", "port", "compress", "u", "p"]
    arr["httpProxy"] = ["type", "port", "compress", "u", "p"]
    arr["secret"] = ["type", "target", "compress", "u", "p", "password"]
    arr["p2p"] = ["type", "password"]
    arr["file"] = ["type", "port", "local_path", "strip_pre"]
    arrClientHide = ["compress", "u", "p", "crypt", "mux"]

    function resetForm() {
        for (var i = 0; i < arr["all"].length; i++) {
            $("#" + arr["all"][i]).css("display", "none")
        }
        o = $("#type option:selected").val()
        for (var i = 0; i < arr[o].length; i++) {
            $("#" + arr[o][i]).css("display", "block")
        }
    }

    function resetClientCnf() {
        for (var i = 0; i < arrClientHide.length; i++) {
            $("#" + arrClientHide[i]).css("display", "block")
        }
        op = $("#use_client  option:selected").val()
        if (op == 1) {
            for (var i = 0; i < arrClientHide.length; i++) {
                $("#" + arrClientHide[i]).css("display", "none")
            }
        }
    }

    $(function () {
        resetForm()
        resetClientCnf()
        $("#type").on("change", function () {
            resetForm()
            resetClientCnf()
        })
        $("#use_client").on("change", function () {
            resetForm()
            resetClientCnf()
        })
        $("#add").on("click", function () {
            $.ajax({
                type: "POST",
                url: "/index/edit",
                data: $("form").serializeArray(),
                success: function (res) {
                    alert(res.msg)
                    if (res.status) {
                        history.back(-1)
                    }
                }
            })
        })
    })
</script>