<?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 moduleId = ${RequestParameters.moduleId!-1};
    var appCode = "${RequestParameters.appCode!-1}";
    var currentRole;

    var functionTypeList = [{
        "description": "本地",
        "meaning": "本地",
        "value": "local"
    }, {
        "description": "在线",
        "meaning": "在线",
        "value": "online"
    }];

    var targetList = [{
        "description": "blank",
        "meaning": "blank",
        "value": "_blank"
    }, {
        "description": "self",
        "meaning": "self",
        "value": "_self"
    }];

    function schemaError() {

    }
    function dsEditable(col) {
        this.moduleId = moduleId;
        this.appCode = appCode;
        if (col == 'appCode') {
            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 appCodeTemp(dataItem) {
        return dataItem.appCode;
    }

    function typeTemp(dataItem) {
        var result;
        functionTypeList.forEach(function (value, index, array) {
            if (dataItem.functionType == 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: functionTypeList,
                index: 0

            });
    }
    function targetTemp(dataItem) {
        var result;
        targetList.forEach(function (value, index, array) {
            if (dataItem.target == value.value) {
                result = value.meaning;
            }
        })
        return result || '';
    }

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

    ]]></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/moduleFunction?moduleId=${RequestParameters.moduleId!-1}"
                    type="GET" dataType="json"/>
            <h:create url="${base.contextPath}/app/addFunction" type="POST" contentType="application/json"/>
            <h:update url="${base.contextPath}/app/addFunction" type="POST" contentType="application/json"/>
            <h:destroy url="${base.contextPath}/app/deleteFunction" type="POST" contentType="application/json"/>
        </h:transport>
        <h:schema data="rows" total="total" errors="schemaError">
            <h:model id="functionId" editable="dsEditable">
                <h:fields>
                    <h:item name="enableFlag" defaultValue="Y" type="boolean" checkedValue="Y" uncheckedValue="N"/>
                    <h:item name="prodFlag" defaultValue="Y" type="boolean" checkedValue="Y" uncheckedValue="N"/>
                    <h:item name="moduleId"/>
                    <h:item name="appCode" defaultValue="${RequestParameters.appCode!-1}">
                        <!--<h:validation readonly="true"/>-->
                    </h:item>
                    <h:item name="functionName">
                        <h:validation required="true"/>
                    </h:item>
                    <h:item name="functionCode">
                        <h:validation required="true"/>
                    </h:item>
                    <h:item name="functionState">
                        <h:validation required="true"/>
                    </h:item>
                    <h:item name="functionIcon">
                        <h:validation required="true"/>
                    </h:item>
                    <h:item name="functionType" defaultValue="local"></h:item>
                    <h:item name="target" defaultValue="_blank"></h:item>
                </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="moduleId" title='模块ID' hidden="true" width="105">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:left"/>
                </h:column>
                <h:column field="appCode" title='APP代码' width="105" template="appCodeTemp">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:left"/>
                </h:column>
                <h:column field="functionName" title='功能名称' width="105">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:left"/>
                </h:column>
                <h:column field="functionCode" title='功能编码' width="105">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:left"/>
                </h:column>
                <h:column field="functionType" title="功能类型" width="105" editor="typeEditor" template="typeTemp">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:left"/>
                </h:column>
                <h:column field="target" title="target" width="105" editor="targetEditor" template="targetTemp">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:left"/>
                </h:column>
                <h:column field="functionState" title='地址' width="105">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:left"/>
                </h:column>
                <h:column field="functionIcon" title='功能图标' width="105">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:left"/>
                </h:column>
                <h:column field="enableFlag" title="是否可用" width="50">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
                <h:column field="prodFlag" 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>