<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ouyangzhaochang2663 $
    $Date: 2010/11/15 07:47:58 $
    $Revision: 1.6 $
    $Purpose: 分配角色
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure><![CDATA[
    ]]></a:init-procedure>
    <a:view>
        <script type="text/javascript"><![CDATA[
            function assignScreen_close(){
				$('sys_user_role_assign').close();
            }
            
            function editorFun_assignDs_grid(record,name){
                if (record.isNew){
                	return 'assignDs_grid_lov';
                }
                return '';
            }
            
            function compareDate(start, end){
                if(start > end){
                    return false;
                }
                return true;
            }
            
            function dateValidator(record, name, value){
                if(name == 'start_date' || name == 'end_date'){
                    var start_date = record.get('start_date');
                    var end_date = record.get('end_date');
                    if(typeof(end_date) != 'undefined' && !Ext.isEmpty(end_date)){
                        if(!compareDate(start_date, end_date)){
                            return '${l:START_GREATER_THAN_END}';
                        }
                    }
                    return true;
                }
            }
            
            function onUpdate_assignDs(ds,record,name,value){
                if(name == 'start_date' || name == 'end_date'){
                    record.validate((name == 'start_date') ? 'end_date' : 'start_date');
                }
            }
            
            function assignDs_grid_add(){
                $('assignDs_grid').showEditorByRecord($('assignDs').create());
            }
            function assignDs_grid_clear(){
                $('assignDs_grid').clear();
            }
            function assignDs_grid_save() {
                var ds = $('assignDs');
                if (ds.validate()) {
                    ds.submit();                   
                }
            }

            
        ]]></script>
        <a:dataSets>
            <a:dataSet id="assignScreen_userDs" loadData="true" model="sys.sys_user">
                <a:fields>
                    <a:field name="user_name" readOnly="true"/>
                    <a:field name="description" readOnly="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="assignDs" autoQuery="true" fetchAll="false" model="sys.SYS8210.sys_user_role_assign" queryUrl="${/request/@context_path}/autocrud/sys.SYS8210.sys_user_role_assign/query?ORDER_FIELD=name&amp;user_id=${/parameter/@user_id}" selectable="true">
                <a:fields>
                    <a:field name="role_code" autoComplete="true" lovGridHeight="340" lovHeight="460" lovService="sys.sys_role?ORDER_FIELD=role_code" lovWidth="500" required="true" title="HAP_SELECT_ROLE">
                        <a:mapping>
                            <a:map from="role_id" to="role_id"/>
                            <a:map from="role_code" to="role_code"/>
                            <a:map from="role_name" to="role_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="user_id" defaultValue="${/parameter/@user_id}"/>
                    <a:field name="company_code" autoComplete="true" autoCompleteField="company_code" lovGridHeight="340" lovHeight="460" lovService="fnd.fnd_companies?ORDER_FIELD=company_code" lovWidth="500" required="true" title="EXP_EMPLOYEE_ASSIGN.CHOOSE_COMPANY">
                        <a:mapping>
                            <a:map from="company_id" to="company_id"/>
                            <a:map from="company_code" to="company_code"/>
                            <a:map from="company_short_name" to="company_short_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="start_date" required="true" validator="dateValidator"/>
                    <a:field name="end_date" validator="dateValidator"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="onUpdate_assignDs"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="assignScreen_close" text="HLS.CLOSE"/>
                <a:gridButton click="assignDs_grid_add" text="HLS.NEW"/>
                <a:gridButton click="assignDs_grid_clear" text="HLS.CLEAR"/>
                <a:gridButton click="assignDs_grid_save" text="HLS.SAVE"/>
            </a:screenTopToolbar>
            <a:form column="2" title="账号信息">
                <a:textField name="user_name" bindTarget="assignScreen_userDs" prompt="SYS_USER.ACCOUNT"/>
                <a:textField name="description" bindTarget="assignScreen_userDs" prompt="SYS_USER.DESCRIPTION"/>
            </a:form>
            <a:grid id="assignDs_grid" bindTarget="assignDs" height="300" navBar="true" width="810">
                <a:toolBar>
                    <a:button type="delete"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="role_code" editor="assignDs_grid_lov" editorFunction="editorFun_assignDs_grid"/>
                    <a:column name="role_name" prompt="SYS_ROLE.ROLE_NAME" width="120"/>
                    <a:column name="company_code" editor="assignDs_grid_lov" width="120"/>
                    <a:column name="company_short_name" prompt="COMPANY_SHORT_NAME" width="144"/>
                    <a:column name="start_date" editor="assignDs_grid_dp" renderer="Leaf.formatDate" width="150"/>
                    <a:column name="end_date" editor="assignDs_grid_dp" renderer="Leaf.formatDate" width="150"/>
                </a:columns>
                <a:editors>
                    <a:lov id="assignDs_grid_lov"/>
                    <a:datePicker id="assignDs_grid_dp"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>