<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:view>
        <a:link id="fnd_dimension_value_hierarchy_com_link" url="${/request/@context_path}/modules/fnd/FND2230/fnd_dimension_value_hierarchy_com.lview"/>
        <div/>
        <script type="text/javascript"><![CDATA[
        
        	function queryFndDimensionValues(){
        		var record=$('fnd_dimension_values_query_ds').getAt(0);
        		var summary_yflag=record.get('summary_flag_Y');
        		var summary_nflag=record.get('summary_flag_N');
        		
        		if(summary_yflag=='Y'&&summary_nflag=='Y'){ 
        			record.set('summary_flag',null);		
        		}
        		else if(summary_yflag=='Y'){
        			record.set('summary_flag','Y');	
        		}
        		else if(summary_nflag=='Y'){
        			record.set('summary_flag','N');	
        		}
        		else{
        			record.set('summary_flag','null');	
        		}
        	 	$('fnd_dimension_values_result_ds').query();
        	 	var para=$('fnd_dimension_values_query_ds').getCurrentRecord().get('dimension_id');
        	 	$('syscom_ds').setQueryParameter('dimension_id',para);
        	 	$('syscom_ds').query();
        	 	//
        	}
        	
        	function resetFndDimensionValues(){
        		$('fnd_dimension_values_query_ds').getCurrentRecord().set('dimension_description','')
        		$('fnd_dimension_values_query_ds').reset();
        	}
        
        	function difValueComRenderer(value ,record, name){
        		var summaryFlag=record.get('summary_flag');
        		if (!record.isNew && summaryFlag=="Y"){
        			var dimensionValueId = record.get('dimension_value_id');        			       			
        			return '<a href="javascript:difValueComRendererWindow('+dimensionValueId+')">${l:FND_DIMENSION_HER_COM.DIF_CHILD_VALUE}</a>';        			
        		}
        	}
        
        	function difValueComRendererWindow(dimensionValueId){
        		new Leaf.Window({
        			id:'fnd_dimension_values_dif_value_com_window', 
        			url:/*fnd_dimension_value_hierarchy_com.screen*/$('fnd_dimension_value_hierarchy_com_link').getUrl()+'?dimension_value_id='+dimensionValueId, 
        			title:'${l:FND_DIMENSION_HER_COM.DIF_CHILD_VALUE}', 
        			height:440,width:530});        		
        	}
        
        	function setinitdata(ds,record,index){
        		record.set('dimension_id',$('fnd_dimension_values_query_ds').getAt(0).get('dimension_id'));
        		record.set('dimension_code',$('fnd_dimension_values_query_ds').getAt(0).get('dimension_code'));
        		record.set('enabled_flag','Y');
        	}
        
        	function dimensionValueCodeEdit(record,name){
        		if(!record.isNew){
        			return '';
        		}
        		return 'dimension_value_code_tf';
        	}
        	
        	function descriptionEdit(record,name){
        		var flag=$('syscom_ds').getAt(0).get('levelflag');
        		//
        		if(flag==3){
        			return 'description_tf';
        		}
        		return '';
        	}
        	
        	function summaryFlagEdit(record,name){
        		if(!record.isNew){
        			return '';
        		}
        		return 'summary_flag_cb';
        	}
        	
        	function enabledFlagEdit(record,name){
        		var flag=$('syscom_ds').getAt(0).get('levelflag');
        		//
        		if(flag==1||flag==3){
        			return 'enabled_flag_cb';
        		}
        		return '';
        	}
        	
        	function syscomLoadFunction(){
        		//$('addrecord').disable();
        		flagset();
        	}
        	
        	function flagset(){
        		//
        		var flag=0;
        	 	var syscomflag=$('syscom_ds').getAt(0);
        	 	if(syscomflag!=null){
        	 		if(syscomflag.get('system_level')=="Y"){
        	 			if(syscomflag.get('company_level')=="Y"){
        	 				flag=1;
        	 				$('addrecord').disable();
        	 				$('btnClear').disable();
        	 				$('btnSave').enable();
        	 			}
        	 			else if(syscomflag.get('company_level')=="N"){
        	 				flag=2;
        	 				$('addrecord').disable();
        	 				$('btnClear').disable();
        	 				$('btnSave').disable();
        	 			}
        	 		}else{
        	 			flag=3;
        	 			if(syscomflag.get('company_level')=="Y"){	        	 			
	        	 			$('addrecord').enable();
	    	 				$('btnClear').enable();
	    	 				$('btnSave').enable();
    	 				}
        	 		}
        	 	}
        	 	syscomflag.set('levelflag',flag);
        	 }
        	 
        	 function savedimension(){
        	 	$('fnd_dimension_values_result_ds').submit();
        	 	return 'summary_flag_cb';
        	 }
		]]></script>
        <a:dataSets>
            <a:dataSet id="fnd_dimensions" loadData="true" model="fnd.FND2230.fnd_dimensions_company"/>
            <a:dataSet id="fnd_dimension_values_query_ds" model="fnd.FND2230.fnd_dimension_values_company">
                <a:fields>
                    <a:field name="dimension_id"/>
                    <a:field name="dimension_code_display" displayField="dimension_code_display" options="fnd_dimensions" required="true">
                        <a:mapping>
                            <a:map from="dimension_id" to="dimension_id"/>
                            <a:map from="dimension_code" to="dimension_code"/>
                            <a:map from="description" to="dimension_description"/>
                            <a:map from="dimension_code_display" to="dimension_code_display"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="dimension_description" readOnly="true"/>
                    <a:field name="dimension_value_code"/>
                    <a:field name="dimension_value_description"/>
                    <a:field name="summary_flag_Y" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                    <a:field name="summary_flag_N" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="fnd_dimension_values_result_ds" model="fnd.FND2230.fnd_dimension_values_company" queryDataSet="fnd_dimension_values_query_ds" selectable="true">
                <a:fields>
                    <a:field name="dimension_id"/>
                    <a:field name="dimension_value_id"/>
                    <a:field name="dimension_value_code" required="true"/>
                    <a:field name="dimension_value_description" required="true"/>
                    <a:field name="summary_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="enabled_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                </a:fields>
                <a:events>
                    <a:event name="add" handler="setinitdata"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="syscom_ds" model="fnd.FND2230.fnd_dimensions_syscomlevel">
                <a:fields>
                    <a:field name="system_level"/>
                    <a:field name="company_level"/>
                </a:fields>
                <a:events>
                    <a:event name="load" handler="syscomLoadFunction"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:form LabelWidth="120" row="1" title="FND_DIMENSION_VALUE.COMP_DIM_DEF" width="800">
                <a:vBox>
                    <a:comboBox name="dimension_code_display" id="dimension_code_cb" bindTarget="fnd_dimension_values_query_ds" prompt="FND_DIMENSIONS.DIMENSION_CODE">
                        <a:events>
                            <a:event name="enterdown" handler="queryFndDimensionValues"/>
                        </a:events>
                    </a:comboBox>
                    <a:textField name="dimension_value_code" bindTarget="fnd_dimension_values_query_ds" prompt="FND_DIMENSION_VALUES.DIMENSION_VALUE_CODE">
                        <a:events>
                            <a:event name="enterdown" handler="queryFndDimensionValues"/>
                        </a:events>
                    </a:textField>
                </a:vBox>
                <a:vBox>
                    <a:textField name="dimension_description" bindTarget="fnd_dimension_values_query_ds" prompt="FND_DIMENSIONS.DESCRIPTION"/>
                    <a:textField name="dimension_value_description" bindTarget="fnd_dimension_values_query_ds" prompt="FND_DIMENSION_VALUES.DESCRIPTION">
                        <a:events>
                            <a:event name="enterdown" handler="queryFndDimensionValues"/>
                        </a:events>
                    </a:textField>
                </a:vBox>
                <a:vBox>
                    <a:checkBox name="summary_flag_Y" bindTarget="fnd_dimension_values_query_ds" prompt="FND_DIMENSION_VALUES.SUMMARY_FLAG">
                        <a:events>
                            <a:event name="enterdown" handler="queryFndDimensionValues"/>
                        </a:events>
                    </a:checkBox>
                    <a:checkBox name="summary_flag_N" bindTarget="fnd_dimension_values_query_ds" prompt="FND_DIMENSION_VALUES.SUMMARY_NFLAG">
                        <a:events>
                            <a:event name="enterdown" handler="queryFndDimensionValues"/>
                        </a:events>
                    </a:checkBox>
                </a:vBox>
            </a:form>
            <a:hBox>
                <a:button click="queryFndDimensionValues" text="HAP_QUERY"/>
                <a:button click="resetFndDimensionValues" text="HAP_RESET"/>
            </a:hBox>
            <a:grid bindTarget="fnd_dimension_values_result_ds" height="330" navBar="true" width="800">
                <a:toolBar>
                    <a:button id="addrecord" disabled="true" type="add"/>
                    <a:button id="btnClear" type="clear"/>
                    <a:button id="btnSave" click="savedimension" icon="${/request/@context_path}/images/save.gif" text="HAP_SAVE"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="dimension_value_code" align="center" editorFunction="dimensionValueCodeEdit" prompt="FND_DIMENSION_VALUES.DIMENSION_VALUE_CODE" sortable="true" width="150"/>
                    <a:column name="dimension_value_description" align="left" editorFunction="descriptionEdit" prompt="FND_DIMENSION_VALUES.DESCRIPTION" sortable="true" width="170"/>
                    <a:column name="summary_flag" align="center" editorFunction="summaryFlagEdit" prompt="FND_DIMENSION_VALUES.SUMMARY_FLAG" sortable="true" width="130"/>
                    <a:column name="enabled_flag" align="center" editorFunction="enabledFlagEdit" prompt="FND_DIMENSION_VALUES.ENABLED_FLAG" sortable="true" width="130"/>
                    <a:column name="dif_value" align="center" prompt="FND_DIMENSION_HER_COM.DIF_CHILD_VALUE" renderer="difValueComRenderer" sortable="true" width="130"/>
                </a:columns>
                <a:editors>
                    <a:textField id="dimension_value_code_tf" typeCase="upper"/>
                    <a:textField id="description_tf"/>
                    <a:checkBox id="summary_flag_cb"/>
                    <a:checkBox id="enabled_flag_cb"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>