{% extends "framework/base.html" %}
{#{% load i18n %}#}
{% block header %}
    <title>{{ _('管理员模型 编辑') }}</title>
{% endblock %}


{% block content %}

    <div class="row header">
        <div class="col-sm-5">
            <h1>{{ _('管理员模型') }}
                <small>{{ _('编辑') }}</small>
            </h1>
        </div>
    </div>

    <hr><br>

    <form action="/myadmin/user/save?{% if data.id %}id={{ data.id }}{% endif %}{% if request.query_params.is_copy %}&is_copy=1{% endif %}"
          method="POST"
          class="form-horizontal"
          role="form">

        <div class="row edit-container">
            <div class="col-sm-6">
                {{ csrf_input }}
                <div class="form-group" style="display:none">
                    <label class="col-sm-3 control-label no-padding-right" for="id_id">
                        {{ _('id') }} </label>

                    <div class="col-sm-8">
                        <input type="number" id="id_id" name="id"
                               class="form-control" value="{{ data.id  or "" }}"
                        >

                        <div id="help_text_id" class="middle text-danger help_text"></div>
                    </div>
                </div>


                <div class="form-group" style="">
                    <label class="col-sm-3 control-label no-padding-right" for="id_alias">
                        {{ _('别名(姓名)') }} <span class="text-danger">*</span></label>

                    <div class="col-sm-8">
                        <input type="text" id="id_alias" name="alias"
                               class="form-control" value="{{ data.alias  or "" }}"
                               maxlength=50
                               required=true
                        >

                        <div id="help_text_alias" class="middle text-danger help_text"></div>
                    </div>
                </div>


                <div class="form-group" style="">
                    <label class="col-sm-3 control-label no-padding-right" for="id_username">
                        {{ _('用户名(登录名)') }} <span class="text-danger">*</span></label>

                    <div class="col-sm-8">
                        <input type="text" id="id_username" name="username"
                               class="form-control" value="{{ data.username  or "" }}"
                               maxlength=50
                               required=true
                        >

                        <div id="help_text_username" class="middle text-danger help_text"></div>
                    </div>
                </div>


                <div class="form-group" style="">
                    <label class="col-sm-3 control-label no-padding-right" for="id_password">
                        {{ _('密码') }} <span class="text-danger">*</span></label>

                    <div class="col-sm-8">
                        <input type="text" id="id_password" name="password"
                               class="form-control" value="{{ data.password  or "" }}"
                               maxlength=32
                               required=true
                        >

                        <div id="help_text_password" class="middle text-danger help_text"></div>
                    </div>
                </div>


                <div class="form-group" style="">
                    <label class="col-sm-3 control-label no-padding-right" for="id_last_ip">
                        {{ _('最后登录ip') }} </label>

                    <div class="col-sm-8">
                        <input type="text" id="id_last_ip" name="last_ip"
                               class="form-control" value="{{ data.last_ip  or "" }}"
                               maxlength=20

                        >

                        <div id="help_text_last_ip" class="middle text-danger help_text"></div>
                    </div>
                </div>


                <div class="form-group" style="">
                    <label class="col-sm-3 control-label no-padding-right" for="id_last_time">
                        {{ _('最后登录时间') }} </label>

                    <div class="col-sm-8">

                        <input type="text" id="id_last_time" name="last_time"
                               class="form-control datetime " value="{{ data.last_time   or "" }}"

                        >

                        <div id="help_text_last_time" class="middle text-danger help_text"></div>
                    </div>
                </div>


                <div class="form-group" style="">
                    <label class="col-sm-3 control-label no-padding-right" for="id_login_count">
                        {{ _('登录次数') }} </label>

                    <div class="col-sm-8">
                        <input type="number" id="id_login_count" name="login_count"
                               class="form-control" value="{{ data.login_count  or "" }}"


                        >

                        <div id="help_text_login_count" class="middle text-danger help_text"></div>
                    </div>
                </div>


                <div class="form-group" style="">
                    <label class="col-sm-3 control-label no-padding-right" for="id_status">
                        {{ _('状态') }} </label>

                    <div class="col-sm-8">
                        <select class="form-control col-lg-5 select2" id="id_status"
                                data-placeholder="{{ _('状态') }}" name="status" svalue="{{ data.status }}">
                            {% for o in data.serializer.instance.fields_map.status.choices %}
                                <option value="{{ o.0 }}">{{ o.1 }}</option>
                            {% endfor %}

                        </select>

                        <div id="help_text_status" class="middle text-danger help_text"></div>
                    </div>
                </div>


                <div class="form-group" style="">
                    <label class="col-sm-3 control-label no-padding-right" for="id_session_key">
                        {{ _('会话key') }} </label>

                    <div class="col-sm-8">
                        <input type="text" id="id_session_key" name="session_key"
                               class="form-control" value="{{ data.session_key  or "" }}"
                               maxlength=40

                        >

                        <div id="help_text_session_key" class="middle text-danger help_text"></div>
                    </div>
                </div>


                <div class="form-group" style="">
                    <label class="col-sm-3 control-label no-padding-right" for="id_create_datetime">
                        {{ _('创建时间') }} </label>

                    <div class="col-sm-8">

                        <input type="text" id="id_create_datetime" name="create_datetime"
                               class="form-control datetime "
                               value="{{ data.create_datetime   or "" }}"

                        >

                        <div id="help_text_create_datetime" class="middle text-danger help_text"></div>
                    </div>
                </div>



            </div>

            <div class="col-sm-6">
                <div class="tabbable ">
                    <ul class="nav nav-tabs padding-12 ">
                        <li class="active">
                            <a data-toggle="tab" href="#tab1">
                                <i class="icon-dashboard bigger-110"></i>{{ _('所属角色') }}
                            </a>
                        </li>
{#                        <li class="">#}
{#                            <a data-toggle="tab" href="#tab2">#}
{#                                <i class="blue "></i>{{ _('其他信息') }}#}
{#                            </a>#}
{#                        </li>#}

                    </ul>
                    <br>
                    <div class="tab-content">

                        <div id="tab1" class="tab-pane active">
                            <div class="alert alert-info">
                                <i class="icon-remove close" data-dismiss="alert">&times;</i>
                                {{ _('角色选择 要勾选,可以重复角色,多个角色权限重叠.') }}
                                <br>
                            </div>
                            <div class="">
                                {% with select_list=data.role %}
                                {% include 'myadmin/widgets/role_table_select.html' %}
                                {% endwith %}
{##}
{#                                    <select class="form-control selectpicker" id="id_role"#}
{#                                            data-placeholder="{{ _('拥有的角色') }}" name="role" multiple="multiple"#}
{#                                            data-url="/myadmin/role/list">#}
{#                                        {% for id in data.role %}#}
{#                                            <option value="{{ id }}" selected="selected">{{ id }}</option>#}
{#                                        {% endfor %}#}
{#                                    </select>#}

                            </div>

                        </div>

                        <div id="tab2" class="tab-pane">
                            <div class="alert alert-info">
                                <button type="button" class="close" data-dismiss="alert">
                                    <i class="icon-remove"></i>
                                </button>
                                <strong>注意!</strong>
                                勾选一级产品后,此角色将拥有这个一级产品下的所有二级产品的查询权限,
                                没有勾选则可查询全部产品.
                                <br>
                            </div>
                            <div class="">

                            </div>
                        </div>



                    </div>
                </div>

            </div>
        </div>

        <div class="row pane edit-save-bar">
            <div class="col-sm-offset-3 col-sm-3">

                <input id="reset-btn" class="btn btn-default" type="reset" value="{{ _('重 置') }}">
                <button id="save-btn" class="btn btn-primary " type="button">
                    {{ _('保 存') }}
                </button>

            </div>
            <div class="col-sm-6">
                <div class="pull-right">
                    <button id="save-edit-btn" class="btn btn-info " type="button">
                        {{ _('保存并继续编辑') }}
                    </button>
                    <button id="save-add-btn" class="btn btn-info " type="button">
                        {{ _('保存并增加另一个') }}
                    </button>
                </div>

            </div>
        </div>

    </form>



    <script>
        var $form = $('form')
        $form.submit(function (e) {
            stopEevent(e)
            return false
        })

        function ajaxPostData(ele, callback) {

            clearHelpText()
            $(ele).attr("disabled", true);
            $.ajax({
                async: true,
                type: "POST",
                url: $form.attr('action'),
                dataType: 'json',
                data: JSON.stringify($form.serializeToJSON()),
                contentType: 'application/json',
                success: function (rsp) {
                    if (rsp.code == 0) {
                        $('[name="id"]').val(rsp.data.id)
                        art.dialog(rsp.msg).time(1)
                        clearHelpText()
                        callback ? callback(rsp) : null
                    } else {
                        rsp.data ? addHelpText(rsp.data) : alertMsg(rsp.msg)
                    }
                },
                error: function (jqXHR, statusText, errorMsg) {
                    ajaxError(jqXHR, statusText, errorMsg)

                },
                complete: function (jqXHR, statusText) {
                    $(ele).removeAttr("disabled");
                }

            })
        }

        $('#save-add-btn').click(function () {
            ajaxPostData(this, function (rsp) {
                if (rsp.code == 0) {
                    window.location.href = window.location.pathname
                }
            })
        })

        $('#save-edit-btn').click(function () {
            ajaxPostData(this, function (rsp) {
                $form.attr('action', '/myadmin/user/save?id=' + rsp.data.id)
                refreshParentTable()

            })
        })

        $('#save-btn').click(function () {
            ajaxPostData(this, function (rsp) {
                refreshParentTable()
                closeSelfDialog()
            })
        })

    </script>
{% endblock %}
