<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wangwei  
    $Date: 2015-11-10 上午9:02:44  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="wfl_screen.WORKFLOW_ASSIGN.hn_get_user_unit_code" rootPath="user_path"/>
    </a:init-procedure>
    <a:view>
        <a:link id="wfl_workflow_assigned_user_id_link" model="wfl_screen.WORKFLOW_ASSIGN.workflow_assigned_user" modelaction="update"/>
        <a:link id="wfl_work_submit_link" model="wfl_screen.WORKFLOW_ASSIGN.workflow_assigned_user" modelaction="execute"/>
        <script type="text/javascript"><![CDATA[
            function assign_wfl_user_assign() {

                var ds = $('assigned_user_id_ds');
                var records = ds.getAll();
                if (records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请选择指派用户!');
                    return;
                }
                if (records.length > 1) {
                    Leaf.showMessage('${l:PROMPT}', '只能指派一个用户!');
                    return;
                }
                Leaf.showConfirm('${l:HLS.PROMPT}', '是否确定已保存指派用户,且将工作流指派给该用户?', function() {
                    Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                    Leaf.request({
                        url: $('wfl_workflow_assigned_user_id_link').getUrl(),
                        para: {
                            instance_id: '${/parameter/@instance_id}',
                            sequence_num: '${/parameter/@sequence_num}',
                            assign_user_id: records[0].get('user_id'),
                            assign_type: '${/parameter/@assign_type}',
                            comment_text:'${/parameter/@comment_text}'
                        },
                        success: function(response) {
                            if (response.result.return_number == 0) {
                                Leaf.SideBar.show({
                                    msg: '提交成功',
                                    duration: 2000
                                });
                                Leaf.Masker.unmask(Ext.getBody());
                                zjwfl5110_approvePage_close();
                            }
                        },
                        failure: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        error: function() {
                            Leaf.Masker.unmask(Ext.getBody());
                        },
                        scope: this
                    });
                });
            }
            
            function user_query() {
                $('assigned_user_id_ds').query();
                $('un_assign_user_id_ds').query();
            }
            
            function win_close() {
                $('zj_wfl_workflow_service_window').close();
            }
            
            
            // function submit_approved() {
            // var ds = $('assigned_user_id_ds');
            // var records = ds.getAll();
            // if (records.length == 0) {
            // Leaf.showMessage('${l:PROMPT}', '请先保存指派用户!');
            // return;
            // }
            // Leaf.showConfirm('${l:HLS.PROMPT}', '您确定提交当前指派人员吗?', function() {
            // Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            // Leaf.request({
            // url: $('wfl_work_submit_link').getUrl(),
            // para: {
            // instance_id: '${/parameter/@instance_id}'
            // },
            // success: function(response) {
            // if (response.result.return_number == 0) {
            // Leaf.SideBar.show({
            // msg: '提交成功',
            // duration: 2000
            // });
            // Leaf.Masker.unmask(Ext.getBody());
            // zjwfl5110_approvePage_close();
            // }
            // },
            // failure: function() {
            // Leaf.Masker.unmask(Ext.getBody());
            // },
            // error: function() {
            // Leaf.Masker.unmask(Ext.getBody());
            // },
            // scope: this
            // });
            // });
            // }
            
            function right_selected() {
                var left_selectedAll = $('un_assign_user_id_ds').getSelected();
                for (var i = 0;i < left_selectedAll.length;i++) {
                    $('assigned_user_id_ds').add(left_selectedAll[i]);
                }
                $('un_assign_user_id_ds_id').clear();
            }
            
            function left_selected() {
                var right_selectedAll = $('assigned_user_id_ds').getSelected();
                for (var i = 0;i < right_selectedAll.length;i++) {
                    $('un_assign_user_id_ds').add(right_selectedAll[i]);
                }
                $('assigned_user_id_ds_id').clear();
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="query_user_ds" autoCreate="true">
                <a:fields>
                    <a:field name="user_name"/>
                    <a:field name="description"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="assigned_user_id_ds" autoQuery="true" queryDataSet="query_user_ds" queryUrl="${/request/@context_path}/autocrud/wfl_screen.WORKFLOW_ASSIGN.workflow_assigned_user/query?instance_id=${/parameter/@instance_id}&amp;sequence_num=${/parameter/@sequence_num}&amp;assign_type=${/parameter/@assign_type}" selectable="true"/>
            <!-- <a:dataSet id="un_assign_user_id_ds" autoQuery="true" model="wfl_screen.WORKFLOW_ASSIGN.workflow_un_assign_user" queryDataSet="query_user_ds" queryUrl="${/request/@context_path}/autocrud/wfl_screen.WORKFLOW_ASSIGN.workflow_un_assign_user/query?position_code=${/parameter/@position_code}&amp;position_flag=${/parameter/@position_flag}&amp;unit_code=${/model/user_path/record/@unit_code}&amp;unit_flag=${/parameter/@unit_flag}&amp;instance_id=${/parameter/@instance_id}&amp;sequence_num=${/parameter/@sequence_num}" selectable="true"/> -->
            <a:dataSet id="un_assign_user_id_ds" autoQuery="true" model="wfl_screen.WORKFLOW_ASSIGN.workflow_un_assign_user" queryDataSet="query_user_ds" queryUrl="${/request/@context_path}/autocrud/wfl_screen.WORKFLOW_ASSIGN.workflow_un_assign_user/query?position_code=${/parameter/@position_code}&amp;position_flag=${/parameter/@position_flag}&amp;unit_code=${/parameter/@unit_code}&amp;unit_flag=${/parameter/@unit_flag}&amp;instance_id=${/parameter/@instance_id}&amp;sequence_num=${/parameter/@sequence_num}&amp;group_flag=${/parameter/@group_flag}&amp;submitted_by=${/parameter/@submitted_by}" selectable="true"/>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="win_close" text="关闭"/>
                <a:gridButton click="user_query" text="查询"/>
                <a:gridButton click="assign_wfl_user_assign" text="确定指派"/>
                <!-- <a:gridButton click="submit_approved" text=""/> -->
            </a:screenTopToolbar>
            <a:form title="查询条件" width="605">
                <a:hBox>
                    <a:textField name="user_name" bindTarget="query_user_ds" prompt="用户代码"/>
                    <a:textField name="description" bindTarget="query_user_ds" prompt="用户名称"/>
                </a:hBox>
            </a:form>
            <a:hBox>
                <a:form title="未指派用户">
                    <a:grid id="un_assign_user_id_ds_id" bindTarget="un_assign_user_id_ds" height="300" navBar="true" width="250">
                        <a:columns>
                            <a:column name="user_name" prompt="用户代码" width="100"/>
                            <a:column name="description" prompt="用户名称" width="100"/>
                        </a:columns>
                    </a:grid>
                </a:form>
                <a:vBox>
                    <a:button click="right_selected" height="25" style="margin-top:30px;" text="&gt;"/>
                    <a:button click="left_selected" height="25" style="margin-top:10px;" text="&lt;"/>
                </a:vBox>
                <a:form title="指派用户">
                    <a:grid id="assigned_user_id_ds_id" bindTarget="assigned_user_id_ds" height="300" navBar="true" width="250">
                        <a:columns>
                            <a:column name="user_name" prompt="用户代码" width="100"/>
                            <a:column name="description" prompt="用户名称" width="100"/>
                        </a:columns>
                    </a:grid>
                </a:form>
            </a:hBox>
        </a:screenBody>
    </a:view>
</a:screen>