<?xml version="1.0" encoding="UTF-8"?>
<h:screen xmlns:h="http://www.hand-china.com/hap">
    <style>
        html {
            overflow: hidden;
        }
    </style>

    <script id="script"><![CDATA[
    var currentRole;


    function schemaError() {

    }
    function dsEditable(col) {


                if (col == 'roleName') {
                    return false;
                } else {
                    return true;
                }
    }
    function parameterMap(options, type) {
        if (type !== "read" && options.models) {
            var datas = options.models;
            if (type == 'create' || type == 'update') {
                datas = options.models.map(function (data) {
                    data['__status'] = (type == 'create' ? 'add' : 'update');
                    return data;
                })
            }
            return kendo.stringify(datas);
        } else if (type === "read") {
            var map = {};
            map.page = options.page;
            map.pagesize = options.pageSize;
            for (var k in map) {
                if (map[k] === '' || map[k] === null || map[k] === undefined)
                    delete map[k]
            }
            return map;
        }
    }
    function gridLocate(e) {
        var d = this.dataItem(e.element);
    }
    function requestError() {

    }
    function typeTemp(dataItem) {
        var result;
        wechatType.forEach(function (value, index, array) {
            if (dataItem.accountType == value.value) {
                result = value.meaning;
            }
        })
        return result || '';
    }

    function typeEditor(container, options) {
        $('<input name="' + options.field + '"/>')
            .appendTo(container)
            .kendoDropDownList({
                dataTextField: "meaning",
                dataValueField: "value",
                valuePrimitive: true,
                dataSource: wechatType
            });
    }


    function addFunction(dataItem) {

        if (dataItem.enableFlag == 'Y') {
            return '<a href="javascript:;" onclick="addMenu(' + dataItem.id + ',\'' + dataItem.moduleName + '\')">添加功能</a>'
        } else {
            return '';
        }
    }
    function addMenu(id, moduleName) {

        if(currentRole=='QUERY_ADMIN') return false;
        Hls.openBox({
            url: "${base.contextPath}/app/appFunction.view?wechatId=" + id + "&title=" + moduleName,
            winId: "menu-div",
            width: "100%"
        });
    }

    function moduleEditor(container, options) {
        $('<input required name="' + options.field + '"/>')
            .appendTo(container)
            .kendoLov($.extend(${lovProvider.getLov(base.contextPath, base.locale, "ROLE_MODULE")}, {
                textField: 'moduleName',
                model: options.model,
                query: function (e) {
                    e.param['roleId'] =options.model.roleId;
                    e.param['appCode']  ="${RequestParameters.appCode!-1}"
                }
            }));
    }

    function roleTemp(dataItem) {
        return dataItem.roleName ;
    }
    function moduleTemp(dataItem) {
        return dataItem.moduleName || '';
    }

    function moduleTemp(dataItem) {
        return dataItem.moduleName || '';
    }


    ]]></script>
    <div id="menu-div"></div>
    <h:dataSource id="gridDataSource" batch="true" pageSize="10" serverPaging="true" error="requestError">
        <h:transport parameterMap="parameterMap">
            <h:read url="${base.contextPath}/app/query/RoleModule?roleId=${RequestParameters.roleId!-1}" type="GET" dataType="json"/>
            <h:create url="${base.contextPath}/app/addRoleModule" type="POST" contentType="application/json"/>
            <h:update url="${base.contextPath}/app/addRoleModule" type="POST" contentType="application/json"/>
            <h:destroy url="${base.contextPath}/app/deleteRoleModule" type="POST" contentType="application/json"/>
        </h:transport>
        <h:schema data="rows" total="total" errors="schemaError">
            <h:model id="roleModuleId" editable="dsEditable">
                <h:fields>
                    <h:item name="enableFlag" defaultValue="Y" type="boolean" checkedValue="Y" uncheckedValue="N"/>
                    <h:item name="homeFlag" defaultValue="Y" type="boolean" checkedValue="Y" uncheckedValue="N"/>
                    <h:item name="roleId" defaultValue="${RequestParameters.roleId!-1}" />
                    <h:item name="roleName" defaultValue="${RequestParameters.roleName!-1}" />
                    <h:item name="appCode" defaultValue="${RequestParameters.appCode!-1}" />
                </h:fields>
            </h:model>
        </h:schema>
    </h:dataSource>
    <h:hlsGridBox hlsGridId="grid" hlsBtnType="add,save" title=""
                  viewModelName="viewModel.data" dataSourceId="gridDataSource">
        <h:hlsGrid id="grid" dataSource="gridDataSource"
                   hlsBtnType="ADD" editable="inline" height="400px" resizable="true" navigatable="true"
                   locate="gridLocate">
            <h:pageable pageSizes="all,5,10,20,50" buttonCount="0" refresh="true">
            </h:pageable>
            <h:columns>
                <h:column title='操作'  width="75">
                    <h:command>
                        <h:item name="edit"/>
                        <h:item name="destroy"/>
                    </h:command>
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
                <h:column field="roleId" hidden="true"   title='角色ID' width="105"  >
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:left"/>
                </h:column>
                <h:column field="roleName"  title='角色名称' width="105" template="roleTemp" >
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:left"/>
                </h:column>
                <h:column field="moduleId"  title='模块名称' width="105" editor="moduleEditor" template="moduleTemp">
                <h:headerAttributes style="text-align:center"/>
                <h:attributes style="text-align:left"/>
                </h:column>
                <h:column field="homeFlag" title="是否主页展示" width="80">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
                <h:column field="enableFlag" title="是否可用" width="50">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
            </h:columns>
        </h:hlsGrid>
    </h:hlsGridBox>
    <script><![CDATA[

    ]]></script>

</h:screen>