<%@ page contentType="text/html;charset=UTF-8" %>
<script type="text/javascript">
    $(document).ready(function () {
        var uid = $("#uid").val();
        window.operateEvents = {
            'click #TableView': function (e, value, row, index) {
                jp.confirm('确认要取消权限吗？', function () {
                    jp.loading();
                    jp.get("${ctx}/sg/managementcenter/privilegepre/deleteAll?pid=" + row.id + "&uid=" + uid, function (data) {
                        if (data.success) {
                            $('#table').bootstrapTable('refresh');
                            jp.success(data.msg);
                        } else {
                            jp.error(data.msg);
                        }
                    })
                })
            }
        };
        //表格初始化
        $('#table').bootstrapTable({
            //请求方法
            method: 'post',
            //类型json
            dataType: "json",
            contentType: "application/x-www-form-urlencoded",
            //是否显示行间隔色
            striped: true,
            //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            cache: false,
            //显示检索按钮
            showSearch: false,
            //显示刷新按钮
            showRefresh: true,
            //显示切换手机试图按钮
            showToggle: false,
            //显示 内容列下拉框
            showColumns: false,
            //显示切换分页按钮
            showPaginationSwitch: false,
            //是否显示分页（*）
            pagination: true,
            //排序方式
            sortOrder: "asc",
            //初始化加载第一页，默认第一页
            pageNumber: 1,
            //每页的记录行数（*）
            pageSize: 10,
            //可供选择的每页的行数（*）
            pageList: [10, 25, 50, 100],
            //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
            url: "${ctx}/sg/managementcenter/privilegepre/data?uid=" + uid,
            //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
            //queryParamsType:'',
            ////查询参数,每次调用是会带上这个参数，可自定义
            queryParams: function (params) {
                var searchParam = $("#searchForm").serializeJSON();
                searchParam.pageNo = params.limit === undefined ? "1" : params.offset / params.limit + 1;
                searchParam.pageSize = params.limit === undefined ? -1 : params.limit;
                searchParam.orderBy = params.sort === undefined ? "" : params.sort + " " + params.order;
                return searchParam;
            },
            onShowSearch: function () {
                $("#search-collapse").slideToggle();
            },
            //分页方式：client客户端分页，server服务端分页（*）
            sidePagination: "server",
            contextMenuTrigger: "right",//pc端 按右键弹出菜单
            contextMenuTriggerMobile: "press",//手机端 弹出菜单，click：单击， press：长按。
            contextMenu: '#context-menu',
            onContextMenuItem: function (row, $el) {
            },
            onClickRow: function (row, $el) {
            },
            columns: [
                {
                    field: 'name',
                    title: '流程名称',
                    sortable: true

                }, {
                    field: 'oneVersion',
                    title: '版本号',
                    sortable: true
                }, {
                    title: '取消权限',
                    events: operateEvents,
                    formatter: function (value, row, index) {
                        return [
                            '<input id="TableView" type="button" value="取消权限" class="form-control btn btn-primary">',
                        ].join('');
                    }
                }]
        });


        if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {//如果是移动端
            $('#table').bootstrapTable("toggleView");
        }

        $('#table').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
            'check-all.bs.table uncheck-all.bs.table', function () {
            $('#remove').prop('disabled', !$('#table').bootstrapTable('getSelections').length);
            $('#edit').prop('disabled', $('#table').bootstrapTable('getSelections').length != 1);
        });

        $("#search").click("click", function () {// 绑定查询按扭
            $('#table').bootstrapTable('refresh');
        });
        $("#reset").click("click", function () {// 绑定查询按扭
            $("#searchForm  input").val("");
            $("#searchForm  select").val("");
            $('#table').bootstrapTable('refresh');
        });

        $('#beginInDate').datetimepicker({
            format: "YYYY-MM-DD HH:mm:ss"
        });
        $('#endInDate').datetimepicker({
            format: "YYYY-MM-DD HH:mm:ss"
        });



    });

function getIdSelections() {
    return $.map($("#table").bootstrapTable('getSelections'), function (row) {
        return row.id
    });
}

function save() {
    var dialogIndex = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(dialogIndex);
}


function edit(id) {
    if (!id) {
        id = getIdSelections();
    }
    jp.openSaveDialog('编辑用户', "${ctx}/sys/user/form?id=" + id, '800px', '680px');

}

function add() {
	var uid = $("#uid").val();
	jp.openSaveDialog('添加权限', "${ctx}/sg/managementcenter/privilegepre/allProcDef?uid=" + uid, '800px', '680px');
}

function refresh() {
    $('#table').bootstrapTable('refresh');
}

</script>