<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Mouse Chow  
    $Date: 2012-12-23 上午10:29:43  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true">
    <a:init-procedure><![CDATA[
    ]]></a:init-procedure>
    <a:view>
        <a:link id="pageLink_chanceMaintain_chanceUpdate" url="${/request/@context_path}/modules/lch/LCH502/lease_chance_update.lview"/>
        <a:link id="pageLink_chanceMaintain_chanceCreate" url="${/request/@context_path}/modules/lch/LCH501/lease_chance_create.lview"/>
        <a:link id="pageLink_chanceMaintain_createProject" url="${/request/@context_path}/modules/lch/LCH502/lease_chance_create_project.lview"/>
        <a:link id="bmLink_chanceMaintain_updateStatus" model="lch.LCH501.lch_lease_chance_hds" modelaction="execute"/>
        <a:link id="sys_service_welcome_link" url="${/request/@context_path}/welcome.lview"/>
        <script type="text/javascript"><![CDATA[
        	function chanceMaintainScreen_forward() {
	            history.go(1);
	        }
	        
	        function chanceMaintainScreen_back() {
	            history.go(-1);
	        }
	        
	        function chanceMaintainScreen_quit() {
	            location.href = $('sys_service_welcome_link').getUrl();
	        }
	    	
	        function chanceMaintainDs_grid_query() {
	            $('chanceMaintainDs').query();
	        }
	        
	        function chanceMaintainDs_grid_refresh() {
	            var ds=$('chanceMaintainDs');
	            ds.query(ds.currentPage);
	        }
	        
	        function chanceMaintainScreen_add() {
                window.location.href=$('pageLink_chanceMaintain_chanceCreate').getUrl();
            }
	        
	        function chanceMaintainDs_grid_clear() {
	            $('chanceMaintainDs_grid').clear();
	        }
			
			function chanceMaintainDs_grid_update(lease_chance_id,status){
			    var maintain_type;
			    if(status=='CLOSED'||status=='CREATED')
			    {
			        maintain_type='READONLY';
			    }
			    else
			    {
			        maintain_type='UPDATE';
			    }
		    	window.location.href=$('pageLink_chanceMaintain_chanceUpdate').getUrl()+'?lease_chance_id=' + lease_chance_id+'&maintain_type='+maintain_type;
			}
			
			function render_chanceMaintainDs_grid(value,record,name)
			{
			    if(name=='lease_chance_code')
			    {
			        return '<a href="javascript:chanceMaintainDs_grid_update(' + record.get('lease_chance_id') + ',\''+ record.get('status') +'\');">' + value + '</a>';
			    }
			    else if(name=='creation_date')
			    {
			        if(!Ext.isEmpty(value))
			        {
			            return value.parseDate('yyyy-mm-dd').format('yyyy-mm-dd');
			        }
			        return '';
			    }   
			}
			
			function chanceMaintainScreen_closeChance()
			{
			    var record=$('chanceMaintainDs').getCurrentRecord();
			    if(Ext.isEmpty(record))
			    {
			        return ;
			    }
			    var status=record.get('status');
			    Leaf.request({
                    url: $('bmLink_chanceMaintain_updateStatus').getUrl(),
                    para: {
                    	lease_chance_id:record.get('lease_chance_id'),
                    	status:'CLOSED'
                    },
                    success: function(res) {
                        chanceMaintainDs_grid_refresh();
                    },
                    scope: this
                });
			}
			function chanceMaintainScreen_createToProject()
			{
			    var record=$('chanceMaintainDs').getCurrentRecord();
			    if(Ext.isEmpty(record))
			    {
			        return ;
			    }
			    var win = new Leaf.Window({
			        url: $('pageLink_chanceMaintain_createProject').getUrl(),
                    id: 'lease_chance_create_project',
                    params: {
                        document_type: record.get('document_type'),
                        lease_chance_id:record.get('lease_chance_id')
                    },
                    title: '${l:PRJ501.PRJ_HISTORY_VERSION}',
                    width: 600,
                    height: 350
                });
                
			    win.on('close',function(){
                	chanceMaintainDs_grid_refresh();
            	});
			    
			}
    		
    	]]></script>
        <a:dataSets>
            <a:dataSet id="chanceMaintain_organizationDs" loadData="true" model="basic.hls_lease_organization_for_lov"/>
            <a:dataSet id="chanceMaintain_channelDs" loadData="true" model="basic.hls_lease_channel_for_lov"/>
            <a:dataSet id="chanceMaintain_divisionDs" loadData="true" model="basic.hls_division_for_lov"/>
            <a:dataSet id="chanceMaintain_statusDs" lookupCode="LCH501_LEASE_CHANCE_STATUS"/>
            <a:dataSet id="chanceMaintain_paraDs" autoCreate="true" model="lch.LCH501.lch_lease_chance_hds">
                <a:fields>
                    <a:field name="status_desc" displayField="code_value_name" options="chanceMaintain_statusDs" returnField="status" valueField="code_value"/>
                    <a:field name="lease_organization_desc" displayField="description" options="chanceMaintain_organizationDs" returnField="lease_organization" valueField="lease_organization"/>
                    <a:field name="lease_channel_desc" displayField="description" options="chanceMaintain_channelDs" returnField="lease_channel" valueField="lease_channel"/>
                    <a:field name="division_desc" displayField="description" options="chanceMaintain_divisionDs" returnField="division" valueField="division"/>
                    <a:field name="lease_chance_code"/>
                    <a:field name="employee_id"/>
                    <a:field name="employee_name" lovGridHeight="300" lovHeight="450" lovService="basic.hls_salesman_assign_v_for_lov" lovWidth="500" title="PRJ501.PRJ_PROJECT.EMPLOYEE_NAME">
                        <a:mapping>
                            <a:map from="employee_id" to="employee_id"/>
                            <a:map from="employee_name" to="employee_name"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="chanceMaintainDs" autoQuery="true" model="lch.LCH501.lch_lease_chance_hds" queryDataSet="chanceMaintain_paraDs" selectable="true" selectionModel="single">
                <a:fields>
                    <a:field name="lease_chance_id"/>
                    <a:field name="lease_chance_code"/>
                    <a:field name="employee_id"/>
                    <a:field name="employee_name" lovGridHeight="300" lovHeight="450" lovService="basic.hls_salesman_assign_v_for_lov" lovWidth="500" title="PRJ501.PRJ_PROJECT.EMPLOYEE_NAME">
                        <a:mapping>
                            <a:map from="employee_id" to="employee_id"/>
                            <a:map from="employee_name" to="employee_name"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="chanceMaintainScreen_forward" text="HLS.FORWARD"/>
                <a:gridButton click="chanceMaintainScreen_back" text="HLS.BACK"/>
                <a:gridButton click="chanceMaintainScreen_quit" text="HLS.EXIT"/>
                <a:gridButton click="chanceMaintainDs_grid_query" text="HLS.QUERY"/>
                <a:gridButton click="chanceMaintainScreen_add" text="HLS.NEW"/>
                <a:gridButton click="chanceMaintainDs_grid_clear" text="HLS.CLEAR"/>
                <a:gridButton click="chanceMaintainScreen_closeChance" text="关闭商机"/>
                <a:gridButton click="chanceMaintainScreen_createToProject" text="商机创建至项目"/>
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="120" marginWidth="30" title="HLS.QUERY_TITLE">
                <a:textField name="lease_chance_code" bindTarget="chanceMaintain_paraDs"/>
                <a:lov name="employee_name" bindTarget="chanceMaintain_paraDs"/>
                <a:textField name="bp_name" bindTarget="chanceMaintain_paraDs"/>
                <a:comboBox name="status_desc" bindTarget="chanceMaintain_paraDs"/>
                <a:comboBox name="lease_organization_desc" bindTarget="chanceMaintain_paraDs"/>
                <a:comboBox name="lease_channel_desc" bindTarget="chanceMaintain_paraDs"/>
                <a:comboBox name="division_desc" bindTarget="chanceMaintain_paraDs"/>
                <a:textField name="short_name" bindTarget="chanceMaintain_paraDs"/>
                <a:datePicker name="creation_date_from" bindTarget="chanceMaintain_paraDs" prompt="LCH501.QUERY_FIELD.CREATION_DATE_FROM"/>
                <a:datePicker name="creation_date_to" bindTarget="chanceMaintain_paraDs" prompt="LCH501.QUERY_FIELD.CREATION_DATE_TO"/>
            </a:form>
            <a:grid id="chanceMaintainDs_grid" bindTarget="chanceMaintainDs" marginHeight="250" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="lease_chance_code" renderer="render_chanceMaintainDs_grid" width="150"/>
                    <a:column name="employee_name"/>
                    <a:column name="lease_organization_desc" width="120"/>
                    <a:column name="lease_channel_desc" width="120"/>
                    <a:column name="division_desc" width="120"/>
                    <a:column name="bp_name" width="150"/>
                    <a:column name="short_name" width="150"/>
                    <a:column name="assets_amount" align="right"/>
                    <a:column name="creation_date" prompt="HLS.CREATION_DATE" renderer="render_chanceMaintainDs_grid" width="80"/>
                    <a:column name="status_desc"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>