<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2017年10月27日 下午1:57:11  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="assign_district_confirm_link" model="hls.HLS051.hls_product_un_assign" modelaction="update"/>
        <a:link id="assign_district_delete_link" model="hls.HLS051.hls_product_un_assign" modelaction="delete"/>
        <script type="text/javascript"><![CDATA[
            function role_select_confirm() {
                var ds = $('assign_result_ds');
                var records = ds.getAll();
                if (records.length == 0) {
            
                        Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                        Leaf.request({
                            url: $('assign_district_delete_link').getUrl(),
                            para: {
                                'product_plan_id': ${/parameter/@product_plan_id}
                            },
                            success: function(res) {
                                Leaf.Masker.unmask(Ext.getBody());
                                Leaf.SideBar.show({
                                    msg: '保存成功',
                                    duration: 2000
                                });
                            },
                            failure: function() {
                                Leaf.Masker.unmask(Ext.getBody());
                            },
                            error: function() {
                                Leaf.Masker.unmask(Ext.getBody());
                            },
                            scope: this
                        });
                } else {
                    var unit_idDS = '';
                    for (var i = 0;i < records.length;i++) {
                        unit_idDS += records[i].get('unit_id');
                        if (i != records.length - 1) {
                            unit_idDS += ',';
                        }
            
                    }
                    Leaf.showConfirm('${l:HLS.PROMPT}', '是否确定已保存大区？', function() {
            
                        Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
                        Leaf.request({
                            url: $('assign_district_confirm_link').getUrl(),
                            para: {
                                'product_plan_id': ${/parameter/@product_plan_id},
                                'unit_id': unit_idDS
                            },
                            success: function(res) {
                                Leaf.Masker.unmask(Ext.getBody());
                                Leaf.SideBar.show({
                                    msg: '保存成功',
                                    duration: 2000
                                });
                            },
                            failure: function() {
                                Leaf.Masker.unmask(Ext.getBody());
                            },
                            error: function() {
                                Leaf.Masker.unmask(Ext.getBody());
                            },
                            scope: this
                        });
                    });
                }
            }
            
            function right_selected() {
                var left_selectedAll = $('not_assign_result_ds').getSelected();
                for (var i = 0;i < left_selectedAll.length;i++) {
                    $('assign_result_ds').add(left_selectedAll[i]);
                }
                $('notSelectGrid').clear();
            }
            
            function left_selected() {
                var right_selectedAll = $('assign_result_ds').getSelected();
                for (var i = 0;i < right_selectedAll.length;i++) {
                    $('not_assign_result_ds').add(right_selectedAll[i]);
                }
                $('SelectGrid').clear();
            }
            
            function role_query() {
                $('not_assign_result_ds').query();
                $('assign_result_ds').query();
            }
            
            function win_close() {
                $('product_assign_district_window').close();
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="not_assign_result_ds" autoCount="true" autoPageSize="true" autoQuery="true" fetchAll="true" model="hls.HLS051.hls_product_un_assign" queryUrl="${/request/@context_path}/autocrud/hls.HLS051.hls_product_un_assign/query?product_plan_id=${/parameter/@product_plan_id}" selectable="true">
                <a:fields>
                    <a:field name="unit_code"/>
                    <a:field name="org_unit_description"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="assign_result_ds" autoCount="true" autoPageSize="true" autoQuery="true" fetchAll="true" model="hls.HLS051.hls_product_assign" queryUrl="${/request/@context_path}/autocrud/hls.HLS051.hls_product_assign/query?product_plan_id=${/parameter/@product_plan_id}" selectable="true">
                <a:fields>
                    <a:field name="unit_code"/>
                    <a:field name="org_unit_description"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="win_close" text="退出"/>
                <a:gridButton click="role_query" text="查询"/>
                <a:gridButton click="role_select_confirm" text="确定分配"/>
            </a:screenTopToolbar>
            <a:form column="2">
                <a:hBox>
                    <a:grid id="notSelectGrid" Height="460" autoFocus="false" bindTarget="not_assign_result_ds" navBar="true" width="280">
                        <a:toolBar>
                            <span style="color:#055a78"><![CDATA[大区选择]]></span>
                        </a:toolBar>
                        <a:columns>
                            <a:column name="unit_code" prompt="部门代码" sortable="true" width="80"/>
                            <a:column name="org_unit_description" prompt="大区描述" width="175"/>
                        </a:columns>
                    </a:grid>
                    <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:grid id="SelectGrid" Height="460" autoFocus="false" bindTarget="assign_result_ds" navBar="true" width="280">
                        <a:toolBar>
                            <span style="color:#055a78"><![CDATA[已选择大区]]></span>
                        </a:toolBar>
                        <a:columns>
                            <a:column name="unit_code" prompt="部门代码" sortable="true" width="80"/>
                            <a:column name="org_unit_description" prompt="大区描述" width="175"/>
                        </a:columns>
                    </a:grid>
                </a:hBox>
            </a:form>
        </a:screenBody>
    </a:view>
</a:screen>
