<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: DJ  
    $Date: 2013-2-26 下午2:37:49  
    $Revision: 1.0  
    $Purpose: calcConfigScreen
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query defaultWhereClause="t1.price_list != ${/parameter/@price_list} and t1.enabled_flag = &apos;Y&apos;" fetchAll="true" model="hls.HLS050.hls_price_list" rootPath="price_list_select_list"/>
    </a:init-procedure>
    <a:view>
        <a:link id="svcLink_config_batch_update" url="${/request/@context_path}/modules/hls/HLS050/hls_fin_calc_config_batch_update.lsc"/>
        <script type="text/javascript"><![CDATA[
        	var temp_list = [];
        	
        	function temp_add()
        	{
        	    var head_records=$('calcConfigScreen_mainDs').getSelected();
                var line_records=$('calcConfigScreen_lineDs').getSelected();
                var m = head_records.length;
                for (var i=0;i<m;i++)
                {
                    temp_list[i]={
                        config_id:head_records[i].get('config_id'),
                        prompt:head_records[i].get('prompt')
                    };
                }
                var n = line_records.length;
                for (var i=0;i<n;i++)
                {
                    temp_list[i+m]={
                        config_id:line_records[i].get('config_id'),
                        prompt:line_records[i].get('prompt')
                    };
                }
        	}
        	
        	function temp_generate_str()
        	{
        	    var length = temp_list.length;
                var too_long = 'N';
                var str = '';
                if(length>10)
                {
                    too_long = 'Y';
                    length = 10;
                }
                for (var i=0;i<length;i++)
                {
                    str=str+temp_list[i]['prompt']+'/'
                }
                if(too_long=='Y')
                {
                    str = str+'...';
                }
                return str;
        	}
        	
        	
        	
        	function winClose_batch_update()
        	{
        	    $('hls_fin_calc_config_batch_update').close();
        	}
        	
        	function addColumnName(column_name,description)
        	{
        	    $('selectColumnNameDs').create({
        	        column_name:column_name,
        	        description:description
        	    });
        	}
            function init_columnNameDs()
            {
                addColumnName('PROMPT','${l:HLS050.HLS_FIN_CALC_CONFIG.PROMPT}');
				addColumnName('ENABLED_FLAG','${l:HLS050.HLS_FIN_CALC_CONFIG.ENABLED_FLAG}');
				addColumnName('DISPLAY_FLAG','${l:HLS050.HLS_FIN_CALC_CONFIG.DISPLAY_FLAG}');
				addColumnName('DISPLAY_ORDER','${l:HLS050.HLS_FIN_CALC_CONFIG.DISPLAY_ORDER}');
				addColumnName('CF_ITEM','${l:HLS.CF_ITEM}');
				addColumnName('INPUT_MODE','${l:HLS050.HLS_FIN_CALC_CONFIG.INPUT_MODE}');
				addColumnName('VALIDATION_TYPE','${l:HLS050.HLS_FIN_CALC_CONFIG.VALIDATION_TYPE}');
				addColumnName('VALIDATION_SQL','${l:HLS050.HLS_FIN_CALC_CONFIG.VALIDATION_SQL}');
				addColumnName('LOV_RETURN_VCODE','${l:HLS050.HLS_FIN_CALC_CONFIG.LOV_RETURN_VCODE}');
				addColumnName('PRECISION','${l:HLS050.HLS_FIN_CALC_CONFIG.PRECISION}');
				addColumnName('ZERO_FILL','${l:HLS050.HLS_FIN_CALC_CONFIG.ZERO_FILL}');
				addColumnName('ALLOW_FORMAT','${l:HLS050.HLS_FIN_CALC_CONFIG.ALLOW_FORMAT}');
				addColumnName('ALLOW_DECIMAL','${l:HLS050.HLS_FIN_CALC_CONFIG.ALLOW_DECIMAL}');
				addColumnName('ALIGNMENT','${l:HLS050.HLS_FIN_CALC_CONFIG.ALIGNMENT}');
				addColumnName('WIDTH','${l:HLS050.HLS_FIN_CALC_CONFIG.WIDTH}');
				addColumnName('PERCENT','${l:HLS050.HLS_FIN_CALC_CONFIG.PERCENT}');
				addColumnName('DEFAULT_VALUE','${l:HLS050.HLS_FIN_CALC_CONFIG.DEFAULT_VALUE}');
				addColumnName('LOV_CASCADE_PARA1','${l:HLS050.HLS_FIN_CALC_CONFIG.LOV_CASCADE_PARA1}');
				addColumnName('LOV_CASCADE_PARA2','${l:HLS050.HLS_FIN_CALC_CONFIG.LOV_CASCADE_PARA2}');
				addColumnName('LOV_CASCADE_PARA3','${l:HLS050.HLS_FIN_CALC_CONFIG.LOV_CASCADE_PARA3}');
				var ds = $('selectColumnNameDs');
				ds.locate(1);
				var record=ds.getAt(0);
				ds.select(record);
				
				temp_add();
                var prompt_str = temp_generate_str();
                $('selectPage_headDs').getAt(0).set('prompt_str',prompt_str);
            }
            
            function submit_batch_update()
            {
                var data={};
                data['datas']=[];
                
                var price_records=$('selectPriceListDs').getSelected();
                if(price_records.length<1)
                {
                    Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS050.ERROR.PLEASE_CHOOSE_PRICE_LIST}');
                    return ;
                }
                var price_list=[];
                for(var i = 0,j=price_records.length;i<j;i++)
                {
                    price_list[i]={
                        value:price_records[i].get('price_list')
                    };
                }
                
                
                data['datas'][0] = {
                	name:'PRICE_LIST',
                	value_list:price_list
                };
                
                var column_records=$('selectColumnNameDs').getSelected();
                if(column_records.length<1)
                {
                    Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS050.ERROR.PLEASE_CHOOSE_COLUMN_NAME}');
                    return ;
                }
                var column_list=[];
                for(var i = 0,j=column_records.length;i<j;i++)
                {
                    column_list[i]={
                    	value:column_records[i].get('column_name')
                    };
                }
                
                data['datas'][1] = {
                	name:'COLUMN_NAME',
                	value_list:column_list
                };
                
                data['include_formula']=$('selectPage_headDs').getAt(0).get('include_formula');
                
                var config_list = [];
                for(var i = 0,j = temp_list.length;i<j;i++)
                {
                    config_list[i]={
                        value : temp_list[i]['config_id']
                    };
                }
                data['datas'][2] = {
                	name:'CONFIG_ID',
                	value_list:config_list
                };
                
                Leaf.showConfirm('${l:HLS.PROMPT}', '${l:HLS.ARE_YOU_SURE}', function()
            	{
            	    Leaf.request({
	                    url: $('svcLink_config_batch_update').getUrl(),
	                    para: data,
	                    success: function(res) {
	                        Leaf.SideBar.show({
	                            msg: '${l:HLS.SUBMIT_SUCCESS}',
	                            duration: 2000
	                        });
	                        winClose_batch_update();
	                    },
	                    scope: this
	                });
        		});
                
                
            }
            
        ]]></script>
        <a:dataSets>
            <a:dataSet id="selectPage_headDs" autoCreate="true">
                <a:fields>
                    <a:field name="include_formula" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="prompt_str" readOnly="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="selectPriceListDs" selectable="true">
                <a:datas dataSource="/model/price_list_select_list"/>
            </a:dataSet>
            <a:dataSet id="selectColumnNameDs" selectable="true">
                <a:fields>
                    <a:field name="column_name"/>
                    <a:field name="description"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="winClose_batch_update" text="HLS.CLOSE"/>
                <a:gridButton click="submit_batch_update" text="HLS.UPDATE"/>
            </a:screenTopToolbar>
            <a:form column="2" height="40" labelSeparator="">
                <a:checkBox name="include_formula" bindTarget="selectPage_headDs" prompt="HLS050.INCLUDE_FORMULA"/>
                <a:textField name="prompt_str" bindTarget="selectPage_headDs" prompt=" " width="700"/>
            </a:form>
            <a:form column="2">
                <a:grid id="selectPriceListDs_grid" bindTarget="selectPriceListDs" height="450" width="500">
                    <a:columns>
                        <a:column name="price_list" width="200"/>
                        <a:column name="description" width="250"/>
                    </a:columns>
                </a:grid>
                <a:grid id="selectColumnNameDs_grid" bindTarget="selectColumnNameDs" height="450" width="500">
                    <a:columns>
                        <a:column name="column_name" prompt="HLS.COLUMN_NAME" width="200"/>
                        <a:column name="description" prompt="HLS.COLUMN_DESC" width="250"/>
                    </a:columns>
                </a:grid>
            </a:form>
        </a:screenBody>
        <script type="text/javascript"><![CDATA[
            Leaf.onReady(function() {
                init_columnNameDs();
            });
        ]]></script>
    </a:view>
</a:screen>
