<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
    	<a:model-query model="sys.SYS1090.sys_dynamic_headers" rootPath="header"/>
    </a:init-procedure>
    <a:view>
        <script type="text/javascript"><![CDATA[
            function dynamicHeadEditSave() {
                $('screen_dymaic_head_edit_ds').submit();
            }
            
            function dynamicHeadEditClose() {
                $('dynamic_edit_window').close();
            }
            
            function onScreenDynamicHeadEditSuccess(){
                dynamicHeadEditClose();
                $('sys_dynamic_result_ds').query();
            }
            
            function onScreenDynamicHeadEditUpdate(ds, record, name, value, ov){
                initDynamicDimension(name,value,record);
                if(name == 'dimension_code'){
                    record.set('dimension_value_desc','');
                    if(value == 'SYSTEM'){
                        record.set('dimension_value','system');
                    }else{
                        record.set('dimension_value','');
                    }                    
                }
                    
            }
            
            function initDynamicDimension(type,value,record){                
                if(type == 'lookup_bm'){
                    record.getField('dimension_value_desc').setLovService(value)
                }
                if(type == 'dimension_code'){
                    if(value == 'SYSTEM'){
                        record.getField('dimension_value_desc').setRequired(false);
                        record.getField('dimension_value_desc').setReadOnly(true);
                    }else{
                        record.getField('dimension_value_desc').setRequired(true);
                        record.getField('dimension_value_desc').setReadOnly(false);
                    }                    
                }
            }
            
        ]]></script>
        <a:dataSets>
            <a:dataSet id="screen_dymaic_head_edit_ds" model="sys.SYS1090.sys_dynamic_headers" autoCreate="true">
            	<a:datas dataSource="/model/header"/>
                <a:fields>
                    <a:field name="comments" required="true" lovService="sys.sys_config_customization_head" lovGridHeight="300" lovHeight="450" lovWidth="350" title="设置集">
                        <a:mapping>
                            <a:map from="head_id" to="customization_header_id"/>
                            <a:map from="comments" to="comments"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="service_name" required="true" lovGridHeight="330" lovHeight="460" lovModel="sys.sys_service" lovWidth="450" title="PAGE_SELECT">
                        <a:mapping>
                            <a:map from="service_id" to="service_id"/>
                            <a:map from="service_name" to="service_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="dimension_type" required="true" lovModel="sys.SYS000.sys_config_dimension" lovGridHeight="300" lovHeight="450" lovWidth="500" title="维度集合">
                        <a:mapping>
                            <a:map from="dimension_code" to="dimension_code"/>
                            <a:map from="dimension_type" to="dimension_type"/>
                            <a:map from="lookup_bm" to="lookup_bm"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="dimension_value_desc" required="true"  lovGridHeight="300" lovHeight="450" lovWidth="500" title="维度值">
                        <a:mapping>
                            <a:map from="id" to="dimension_value"/>
                            <a:map from="name" to="dimension_value_desc"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="onScreenDynamicHeadEditUpdate"/>
                    <a:event name="submitsuccess" handler="onScreenDynamicHeadEditSuccess"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:fieldSet column="1" title="动态配置" width="565" style="margin:10px;">
                <a:lov name="comments" bindTarget="screen_dymaic_head_edit_ds" prompt="个性化集" width="200"/>
                <a:hBox prompt="页面名称" padding="0">
                    <a:lov name="service_name" prompt="" bindTarget="screen_dymaic_head_edit_ds" width="476"/>                  
                </a:hBox>
                <a:hBox padding="0" prompt="维度">
                    <a:lov name="dimension_type" bindTarget="screen_dymaic_head_edit_ds" width="200"/>
                    <a:lov name="dimension_value_desc" bindTarget="screen_dymaic_head_edit_ds" prompt="维度值"  width="200"/>
                </a:hBox>
            </a:fieldSet>
            <script type="text/javascript"><![CDATA[
            	function initDynamicHeadEdit(){
                    var record = $('screen_dymaic_head_edit_ds').getCurrentRecord();
                    initDynamicDimension('lookup_bm', record.get('lookup_bm'),record);
                    initDynamicDimension('dimension_code', record.get('dimension_code'),record);
                }
                initDynamicHeadEdit();
            ]]></script>
        </a:screenBody>
        <a:windowToolbar>
            <a:button click="dynamicHeadEditSave" text="保存" width="90"/>
            <a:button click="dynamicHeadEditClose" text="关闭" width="90"/>
        </a:windowToolbar>
    </a:view>
</a:screen>