<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang  
    $Date: 2014-7-8 上午11:48:56  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="pageLink_screen_setup" url="${/request/@context_path}/modules/hls/HLS030/hls_doc_layout_tab_screen.lview"/>
        <a:link id="pageLink_tab_setup" url="${/request/@context_path}/modules/hls/HLS030N/hls_doc_layout_tab_n.lview"/>
        <a:link id="pageLink_config_setup" url="${/request/@context_path}/modules/hls/HLS030/hls_doc_layout_config.lview"/>
        <a:link id="pageLink_layout_copy" url="${/request/@context_path}/modules/hls/HLS030/hls_doc_layout_copy.lview"/>
        <a:link id="pageLink_tree_setup" url="${/request/@context_path}/modules/hls/HLS030/hls_doc_layout_tree_setup.lview"/>
        <a:link id="pageLink_button_setup" url="${/request/@context_path}/modules/hls/HLS030/hls_doc_layout_button_setup.lview"/>
        <a:link id="pageLink_welcome" url="${/request/@context_path}/welcome.lview"/>
        <a:link id="hls_doc_layout_cache_clear_link_id" url="${/request/@context_path}/modules/hls/HLS030/hls_doc_layout_cache_clear.lsc"/>
        <a:link id="hls_doc_layout_preview_link" url="${/request/@context_path}/modules/hls/HLS030N/hls_doc_layout_preview.lview"/>
        <a:link id="hls_doc_layout_tree_preview_link" url="${/request/@context_path}/modules/hls/HLS030N/hls_doc_layout_tree_preview.lview"/>
        <a:link id="get_tree_code_query_link" model="hls.HLS030N.hls_doc_layout_tree_code_flag" modelaction="query"/>
        <script type="text/javascript"><![CDATA[
            function layoutScreen_query() {
                $('layoutDs').query();
            }
            
            function layoutScreen_clear() {
                $('layoutDs_grid').clear();
            }
            
            function layoutScreen_add() {
                $('layoutDs_grid').showEditorByRecord($('layoutDs').create());
            }
            
            function layoutScreen_save() {
                var ds = $('layoutDs');
                if (ds.validate()) {
                    ds.submit();
                }
            }
            
            function layoutScreen_quit() {
                location.href = $('pageLink_welcome').getUrl();
            }
            
            function editFunction_layoutDs_grid(record, name) {
                if (name == 'layout_code') {
                    if (record.isNew) {
                        return 'layoutDs_grid_tf_upper';
                    }
                    return '';
                } else if (name == 'document_category_desc') {
                    // if (record.isNew) {
                        // return 'layoutDs_grid_lov';
                    // }
                    return 'layoutDs_grid_lov';
                }
                return '';
            }
            
            function winOpen_tab_setup(layout_code, document_category) {
                new Leaf.Window({
                    id: 'hls_doc_layout_tab',
                    url: $('pageLink_tab_setup').getUrl(),
                    params: {
                        layout_code: layout_code,
                        document_category: document_category
                    },
                    title: '${l:HLS030.WIN_TITLE.TAB_SETUP}' + '(' + layout_code + ')',
                    fullScreen: true
                });
            }
            
            function winOpen_screen_setup(layout_code) {
                new Leaf.Window({
                    id: 'hls_doc_layout_tab_screen',
                    url: $('pageLink_screen_setup').getUrl(),
                    params: {
                        layout_code: layout_code
                    },
                    title: '${l:HLS030.WIN_TITLE.SCREEN_SETUP}',
                    fullScreen: true,
                    draggable: true
                });
            }
            
            function winOpen_config_setup(layout_code) {
                new Leaf.Window({
                    id: 'hls_doc_layout_config',
                    url: $('pageLink_config_setup').getUrl(),
                    params: {
                        layout_code: layout_code
                    },
                    title: '${l:HLS030.WIN_TITLE.CONFIG_SETUP}',
                    fullScreen: true,
                    draggable: true
                });
            }
            
            function winOpen_layout_copy(layout_code) {
                new Leaf.Window({
                    id: 'hls_doc_layout_copy',
                    url: $('pageLink_layout_copy').getUrl(),
                    params: {
                        layout_code: layout_code
                    },
                    title: '${l:HLS030.WIN_TITLE.LAYOUT_COPY}',
                    width: 500,
                    height: 200
                });
            }
            
            function winOpen_tree_setup(layout_code) {
                new Leaf.Window({
                    id: 'hls_doc_tree_setup',
                    url: $('pageLink_tree_setup').getUrl(),
                    params: {
                        layout_code: layout_code
                    },
                    title: '${l:HLS030.TREE_SETUP}',
                    fullScreen: true
                });
            }
            
            function winOpen_button_setup(layout_code, layout_desc) {
                new Leaf.Window({
                    id: 'hls_doc_button_setup',
                    url: $('pageLink_button_setup').getUrl(),
                    params: {
                        layout_code: layout_code,
                        layout_desc: layout_desc
                    },
                    title: '${l:HLS031.BUTTON_CONFIG}',
                    fullScreen: true
                });
            }
            
            function render_layoutDs_grid(value, record, name) {
                var layout_code = record.get('layout_code');
                if (name == 'layout_code') {
                    if (record.isNew) {
                        return value;
                    } else {
                        return '<a href="javascript:winOpen_tab_setup(\'' + layout_code + '\',\'' + record.get('document_category') + '\');">' + value + '</a>';
                    }
                }
                if (!record.isNew) {
                    if (name == 'screen_setup') {
                        return '<a href="javascript:winOpen_screen_setup(\'' + layout_code + '\');">' + '${l:HLS030.LINK.SCREEN_SETUP}' + '</a>';
                    } else if (name == 'tab_setup') {
                        return '<a href="javascript:winOpen_tab_setup(\'' + layout_code + '\',\'' + record.get('document_category') + '\');">' + '${l:HLS030.LINK.TAB_SETUP}' + '</a>';
                    } else if (name == 'config_setup') {
                        return '<a href="javascript:winOpen_config_setup(\'' + layout_code + '\');">' + '${l:HLS030.LINK.CONFIG_SETUP}' + '</a>';
                    } else if (name == 'layout_copy') {
                        return '<a href="javascript:winOpen_layout_copy(\'' + layout_code + '\');">' + '${l:HLS030.LINK.LAYOUT_COPY}' + '</a>';
                    } else if (name == 'tree_setup' && record.get('document_category') == 'PROJECT') {
                        return '<a href="javascript:winOpen_tree_setup(\'' + layout_code + '\');">' + '${l:HLS030.TREE_SETUP}' + '</a>';
                    } else if (name == 'button_setup') {
                        var layout_desc = record.get('description');
                        return '<a href="javascript:winOpen_button_setup(\'' + layout_code + '\',\'' + layout_desc + '\');">' + '${l:HLS031.BUTTON_CONFIG}' + '</a>';
                    }
                    return '';
                }
                return '';
            }
            
            function onSubmitSuccess_layoutDs(ds) {
                layoutScreen_query();
            }
            
            function layoutCache_clear() {
                var records = $('layoutDs').getSelected();
                var saveData = [];
                if (!records.length) {
                    Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                    return;
                } else {
                    for (var i = 0;i < records.length;i++) {
                        saveData.push(records[i].data);
                    }
                    Leaf.request({
                        url: $('hls_doc_layout_cache_clear_link_id').getUrl(),
                        para: saveData,
                        success: function(res) {
                            Leaf.SideBar.show({
                                msg: '${l:HLS.SUBMIT_SUCCESS}',
                                duration: 2000
                            });
                        },
                        scope: this
                    });
                }
            }
            
            function layoutScreen_preview() {
                var records = $('layoutDs').getSelected();
                if (records.length != 1) {
                    Leaf.showMessage('${l:PROMPT}', '请仅选择一条记录！');
                    return;
                } else {
                    var layout_code = records[0].get('layout_code');
                    var document_category = records[0].get('document_category');
                    //如果存在tree_code就进入tree_preview页面
                    Leaf.request({
                        url: $('get_tree_code_query_link').getUrl(),
                        para: {
                            'layout_code': records[0].get('layout_code')
                        },
                        success: function(data) {
                            if (data.result.record) {
                                if (data.result.record['tree_code_number'] == 0) {
                                    new Leaf.Window({
                                        id: 'hls_doc_layout_preview_win',
                                        url: $('hls_doc_layout_preview_link').getUrl(),
                                        params: {
                                            'winid': 'hls_doc_layout_preview_win',
                                            'layout_code': layout_code,
                                            'document_category': document_category
                                        },
                                        fullScreen: true
                                    });
                                } else {
                                    new Leaf.Window({
                                        id: 'hls_doc_layout_tree_preview_win',
                                        url: $('hls_doc_layout_tree_preview_link').getUrl(),
                                        params: {
                                            'winid': 'hls_doc_layout_tree_preview_win',
                                            'layout_code': layout_code,
                                            'document_category': document_category
                                        },
                                        fullScreen: true
                                    });
                                }
                            }
                        },
            
                        scope: this
                    });
            
                }
            }
            
            function test() {
                new Leaf.Window({
                    url: '${/request/@context_path}/test.lview',
                    fullScreen: true
                });
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="enabled_flag_ds" lookupCode="HLS_CHECKBOX"/>
            <a:dataSet id="layout_query_ds">
                <a:fields>
                    <a:field name="layout_code_ref"/>
                    <a:field name="document_category_desc" lovGridHeight="300" lovHeight="450" lovService="hls.HLS030.hls_document_category_lov" lovWidth="600" title="HLS.DOCUMENT_CATEGORY">
                        <a:mapping>
                            <a:map from="description" to="document_category_desc"/>
                            <a:map from="document_category" to="document_category"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="description"/>
                    <a:field name="enabled_flag" defaultValue="Y"/>
                    <a:field name="enabled_flag_desc" defaultValue="是" displayField="code_value_name" options="enabled_flag_ds" returnField="enabled_flag" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="layoutDs" autoPageSize="true" autoQuery="true" model="hls.HLS030.hls_doc_layout" queryDataSet="layout_query_ds" selectable="true">
                <a:fields>
                    <a:field name="layout_code" required="true"/>
                    <a:field name="description" required="true"/>
                    <a:field name="enabled_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                    <a:field name="document_category_desc" autoComplete="true" lovGridHeight="300" lovHeight="450" lovLabelWidth="100" lovService="hls.HLS030.hls_document_category_lov" lovWidth="600" title="HLS.DOCUMENT_CATEGORY">
                        <a:mapping>
                            <a:map from="description" to="document_category_desc"/>
                            <a:map from="document_category" to="document_category"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
                <a:events>
                    <a:event name="submitsuccess" handler="onSubmitSuccess_layoutDs"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="layoutScreen_quit" text="HLS.CLOSE"/>
                <a:gridButton click="layoutScreen_query" text="HLS.QUERY"/>
                <a:gridButton click="layoutScreen_add" text="HLS.NEW"/>
                <a:gridButton click="layoutScreen_clear" text="HLS.CLEAR"/>
                <a:gridButton click="layoutScreen_save" text="HLS.SAVE"/>
                <a:gridButton click="layoutCache_clear" text="HLS.LAYOUT_CACHE_CLEAR"/>
                <a:gridButton click="layoutScreen_preview" text="预览"/>
                <!-- <a:gridButton click="test" text="test"/> -->
            </a:screenTopToolbar>
            <a:form column="4" title="HLS.QUERY_TITLE">
                <a:lov name="document_category_desc" bindTarget="layout_query_ds" prompt="HLS.DOCUMENT_CATEGORY_DESC">
                    <a:events>
                        <a:event name="enterdown" handler="layoutScreen_query"/>
                    </a:events>
                </a:lov>
                <a:textField name="layout_code_ref" bindTarget="layout_query_ds" prompt="HLS.LAYOUT_CODE" typeCase="upper">
                    <a:events>
                        <a:event name="enterdown" handler="layoutScreen_query"/>
                    </a:events>
                </a:textField>
                <a:textField name="description" bindTarget="layout_query_ds" prompt="HLS.DESCRIPTION">
                    <a:events>
                        <a:event name="enterdown" handler="layoutScreen_query"/>
                    </a:events>
                </a:textField>
                <a:comboBox name="enabled_flag_desc" bindTarget="layout_query_ds" prompt="HLS.ENABLED_FLAG">
                    <a:events>
                        <a:event name="enterdown" handler="layoutScreen_query"/>
                    </a:events>
                </a:comboBox>
            </a:form>
            <a:grid id="layoutDs_grid" autoFocus="true" bindTarget="layoutDs" marginHeight="150" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="layout_code" editorFunction="editFunction_layoutDs_grid" renderer="render_layoutDs_grid" width="200"/>
                    <a:column name="description" editor="layoutDs_grid_tf" width="200"/>
                    <a:column name="width" editor="layoutDs_grid_nf_integer" prompt="HLS.SCREEN_WIDTH" width="80"/>
                    <a:column name="height" editor="layoutDs_grid_nf_integer" prompt="HLS.SCREEN_HEIGHT" width="80"/>
                    <a:column name="enabled_flag" align="center" editor="layoutDs_grid_check" width="60"/>
                    <a:column name="order_seq" align="right" editor="layoutDs_grid_nf_integer" width="60"/>
                    <a:column name="document_category_desc" editorFunction="editFunction_layoutDs_grid" width="120"/>
                    <a:column name="tab_setup" align="center" prompt="HLS030.WIN_TITLE.TAB_SETUP" renderer="render_layoutDs_grid"/>
                    <a:column name="button_setup" align="center" prompt="HLS031.BUTTON_CONFIG" renderer="render_layoutDs_grid" width="90"/>
                    <a:column name="tree_setup" align="center" prompt="HLS030.TREE_SETUP" renderer="render_layoutDs_grid" width="90"/>
                    <!--
                    <a:column name="screen_setup" align="center" prompt="HLS030.WIN_TITLE.SCREEN_SETUP" renderer="render_layoutDs_grid"/>
                    <a:column name="config_setup" align="center" prompt="HLS030.WIN_TITLE.CONFIG_SETUP" renderer="render_layoutDs_grid"/>
                    -->
                    <a:column name="layout_copy" align="center" prompt="HLS030.WIN_TITLE.LAYOUT_COPY" renderer="render_layoutDs_grid"/>
                </a:columns>
                <a:editors>
                    <a:lov id="layoutDs_grid_lov"/>
                    <a:numberField id="layoutDs_grid_nf_integer" allowDecimals="false" allowNegative="false"/>
                    <a:textField id="layoutDs_grid_tf"/>
                    <a:textField id="layoutDs_grid_tf_upper" maxLength="30" typeCase="upper"/>
                    <a:checkBox id="layoutDs_grid_check"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
