<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang 
    $Date: 2014-12-18 上午08:52:17  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:view>
        <a:link id="con222_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="con222_con_doc_borrowing_app_borrow_link_id" model="cont.CON222.con_doc_borrowing_app_borrow" modelaction="batch_update"/>
        <a:link id="con_app_renew_link" url="${/request/@context_path}/modules/cont/CON222/con_doc_borrowing_app_renew.lview"/>
        <a:link id="con_app_return_link" url="${/request/@context_path}/modules/cont/CON222/con_doc_borrowing_app_return.lview"/>
        <a:link id="con_app_detail_link" url="${/request/@context_path}/modules/cont/CON222/con_doc_borrowing_app_detail.lview"/>
        <script type="text/javascript"><![CDATA[
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_doc_borrowing_app_hd');
                var records = $(ds_id).getSelected();
                if (!records.length) {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    Leaf.showMessage('提示', '请先选择数据！');
                    return;
                }
                var savaData = [];
                for (var i = 0;i < records.length;i++) {
                    var record = records[i];
                    record.set('_status', 'update');
                    savaData.push(record.data);
                }
                Leaf.request({
                    url: $('con222_con_doc_borrowing_app_borrow_link_id').getUrl(),
                    para: savaData,
                    success: function(res) {
                        Leaf.SideBar.show({
                            msg: '成功借出',
                            duration: 2000
                        });
            
                        function con222_on_result_load(ds) {
                            $(ds_id).un('load', con222_on_result_load);
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        }
                        $(ds_id).on('load', con222_on_result_load);
                        $(ds_id).query();
                    },
                    failure: function(res) {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function(res) {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            };
            
            //续借
              window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_doc_borrowing_app_hd');
                var records = $(ds_id).getSelected();
                if (records.length !=1) {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    Leaf.showMessage('提示', '请先选择单条数据！');
                    return;
                }
                if(records[0].get('status') != 'BORROWING'){
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    Leaf.showMessage('${l:PROMPT}','非借出状态不能续借！');
                    return;
                }
                
                
                var param = records[0].data;
                param['function_code'] = 'CON222D';
                param['function_usage'] = 'CREATE';
                param['url_title'] = '续借';

                 hls_doc_get_layout_code('con222_get_layout_code_link_id', param, 'con_app_renew_link', ds_id);
            
               
            };
            
            //借阅明细
               window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_doc_borrowing_app_hd');
               var records = $(ds_id).getSelected();
                 if (records.length !=1) {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    Leaf.showMessage('提示', '请先选择单条数据！');
                    return;
                }
                
                var param = records[0].data;
                param['function_code'] = 'CON222E';
                param['function_usage'] = 'CREATE';
                param['url_title'] = '借阅明细';

                 hls_doc_get_layout_code('con222_get_layout_code_link_id', param, 'con_app_detail_link', ds_id);
               
            };
            
            window['${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record, config_records, bp_seq) {
                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            };
            
            window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function(ds, record, res, bp_seq) {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_doc_borrowing_app_hd');
                $(ds_id).query($(ds_id).currentPage);
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
