<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: chenlingfeng  
    $Date:2017-7-17 18:32:09
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="basic.hls_sys_time_default_value" rootPath="default_value_path"/>
    </a:init-procedure>
    <a:view template="default">
        <a:link id="hls2101_submit_document_grant_reques_link" model="hls.HLS2101.submit_document_grant_reques" modelaction="update"/>
        <script type="text/javascript"><![CDATA[
            function hls2101d_win_lock() {
                Leaf.Masker.mask($('${/parameter/@winid}').wrap, '正在执行');
            }
            
            function hls2101d_win_unlock() {
                Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
            }
            
            function hls2101d_win_close() {
                $('${/parameter/@winid}').close();
            }
            
            function hls2101d_submit() {
                var record = $('submit_document_grant_reques_ds').getCurrentRecord();
                if ($('submit_document_grant_reques_ds').validate()){
                if (record) {
                    Leaf.showConfirm('提示','确认是否提交授权申请？',function(){
                    hls2101d_win_lock();
                    Leaf.request({
                        url: $('hls2101_submit_document_grant_reques_link').getUrl(),
                        para: {
                            trx_category: record.get('trx_category'),
                            trx_id: record.get('trx_id'),
                            trx_name: record.get('trx_name'),
                            document_owner_user_id: record.get('document_owner_user_id'),
                            start_date: record.get('start_date'),
                            end_date: record.get('end_date')
                        },
                        success: function(res) {
                            Leaf.showMessage('${l:PROMPT}', '提交成功');
                            hls2101d_win_unlock();
                            hls2101d_win_close();
                        },
                        failure: function() {
                            hls2101d_win_unlock();
                        },
                        error: function() {
                            hls2101d_win_unlock();
                        },
                        scope: this
                    });
                    },null,null,null);
                }}
            }
            
            function dateValidator(record, name, value) {
                var start_date = Leaf.formatDate(record.get('start_date'));
                var end_date = Leaf.formatDate(record.get('end_date'));
                var now_date = "${/model/default_value_path/record/@now_time}";
                if (name == 'start_date') {
                    if (start_date < now_date) {
                        return '起始时间不能小于当前时间';
                    }
                    if (!end_date) {
                        return true;
                    }
                    if (start_date > end_date) {
                        return '起始时间不能大于结束日期';
                    }
                }
                if (name == 'end_date') {
                    if (!start_date) {
                        return true;
                    }
                    if (start_date > end_date) {
                        return '起始时间不能大于结束日期';
                    }
                }
                return true;
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="submit_document_grant_reques_ds" autoCreate="true">
                <a:fields>
                    <a:field name="trx_name" defaultValue="${/parameter/@trx_name}" readOnly="true" required="true"/>
                    <a:field name="trx_category" defaultValue="${/parameter/@trx_category}"/>
                    <a:field name="trx_number" defaultValue="${/parameter/@trx_number}" readOnly="true" required="true"/>
                    <a:field name="trx_id" defaultValue="${/parameter/@trx_id}" readOnly="true" required="true"/>
                    <a:field name="document_owner_user_id" defaultValue="${/parameter/@document_owner_user_id}"/>
                    <a:field name="start_date" defaultValue="${/model/default_value_path/record/@now_time}" required="true" validator="dateValidator"/>
                    <a:field name="end_date" defaultValue="${/model/default_value_path/record/@never_date}" required="true" validator="dateValidator"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="hls2101d_win_close" text="HLS.BACK"/>
                <a:gridButton click="hls2101d_submit" text="HLS.SUBMIT"/>
            </a:screenTopToolbar>
            <a:form column="1" title=" ">
                <a:textField name="trx_name" bindTarget="submit_document_grant_reques_ds" prompt="数据名称" width="250"/>
                <a:textField name="trx_number" bindTarget="submit_document_grant_reques_ds" prompt="分类" width="250"/>
                <a:datePicker name="start_date" bindTarget="submit_document_grant_reques_ds" prompt="起始时间" width="250"/>
                <a:datePicker name="end_date" bindTarget="submit_document_grant_reques_ds" prompt="结束时间" width="250"/>
            </a:form>
        </a:screenBody>
    </a:view>
</a:screen>
