<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ouyangzhaochang2663 $
    $Date: 2010/11/22 01:49:31 $
    $Revision: 1.4 $
    $Purpose: 责任中心定义
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure/>
    <a:view template="default">
        <a:link id="pageLink_childResponsibilityCenter" url="${/request/@context_path}/modules/fnd/FND2110/fnd_resp_centers_hierarchy.lview"/>
        <a:link id="sys_service_welcome_link" url="${/request/@context_path}/welcome.lview"/>
        <div/>
        <script type="text/javascript"><![CDATA[
        	
            function responsibilityCenterDs_grid_add() {
                $('responsibilityCenterDs_grid').showEditorByRecord($('responsibilityCenterDs').create());
            }
            
            function responsibilityCenterDs_grid_clear() {
                $('responsibilityCenterDs_grid').clear();
            }
            
            function responsibilityCenterDs_grid_remove() {
                $('responsibilityCenterDs_grid').remove();
            }
            
            function responsibilityCenterDs_grid_submit() {
                var result_ds = $('responsibilityCenterDs');
                if (result_ds.validate()) {
                    result_ds.submit();
                }
            }
            
            function responsibilityCenterScreen_next() {
                history.go(1);
            }
            
            function responsibilityCenterScreen_back() {
                history.go(-1);
            }
            
            function responsibilityCenterScreen_quit() {
                location.href = $('sys_service_welcome_link').getUrl();
                parent.shMenu('show');
            }
            
            function query_responsibilityCenter() {
                $('responsibilityCenterDs').query();
            }
            
            function reset_responsibilityCenter() {
                $('para_responsibilityCenterDs').reset();
            }
            
            function editorFunction_responsibilityCenterDs_grid(record, name) {
                if (record.isNew) {
                    if(name=='responsibility_center_code')
                    {
                        return 'responsibilityCenterDs_grid_editor_tf_upper';
                    }
                    if(name=='summary_flag')
                    {
                        return 'responsibilityCenterDs_grid_editor_check';
                    }
                    
                }
                return '';
            }
            
            function render_responsibilityCenterDs_grid(value, record, name) {
                var responsibility_center_id = record.get('responsibility_center_id');
            
                if (responsibility_center_id && record.get('summary_flag') == 'Y') {
                    return '<a href="javascript:winOpen_childResponsibilityCenter(' + responsibility_center_id + ')">${l:FND2110.LINK.CHILD_RESPONSIBILITY_CENTER}</a>';
                }
            
            }
            
            function winOpen_childResponsibilityCenter(responsibility_center_id) {
                new Leaf.Window({
                    id: 'fnd_resp_centers_hierarchy',
                    url: $('pageLink_childResponsibilityCenter').getUrl(),
                    params:{
	                	responsibility_center_id:responsibility_center_id
	                },
                    title: '${l:FND2110.WIN_TITLE.CHILD_RESPONSIBILITY_CENTER}',
                    height: 500,
                    width: 650
                });
            }
            
            function validate_responsibilityCenterDs(record, name, value) {
                if (name == "start_date_active" || name == "end_date_active") {
                    var start_date = record.get('start_date_active');
                    var end_date = record.get('end_date_active');
                    if (!Ext.isEmpty(end_date)) 
                    {
                        if (!compareDate(start_date, end_date)) {
                            return '${l:HLS.VALIDITY_ERROR}';
                        }
                    }
                    return true;
                }
            }
            
            function compareDate(start, end) {
                if (start > end) {
                    return false;
                }
                return true;
            }
            
        ]]></script>
        <a:dataSets>
            <a:dataSet id="respCenterTypeDs" lookupCode="RESP_CENTER_TYPE"/>
            <a:dataSet id="para_responsibilityCenterDs" model="fnd.FND2110.fnd_responsibility_centers"/>
            <a:dataSet id="responsibilityCenterDs" autoQuery="true" fetchAll="false" model="fnd.FND2110.fnd_responsibility_centers" pageSize="15" queryDataSet="para_responsibilityCenterDs" selectable="true">
                <a:fields>
                    <a:field name="company_id" defaultValue="${/session/@company_id}"/>
                    <a:field name="responsibility_center_code" required="true"/>
                    <a:field name="responsibility_center_name" required="true"/>
                    <a:field name="resp_center_type_name" displayField="code_value_name" options="respCenterTypeDs" required="true" returnField="resp_center_type_code" valueField="code_value"/>
                    <a:field name="summary_flag" checkedValue="Y" defaultValue="N" unCheckedValue="N"/>
                    <a:field name="start_date_active" required="true" validator="validate_responsibilityCenterDs"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar height="29">
                <a:button click="responsibilityCenterScreen_back" height="20" icon="${/request/@context_path}/images/back.png" iconAlign="left" text="HLS.BACK" width="50"/>
                <a:separator style="margin-left:3px;"/>
                <a:button click="responsibilityCenterScreen_next" height="20" icon="${/request/@context_path}/images/forward.png" iconAlign="left" text="HLS.FORWARD" width="50"/>
                <a:separator style="margin-left:3px;"/>
                <a:button click="responsibilityCenterDs_grid_add" height="20" icon="${/request/@context_path}/images/add.png" iconAlign="left" text="HLS.NEW" width="50"/>
                <a:separator style="margin-left:3px;"/>
                <a:button click="responsibilityCenterDs_grid_clear" height="20" icon="${/request/@context_path}/images/clear.png" iconAlign="left" text="HLS.CLEAR" width="50"/>
                <a:separator style="margin-left:3px;"/>
                <a:button click="responsibilityCenterDs_grid_submit" height="20" icon="${/request/@context_path}/images/save.png" iconAlign="left" text="HLS.SAVE" width="50"/>
                <a:separator style="margin-left:3px;"/>
                <a:button click="responsibilityCenterScreen_quit" height="20" icon="${/request/@context_path}/images/quit.png" iconAlign="left" text="HLS.EXIT" width="50"/>
                <a:separator style="margin-left:3px;"/>
                <a:button click="query_responsibilityCenter" height="20" icon="${/request/@context_path}/images/search.png" iconAlign="left" text="HLS.QUERY" width="50"/>
                <a:separator style="margin-left:3px;"/>
            </a:screenTopToolbar>
            <a:form column="2" labelWidth="100" title="HAP_QUERY_TITLE">
                <a:textField name="responsibility_center_code" bindTarget="para_responsibilityCenterDs" typeCase="upper" width="150">
                    <a:events>
                        <a:event name="enterdown" handler="query_responsibilityCenter"/>
                    </a:events>
                </a:textField>
                <a:textField name="responsibility_center_name" bindTarget="para_responsibilityCenterDs" width="150">
                    <a:events>
                        <a:event name="enterdown" handler="query_responsibilityCenter"/>
                    </a:events>
                </a:textField>
            </a:form>
            <a:grid id="responsibilityCenterDs_grid" bindTarget="responsibilityCenterDs" marginHeight="180" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="responsibility_center_code" align="center" editorFunction="editorFunction_responsibilityCenterDs_grid" sortable="true" width="150"/>
                    <a:column name="responsibility_center_name" align="left" editor="responsibilityCenterDs_grid_editor_tf" width="150"/>
                    <a:column name="resp_center_type_name" align="center" editor="responsibilityCenterDs_grid_editor_comb"/>
                    <a:column name="start_date_active" align="center" editor="responsibilityCenterDs_grid_editor_dp" renderer="Leaf.formatDate" sortable="true"/>
                    <a:column name="end_date_active" align="center" editor="responsibilityCenterDs_grid_editor_dp" renderer="Leaf.formatDate" sortable="true"/>
                    <a:column name="summary_flag" align="center" editorFunction="editorFunction_responsibilityCenterDs_grid" sortable="true" width="50"/>
                    <a:column name="responsibility_center_id" align="center" prompt="FND2110.WIN_TITLE.CHILD_RESPONSIBILITY_CENTER" renderer="render_responsibilityCenterDs_grid"/>
                </a:columns>
                <a:editors>
                    <a:textField id="responsibilityCenterDs_grid_editor_tf_upper" typeCase="upper"/>
                    <a:textField id="responsibilityCenterDs_grid_editor_tf"/>
                    <a:comboBox id="responsibilityCenterDs_grid_editor_comb"/>
                    <a:datePicker id="responsibilityCenterDs_grid_editor_dp"/>
                    <a:checkBox id="responsibilityCenterDs_grid_editor_check"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>