Ext.namespace('CC');
Ext.namespace('CC.b');
Ext.namespace('CC.b.mod');

CC.b.mod.cms = function(){

	return{
	
		config : {},
	
		init : function(){
			CC.f.mod.cms.init();
		}
	}

}();

Ext.namespace('CC.f');
Ext.namespace('CC.f.mod');

CC.f.mod.cms = function(){
	
	return{
		
		ajaxUrl : CC_baseURL +'cms/',
		
		grids : {},
		formItems : [],
		windows: [],
		
		tree :{},
		filter_form :{},
		site_select :{},
		lang_select :{},
		
			
		ID : null,
		LANG_ID : null,
		
		init : function(){
			eval( 'this.'+ CC.b.mod.cms.config.start_event +'();' );
		},
		
		menu_editor : function () {
			this.site_select = CC.help.form.createCombo(
				null,
				'cms',
				null,
				{
					dataIndex : 'site_select',
					fieldLabel : CC.b.mod.cms.config.labelSite,
					displayField : 'text',
		    		valueField : 'value',
					mode : 'remote',
					store : { 
						url : 'extComboSite',	
		      			fields : [
		      				'value',
		      				'text'
						]
					},
					triggerAction : 'all',
		       		autoLoad : true,
		       		typeAhead : true,
		       		forceSelection : true,
					allowBlank : false,
					ownValue : {
						value : CC.b.mod.cms.config.cmsSite.ID,
						text : CC.b.mod.cms.config.cmsSite.DOMAIN
					}
				}
			);
			this.site_select.on('select', 
				function( comboObj, selectedOption ) {
					CC.f.mod.cms.tree.treeLoaderParams.SITE_ID = selectedOption.data.value;
					CC.f.mod.cms.tree.reload();
				}
			);
			
			this.lang_select = CC.help.form.createCombo(
				null,
				'cms',
				null,
				{
					dataIndex : 'lang_select',
					fieldLabel : CC.b.mod.cms.config.labelLanguage,
					displayField : 'text',
					valueField : 'value',
					mode : 'remote',
					store : { 
						url : 'extComboLang',	
						fields : [
						          'value',
						          'text'
						          ]
					},
					triggerAction : 'all',
					autoLoad : true,
					typeAhead : true,
					forceSelection : true,
					allowBlank : false,
					ownValue : {
						value : CC.b.mod.cms.config.cmsLang.ID,
						text : CC.b.mod.cms.config.cmsLang.NAME
					}
				}
			);
			this.lang_select.on('select', 
				function( comboObj, selectedOption ) {
					CC.f.mod.cms.tree.treeLoaderParams.LANG_ID = selectedOption.data.value;
					CC.f.mod.cms.tree.reload();
				}
			);
			
			this.tree = new Ext.TreeBar({
				moduleName : 'cms',
				gridName : 'cms_menu',
				dataIndex : 'menuTree',
				editableRoot : false,
				title: CC.b.mod.cms.config.titleMenu,
				urlGetData : this.ajaxUrl+'extMenuTree',
				urlGetTreeFormItem : this.ajaxUrl+'extMenuForm',
				urlTreeHandler : this.ajaxUrl+'extMenuItemSave',
				urlTreeDelete : this.ajaxUrl+'extMenuItemDelete',
				windowedForms: false,
				buttons : {
					create : CC.b.mod.cms.config.buttonCreateMenu,
					edit : CC.b.mod.cms.config.buttonEditMenu,
					del : CC.b.mod.cms.config.buttonDeleteMenu,
					changeParent : null
				}
			});
			this.tree.treeLoaderParams.LANG_ID = CC.b.mod.cms.config.cmsLang.ID;
			
			Ext.apply(
				this.filter_form,
				{
					xtype : 'form',
					labelAlign : 'top',
					border : false,
					items :[
						this.site_select,
						this.lang_select
					]	
				}
			);
			CC.main.layout.west.add( this.filter_form );
			
			CC.main.layout.west.add( this.tree );
			CC.main.layout.west.setWidth( 200 );
			
			CC.main.layout.center.add( { border: false } );
			CC.main.layout.center.doLayout();
			
			Ext.getCmp('CCWiew').doLayout();
		},
		
		saveMenuItem : function() {
			if ( CC.f.mod.cms.tree.saveNode(null) ) {
				CC.main.layout.clearCenter();
			}
		},
		
		closeForm : function() {
			CC.main.layout.clearCenter();
		},
		
		reloadTree : function() {
			this.tree.reload();
		}
		
	}
	
}();
