@{
    Layout = null;
}
<style>
    #jbsxBox label { width: 170px; padding: 2px; margin: 2px; border: 1px solid lightgray; cursor: pointer; border-radius: 5px; }
    #jbsxBox .moduleName { width: 340px; float: left; /*border: 1px solid #efefef;*/ margin-top: 2px; padding: 4px; line-height: 30px; height: 30px; }
    #jbsxBox .moduleName span { float: right; line-height: 30px; height: 30px; }
</style>
<form method="post" id="NewsEdit" action="/Manage/Role/Action_RoleFunctionActionRela_Config?F_RoleId=@Request.QueryString["F_RoleId"].ToString()" class="pageForm required-validate"
      onsubmit="return iframeCallbackTest(this)">
    <div class="tabs" style="margin-bottom:5px;">
        <div id="UserRoleRela_tabsContent" class="tabsContent" style="padding: 0px; border-style: none;">
            <div id="layout">
                <div id="UserRoleRela_sidebar_sMids" class="sidebar_sMid" layoutH="8" style="float: left;
                    width: 24px; height: 100%; display: none; z-index: 21; border: 1px solid #B8D0D6;">
                    <div style="background: none repeat scroll 0 0 #EFF5F6;">
                        <div id="Page_sidebar_sMid" class="toggleCollapse" style="background: none repeat scroll 0 0 transparent;
                            border: 0 none;">
                            <div style="background-position: -2px -147px; border: 0 none; width: 21px;">
                            </div>
                        </div>
                    </div>
                </div>
                @Html.Raw(Html.WebRela_Config_New(ViewData["ConfigInfo"] as List<RelaInfo>, false))
            </div>
        </div>
    </div>
    <div class="formBar" style="border-width: 1px;">
        <label style="float: left">
            <input type="checkbox" class="checkboxCtrl" group="c1" />全选
        </label>
        <ul>
            @*<li>
                    <div class="button">
                        <div class="buttonContent">
                            <button type="button" class="checkboxCtrl" group="c1" selecttype="invert">
                                反选
                            </button>
                        </div>
                    </div>
                </li>*@
            <li>
                <div class="button">
                    <div class="buttonContent">
                        <button type="button" onclick="ContrarySelect()">
                            反选
                        </button>
                    </div>
                </div>
            </li>
            <li>
                <div class="buttonActive">
                    <div class="buttonContent">
                        <button type="submit">
                            提交
                        </button>
                    </div>
                </div>
            </li>
        </ul>
    </div>
</form>

<script language="javascript" type="text/javascript">
    /*
    * 带文件上传的ajax表单提交
    */
    function iframeCallbackTest(form, callback) {
        var $form = $(form), $iframe = $("#callbackframe");
        if (!$form.valid()) { return false; }

        if ($iframe.size() == 0) {
            $iframe = $("<iframe id='callbackframe' name='callbackframe' src='about:blank' style='display:none'></iframe>").appendTo("body");
        }
        if (!form.ajax) {
            $form.append('<input type="hidden" name="ajax" value="1" />');
        }
        form.target = "callbackframe";

        _iframeResponse($iframe[0], callback || navTabAjaxDoneEdit);
    }
    /*
    * 处理结果的回调
    */
    function navTabAjaxDoneEdit(json) {
        ajaxDoneEdit(json);
        //json = window.JSON.parse(json.toString().replace('<pre>', '').replace('</pre>', ''));
        if (json.statusCode == DWZ.statusCode.ok) {
            if (json.navTabId) { //把指定navTab页面标记为需要“重新载入”。注意navTabId不能是当前navTab页面的
                navTab.reloadFlag(json.navTabId);
            } else { //重新载入当前navTab页面
                navTabPageBreak({}, json.rel);
            }
            if ("closeCurrent" == json.callbackType) {
                setTimeout(function () { navTab.closeCurrentTab(json.navTabId); }, 100);
            } else if ("forward" == json.callbackType) {
                navTab.reload(json.forwardUrl);
            } else if ("forwardConfirm" == json.callbackType) {
                alertMsg.confirm(json.confirmMsg || DWZ.msg("forwardConfirmMsg"), {
                    okCall: function () {
                        navTab.reload(json.forwardUrl);
                    }
                });
            } else {
                navTab.getCurrentPanel().find(":input[defaultValue]").each(function () {
                    var defaultVal = $(this).attr("defaultValue");
                    $(this).val(defaultVal);
                });
            }
        }
    }
    /*
    * 处理结果的回调
    */
    function ajaxDoneEdit(json) {
        // 添加格式处理
        //json = window.JSON.parse(json.toString().replace('<pre>', '').replace('</pre>', ''));
        if (json.statusCode === undefined && json.message === undefined) { // for iframeCallback
            if (alertMsg) return alertMsg.error(json);
            else return alert(json);
        }
        if (json.statusCode == DWZ.statusCode.error) {
            if (json.message && alertMsg) alertMsg.error(json.message);
        } else if (json.statusCode == DWZ.statusCode.timeout) {
            if (alertMsg) alertMsg.error(json.message || DWZ.msg("sessionTimout"), { okCall: DWZ.loadLogin });
            else DWZ.loadLogin();
        } else {
            if (json.message && alertMsg) {
                var message = json.message.toString().split('|');
                alertMsg.correct(message[0]);
                if (message.length > 1) {
                    //$.pdialog.reload("/Manage/User/Edit?Action=Edit&F_Id=" + message[1] + "&F_TypeId=" + $("#User_TypeId").html(), "", "UserEditPage");
                }
            }
        }
    }
    /*
    * 重新载入页面
    */
    function reloadPage() {
        //$.pdialog.reload('/Manage/User/Edit?Action=Add&F_TypeId=' + $("#User_TypeId").html(), '', 'UserEditPage');
    }
</script>

<script>
    // 初始化展示
    function initView() {
        var str = "";
        $("[name='c1'][checked]").each(function () {
            str += $(this).attr("Info") + "<br />";
        })
        $("#UserRoleRela_MidTree .InfoItems").html("");
        $("#UserRoleRela_MidTree .InfoItems").html(str);
    }

    // e是控件ID
    function Item_CheckAll(e) {
        var items = $("[moduleid=" + e + "]");
        var obj = $("#item_cb_all_" + e);
        var result = true;
        if (obj != undefined) {
            result = obj[0].checked;
        }

        for (var i = 0; i < items.length; i++) {
            items[i].checked = result;
        }

        var objModule = $("#item_cb_" + e);
        objModule[0].checked = result;
    }

    // 反选处理
    function ContrarySelect() {
        var items_action = $("[name=c1]");
        var items_function = $("[name=functions]");

        for (var i = 0; i < items_action.length; i++) {
            if (items_action[i].checked) {
                items_action[i].checked = false;
            } else {
                items_action[i].checked = true;
            }
        }

        for (var i = 0; i < items_function.length; i++) {
            if (items_function[i].checked) {
                items_function[i].checked = false;
            } else {
                items_function[i].checked = true;
            }
        }
    }

    // 点击功能处理
    $("[name='functions']").click(function () {
        if ($(this).attr("checked") != "checked") {
            $(this).removeAttr("checked");


            var value = $(this).attr('value');
            var objModule = $("#item_cb_all_" + value);
            objModule[0].checked = false;

            var items = $("[moduleid=" + value + "]");
            for (var i = 0; i < items.length; i++) {
                items[i].checked = false;
            }
        }
    })

    // 点击功能按钮处理
    $("[name='c1']").click(function () {
        if ($(this).attr("checked") != "checked") {
            $(this).removeAttr("checked");
        } else {
            $(this).attr('checked', 'checked');
            var value = $(this).attr('moduleid');
            var objModule = $("#item_cb_" + value);
            objModule[0].checked = true;
        }
        initView();
    })
</script>