<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('用户分配项目')"/>
</head>
<body>
<div class="main-content">
    <form id="form-user-add" class="form-horizontal">
        <input type="hidden" id="userId" name="userId" th:value="${user.userId}">
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-5">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">用户名称：</label>
                    <div class="col-sm-8">
                        <input name="userName" class="form-control" type="text" disabled th:value="${user.userName}">
                    </div>
                </div>
            </div>
            <div class="col-sm-5">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">登录账号：</label>
                    <div class="col-sm-8">
                        <input name="loginName" class="form-control" type="text" disabled th:value="${user.loginName}">
                    </div>
                </div>
            </div>
        </div>

        <h4 class="form-header h4">分配项目</h4>
        <!--            <div class="col-sm-9" id="myButtons">-->
        <!--            <label class="radio-box">-->
        <!--                <input type="radio" name="allproject" value="false" id="radio1" th:checked="${project.mine['all']!=true}">自定义项目</label>-->
        <!--                <label class="radio-box">-->
        <!--                <input type="radio" name="allproject" value="true" id="radio2" th:checked="${project.mine['all']}">所有项目</label>-->
        <!--            </div>-->
        <div class="row" id="projectTable">
            <div class="col-sm-12">
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </form>
</div>

<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler('all')"><i class="fa fa-check"></i>关联全部
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="submitHandler('clearAll')"><i
                class="fa fa-remove"></i>全部清除
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "system/user/authProject";
    var projects = [[${project.list}]];
    var mine = [[${project.mine}]];
    var statusDatas = [[${@dict.getType('project_status')}]];

    $(function () {
        var options = {
            data: projects,
            sidePagination: "client",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            clickToSelect: true,
            maintainSelected: true,
            onCheck: function (row) {
                mine[row.id] = true;
            },
            onUncheck: function (row) {
                delete mine[row.id];
            },
            columns: [{
                checkbox: true,
                formatter: function (value, row, index) {
                    return {checked: mine[row.id]};
                }

            },
                {
                    field: 'id',
                    title: '项目ID',
                    visible: false
                },
                {
                    field: 'name',
                    title: '项目名称'
                },
                {
                    field: 'remark',
                    title: '备注',
                    sortable: true
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    field: 'createBy',
                    title: '创建者',
                    sortable: true
                }]
        };
        $.table.init(options);
        // changeAll();
    });

    /* 添加角色-提交 */
    function submitHandler(command) {
        if (command != undefined && command != '') {
            $.modal.confirm("确认要" + (command == 'all' ? "关联" : "清除") + "全部项目?", function () {
                var data = {"userId": $("#userId").val(), "mine": command};
                $.operate.saveTab(prefix + "/insert", data);
            });
        } else {
            var data = {"userId": $("#userId").val(), "mine": Object.keys(mine).join()};
            $.operate.saveTab(prefix + "/insert", data);
        }

    }

    //$("input:radio[name='allproject']").on('ifChecked',changeAll);
    // function changeAll(){
    // 	if($("input:radio[name='allproject']:checked").val()=="true") {
    // 		$("#projectTable").hide();
    // 	} else {
    // 		$("#projectTable").show();
    // 	}
    // }
</script>
</body>
</html>