<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: duzhihong  
    $Date: 2015-1-14 下午3:01:09  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:view>
        <a:link id="con_batch_adjust_add_check_link" model="cont.CON112.con_batch_adjust_add_check" modelaction="update"/>
        <a:link id="batch_adjust_detail_link" url="${/request/@context_path}/modules/cont/CON112/con_batch_adjust_interest_detail.lview"/>
        <a:link id="batch_adjust_detail_query_link" url="${/request/@context_path}/modules/cont/CON112/con_batch_adjust_detail_for_query.lview"/>
        <a:link id="hn_pranayama_notice_templet_link" url="${/request/@context_path}/modules/cont/CON112/con_pranayama_notice_templet_print.lview"/>
        <script type="text/javascript"><![CDATA[
            function lock_list_window() {
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            }
            
            function unlock_list_window() {
                Leaf.Masker.unmask(Ext.getBody());
            }
            
            function query_bacth_adjust_hd() {
                $('bacth_adjust_hd_ds').query();
            }
            
            function submitsuccess(ds, res) {
                ds.query();
            }
            
            function open_detail(value, record, name) {
                if (record.isNew) {
                    return '';
                } else {
            
                    return '<a href="javascript:batch_adjust(\'' + record.get('batch_hd_id') + '\',\'' + record.get('approval_status') + '\');">' + '调息' + '</a>';
                }
            
            }
            
            function batch_adjust(batch_hd_id, approval_status) {
                // lock_list_window();
                // Leaf.request({
                // url: $('batch_adjust_interest_link').getUrl(),
                // para: {
                // batch_hd_id: batch_hd_id
                // },
                // success: function(args) {
                // unlock_list_window();
                var url;
                if (approval_status == 'APPROVED' || approval_status == 'APPROVING') {
                    url = $('batch_adjust_detail_query_link').getUrl();
                } else {
                    url = $('batch_adjust_detail_link').getUrl();
                }
                var win = new Leaf.Window({
                    id: 'batch_adjust_detail_winid',
                    url: url,
                    params: {
                        batch_hd_id: batch_hd_id,
                        approval_status: approval_status,
                        win_id: 'batch_adjust_detail_winid'
                    },
                    title: '调息明细界面',
                    fullScreen: true
                });
                win.on('close', function() {
                    $('bacth_adjust_hd_ds').query();
                });
                // },
                // scope: this,
                // sync: true
                // });
            }
            
            function batch_adjust_grid_add() {
                Leaf.request({
                    url: $('con_batch_adjust_add_check_link').getUrl(),
                    success: function(res) {
                        var add_flag = res.result.add_flag;
                        if (add_flag == 'N') {
                            Leaf.showMessage('${l:PROMPT}', '请先提交已创建的调息申请（或其他用户可能创建了调息申请，但未提交）！');
                        } else {
                            $('bacth_adjust_hd_ds').create();
                        }
                    },
                    scope: this,
                    sync: true
                });
            
            }
            
            function delete_batch_req() {
                Leaf.showConfirm('提示', '是否确认删除', function() {
                    var records = $('bacth_adjust_hd_ds').getSelected();
                    var approval_status = records[0].get('approval_status');
                    if (approval_status != 'NEW') {
                        Leaf.showMessage('${l:PROMPT}', '新建的申请才允许删除！');
                        return;
                    }
                    $('bacth_adjust_hd_ds').remove(records[0]);
                });
            }
            
            function batch_adjust_grid_save() {
                var ds = $('bacth_adjust_hd_ds');
                if (ds.validate()) {
                    ds.submit();
                }
            
            }
            
            function pranayama_notice_print() {
                var record = $('bacth_adjust_hd_ds').getSelected();
                var batch_hd_id = record[0].get('batch_hd_id');
                Leaf.showConfirm('提示', '确定要打印选中项吗？', function() {
                    Leaf.Masker.unmask(Ext.getBody()); //解锁
                    var templt_name = 'hn_pranayama_notice_templet.xml';
                    Leaf.Masker.unmask(Ext.getBody()); //解锁
                    var url = $('hn_pranayama_notice_templet_link').getUrl() + '?templt_name=' + templt_name + '&batch_hd_id=' + batch_hd_id;
                    var form = document.createElement("form");
                    form.target = "word_export_window";
                    form.method = "post";
                    form.action = url;
                    var iframe = Ext.get('word_export_window') || new Ext.Template('<iframe id ="word_export_window" name="word_export_window" style="position:absolute;left:-10000px;top:-10000px;width:1px;height:1px;display:none"></iframe>').insertFirst(document.body, {}, true);
                    document.body.appendChild(form);
                    form.submit();
                    Ext.fly(form).remove();
            
                });
            }  
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=BATCH_ADJUST_REQ"/>
        <a:dataSets>
            <a:dataSet id="approval_status_ds" lookupCode="CON_WFL_STATUS"/>
            <a:dataSet id="bacth_adjust_hd_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="batch_num"/>
                    <a:field name="approval_status_n" displayField="code_value_name" options="approval_status_ds" returnField="code_value" valueField="approval_status"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="bacth_adjust_hd_ds" autoQuery="true" model="cont.CON112.con_batch_adjust_interest_hd" queryDataSet="bacth_adjust_hd_query_ds" selectable="true" selectionModel="single">
                <a:fields>
                    <a:field name="batch_num"/>
                    <a:field name="description"/>
                    <a:field name="approval_status_n" displayField="code_value_name" options="approval_status_ds" returnField="code_value" valueField="approval_status"/>
                    <a:field name="batch_hd_id"/>
                </a:fields>
                <a:events>
                    <a:event name="submitsuccess" handler="submitsuccess"/>
                    <a:event name="query" handler="aut_authority_list_validate_query"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="batch_adjust_grid_add" text="HLS.NEW"/>
                <!-- <a:gridButton click="" text="批量调息"/> -->
                <a:gridButton click="batch_adjust_grid_save" text="保存"/>
                <!-- <a:gridButton bind="batch_adjust_grid" type="save"/> -->
                <a:gridButton click="delete_batch_req" text="删除"/>
                <a:gridButton click="query_bacth_adjust_hd" text="HLS.QUERY"/>
                <a:gridButton click="pranayama_notice_print" text="调息通知书"/>
            </a:screenTopToolbar>
            <a:form column="2" labelWidth="100" title="查询">
                <a:textField name="batch_num" bindTarget="bacth_adjust_hd_query_ds" prompt="批量调息编号"/>
                <a:comboBox name="approval_status_n" bindTarget="bacth_adjust_hd_query_ds" prompt="审批状态"/>
            </a:form>
            <a:grid id="batch_adjust_grid" bindTarget="bacth_adjust_hd_ds" marginHeight="150" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="batch_num" prompt="批量调息编号" width="150"/>
                    <a:column name="description" editor="bacth_ta" prompt="说明" width="250"/>
                    <a:column name="batch_hd_id" prompt="调息" renderer="open_detail"/>
                    <!-- <a:column prompt="项目经理"/>
					<a:column prompt="部门负责人"/> -->
                    <a:column name="approval_status_n" prompt="审批状态"/>
                </a:columns>
                <a:editors>
                    <a:textArea id="bacth_ta"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
