<?xml version="1.0" encoding="utf-8"?>
<h:screen xmlns:h="http://www.hand-china.com/hap">
    <script src="${base.contextPath}/common/code?yesno=SYS.YES_NO" type="text/javascript"></script>
    <script src="${base.contextPath}/common/code?lovTypes=SYS.LOV_EDITOR_TYPE" type="text/javascript"></script>
    <script src="${base.contextPath}/common/code?alignType=SYS.ALIGN_TYPE" type="text/javascript"></script>

    <style>
        .query-button {
            font-size: 13px;
            text-align: center;
            margin-top: 0px;
            float: left;
            width: 70px;
            height: 30px;
            color: white;
            border-radius: 5px 5px 5px 5px;
            background-color: #00b3b3;
            /* vertical-align: center;*/
            line-height: 30px;
        }
        #editForm{
            width:96%!important;
        }
        div.panel-heading.hlsform-header{
            display:none;
        }
    </style>

    <script><![CDATA[
    var lovId =${RequestParameters.lovId!0};

    $.each(lovTypes, function (i, n) {
        n.value = n.value.toLowerCase();
    });

    $.each(alignType, function (i, n) {
        n.value = n.value.toLowerCase();
    });

    var crudServiceBaseUrl = '${base.contextPath}/sys/lovitem';
    var viewModel2 = kendo.observable({
        selected: {},
        create: function (e) {
            $("#grid").data('kendoGrid').addRow();
        },
        remove: function (e) {
            Hap.deleteGridSelection({
                grid: $("#grid")
            });
        },
        source: lovTypes,
        dataDsType: [
            {value: 'url', text: '<@spring.message "lovitem.ds_type.url"/>'},
            {value: 'code', text: '<@spring.message "lovitem.ds_type.code"/>'}
        ],
        onConditionFieldTypeSelect: function (e) {
            var item = e.item;
            var text = item.text();
            //获取到下拉框选中内容 根据选中内容判断是否显示
            if (text === "下拉框" || text === "Select") {
                $("#urlBox").css("display", "none");
                $("#conditionFieldSelectTfBox").css("display", "none");
                $("#conditionFieldSelectVfBox").css("display", "none");
                $("#selectCodeBox").css("display", "none");
                $("#dsTypeBox").css("display", "block");
                viewModel2.selected.set('conditionFieldSelectCode', '');
                viewModel2.selected.set('conditionFieldSelectUrl', '');
                viewModel2.selected.set('conditionFieldSelectTf', '');
                viewModel2.selected.set('conditionFieldSelectVf', '');

            }
            else {
                $("#urlBox").css("display", "none");
                $("#conditionFieldSelectTfBox").css("display", "none");
                $("#conditionFieldSelectVfBox").css("display", "none");
                $("#selectCodeBox").css("display", "none");
                $("#dsTypeBox").css("display", "none");
                viewModel2.selected.set('conditionFieldSelectCode', '');
                viewModel2.selected.set('conditionFieldSelectUrl', '');
                viewModel2.selected.set('conditionFieldSelectTf', '');
                viewModel2.selected.set('conditionFieldSelectVf', '');
                viewModel2.selected.set('comboboxType', '');
            }
        },
        oncomboboxTypeSelect: function (e) {
            var item = e.item;
            var text = item.text();
            //获取到下拉框选中内容 根据选中内容判断是否显示
            if (text === "URL") {
                $("#selectCodeBox").css("display", "none");
                viewModel2.selected.set('conditionFieldSelectCode', '');
                $("#urlBox").css("display", "block");
                $("#conditionFieldSelectTfBox").css("display", "block");
                $("#conditionFieldSelectVfBox").css("display", "block");
            }
            else if (text === "快速编码" || text === "Sys Code") {
                $("#urlBox").css("display", "none");
                $("#conditionFieldSelectTfBox").css("display", "none");
                $("#conditionFieldSelectVfBox").css("display", "none");
                $("#selectCodeBox").css("display", "block");
                viewModel2.selected.set('conditionFieldSelectUrl', '');
                viewModel2.selected.set('conditionFieldSelectTf', '');
                viewModel2.selected.set('conditionFieldSelectVf', '');

            }
            else {
                $("#urlBox").css("display", "none");
                $("#conditionFieldSelectTfBox").css("display", "none");
                $("#conditionFieldSelectVfBox").css("display", "none");
                $("#selectCodeBox").css("display", "none");
                viewModel2.selected.set('conditionFieldSelectCode', '');
                viewModel2.selected.set('conditionFieldSelectUrl', '');
                viewModel2.selected.set('conditionFieldSelectTf', '');
                viewModel2.selected.set('conditionFieldSelectVf', '');
            }
        }
    });

    var viewModel = kendo.observable({
        model: {},
        isEnabled:<#if RequestParameters.lovId ??> false, <#else> true, </#if>
        pageSizeData:["5","10","20","50","ALL"],
        sqlTypeData:[{ text: "<@spring.message 'lov.sqlId'/>", value: "<@spring.message 'lov.sqlId'/>" },
            { text: "<@spring.message 'lov.customsql'/>", value: "<@spring.message 'lov.customsql'/>" },
            { text: "<@spring.message 'lovitem.ds_type.url'/>",value:"<@spring.message 'lovitem.ds_type.url'/>"}]
    });

    var parameterMap = function (options, type) {
        if (type !== "read" && options.models) {
            var datas = Hap.prepareSubmitParameter(options, type);
            return kendo.stringify(datas);
        } else if (type === "read") {
            var p = Hap.prepareQueryParameter(viewModel.model.toJSON(), options);
            p.lovId = lovId;
            return p;
        }
    }

    var requestEndFunc = function (e) {
        var response = e.response;
        if (!response)
            return;
    }

    var locateFunc = function (e) {
        var model = this.dataItem(e.element);
        viewModel2.set("selected", model);
    }

    var columnEditor = function (container, options) {
        $('<input name="' + options.field + '"/>').appendTo(container)
            .kendoCheckbox({
                checkedValue: 'Y',
                uncheckedValue: 'N'
            });
    }

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

    var alignTem = function (dataItem) {
        var v = dataItem.gridFieldAlign;
        $.each(alignType, function (i, n) {
            if ((n.value || '').toLowerCase() == (v || '').toLowerCase()) {
                v = n.meaning;
                return false;
            }
        })
        return v || '';
    }

    var conditionEditor = function (container, options) {
        $('<input name="' + options.field + '"/>').appendTo(container)
            .kendoCheckbox({
                checkedValue: 'Y',
                uncheckedValue: 'N',
                change:function(e){
                    $("#grid").data("kendoGrid").refresh();
                }
            });
    }

    var typeTem = function (e) {
        if (e.conditionField == 'Y') {
            return '<a href="javascript:void(0)" id="lovItemType"   onclick="openEditor(this)"><@spring.message "lovitem.type"/></a>'
        }
        return '';
    }

    function closeLovWindow(){
        window.parent.$("#"+"${RequestParameters.hlsWindowId}").data('kendoWindow').close();
    }

    function saveLov() {
        if(validator.validate()){
            var sqlType = $("#sqlType").val();
            var sql = "";
            if(sqlType=="<@spring.message 'lov.sqlId'/>"){
                sql = $("#sqlId").val();
                viewModel.model.set("customSql","");
                viewModel.model.set("customUrl","");
            }else if(sqlType=="<@spring.message 'lov.customsql'/>"){
                sql = $("#customSql").val();
                viewModel.model.set("sqlId","");
                viewModel.model.set("customUrl","");
            }else{
                sql = $("#customUrl").val();
                viewModel.model.set("sqlId","");
                viewModel.model.set("customSql","");
            }

            viewModel.model.delayLoad = viewModel.model.delayLoad === true ? 'Y' : 'N'
            viewModel.model.needQueryParam = viewModel.model.needQueryParam === true ? 'Y' : 'N'
            viewModel.model.canPopup = 'Y'
            Hap.submitForm({
                url: '${base.contextPath}/sys/lov/submit',
                formModel: viewModel.model,
                grid: {
                    lovItems: $('#grid')
                },
                success: function (result) {
                    Hls.getWindowObj("sys_lov").contentWindow.$('#grid').data('kendoGrid').dataSource.page(1);
                    closeLovWindow();
                }
            });
        }


    }
    ]]></script>
    <!-- 编辑界面 -->
    <div id="queryEdit" style="width:500px!important;display: none">
    <h:hlsForm id="editForm">
        <h:hlsHBox>
        <h:hlsCombobox bind="source:source,value:selected.conditionFieldType,events:{select:onConditionFieldTypeSelect}" name="conditionFieldType" style="width:100%"
                       prompt='<@spring.message "lovitem.field_type"/>' promptColspan="3" colspan="9" dataTextField="meaning" dataValueField="value" valuePrimitive="true"/>
        </h:hlsHBox>
        <h:hlsHBox>
        <h:hlsNumericTextBox id="conditionFieldLabelWidth" bind="value:selected.conditionFieldLabelWidth" colspan="9" format="n0"
                             prompt='<@spring.message "lovitem.conditionfieldlabelwidth"/>' promptColspan="3" style="width:100%"/>
        </h:hlsHBox>
        <h:hlsHBox>
            <h:hlsNumericTextBox id="conditionFieldWidth" bind="value:selected.conditionFieldWidth" colspan="9" format="n0"
                                 prompt='<@spring.message "lovitem.conditionfieldwidth"/>' promptColspan="3" style="width:100%"/>
        </h:hlsHBox>
        <h:hlsHBox>
            <h:hlsNumericTextBox id="conditionFieldSequence" bind="value:selected.conditionFieldSequence" colspan="9" format="n0"
                                 prompt='<@spring.message "lovitem.conditionfieldsequence"/>' promptColspan="3" style="width:100%"/>
        </h:hlsHBox>
        <h:hlsHBox>
            <h:hlsMaskedTextBox id="conditionFieldName" name="conditionFieldName" bind="value:selected.conditionFieldName" colspan="9"
                                prompt='<@spring.message "lovitem.conditionfieldname"/>' promptColspan="3" style="width:100%"/>
        </h:hlsHBox>
        <div id="dsTypeBox" style="display:none">
        <h:hlsHBox>
            <h:hlsCombobox bind="source:dataDsType,value:selected.comboboxType,events:{select:oncomboboxTypeSelect}" name="conditionFieldType" style="width:100%"
                           prompt='<@spring.message "lovitem.field_type"/>' promptColspan="3" colspan="9" dataTextField="text" dataValueField="value" valuePrimitive="true"/>
        </h:hlsHBox>
        </div>
        <div id="urlBox" style="display:none">
        <h:hlsHBox>
            <h:hlsMaskedTextBox id="conditionFieldSelectUrl" name="conditionFieldSelectUrl" bind="value:selected.conditionFieldSelectUrl" colspan="9"
                                prompt='<@spring.message "Url"/>' promptColspan="3" style="width:100%"/>
        </h:hlsHBox>
        </div>
        <div id="conditionFieldSelectVfBox" style="display:none">
        <h:hlsHBox>
            <h:hlsMaskedTextBox id="conditionFieldSelectVf" name="conditionFieldSelectVf" bind="value:selected.conditionFieldSelectVf" colspan="9"
                                prompt='<@spring.message "valueField"/>' promptColspan="3" style="width:100%"/>
        </h:hlsHBox>
        </div>
        <div id="conditionFieldSelectTfBox" style="display:none">
        <h:hlsHBox>
            <h:hlsMaskedTextBox id="conditionFieldSelectTf" name="conditionFieldSelectTf" bind="value:selected.conditionFieldSelectTf" colspan="9"
                                prompt='<@spring.message "textField"/>' promptColspan="3" style="width:100%"/>
        </h:hlsHBox>
        </div>
        <div id="selectCodeBox" style="display:none">
        <h:hlsHBox>
            <h:hlsMaskedTextBox id="conditionFieldSelectCode" name="conditionFieldSelectCode" bind="value:selected.conditionFieldSelectCode" colspan="9"
                                prompt='<@spring.message "lovitem.conditionfieldselectcode"/>' promptColspan="3" style="width:100%"/>
        </h:hlsHBox>
        </div>
        <h:hlsHBox style="display:none">
            <h:hlsMaskedTextBox id="conditionFieldTextfield" name="conditionFieldTextfield" bind="value:selected.conditionFieldTextfield" colspan="9"
                                prompt='<@spring.message "textField"/>' promptColspan="3" style="width:100%"/>
        </h:hlsHBox>
        <h:hlsHBox style="display:none">
            <h:hlsMaskedTextBox id="conditionFieldLovCode" name="conditionFieldLovCode" bind="value:selected.conditionFieldLovCode" colspan="9"
                                prompt='<@spring.message "lovitem.conditionfieldlovcode"/>' promptColspan="3" style="width:100%"/>
        </h:hlsHBox>
    </h:hlsForm>
    <div class="pull-right" style="padding-bottom:10px;margin-right: 15px;margin-top:20px;">
        <span id="hideForm" style="cursor: pointer" onclick="hideForm()" class="pull-right query-button" type="button">
            <@spring.message "hap.ok"/>
        </span>
    </div>
    <script>
    kendo.bind($('#editForm'),viewModel2);
    </script>
    </div>
    <h:hlsForm id="lovForm" style="width:100%;" title="Lov信息">
        <h:hlsHBox>
            <h:hlsMaskedTextBox id="code" name="code" bind="enabled:isEnabled,value:model.code" colspan="3"
                                prompt='<@spring.message "lov.code"/>' promptColspan="1" required="true" validationMessage="此项必须填写" style="width:100%"/>
            <h:hlsMaskedTextBox id="description" name="description" bind="value:model.description" colspan="3"
                         prompt='<@spring.message "lov.description"/>' promptColspan="1"  style="width:100%"/>
            <h:hlsMaskedTextBox id="title" name="title" bind="value:model.title" colspan="3"
                                prompt='<@spring.message "lov.title"/>' promptColspan="1"  style="width:100%"/>
        </h:hlsHBox>
        <h:hlsHBox>
            <h:hlsMaskedTextBox id="placeholder" name="placeholder" bind="value:model.placeholder" colspan="3"
                                prompt='<@spring.message "lov.placeholder"/>' promptColspan="1" style="width:100%"/>
            <h:hlsMaskedTextBox id="valueField" name="valueField" bind="value:model.valueField" colspan="3"
                                prompt='<@spring.message "lov.valuefield"/>' promptColspan="1" required="true" validationMessage="此项必须填写"  style="width:100%"/>
            <h:hlsMaskedTextBox id="textField" name="textField" bind="value:model.textField" colspan="3"
                                prompt='<@spring.message "lov.textfield"/>' promptColspan="1" required="true" validationMessage="此项必须填写"  style="width:100%"/>
        </h:hlsHBox>
        <h:hlsHBox>
            <h:hlsNumericTextBox id="height" bind="value:model.height" colspan="3" value="400" format="n0"
                                 prompt='<@spring.message "lov.height"/>' promptColspan="1" style="width:100%"/>
            <h:hlsNumericTextBox id="width" bind="value:model.width" colspan="3" value="500" format="n0"
                                 prompt='<@spring.message "lov.width"/>' promptColspan="1" style="width:100%"/>
            <h:hlsNumericTextBox id="queryColumns" bind="value:model.queryColumns" colspan="3" value="500" format="n0"
                                 prompt='<@spring.message "lov.querycolumns"/>' promptColspan="1" style="width:100%"/>
        </h:hlsHBox>
        <h:hlsHBox>
            <h:hlsDropDownList bind="value:model.lovPageSize,source:pageSizeData" id="lovPageSize" name="lovPageSize" style="width:100%" prompt='<@spring.message "lov.pagesize"/>'
                               promptColspan="1" colspan="3" value="10" valuePrimitive="true"/>
            <h:hlsDropDownList  id="sqlType" name="sqlType" style="width:100%" prompt='<@spring.message "lov.sqltype"/>'
                               promptColspan="1" colspan="3" />
            <h:hlsMaskedTextBox id="sqlId" name="sqlId" bind="value:model.sqlId" colspan="3"
                                prompt='<@spring.message "lov.sqlid"/>' promptColspan="1" required="true" validationMessage="此项必须填写"  style="width:100%"/>
            <h:hlsMaskedTextBox id="customUrl" name="customUrl" bind="value:model.customUrl" colspan="3"
                                prompt='<@spring.message "lovitem.ds_type.url"/>' promptColspan="1" required="true" validationMessage="此项必须填写"  style="width:100%;display:none"/>
            <script>
            $('#customUrl-prompt').css("display","none")
            </script>
            <h:hlsTextArea id="customSql" name="customSql" bind="value:model.customSql" colspan="3"
                           prompt='<@spring.message "lov.customsql"/>' promptColspan="1" required="true" validationMessage="此项必须填写"  style="width:100%;display:none"/>
            <script>
            $('#customSql-prompt').css("display","none")
            </script>
        </h:hlsHBox>
    </h:hlsForm>
    <h:dataSource id="dataSource" batch="true" serverPaging="false" requestEnd="requestEndFunc">
        <h:transport parameterMap="parameterMap">
            <h:read url="${base.contextPath}/sys/lovitem/query"/>
            <h:destroy contentType="application/json" type="POST" url="${base.contextPath}/sys/lovitem/remove"/>
        </h:transport>
        <h:schema data="rows" total="total">
            <h:model id="lovItemId">
                <h:fields>
                    <h:item name="display" type="string">
                        <h:validation required="true"/>
                    </h:item>
                    <h:item name="gridFieldName" type="string">
                        <h:validation required="true"/>
                    </h:item>
                    <h:item name="gridFieldWidth" type="number" defaultValue="200">
                    </h:item>
                    <h:item name="gridField" type="boolean" defaultValue="N" checkedValue="Y" uncheckedValue="N">
                    </h:item>
                    <h:item name="gridFieldAlign">
                        <h:validation required="true"/>
                    </h:item>
                    <h:item name="conditionField" type="boolean" checkedValue="Y" uncheckedValue="N">
                    </h:item>
                    <h:item name="gridFieldSequence" type="number">
                    </h:item>
                    <h:item name="conditionFieldWidth" type="number" defaultValue="200">
                    </h:item>
                    <h:item name="conditionFieldSequence" type="number" defaultValue="1">
                    </h:item>
                    <h:item name="isAutocomplete" type="checkbox">
                    </h:item>
                    <h:item name="autocompleteField" type="checkbox">
                    </h:item>
                </h:fields>
            </h:model>
        </h:schema>
    </h:dataSource>
    <h:hlsGridBox id="gridBox" hlsGridId="grid" hlsBtnType="add" dataSourceId="dataSource">
        <h:hlsGrid id="grid"  dataSource="dataSource" style="height:340px!important;" sortable="false" resizable="true"
                   editable="true" autoResize="false" hlsBtnType="DELETE" selectable='multiple,rowbox' locate="locateFunc">
            <h:columns>
                <h:column title='<@spring.message "lovitem.display"/>' field="display" width="210px">
                    <h:headerAttributes style="text-align:center" class="table-header-cell"/>
                </h:column>
                <h:column title='<@spring.message "lovitem.name"/>' field="gridFieldName" width="100px">
                    <h:headerAttributes style="text-align:center" class="table-header-cell"/>
                </h:column>
                <h:column title='<@spring.message "lovitem.gridfieldwidth"/>' field="gridFieldWidth" width="70px">
                    <h:headerAttributes style="text-align:center" class="table-header-cell"/>
                </h:column>
                <h:column title='<@spring.message "lovitem.gridcolumn"/>' field="gridField" width="60px" editor="fn:columnEditor">
                    <h:headerAttributes style="text-align:center" class="table-header-cell"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
                <h:column title='<@spring.message "lovitem.gridcolumnalign"/>' field="gridFieldAlign" width="80px" editor="fn:alignEditor" template="fn:alignTem">
                    <h:headerAttributes style="text-align:center" class="table-header-cell"/>
                </h:column>
                <h:column title='<@spring.message "lovitem.conditionfield"/>' field="conditionField" width="80px" editor="fn:conditionEditor">
                    <h:headerAttributes style="text-align:center" class="table-header-cell"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
                <h:column title='<@spring.message "lovitem.gridfieldsequence"/>' field="gridFieldSequence" width="60px">
                    <h:headerAttributes style="text-align:center" class="table-header-cell"/>
                </h:column>
                <h:column title='<@spring.message "lovitem.type"/>' width="80px" template="fn:typeTem">
                    <h:headerAttributes style="text-align:center" class="table-header-cell"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
            </h:columns>
        </h:hlsGrid>
    </h:hlsGridBox>
    <div style="height:50px!important;">
    </div>
    <h:hlsToolBar>
        <h:hlsButton id="save" click="saveLov" text="保存"></h:hlsButton>
        <h:hlsButton id="cancel" click="closeLovWindow" text="取消"></h:hlsButton>
    </h:hlsToolBar>
    <script><![CDATA[
    var validator = $("#lovForm").kendoValidator({
        invalidMessageType : "tooltip"
    }).data("kendoValidator");

    var getSqlTypeSelect = function(dSqlType){
        if(dSqlType == 0){
            viewModel.model.set("customSql","");
            viewModel.model.set("customUrl","");
            $("#customSql").css('display','none');
            $("#customUrl").css('display','none');
            $("#sqlId").css('display','block');
            $("#sqlId-prompt").empty();
            $("#sqlId-prompt").html('<span id="sqlId-prompt-required" class="hlsRequiredPromptImage">*</span><@spring.message "lov.sqlId"/>');
            $("#sqlId").attr("required",true);
            $("#customSql").attr("required",false);
            $("#customUrl").attr("required",false);
        }else if(dSqlType == 1){
            viewModel.model.set("sqlId","");
            viewModel.model.set("customUrl","");
            $("#sqlId").css('display','none');
            $("#customUrl").css('display','none');
            $("#customSql").css('display','block');
            $("#customSql").attr("required",true);
            $("#sqlId-prompt").empty();
            $("#sqlId-prompt").html('<span id="sqlId-prompt-required" class="hlsRequiredPromptImage">*</span><@spring.message "lov.customSql"/>');
            $("#sqlId").attr("required",false);
            $("#customUrl").attr("required",false);
        }else if(dSqlType == 2){
            viewModel.model.set("sqlId","");
            viewModel.model.set("customSql","");
            $("#sqlId").css('display','none');
            $("#customSql").css('display','none');
            $("#customUrl").css('display','block');
            $("#sqlId-prompt").empty();
            $("#sqlId-prompt").html('<span id="sqlId-prompt-required" class="hlsRequiredPromptImage">*</span><@spring.message "lovitem.ds_type.url"/>');
            $("#sqlId").attr("required",false);
            $("#customSql").attr("required",false);
            $("#customUrl").attr("required",true);
        }
        $("#sqlType").kendoDropDownList({
            dataTextField: "text",
            dataValueField: "value",
            dataSource: {
                data:[{ text: "<@spring.message 'lov.sqlId'/>", value: "<@spring.message 'lov.sqlId'/>" },
                    { text: "<@spring.message 'lov.customsql'/>", value: "<@spring.message 'lov.customsql'/>" },
                    { text: "<@spring.message 'lovitem.ds_type.url'/>",value:"<@spring.message 'lovitem.ds_type.url'/>"}]
            },
            animation: false,
            index:dSqlType,
            change: function(e) {
                var value = this.value();
                if(value=="<@spring.message 'lov.customsql'/>"){
                    $("#sqlId").css('display','none');
                    $("#customUrl").css('display','none');
                    $("#customSql").css('display','block');
                    $("#customSql").attr("required",true);
                    $("#sqlId-prompt").empty();
                    $("#sqlId-prompt").html('<span id="sqlId-prompt-required" class="hlsRequiredPromptImage">*</span><@spring.message "lov.customSql"/>');
                    $("#sqlId").attr("required",false);
                    $("#customUrl").attr("required",false);
                }else if(value=="<@spring.message 'lov.sqlId'/>"){
                    $("#customSql").css('display','none');
                    $("#customUrl").css('display','none');
                    $("#sqlId").css('display','block');
                    $("#sqlId-prompt").empty();
                    $("#sqlId-prompt").html('<span id="sqlId-prompt-required" class="hlsRequiredPromptImage">*</span><@spring.message "lov.sqlId"/>');
                    $("#sqlId").attr("required",true);
                    $("#customSql").attr("required",false);
                    $("#customUrl").attr("required",false);
                }else{
                    $("#sqlId").css('display','none');
                    $("#customSql").css('display','none');
                    $("#customUrl").css('display','block');
                    $("#sqlId-prompt").empty();
                    $("#sqlId-prompt").html('<span id="sqlId-prompt-required" class="hlsRequiredPromptImage">*</span><@spring.message "lovitem.ds_type.url"/>');
                    $("#sqlId").attr("required",false);
                    $("#customSql").attr("required",false);
                    $("#customUrl").attr("required",true);
                }
            }
        });
    }
        <#if RequestParameters.lovId??>
    $.ajax({
        url: '${base.contextPath}/sys/lov/load?lovId=${RequestParameters.lovId!0}',
        type: "POST",
        dataType: "json",
        contentType: "application/json",
        // data       : kendo.stringify(para),
        success: function (args) {
            var a0 = args.rows[0] || {};
            var defaultSqlType = 0;
            for (var k in a0) {
                if(k=='sqlId'){
                    if(a0[k]){
                        defaultSqlType = 0;
                    }
                }
                if(k=='customSql'){
                    if(a0[k]){
                        defaultSqlType = 1;
                    }
                }
                if(k=='customUrl'){
                    if(a0[k]){
                        defaultSqlType = 2;
                    }
                }
                if (k == 'delayLoad' || k == 'needQueryParam') {
                    var elementId = k;
                    viewModel.model.set(k, a0[k] == 'Y');
                    if(viewModel.model.get(k)){
                        $("#"+k).attr("checked",true);
                    }
                }
                else
                    viewModel.model.set(k, a0[k]);
            }
            getSqlTypeSelect(defaultSqlType);
        },
        error: function () {

        }
    });

    <#else>
    var defaultSqlType = 0;
    getSqlTypeSelect(defaultSqlType);
    </#if>
    var edit;
    function openEditor(item) {
        edit = $("#queryEdit").kendoWindow({
            width: 500,
            resizable:false,
            title: '<@spring.message "lovitem.type"/>',
            modal: true,
            open: function () {
                //打开时对其做处理
                if (viewModel2.selected.conditionFieldType == "select") {
                    $("#dsType").css("display", "block")
                    if (!viewModel2.selected.comboboxType) {
                        if (viewModel2.selected.conditionFieldSelectCode) {
                            viewModel2.selected.set('comboboxType', "code")
                        } else if (viewModel2.selected.conditionFieldSelectUrl
                            || viewModel2.selected.conditionFieldSelectVf
                            || viewModel2.selected.conditionFieldSelectTf) {
                            viewModel2.selected.set('comboboxType', "url")
                        }
                    }

                    // if(viewModel2.selected.comboboxType){
                    if (viewModel2.selected.comboboxType == "url") {
                        $("#selectCodeBox").css("display", "none")
                        viewModel2.selected.set('conditionFieldSelectCode', '')
                        $("#urlBox").css("display", "block")
                        $("#conditionFieldSelectTfBox").css("display", "block")
                        $("#conditionFieldSelectVfBox").css("display", "block")
                    } else if (viewModel2.selected.comboboxType == "code") {
                        $("#urlBox").css("display", "none")
                        viewModel2.selected.set('conditionFieldSelectUrl', '')
                        $("#conditionFieldSelectTfBox").css("display", "none")
                        viewModel2.selected.set('conditionFieldSelectTf', '')
                        $("#conditionFieldSelectVfBox").css("display", "none")
                        viewModel2.selected.set('conditionFieldSelectVf', '')
                        $("#selectCodeBox").css("display", "block")
                    }
                } else {
                    $("#urlBox").css("display", "none")
                    $("#conditionFieldSelectTfBox").css("display", "none")
                    $("#conditionFieldSelectVfBox").css("display", "none")
                    $("#selectCodeBox").css("display", "none")
                    $("#dsTypeBox").css("display", "none")
                    viewModel2.selected.set('conditionFieldSelectCode', '')
                    viewModel2.selected.set('conditionFieldSelectUrl', '')
                    viewModel2.selected.set('conditionFieldSelectTf', '')
                    viewModel2.selected.set('conditionFieldSelectVf', '')
                }
            }
        }).data("kendoWindow");
        edit.center().open();

    }

    function hideForm() {
        edit.close();
    }

    ]]></script>
</h:screen>