<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Peter Soong  
    $Date: 2014-07-08 14:54:34 
    $Revision: 1.0  
    $Purpose: 条件表维护
-->
<a:screen xmlns:c="leaf.application.action" xmlns:p="uncertain.proc" xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query model="sys.SYS210.get_sys_table" rootPath="sys_table_path"/>
        <a:model-query autocount="false" fetchall="true" model="sys.SYS210.get_line_dimension" rootpath="line_dimension"/>
    </a:init-procedure>
    <a:view>
        <!-- <a:link id="sys_service_welcome_link" url="${/request/@context_path}/welcome.lview"/> -->
        <a:link id="sys_dimensions_delete_link" model="sys.SYS210.sys_dimensions_detail" modelaction="delete"/>
        <a:screen-include screen="modules/hls/hls_common_javascript.lview"/>
        <script type="text/javascript"><![CDATA[
            function queryFunction() {
                $('lease_times_Ds').query();
            }
            
            function sys_201_quit() {
                $('sys_dimensions_detail_id').close();
            }
            
            function onSubmit(ds) {
                var fieldsRecords = $('grps_ln_ds').getAll();
                var records = $('lease_times_Ds').getAll();
                for (var i = 0;i < records.length;i++) {
                    var codes = 'condition_code';
                    var values = records[i].get('condition_code');
                    /*  var codes = fieldsRecords[0].get('mapping_condition_code');
                     var values = records[i].get(codes);
                     if ( !! (fieldsRecords[0].get('ref_id_field'))) {
                     var c = fieldsRecords[0].get('mapping_condition_code') + '_c';
                     codes = codes + '*' + fieldsRecords[0].get('mapping_condition_code') + '_c';
                     values = values + '*' + records[i].get(c);
                     }*/
                    if (typeof(values) != "undefined") {
                        for (var j = 0;j < fieldsRecords.length;j++) {
                            var code = fieldsRecords[j].get('mapping_condition_code');
                            if (typeof(records[i].get(code)) != "undefined") {
                                codes = codes + '*' + code;
                                values = values + '*' + records[i].get(code);
                                if ( !! (fieldsRecords[j].get('ref_id_field'))) {
                                    c = code + '_c';
                                    codes = codes + '*' + c;
                                    values = values + '*' + records[i].get(c);
                                }
                                /* alert(codes);
                                 alert(values); */
                            }
                        }
                        //codes = codes + '*' + 'condition_code';
                        // values = values + '*' + records[i].get('condition_code');
                        records[i].set('mapping_condition', codes);
                        records[i].set('mapping_condition_value', values);
                        records[i].set('generated_table', '${/model/sys_table_path/record/@generated_table}');
                    }
                }
            
            
            }
            
            function submitSuccess() {
                $('lease_times_Ds').query();
            }
            
            function removeDelete(ds, record, index) {
            
                record.set('generated_table', '${/model/sys_table_path/record/@generated_table}');
                Leaf.request({
                    url: $('sys_dimensions_delete_link').getUrl(),
                    para: record.data,
                    success: function(args) {
                        $('lease_times_Ds').query();
                    },
                    scope: this
                });
            
            }
            
            function lov_event(lov) {
            
                var record = $('lease_times_Ds').getCurrentRecord();
                var condition_code_desc = record.getMeta().getField('condition_code_desc');
                var condition_usage_type = '${/parameter/@condition_usage_type}';
                condition_code_desc.setLovPara('condition_usage_type', condition_usage_type);
            }
            
            function sys_201_save() {
                $('lease_times_Ds').submit();
            }
            
            function sys_201_clear() {
                $('lease_times_grid').clear();
            }
            
            function sys_201_add() {
                $('lease_times_grid').showEditorByRecord($('lease_times_Ds').create());
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="grps_ln_ds">
                <a:datas dataSource="/model/line_dimension"/>
            </a:dataSet>
            <a:dataSet id="sys210_query_da" autoCreate="true"/>
            <a:dataSet id="lease_times_Ds" autoPageSize="true" autoQuery="true" model="sys.SYS210.sys_dimensions_detail" queryDataSet="sys210_query_da" queryUrl="${/request/@context_path}/autocrud/sys.SYS210.sys_dimensions_detail/query?generated_table=${/model/sys_table_path/record/@generated_table}" selectable="true" submitUrl="${/request/@context_path}/autocrud/sys.SYS210.sys_dimensions_detail/batch_update?generated_table=${/model/sys_table_path/record/@generated_table}">
                <a:fields>
                    <a:field name="generated_table" defaultValue="${/model/sys_table_path/record/@generated_table}"/>
                    <a:field name="condition_code_desc" lovGridHeight="320" lovHeight="460" lovService="sys.SYS210.sys_condition_code_lov" lovWidth="550" required="true" title="条件代码选择">
                        <a:mapping>
                            <a:map from="condition_code" to="condition_code"/>
                            <a:map from="description" to="condition_code_desc"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="condition_code"/>
                    <a:placeHolder id="dynamicLineFields"/>
                </a:fields>
                <a:events>
                    <a:event name="beforesubmit" handler="onSubmit"/>
                    <a:event name="submitsuccess" handler="submitSuccess"/>
                    <a:event name="remove" handler="removeDelete"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="sys_201_quit" text="HLS.EXIT"/>
                <a:gridButton click="sys_201_add" text="HLS.NEW"/>
                <a:gridButton click="sys_201_clear" text="HLS.REMOVE"/>
                <a:gridButton click="sys_201_save" text="HLS.SAVE"/>
                <a:gridButton click="queryFunction" text="HLS.QUERY"/>
            </a:screenTopToolbar>
            <a:form column="2" title="查询条件">
                <a:textField name="function" bindTarget="sys210_query_da" prompt="功能号"/>
            </a:form>
            <a:grid id="lease_times_grid" bindTarget="lease_times_Ds" marginHeight="160" marginWidth="100" navBar="true">
                <a:columns>
                    <a:column name="condition_code_desc" align="center" editor="lease_times_grid_lov" prompt="条件代码" width="200"/>
                    <a:placeHolder id="dynamicLineColumn"/>
                </a:columns>
                <a:editors>
                    <a:textField id="lease_times_grid_tf"/>
                    <a:lov id="lease_times_grid_lov">
                        <a:events>
                            <a:event name="beforetriggerclick" handler="lov_event"/>
                        </a:events>
                    </a:lov>
                    <a:lov id="dy_grid_lov"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
    <a:view-config>
        <c:create-config targetId="dynamicLineFields">
            <p:loop nullable="true" source="/model/line_dimension">
                <!-- 判断是否是LOV  -->
                <p:switch test="@lov_flag">
                    <p:case value="Y">
                        <p:switch test="@ref_id_field">
                            <p:case value="null">
                                <c:process-config>
                                    <a:field name="${@mapping_condition_code}" lovGridHeight="300" lovHeight="450" lovUrl="${/request/@context_path}/modules/sys/SYS210/sys_condition_code_lov.lview?condition_table=${/parameter/@condition_table}&amp;mapping_condition_code=${@mapping_condition_code}" lovWidth="500" required="true" title="选择">
                                        <a:mapping>
                                            <a:map from="code" to="${@mapping_condition_code}"/>
                                            <!-- <a:map from="id" to="${@mapping_condition_code}"/>  -->
                                        </a:mapping>
                                    </a:field>
                                </c:process-config>
                            </p:case>
                            <p:case value="*">
                                <c:process-config>
                                    <a:field name="${@mapping_condition_code}_c" lovGridHeight="400" lovHeight="450" lovUrl="${/request/@context_path}/modules/sys/SYS210/sys_condition_code_lov.lview?condition_table=${/parameter/@condition_table}&amp;mapping_condition_code=${@mapping_condition_code}" lovWidth="500" required="true" title="选择">
                                        <a:mapping>
                                            <a:map from="code" to="${@mapping_condition_code}_c"/>
                                            <a:map from="id" to="${@mapping_condition_code}"/>
                                        </a:mapping>
                                    </a:field>
                                    <a:field name="${@mapping_condition_code}"/>
                                </c:process-config>
                            </p:case>
                        </p:switch>
                    </p:case>
                    <!-- END 判断是否是显示为code 存储为id  -->
                    <p:case value="N">
                        <c:process-config>
                            <a:field name="${@mapping_condition_code}"/>
                        </c:process-config>
                    </p:case>
                </p:switch>
                <!-- END  判断是否是LOV  -->
                <!-- 
                <c:process-config>
                    <a:field name="${@mapping_condition_code}"/>
                </c:process-config> -->
            </p:loop>
        </c:create-config>
        <c:create-config targetId="dynamicLineColumn">
            <p:loop nullable="true" source="/model/line_dimension">
                <p:switch test="@lov_flag">
                    <!-- 判断是否是LOV  -->
                    <p:case value="Y">
                        <!-- <c:process-config>
                            <a:column name="${@mapping_condition_code}" editor="dy_grid_lov" prompt="${@mapping_condition_sql_desc}" width="200"/>
                        </c:process-config> -->
                        <!-- 判断是否是显示为code 存储为id  -->
                        <p:switch test="@ref_id_field">
                            <p:case value="null">
                                <c:process-config>
                                    <a:column name="${@mapping_condition_code}" editor="dy_grid_lov" prompt="${@mapping_condition_sql_desc}" sortable="true" width="200"/>
                                </c:process-config>
                            </p:case>
                            <p:case value="*">
                                <c:process-config>
                                    <a:column name="${@mapping_condition_code}_c" editor="dy_grid_lov" prompt="${@mapping_condition_sql_desc}" sortable="true" width="200"/>
                                </c:process-config>
                            </p:case>
                        </p:switch>
                        <!-- END 判断是否是显示为code 存储为id  -->
                    </p:case>
                    <p:case value="N">
                        <c:process-config>
                            <a:column name="${@mapping_condition_code}" editor="lease_times_grid_tf" prompt="${@mapping_condition_sql_desc}" sortable="true" width="200"/>
                        </c:process-config>
                    </p:case>
                </p:switch>
                <!-- END  判断是否是LOV  -->
                <!--   
                <c:process-config>
                    <a:column name="${@mapping_condition_code}" align="center" editor="lease_times_grid_tf" prompt="${@mapping_condition_sql_desc}" width="200"/>
                </c:process-config> -->
            </p:loop>
        </c:create-config>
    </a:view-config>
</a:screen>