<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wangwei  
    $Date: 2014-9-25 上午9:44:40  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure/>
    <a:view>
        <a:link id="pageLink_welcome" url="${/request/@context_path}/welcome.lview"/>
        <a:link id="home_page_set_link" model="sys.SYS880.home_page_set" modelaction="update"/>
        <a:link id="sys_page_assgin_user_id" url="${/request/@context_path}/modules/sys/SYS880/sys_home_page_assign_user.lview"/>
        <a:link id="sys_page_assgin_role_id" url="${/request/@context_path}/modules/sys/SYS880/sys_home_page_assign_role.lview"/>
        <a:link id="sys_page_assgin_company_id" url="${/request/@context_path}/modules/sys/SYS880/sys_home_page_assign_company.lview"/>
        <a:link id="assign_info_query_id" url="${/request/@context_path}/modules/sys/SYS880/sys_assign_info_query.lview"/>
        <script type="text/javascript"><![CDATA[
            function exit_to_welecome() {
                location.href = $('pageLink_welcome').getUrl();
            }
            
            function reset_query_ds() {
                $('query_ds').reset();
            }
            
            function assign_info_query() {
                var url=$('assign_info_query_id').getUrl();
                 // Leaf.go(url);
                new Leaf.Window({
                    id: 'assign_info_query_window',
                    fullScreen:true,
                    url: url
                });
            }
            
            function userScreen_userDs_query() {
                $('sys_page_favorites_ds').query();
            }
            
            function assign_user() {
                var records = $('sys_page_favorites_ds').getSelected();
                if (records.length != 1) {
                    Leaf.showMessage('${l:PROMPT}', '请选择一条记录');
                    return;
                }
                var role_id = records[0].get('role_id');
                var user_id = records[0].get('user_id');
                var company_id = records[0].get('company_id');
                var function_code = records[0].get('function_code');
                var win = new Leaf.Window({
                    id: 'sys_page_assgin_user_id_win',
                    url: $('sys_page_assgin_user_id').getUrl(),
                    params: {
                        assign_type: 'ROLE',
                        company_id: company_id,
                        user_id: user_id,
                        role_id: role_id,
                        function_code: function_code,
                        parent_dataset_id: 'sys_page_favorites_ds'
                    },
                    title: '用户分配',
                    width:1100,
                    height:600
                });
                win.on('close', function() {
                    $('sys_page_favorites_ds').query();
                });
            }
            
            function assign_role() {
                var records = $('sys_page_favorites_ds').getSelected();
                if (records.length != 1) {
                    Leaf.showMessage('${l:PROMPT}', '请选择一条记录');
                    return;
                }
                var role_id = records[0].get('role_id');
                var user_id = records[0].get('user_id');
                var company_id = records[0].get('company_id');
                var function_code = records[0].get('function_code');
                var win = new Leaf.Window({
                    id: 'sys_page_assgin_role_id_win',
                    url: $('sys_page_assgin_role_id').getUrl(),
                    params: {
                        assign_type: 'ROLE',
                        company_id: company_id,
                        user_id: user_id,
                        role_id: role_id,
                        function_code: function_code,
                        parent_dataset_id: 'sys_page_favorites_ds'
                    },
                    title: '角色分配',
                    width:1000,
                    height:600
                });
                win.on('close', function() {
                    $('sys_page_favorites_ds').query();
                });
            }
            
            function assign_company() {
                var records = $('sys_page_favorites_ds').getSelected();
                if (records.length != 1) {
                    Leaf.showMessage('${l:PROMPT}', '请选择一条记录');
                    return;
                }
                var role_id = records[0].get('role_id');
                var user_id = records[0].get('user_id');
                var company_id = records[0].get('company_id');
                var function_code = records[0].get('function_code');
                var win = new Leaf.Window({
                    id: 'sys_page_assgin_company_id_win',
                    url: $('sys_page_assgin_company_id').getUrl(),
                    params: {
                        assign_type: 'COMPANY',
                        company_id: company_id,
                        user_id: user_id,
                        role_id: role_id,
                        function_code: function_code,
                        parent_dataset_id: 'sys_page_favorites_ds'
                    },
                    title: '公司分配',
                    width:780,
                    height:530
                });
                win.on('close', function() {
                    $('sys_page_favorites_ds').query();
                });
            }
            
            function bathch_assign() {
                var records = $('sys_page_favorites_ds').getSelected();
                if (records.length != 1) {
                    Leaf.showMessage('${l:PROMPT}', '请选择一条记录');
                    return;
                }
                Leaf.showConfirm('${l:HLS.PROMPT}', '是否确定为所有用户分配首页?', function() {
                    // var role_id = records[0].get('role_id');
                    // var user_id = records[0].get('user_id');
                    // var company_id = records[0].get('company_id');
                    var function_code = records[0].get('function_code');
                    Leaf.request({
                        url: $('home_page_set_link').getUrl(),
                        para: {
                            assign_type: 'COMPANY',
                            company_id: company_id,
                            user_id: user_id,
                            role_id: role_id,
                            function_code: function_code
                        },
                        success: function() {
                            Leaf.SideBar.show({
                                msg: '操作成功',
                                duration: 2000
                            });
                            $('sys_page_favorites_ds').query();
                        },
                        scope: this
                    });
                });
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="home_page_flag_ds">
                <a:datas>
                    <a:record value_code="Y" value_name="是"/>
                    <a:record value_code="N" value_name="否"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="function_code"/>
                    <a:field name="function_name"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="sys_page_favorites_ds" autoPageSize="true" autoQuery="true" model="sys.SYS880.sys_function_v" queryDataSet="query_ds" selectable="true">
                <a:fields>
                    <a:field name="function_code"/>
                    <a:field name="function_name"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="exit_to_welecome" text="HLS.EXIT"/>
                <a:gridButton click="reset_query_ds" text="HLS.RESET"/>
                <a:gridButton click="userScreen_userDs_query" text="HLS.QUERY"/>
                <a:gridButton click="assign_user" text="分配用户"/>
                <a:gridButton click="assign_role" text="分配角色"/>
                <a:gridButton click="assign_company" text="分配公司"/>
                <!-- <a:gridButton click="bathch_assign" text="批量分配"/> -->
                <a:toolbarButton click="assign_info_query" text="分配记录查询" width="100"/>
            </a:screenTopToolbar>
            <a:form title="首页分配">
                <a:hBox>
                    <a:textField name="function_code" bindTarget="query_ds" prompt="功能代码"/>
                    <a:textField name="function_name" bindTarget="query_ds" prompt="功能名称"/>
                </a:hBox>
            </a:form>
            <a:grid bindTarget="sys_page_favorites_ds" marginHeight="200" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="function_code" prompt="功能代码" width="250"/>
                    <a:column name="function_name" prompt="功能名" width="400"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>