<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: LR  
    $Date: 2013-7-25 上午10:54:35  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query model="basic.sys_session_info" rootPath="con201_session_info"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con201_basic_clause_text_link" url="${/request/@context_path}/modules/cont/CON201/con_basic_clause_text.lview"/>
        <script type="text/javascript"><![CDATA[
            function con201_basic_clause_add() {
                var dataset = $('con201_basic_clause_result_ds');
                var record = dataset.getCurrentRecord();
                if (!Leaf.isEmpty(record)) {
                    var parent_clause_id = record.get('clause_id');
                    var parent_clause_code = record.get('clause_code');
                    var clause_usage_name = record.get('clause_usage_name');
                    var clause_usage = record.get('clause_usage');
                    if (parent_clause_id) {
                        var record1 = new Leaf.Record({
                            parent_clause_id: parent_clause_id,
                            parent_clause_code: parent_clause_code,
                            approval_status: 'APPROVED',
                            approval_status_name: '${l:CON201.UNAPPROVED}',
                            clause_usage: clause_usage,
                            clause_usage_name: clause_usage_name,
                            enabled_flag: 'Y',
                            expand_flag: 'Y'
                        });
                        dataset.add(record1);
                    } else {
                        Leaf.showMessage('${l:HLS.PROMPT}', '${l:CON201.AFTER_SAVE_ADD}');
                    }
                }
            }
            
            function con201_basic_clause_query() {
                $('con201_basic_clause_result_ds').query();
            }
            
            function con201_basic_clause_addtop() {
                var dataset = $('con201_basic_clause_result_ds');
                var record1 = new Leaf.Record({
                    parent_clause_id: '',
                    approval_status: 'APPROVED',
                    approval_status_name: '${l:CON201.UNAPPROVED}',
                    enabled_flag: 'Y',
                    expand_flag: 'Y'
                });
                dataset.add(record1);
            }
            
            function con201_basic_clause_save() {
                $('con201_basic_clause_result_ds').submit();
            }
            
            function con201_basic_clause_submit() {}
            
            function con201_basic_clause_deleteNote() {
                Leaf.showConfirm('${l:HLS.PROMPT}', '${l:HLS030.CONFIRM_DELETE}', function okFun() {
                    var ds = $('con201_basic_clause_result_ds');
                    var records = ds.getSelected();
                    if (records.length > 0) {
                        ds.remove(records);
                    }
                });
            }
            
            function con201_basic_clause_clearNote() {
                var ds = $('con201_basic_clause_result_ds');
                var records = ds.getSelected();
                for (var i = 0;i < records.length;i++) {
                    records[i].isNew = true;
                }
                ds.remove(records);
            }
            
            function windowopen_clause_text(id) {
                new Leaf.Window({
                    id: 'con201_basic_clause_text_window',
                    url: $('con201_basic_clause_text_link').getUrl(),
                    params: null,
                    title: '${l:CON201.CON_BASIC_CLAUSE_EDIT}',
                    width: 500,
                    height: 450
                });
            }
            
            function con201_basic_clause_grid_render(value, record, name) {
                if (name == 'company_short_name') {
                    return '${/model/con201_session_info/record/@company_short_name}';
                } else if (name == 'edit') {
                    return '<a href="javascript:windowopen_clause_text(\'' + record.id + '\');">${l:CON201.EDIT}</a>';
                }
            }
            
            function con201_basic_clause_result_ds_Onselect(ds, record, all) {
                if (!all) {
                    var parent_clause_id = record.get('clause_id');
                    var records = ds.getAll();
                    var selectedRecords1 = ds.getSelected();
                    for (var i = 0;i < records.length;i++) {
                        if (records[i].get('parent_clause_id') == record.get('clause_id') && !Leaf.isEmpty(record.get('clause_id'))) {
                            if (selectedRecords1.indexOf(records[i]) == -1) {
                                ds.select(records[i]);
                            }
                        }
                    }
                }
            }
            
            function con201_basic_clause_result_ds_Onunselect(ds, record, all) {
                if (!all) {
                    var parent_clause_id = record.get('clause_id');
                    if (!Leaf.isEmpty(parent_clause_id)) {
                        var records = ds.getAll();
                        var selectedRecords1 = ds.getSelected();
                        for (var i = 0;i < records.length;i++) {
                            if (records[i].get('clause_id') == record.get('parent_clause_id') && !Leaf.isEmpty(record.get('clause_id'))) {
                                if (selectedRecords1.indexOf(records[i]) != -1) {
                                    ds.unSelect(records[i]);
                                }
                            }
                        }
                    }
                }
            }
            
            function con201_basic_clause_grid_cellclick(grid, row, name, record) {
                if (name == 'parent_clause_code') {
                    record.getField('parent_clause_code').setLovService('cont.CON201.con_basic_clause');
                    record.getField('parent_clause_code').setLovPara('not_clause_code', record.get('clause_code'));
                }
            }
            
            function con201_basic_clause_result_ds_Onupdate(ds, record, name, value, oldvalue) {
                if (name == 'clause_code') {
                    var clause_id = record.get('clause_id');
                    if (!Leaf.isEmpty(clause_id)) {
                        var records = ds.getAll();
                        for (var i = 0;i < records.length;i++) {
                            var parent_clause_id = records[i].get('parent_clause_id');
                            if (parent_clause_id == clause_id) {
                                records[i].set('parent_clause_code', value, true);
                            }
                        }
                    }
                }
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="con201_basic_clause_tmplet_usage_ds" lookupCode="CON_TMPLET_USAGE"/>
            <a:dataSet id="con201_basic_clause_approval_status_ds" lookupCode="CON_TERMS_APPROVE_STATUS"/>
            <a:dataSet id="con201_clause_style_name_ds" lookupCode="CON_CLAUSE_STYLE"/>
            <a:dataSet id="con201_basic_clause_enabled_status_ds" lookupCode="ENABLED_STATUS"/>
            <a:dataSet id="con201_basic_clause_query_ds">
                <a:fields>
                    <a:field name="clause_code"/>
                    <a:field name="description"/>
                    <a:field name="clause_usage_name" displayField="code_value_name" options="con201_basic_clause_tmplet_usage_ds" returnField="clause_usage" valueField="code_value"/>
                    <a:field name="approval_status_name" displayField="code_value_name" options="con201_basic_clause_approval_status_ds" returnField="approval_status" valueField="code_value"/>
                    <a:field name="enabled_flag_des" displayField="code_value_name" options="con201_basic_clause_enabled_status_ds" returnField="enabled_flag" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con201_basic_clause_result_ds" autoCount="false" fetchAll="true" model="cont.CON201.con_basic_clause" queryDataSet="con201_basic_clause_query_ds" selectable="true">
                <a:fields>
                    <a:field name="clause_code" required="true"/>
                    <a:field name="description" required="true"/>
                    <a:field name="clause_usage" required="true"/>
                    <a:field name="enabled_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                    <a:field name="content_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="content_number_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                    <a:field name="expand_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="clause_usage_name" displayField="code_value_name" options="con201_basic_clause_tmplet_usage_ds" required="true" returnField="clause_usage" valueField="code_value"/>
                    <a:field name="clause_style_name" displayField="code_value_name" options="con201_clause_style_name_ds" returnField="clause_style" valueField="code_value"/>
                    <a:field name="approval_status" defaultValue="APPROVED"/>
                    <a:field name="approval_status_name"/>
                    <a:field name="parent_clause_code" lovGridHeight="320" lovHeight="450" lovWidth="500" title="CON201.CON_BASIC_CLAUSE.PARENT_CLAUSE_CODE">
                        <a:mapping>
                            <a:map from="clause_id" to="parent_clause_id"/>
                            <a:map from="clause_code" to="parent_clause_code"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
                <a:events>
                    <a:event name="select" handler="con201_basic_clause_result_ds_Onselect"/>
                    <a:event name="unselect" handler="con201_basic_clause_result_ds_Onunselect"/>
                    <a:event name="update" handler="con201_basic_clause_result_ds_Onupdate"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="con201_basic_clause_addtop" text="HLS030.TREE_ADDTOP"/>
                <a:gridButton click="con201_basic_clause_add" text="HLS030.TREE_ADDSON"/>
                <a:gridButton click="con201_basic_clause_query" text="HLS.QUERY" width="80"/>
                <a:gridButton click="con201_basic_clause_save" text="HLS.SAVE" width="80"/>
                <a:gridButton click="con201_basic_clause_submit" text="CON201.SUBMIT" width="80"/>
                <a:gridButton click="con201_basic_clause_deleteNote" text="HLS.REMOVE" width="80"/>
                <a:gridButton click="con201_basic_clause_clearNote" text="HLS.CLEAR" width="80"/>
            </a:screenTopToolbar>
            <a:form labelSeparator=" " row="1">
                <a:textField name="clause_code" bindTarget="con201_basic_clause_query_ds" prompt="CON201.CON_BASIC_CLAUSE.CLAUSE_CODE"/>
                <a:textField name="description" bindTarget="con201_basic_clause_query_ds" prompt="CON201.CON_BASIC_CLAUSE.DESCRIPTION"/>
                <a:comboBox name="clause_usage_name" bindTarget="con201_basic_clause_query_ds" prompt="CON201.CON_BASIC_CLAUSE.CLAUSE_USAGE_NAME"/>
                <a:comboBox name="approval_status_name" bindTarget="con201_basic_clause_query_ds" prompt="CON201.CON_BASIC_CLAUSE.APPROVAL_STATUS_NAME"/>
                <a:comboBox name="enabled_flag_des" bindTarget="con201_basic_clause_query_ds" prompt="CON201.CON_BASIC_CLAUSE.ENABLED_FLAG_DES"/>
            </a:form>
            <a:treeGrid id="con201_basic_clause_functionTreeGrid" bindTarget="con201_basic_clause_result_ds" expandField="expand_flag" idField="clause_id" marginHeight="130" marginWidth="50" parentField="parent_clause_id" sequenceField="order_seq" showCheckBox="false" width="800">
                <a:columns>
                    <a:column name="clause_code" editor="con201_basic_clause_grid_tf" prompt="CON201.CON_BASIC_CLAUSE.CLAUSE_CODE" width="250"/>
                    <a:column name="description" editor="con201_basic_clause_grid_tf" prompt="CON201.CON_BASIC_CLAUSE.DESCRIPTION" width="120"/>
                    <a:column name="clause_usage_name" editor="con201_basic_clause_grid_cb" prompt="CON201.CON_BASIC_CLAUSE.CLAUSE_USAGE_NAME" width="120"/>
                    <a:column name="edit" prompt="CON201.CON_BASIC_CLAUSE.EDIT" renderer="con201_basic_clause_grid_render" width="70"/>
                    <a:column name="parent_clause_code" editor="con201_basic_clause_grid_lov" prompt="CON201.CON_BASIC_CLAUSE.PARENT_CLAUSE_CODE" width="150"/>
                    <a:column name="approval_status_name" prompt="CON201.CON_BASIC_CLAUSE.APPROVAL_STATUS_NAME" width="100"/>
                    <a:column name="order_seq" align="right" editor="con201_basic_clause_grid_nf" prompt="HLS030.TREE_SEQ" width="60"/>
                    <a:column name="company_short_name" prompt="CON201.CON_BASIC_CLAUSE.COMPANY_SHORT_NAME" renderer="con201_basic_clause_grid_render" width="100"/>
                    <a:column name="clause_style_name" editor="con201_basic_clause_grid_cb" prompt="CON201.CLAUSE_STYLE" width="80"/>
                    <a:column name="indfirstline_number" editor="con201_basic_clause_grid_num" prompt="CON201.INDFIRSTLINE_NUMBER" width="80"/>
                    <a:column name="indleft_number" editor="con201_basic_clause_grid_num" prompt="CON201.INDLEFT_NUMBER" width="80"/>
                    <a:column name="content_number_flag" editor="con201_basic_clause_grid_ck" prompt="CON201.CONTENT_NUMBER_FLAG" width="80"/>
                    <a:column name="content_flag" editor="con201_basic_clause_grid_ck" prompt="CON201.CONTENT_FLAG" width="80"/>
                    <a:column name="enabled_flag" editor="con201_basic_clause_grid_ck" prompt="HLS030.ENABLED_FLAG" width="80"/>
                    <a:column name="expand_flag" editor="con201_basic_clause_grid_ck" prompt="HLS030.EXPAND_FLAG" width="80"/>
                </a:columns>
                <a:editors>
                    <a:numberField id="con201_basic_clause_grid_nf" allowDecimals="false" allowNegative="false" max="999"/>
                    <a:numberField id="con201_basic_clause_grid_num" allowDecimals="true" allowNegative="true"/>
                    <a:textField id="con201_basic_clause_grid_tf"/>
                    <a:checkBox id="con201_basic_clause_grid_ck"/>
                    <a:comboBox id="con201_basic_clause_grid_cb"/>
                    <a:lov id="con201_basic_clause_grid_lov"/>
                </a:editors>
                <a:events>
                    <a:event name="cellclick" handler="con201_basic_clause_grid_cellclick"/>
                </a:events>
            </a:treeGrid>
        </a:screenBody>
    </a:view>
</a:screen>
