<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: hand  
    $Date: 2016-7-1 上午11:00:42  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure/>
    <a:view>
        <a:link id="update_collection_way_area" model="cont.CON630.con_collection_way_update" modelaction="batch_update"/>
        <a:link id="delete_collection_way_area" model="cont.CON630.con_collection_way_delete" modelaction="batch_update"/>
        <script type="text/javascript"><![CDATA[
            function quit() {
                    $('con_collection_way_window').close();
            }
            
            function save() {
                //
                var ds = $('con_collection_ways_result_ds');
                // var records=ds.getSelected();
                var records = ds.getAll();
                var saveData = [];
                for (var i = 0;i < records.length;i++) {
                    var record = records[i];
                   // if(record.getdate){
                    if (record.isNew == false) {
                        record.set('_status', 'update');
                    } else if (record.isNew == true) {
                        record.set('_status', 'insert');
                    }
               // }
                    record.set('type_id', '${/parameter/@type_id}');
                    record.set('way_id', '${/parameter/@way_id}');
                    saveData.push(record.data);
                }
                console.log(records);
                Leaf.request({
                    url: $('update_collection_way_area').getUrl(),
                    para: saveData,
                    success: function(args) {
                        Leaf.Masker.unmask(Ext.getBody());
                        Leaf.SideBar.show({
                            msg: '操作成功',
                            duration: 5000
                        });
                        $('con_collection_ways_result_ds').query();
                    },
                    failure: function(args) {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    error: function(args) {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    scope: this
            
                });
            }
            
            function remove() {
                var ds = $('con_collection_ways_result_ds');
                var records=ds.getSelected();
                //var records = ds.getAll();
                var saveData = [];
                for (var i = 0;i < records.length;i++) {
                    var record = records[i];
                    record.set('_status', 'delete');
                    record.set('type_id', '${/parameter/@type_id}');
                    saveData.push(record.data);
                }
                console.log(records);
                Leaf.request({
                    url: $('delete_collection_way_area').getUrl(),
                    para: saveData,
                    success: function(args) {
                        Leaf.Masker.unmask(Ext.getBody());
                        Leaf.SideBar.show({
                            msg: '操作成功',
                            duration: 5000
                        });
                         $('con_collection_ways_result_ds').query();
                    },
                    failure: function(args) {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    error: function(args) {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    scope: this
                });
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="con_collection_methods_result_ds" autoQuery="true" model="cont.CON630.con_collection_methods"/>
            <a:dataSet id="con_collection_ways_query_ds" autoCreate="true">
                <a:fields/>
            </a:dataSet>
            <!-- queryUrl="${/request/@context_path}/autocrud/cont.CON630.con_collection_ways/query" -->
            <a:dataSet id="con_collection_ways_result_ds" autoQuery="true" model="cont.CON630.con_collection_way" queryDataSet="con_collection_ways_query_ds" queryUrl="${/request/@context_path}/autocrud/cont.CON630.con_collection_way/query?type_id=${/parameter/@type_id}" selectable="true">
                <a:fields>
                    <!-- <a:field name="description" displayField="description" options="con_collection_methods_result_ds" returnField="methods_id" valueField="methods_id"/> -->
                    <a:field name="description" displayField="description" options="con_collection_methods_result_ds">
                        <a:mapping>
                            <a:map from="description" to="description"/>
                            <a:map from="methods_id" to="methods_id"/>
                        </a:mapping>
                    </a:field>
                    <!-- <a:field name="type_id" defaultValue="${/parameter/@type_id}"/> -->
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="quit" text="关闭"/>
                <a:gridButton click="save" text="保存"/>
                <a:gridButton click="remove" text="删除"/>
            </a:screenTopToolbar>
            <a:grid id="grid_id5" bindTarget="con_collection_ways_result_ds" height="400" width="380">
                <a:toolBar>
                    <a:button type="add"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="description" editor="conll_cmb" prompt="催收名称" width="100"/>
                </a:columns>
                <a:editors>
                    <a:comboBox id="conll_cmb" bindTarget="con_collection_methods_result_ds"/>
                </a:editors>
            </a:grid>
            <a:hBox/>
        </a:screenBody>
    </a:view>
</a:screen>