<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129  
    $Date: 2013-9-13 下午2:37:49  
    $Revision: 1.0  
    $Purpose: configFormulaScreen
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure/>
    <a:view>
        <script type="text/javascript"><![CDATA[
        
        function configFormulaScreen_add() {
            $('configFormulaScreen_mainDs_grid').showEditorByRecord($('configFormulaScreen_mainDs').create());
        }
        
        function configFormulaScreen_close(){
            $('hls_fin_calc_config_tplt_fl').close();
        }
        function configformulascreen_remove(){
            $('configFormulaScreen_mainDs_grid').remove();
        }
        
        function configFormulaScreen_save() {
            var ds = $('configFormulaScreen_mainDs');
            if (ds.validate()) {
                ds.submit();
            }
        }
        
        function editFunction_configFormulaScreen_schedule_name(record, name) {
            if(record.isNew)
            {
                return 'configFormulaScreen_mainDs_grid_tf';
            }
            else
            {
                return '';
            }
        }
        
        function configFormulaScreen_load()
        {
            Leaf.request({
                url: $('bmLink_configFormulaScreen_load').getUrl(),
                para:{
                },
                success: function (res)
                {
                    configFormulaScreen_query();
                },
                scope: this
            });
        }
        
        function editFunction_configFormulaScreen_price_list(record,name)
        {
    	    if(record.isNew){
    	        return 'configFormulaScreen_mainDs_grid_tf_upper';
    	    }else{
    	        return '';
    	    }
        }
        
        function winOpen_configFormulaScreen_set_up(price_list)
        {
            new Leaf.Window({
                id: 'hls_fin_calc_config',
                url: $('pageLink_configFormulaScreen_set_up').getUrl(),
                params:{
                	price_list:price_list
                },
                title: '${l:FND050.WIN_TITLE.SET_UP}',
                fullScreen:true
            });
        }
        
        function onSubmitSuccess_configFormulaScreen_mainDs(ds,res)
        {
            ds.query(ds.currentPage);
        }
         
        function onupdate_configFormulaScreen_mainDs(ds,record,name,value,old_value){
            if(name=='matrix_j_type'){
                if(value=='CYCLE'){
                    record.getField('matrix_j_interval').setRequired(true);
                }else{
                    record.getField('matrix_j_interval').setRequired(false);
                }
            }
        }
        function hls050_editor_calc_seq(record,name){
            if('${/parameter/@layout_area_seq}'=='L'){
                record.getField(name).setRequired(true);
            }else{
                record.getField(name).setRequired(false);
            }
            return 'configFormulaScreen_mainDs_grid_nf';
        }
          function hls050_editor_matrix_j_type_display(record,name){
            if('${/parameter/@layout_area_seq}'=='L'){
                record.getField(name).setRequired(true);
            }else{
                record.getField(name).setRequired(false);
            }
            return 'configFormulaScreen_mainDs_grid_comb';
        }  
         function hls050_editor_matrix_j_initial(record,name){
            if('${/parameter/@layout_area_seq}'=='L'){
                record.getField(name).setRequired(true);
            }else{
                record.getField(name).setRequired(false);
            }
            return 'configFormulaScreen_mainDs_grid_tf';
        }
        function hls050_editor_calc_formula(record,name){
            /* if('${/parameter/@layout_area_seq}'=='L'){
                record.getField(name).setRequired(true);
            }else{
                record.getField(name).setRequired(false);
            } */
            return 'configFormulaScreen_mainDs_grid_tf';
        }
        
        function enabled_flag_validate(record,name,value)
        {
            var records=$('configFormulaScreen_mainDs').getAll();
            var index=$('configFormulaScreen_mainDs').indexOf(record);
            if(value=='Y')
            {
               for(var i=0;i<records.length;i++)
	            {
	                if(records[i].get('enabled_flag')=='Y' && i!=index )
	                {	
	                    return '不能同时启用多个公式';
	                }
	            }
            }
            return true;
        }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="configFormulaScreen_matrixJTypeDs" lookupCode="HLS050_MATRIX_J_TYPE"/>
            <a:dataSet id="calcConfigScreen_defaultDs" autoQuery="true" fetchAll="true" model="hls.HLS055.hls_fin_calc_config_default_value" queryUrl="${/request/@context_path}/autocrud/hls.HLS055.hls_fin_calc_config_default_value/query?column_id=${/parameter/@column_id}&amp;layout_area_seq=${/parameter/@layout_area_seq}">
                <a:fields>
                    <a:field name="column_code" prompt="HLS050.HLS_FIN_CALC_CONFIG.COLUMN_CODE" readOnly="true"/>
                    <a:field name="column_name" prompt="HLS050.HLS_FIN_CALC_CONFIG.COLUMN_NAME" readOnly="true"/>
                    <a:field name="prompt" prompt="HLS050.HLS_FIN_CALC_CONFIG.PROMPT" readOnly="true"/>
                    <a:field name="data_type_display" prompt="HLS050.HLS_FIN_CALC_CONFIG.DATA_TYPE" readOnly="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="configFormulaScreen_mainDs" autoQuery="true" model="hls.HLS055.hls_fin_calc_config_tplt_fl" queryUrl="${/request/@context_path}/autocrud/hls.HLS055.hls_fin_calc_config_tplt_fl/query?column_id=${/parameter/@column_id}&amp;layout_area_seq=${/parameter/@layout_area_seq}" selectable="true">
                <a:fields>
                    <a:field name="formula_id"/>
                    <a:field name="layout_area_seq" defaultValue="${/parameter/@layout_area_seq}"/>
                    <a:field name="matrix_i" defaultValue="${/parameter/@column_id}"/>
                    <a:field name="matrix_j_type_display" displayField="code_value_name" options="configFormulaScreen_matrixJTypeDs" returnField="matrix_j_type" valueField="code_value"/>
                    <a:field name="column_id" defaultValue="${/parameter/@column_id}"/>
                    <a:field name="company_id"/>
                    <a:field name="enabled_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="calc_seq"/>
                    <a:field name="matrix_j_initial"/>
                    <a:field name="calc_formula" required="true"/>
                    <a:field name="matrix_j_type"/>
                    <a:field name="enabled_flag" validator="enabled_flag_validate"/>
                </a:fields>
                <a:events>
                    <a:event name="submitsuccess" handler="onSubmitSuccess_configFormulaScreen_mainDs"/>
                    <a:event name="update" handler="onupdate_configFormulaScreen_mainDs"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="configFormulaScreen_close" text="HLS.CLOSE"/>
                <a:gridButton click="configFormulaScreen_add" text="HLS.NEW"/>
                <a:gridButton click="configformulascreen_remove" text="HLS.REMOVE"/>
                <a:gridButton click="configFormulaScreen_save" text="HLS.SAVE"/>
            </a:screenTopToolbar>
            <a:form bindTarget="calcConfigScreen_defaultDs" column="4" title=" " width="860">
                <a:textField name="column_code" bindTarget="calcConfigScreen_defaultDs" style="margin-left:23px"/>
                <a:textField name="column_name" bindTarget="calcConfigScreen_defaultDs" style="margin-left:10px"/>
                <a:textField name="data_type_display" bindTarget="calcConfigScreen_defaultDs" style="margin-left:10px"/>
                <a:textField name="prompt" bindTarget="calcConfigScreen_defaultDs" style="margin-left:10px"/>
            </a:form>
            <a:switch test="/parameter/@layout_area_seq">
                <a:case value="L">
                    <a:grid id="configFormulaScreen_mainDs_grid" bindTarget="configFormulaScreen_mainDs" height="300" navBar="true" width="860">
                        <a:columns>
                            <a:column name="layout_area_seq" width="60"/>
                            <a:column name="matrix_i" width="50"/>
                            <a:column name="calc_seq" align="right" editorFunction="hls050_editor_calc_seq" width="60"/>
                            <a:column name="matrix_j_type_display" editorFunction="hls050_editor_matrix_j_type_display" width="60"/>
                            <a:column name="matrix_j_initial" editorFunction="hls050_editor_matrix_j_initial" width="50"/>
                            <a:column name="matrix_j_interval" editor="configFormulaScreen_mainDs_grid_tf" width="50"/>
                            <a:column name="calc_formula" editorFunction="hls050_editor_calc_formula" width="400"/>
                            <a:column name="enabled_flag" editor="configFormulaScreen_mainDs_grid_check" width="60"/>
                        </a:columns>
                        <a:editors>
                            <a:textField id="configFormulaScreen_mainDs_grid_tf"/>
                            <a:lov id="configFormulaScreen_mainDs_grid_lov"/>
                            <a:checkBox id="configFormulaScreen_mainDs_grid_check"/>
                            <a:numberField id="configFormulaScreen_mainDs_grid_nf" allowDecimals="false"/>
                            <a:comboBox id="configFormulaScreen_mainDs_grid_comb"/>
                        </a:editors>
                    </a:grid>
                </a:case>
                <a:case value="H">
                    <a:grid id="configFormulaScreen_mainDs_grid" bindTarget="configFormulaScreen_mainDs" height="300" navBar="true" width="860">
                        <a:columns>
                            <a:column name="layout_area_seq" width="60"/>
                            <a:column name="matrix_i" width="60"/>
                            <a:column name="calc_formula" editor="configFormulaScreen_mainDs_grid_tf" width="500"/>
                            <a:column name="enabled_flag" editor="configFormulaScreen_mainDs_grid_check" width="60"/>
                        </a:columns>
                        <a:editors>
                            <a:textField id="configFormulaScreen_mainDs_grid_tf"/>
                            <a:checkBox id="configFormulaScreen_mainDs_grid_check"/>
                        </a:editors>
                    </a:grid>
                </a:case>
            </a:switch>
        </a:screenBody>
    </a:view>
</a:screen>
