Ext.namespace('fcbm.component');

/*
 config = {
 	codeLangue: 'fr',
 	name: '08.01',
 	type: 'atlas|training',
 	circumstances: 'Homme de 77 ans avec décompensation cardiaque. Affection hématologique 4 ans auparavant.',
 	tabPanel: myTabPanel
 }
 */
fcbm.component.DocumentRenderer = function (config) {
	
	return {
		/*
		 * Properties
		 */
		initialConfig: Ext.apply(config),
		document: null,
		imageWall: null,
		modeSolution: false,
		
		/*
		 * Methods
		 */
		loadDocument: function () {
			
			this.document = new fcbm.model.Document (
				this.initialConfig.type,
				this.initialConfig.name, 
				this.initialConfig.circumstances,
				'data/documents/'+this.initialConfig.codeLangue+'/' + this.initialConfig.name, 
				this.initialConfig.codeLangue
			);
			this.document.on('Ready', function() {
				this.component.showDocument();
			},
			{component: this});
		},
		
		showDocument: function () {
			var tabPanel = this.initialConfig.tabPanel;
			
			document.imgAnnotationMgr = new fcbm.component.ImageAnnotationManager({
				document: this.document
			});
			this.imageWall = new fcbm.component.ImageWall({
				document: this.document,
				type: this.initialConfig.type,
				parentCmp: tabPanel,
				imgAnnotationMgr: document.imgAnnotationMgr
			});
			
			if (this.initialConfig.type == 'training') {
				var imageWall = this.imageWall;
				
				var tabClinicPresentation = this.getClinicPresentationPanel();
				var tabMurImages = this.getImgWallPanel(imageWall, this.document.imageWall.imgWall.wall1, 5, 5);
				var tabReponse = this.getReponsePanel();
				if (document.currentFile.document.imageWall.imgWall.hasWall2) 
					var tabMurImages2 = this.getImgWallPanel2(imageWall, this.document.imageWall.imgWall.wall2, 2, 5);
				
				// on ajoute la tab au tabPanel
				tabPanel.add(tabClinicPresentation);
				tabPanel.add(tabMurImages);
				if (document.currentFile.document.imageWall.imgWall.hasWall2) 
					tabPanel.add(tabMurImages2);
				tabPanel.add(tabReponse);
				
				// TAB présentation clinique
				tabPanel.setActiveTab('tabClinicPresentation');
				Ext.getCmp("panel_histCli").body.update(this.document.clinicPresentation);
				Ext.getCmp('panel_questions').body.update(this.document.questions);
				
				Ext.getCmp('text_dossier').setValue(this.document.name);
				Ext.getCmp('text_circonstances').setValue(this.document.circumstances);
				// TAB Réponse
				Ext.getCmp('text_dossier2').setValue(this.document.name);
				Ext.getCmp('text_circonstances2').setValue(this.document.circumstances);
			} else {
				this.setModeSolution ();
			}
		},

		verifReponse: function () {
			
			var messages = [];
			if (Ext.getCmp('grid_hypoDiag').getStore().getCount() == 0)
				messages.push("Sélectionner vos hypothèses de diagnostic");
			if (Ext.getCmp('grid_liste_examens').getStore().getCount() == 0)
				messages.push("Sélectionner les examens complémentaires");
			if (Ext.getCmp('grid_liste_annoCyto').getStore().getCount() == 0)
				messages.push("Sélectionner les anomalies cytologiques");
			if (Ext.get('text_repQuestions').getValue().length == 0)
				messages.push("Saisir vos réponses aux questions");
			if (document.imgAnnotationMgr.leucoCountNb == 0)
				messages.push("Saisir la formule leucocytaire depuis l'onglet mur d'images (zoom)");
			
			
			var verif = (messages.length > 0 ? false : true);
			
			if (verif) {
				new fcbm.model.Compteurs ("DossiersTermines");
				
				document.loaderTimeOut = false;
				setTimeout(function () {
					document.loaderTimeOut = true;
				}, 3000);
				document.loader = new fcbm.component.Loader("Veuillez patienter...", ["document.loaderTimeOut"]);
				
				this.setModeSolution.defer(deferTimeToShowLoader, this);
				
			} else {
				var msg = 	"<b>Pour valider votre réponse, vous devez : </b><br/><br/><br/>" + 
							"<ul style=\"list-style-type: disc;margin-left: 16px;\">";
				for (var i=0; i<messages.length; i++) {
					msg += 	"<li>" + messages[i] + "</li>";
				}
				msg += 		"</ul>";
				
				Ext.MessageBox.show({
					title: 'Validation de votre réponse',
					msg: msg,
					buttons: Ext.Msg.OK,
					icon: Ext.MessageBox.ERROR,
					minWidth: 400
				});
			}
		},
		
		setModeSolution: function () {

			this.modeSolution = true;
			document.imgAnnotationMgr.setSolutionMode();
			
			var tabPanel = this.initialConfig.tabPanel;
			
			tabPanel.add(this.getSolutionPanel());
			tabPanel.setActiveTab('tabSolution');
			if (document.currentFile.document.imageWall.imgWall.hasSol2)
				tabPanel.add(this.getSolutionPanel2());
			
			// TAB Solution
			Ext.getCmp('text_dossier3').setValue(this.document.name);
			Ext.getCmp('text_circonstances3').setValue(this.document.circumstances);
			if (document.currentFile.document.imageWall.imgWall.hasSol2) {
				Ext.getCmp('text_dossier4').setValue(this.document.name);
				Ext.getCmp('text_circonstances4').setValue(this.document.circumstances);
			}
			
			// On désacte certains éléments en mode solution
			if (this.initialConfig.type == 'training') {
				Ext.getCmp('btn-valider').disable();
				Ext.getCmp('btn-anoCytoGrid').disable();
				if (Ext.getCmp('btn-anoCytoZoom') != null)
					Ext.getCmp('btn-anoCytoZoom').disable();
				Ext.getCmp('panel_hypoDiag').tools['edit'].setVisible(false);
				Ext.getCmp('panel_examens').tools['edit'].setVisible(false);
				Ext.getCmp('panel_annoCyto').tools['edit'].setVisible(false);
				Ext.getCmp('text_repQuestions').disable();
			}
		 },
		
		/*
		 * Descriptions des onglets
		 */
		getClinicPresentationPanel: function () {
			
			var numerationStore = this.document.numeration.getDataStore();
			
			var clinicPresentationTab = new Ext.FormPanel({
				id: 'tabClinicPresentation',
				frame: true,
				autoScroll: true,
				title: 'Présentation clinique',
				bodyStyle: 'padding:5px 5px 0',
				items: [{
					xtype: 'textfield',
					fieldLabel: 'Dossier ',
					id: 'text_dossier',
					readOnly: true,
					width: 50
				}, {
					xtype: 'textfield',
					fieldLabel: 'Circonstances ',
					id: 'text_circonstances',
					readOnly: true,
					width: 585
				},{
					xtype: 'panel',
					id: 'panel_columnNumeQuest',
					width: '100%',
					layout: 'column',
					header: false,
					style: 'margin-top: '+ defaultCSSMargin,
					items: [{
						id: 'panel_numeration',
						title: 'Numération',
						width: 150,
						height: 520,
						bodyStyle: 'background-color: #ffffff;padding: 3px;',
						frame: true,
						items: [{
							xtype: 'grid',
						 	id: 'grid_numeration', 
					        ds: numerationStore,
					        columns: [
								{header: "Name", sortable: false, dataIndex: 'name1', renderer: this.numerationItemRenderer, width: 90},
								{header: "Val", sortable: false, align: 'right', dataIndex: 'value1', width: 35, renderer: this.numerationRenderer1},
								{
									header: "Categorie",
									sortable: false,
									dataIndex: 'cat1',
									hidden: true
								}
							],
					        width:150,
							height: 515,
					        autoHeight: true, 
							stripeRows: true,
							hideHeaders: true,
							view: new Ext.grid.GroupingView({
								showGroupName: false,
								startCollapsed: false,
								interceptMouse : Ext.emptyFn
							}), 
					        autoScroll:false
					    }]
					}, {
							xtype: 'panel',
							frame: false,
							border: false,
							style: 'margin-left: ' + defaultCSSMargin,
							columnWidth: 1,
							items: [
							{
								xtype: 'panel',
								title: 'Histoire clinique',
								id: 'panel_histCli',
								width: '100%',
								height:265,
								frame: true,
								autoScroll: true,
								bodyStyle: 'background-color: #ffffff;padding: 3px;',
								cls: 'x-tool-left',
								tools: [{
									id: 'maximize',
									qtip: "Agrandir la fenêtre de visualisation",
									handler: function(event, toolEl, panel){
										if (Ext.getCmp('window_histCli') == null) {
											new Ext.Window({
												title: 'Histoire clinique',
												id: 'window_histCli',
												width: defaultWindowWidth,
												height: defaultWindowHeight,
												modal: true,
												bodyStyle: 'background-color: #ffffff; padding: 3px;',
												maximizable: true,
												plain: true,
												html: document.currentFile.document.clinicPresentation
											}).show();
										}
									}
								}]
							},
							{
								xtype: 'panel',
								frame: true,
								title: 'Questions',
								id: 'panel_questions',
								bodyStyle: 'background-color: #ffffff;padding: 3px;',
								style: 'margin-top: ' + defaultCSSMargin, 
								height: 250,
								tools: [{
									id: 'maximize',
									qtip: "Agrandir la fenêtre de visualisation",
									handler: function(event, toolEl, panel){
										if (Ext.getCmp('window_questions') == null) {
											new Ext.Window({
												title: 'Questions',
												id: 'window_questions',
												width: defaultWindowWidth,
												height: defaultWindowHeight,
												modal: true,
												maximizable: true,
												plain: true,
												bodyStyle: 'background-color: #ffffff;padding: 3px;',
												html: document.currentFile.document.questions
											}).show();
											
										}
									}
								}]
							}
							]		
						}]
				
				},
				{
					xtype: 'panel',
					id: 'mention-footer-presentation',
					html: 	"<div align=\"center\">" +
							"Allez maintenant réaliser l'examen du frottis (mur d'images : bouton en haut de l'écran)." + 
							"</div>"
				}]
			});
			
			return clinicPresentationTab;
		},
		
		getImgWallPanel: function (imageWallCmp, imagesArray, nCol, nRow) {
			
			var imgWallTab = new Ext.FormPanel({
				id: 'tabMurImages',
				frame: true,
				title: "Mur d'images",
				autoScroll: true,
				bodyStyle: 'padding:5px 5px 0',
				items: [
					imageWallCmp.showGrid('Wall1', imagesArray, nCol, nRow)
				]
			});
			
			return imgWallTab;
		},
		
		getImgWallPanel2: function (imageWallCmp, imagesArray, nCol, nRow) {
				
			var imgWallTab2 = new Ext.FormPanel({
				id: 'tabMurImages2',
				frame: true,
				title: "Mur d'images (suite)",
				autoScroll: true,
				bodyStyle: 'padding:5px 5px 0',
				items: [{
						xtype: 'panel',
						layout: 'column',
						items: [{
								xtype: 'panel',
								width: imgWallDefaultTinyWidth*nCol,
								items: [
										imageWallCmp.showGrid('Wall2', imagesArray, nCol, nRow)
									]
							},
							{
								xtype: 'panel',
								title: "Commentaires mur d'images",
								columnWidth: 1,
								frame: true,
								style: 'margin-left: ' + defaultCSSMargin, 
								bodyStyle: 'background-color: #ffffff;padding: 3px;',
								height: imgWallDefaultTinyHeight*nRow,
								html: document.currentFile.document.CommentWall2
							}
						]
					}
				]
			});
			
			return imgWallTab2;
		},
		
		getReponsePanel: function () {
			
			// Initialisation des grilles
			
			var ds_hypoDiag = new Ext.data.Store({
				proxy: new Ext.data.MemoryProxy([]),
			    reader: new Ext.data.ArrayReader({}, [{name: 'id'},{name: 'desc'},{name: 'isUnique'},{name: 'idSynonyme'},{name: 'idCat'},{name: 'descCat'}])
			});
			var ds_examens = new Ext.data.Store({
				proxy: new Ext.data.MemoryProxy([]),
			    reader: new Ext.data.ArrayReader({}, [{name: 'id'},{name: 'desc'},{name: 'isUnique'},{name: 'idSynonyme'},{name: 'idCat'},{name: 'descCat'}])
			});
			var ds_annoCyto = new Ext.data.Store({
				proxy: new Ext.data.MemoryProxy([]),
			    reader: new Ext.data.ArrayReader({}, [{name: 'id'},{name: 'desc'},{name: 'isUnique'},{name: 'idSynonyme'},{name: 'idCat'},{name: 'descCat'}])
			});
			
			var tabReponse = new Ext.FormPanel({
				id: 'tabReponse',
				frame: true,
				autoScroll: true,
				title: "Réponse",
				bodyStyle: 'padding:5px 5px 0',
				items: [
					{
						xtype: 'textfield',
						fieldLabel: 'Dossier ',
						id: 'text_dossier2',
						readOnly: true,
						width: 50
					}, {
						xtype: 'textfield',
						fieldLabel: 'Circonstances ',
						id: 'text_circonstances2',
						width: 585,
						readOnly: true
					},
					{
						xtype: 'panel',
						id: 'panel_columnReponse',
						width: '100%',
						layout: 'column',
						header: false,
						style: 'margin-top: ' + defaultCSSMargin,
						items: [{
								xtype: 'panel',
								width: 380,
								items: [
									{
										xtype: 'panel',
										id: 'panel_formLeuco',
										title: 'Formule leucocytaire',
										height: 440,
										frame: true,
										items: [{
											xtype: 'grid',
											id: 'grid_formLeuco',
											autoExpandColumn: 'item',
											ds: document.imgAnnotationMgr.leucoCountDataStore,
											cm: document.imgAnnotationMgr.leucoCountColumnView,
											height: 435, 
											stripeRows: true,
									        autoScroll:false
										}]
									},
									{
										xtype: 'panel',
										width: 380,
										frame: true,
										title: 'Anomalies cytologiques',
										id: 'panel_annoCyto',
										layout: 'fit',
										style: 'margin-top: ' + defaultCSSMargin,
										tools: [{
											id: 'edit',
											qtip: "Modifier la liste",
											handler: function(event, toolEl, panel){
												document.loaderTimeOut = false;
												setTimeout(function () {
													document.loaderTimeOut = true;
												}, timeOutRenderList);
												document.loader = new fcbm.component.Loader("Chargement de la liste", ["document.loaderTimeOut"]);
												
												var showList = function(){
													new fcbm.component.List({
														id: 'window_List',
														itemName: 'Anomalie cytologique',
														title: 'Liste des anomalies cytologiques',
														list: document.listes.liste_CytoSigns,
														gridId: 'grid_liste_annoCyto',
														forceCategoryNameTo: null,
														type: 'annoCyto'
													}).show();
												};
												showList.defer(deferTimeToShowLoader, this);
											}
										}],
										items: [{
											xtype: 'grid',
											id: 'grid_liste_annoCyto',
											width: '100%',
											height: 63,
											stripeRows: true,
											autoScroll:true,
											hideHeaders: true,
											store: ds_annoCyto,
											columns: [
												{
													header: "Cat",
													menuDisabled: true,
													width: 80,
													dataIndex: 'descCat',
													sortable: false,
													renderer: function(data, cell, record, rowIndex, columnIndex, storeDocuments){
														if (data == 'ZZZ') 
															return "Autres réponses";
														else 
															return data;
													}
												},
												{header: "Item", menuDisabled: true, width: 250, dataIndex: 'desc', sortable: false}
											],
											viewConfig: {
									            forceFit:true
									        }
										}]
									}
								]
							},
							{
								xtype: 'panel',
								id: 'panel_col2Reponses',
								style: 'margin-left: ' + defaultCSSMargin,
								columnWidth: 1,
								header: false,
								items: [
									{
										xtype: 'panel',
										title: 'Hypothèses de diagnostic',
										id: 'panel_hypoDiag',
										frame: true,
										layout: 'fit',
										tools: [{
											id: 'edit',
											qtip: "Modifier la liste",
											handler: function(event, toolEl, panel){											
												document.loaderTimeOut = false;
												setTimeout(function () {
													document.loaderTimeOut = true;
												}, timeOutRenderList);
												document.loader = new fcbm.component.Loader("Chargement de la liste", ["document.loaderTimeOut"]);
												
												var showList = function () {
													new fcbm.component.List({
														id: 'window_List',
														itemName: 'Pathologie',
														title: 'Liste des pathologies',
														list: document.listes.liste_Diagnostics,
														gridId: 'grid_hypoDiag',
														forceCategoryNameTo: 'Pathologies',
														type: 'hypDiag'
													}).show();	
												};
												
												showList.defer(deferTimeToShowLoader, this);
												
											}
										}],
										items: [{
											xtype: 'grid',
											id: 'grid_hypoDiag',
											width: '100%',
											height: 63,
											stripeRows: true,
			        						autoExpandColumn: 'Item',
											autoScroll:true,
											hideHeaders: true,
											store: ds_hypoDiag,
											columns: [
												{header: "Index", menudisabled: true, width: 25, dataIndex: 'id', sortable: false, 
													renderer: function(value, metadata, record, rowIndex, colIndex, store) {
														return rowIndex+1;
													}
												},
												{header: "Item", id:'Item', width: 1000, menuDisabled: true, dataIndex: 'desc', sortable: false}
											],
											viewConfig: {
									            forceFit:true
									        }
										}]
									},
									{
										xtype: 'panel',
										title: 'Examens complémentaires à réaliser',
										id: 'panel_examens',
										frame: true,
										layout: 'fit',
										style: 'margin-top: ' + defaultCSSMargin,
										tools: [{
											id: 'edit',
											qtip: "Modifier la liste",
											handler: function(event, toolEl, panel){
												document.loaderTimeOut = false;
												setTimeout(function () {
													document.loaderTimeOut = true;
												}, timeOutRenderList);
												document.loader = new fcbm.component.Loader("Chargement de la liste", ["document.loaderTimeOut"]);
												
												var showList = function(){
													new fcbm.component.List({
														id: 'window_List',
														itemName: 'Examen',
														title: 'Liste des investigations',
														list: document.listes.liste_Investigations,
														gridId: 'grid_liste_examens',
														forceCategoryNameTo: 'Examens',
														type: 'examens'
													}).show();
												};
												
												showList.defer(deferTimeToShowLoader, this);
											}
										}],
										items: [{
											xtype: 'grid',
											id: 'grid_liste_examens',
											width: '100%',
											height: 215,
											stripeRows: true,
			        						autoExpandColumn: 0,
											autoScroll:true,
											hideHeaders: true,
											store: ds_examens,
											columns: [
												{header: "Item", menuDisabled: true, width: 100, dataIndex: 'desc', sortable: true}
											],
											viewConfig: {
									            forceFit:true
									        }
										}]
									},
									{
										xtype: 'panel',
										columnWidth: 1,
										frame: true,
										title: 'Réponse aux questions',
										id: 'panel_repQuestions',
										style: 'margin-top: ' + defaultCSSMargin,
										tools: [{
											id: 'maximize',
											qtip: "Questions",
											handler: function(event, toolEl, panel){
												if (Ext.getCmp('window_repQuestions') == null) {
													new Ext.Window({
														title: 'Questions',
														id: 'window_questions',
														width: defaultWindowWidth,
														height: defaultWindowHeight,
														modal: true,
														maximizable: true,
														plain: true,
														bodyStyle: 'background-color: #ffffff;padding: 3px;',
														html: document.currentFile.document.questions
													}).show();
													
												}
											}
										}],
										items: [
											{
												xtype: 'textarea',
												id: 'text_repQuestions',
												width: '100%',
												height: 130
											}
										]
									},
									{
										xtype: 'panel',
										style: 'margin-top: ' + defaultCSSMargin,
										width: '100%',
										bodyCfg: {tag:'center'},
										items: [{
											xtype: 'button',
											id: 'btn-valider',
											text: 'Valider',
											handler: this.verifReponse,
											scope: this	
										}]
									}		
								]
							}
						]
					}
				]
			});
			return tabReponse;
		},

		getSolutionPanel: function () {
			
			if (this.initialConfig.type == 'training') {
				var storeFormLeuco = document.imgAnnotationMgr.leucoCountDataStore;
				var cmFormLeuco = document.imgAnnotationMgr.leucoCountSolutionColumnView;
				var storeFormDiagnostic = this.getSolDiagnosticDataStore();
				var cmDiagnostic = new Ext.grid.ColumnModel([
					{header: " ", menuDisabled: true, width: 20, dataIndex: 'idx', resizable: false, sortable: false},
					{header: "Référence", menuDisabled: true, width: 200, dataIndex: 'descRef', resizable: true, sortable: false},
					{header: "Vous", menuDisabled: true, dataIndex: 'descRep', resizable: true, sortable: false, id: 'vous'}
				]);
				var storeExamens = this.getSolExamensDataStore();
				var cmExamens = new Ext.grid.ColumnModel([
					{header: "Référence", menuDisabled: true, width: 200, dataIndex: 'descRef', sortable: false, resizable: true},
					{header: "Vous", menuDisabled: true, dataIndex: 'descRep', sortable: false, resizable: true, id: 'vous'}
				]);
				var storeAnoCyto = this.getSolAnnoCytoDataStore();
				var cmAnoCyto = new Ext.grid.ColumnModel([
					{header: "Référence", menuDisabled: true, width: 200, dataIndex: 'descRef', sortable: false, resizable: true, renderer: this.solAnoCytoRenderer},
					{header: "Vous", menuDisabled: true, dataIndex: 'descRep', sortable: false, resizable: true, renderer: this.solAnoCytoRenderer, id: 'vous'}
				]);
				
			} else {
				var gb = document.currentFile.document.numeration.getGBValue ();
				var storeFormLeuco = document.currentFile.document.formuleLeuco.getDataStoreAtlas(gb);
				var cmFormLeuco = document.imgAnnotationMgr.leucoCountColumnView;
				
				var storeFormDiagnostic = this.getSolDiagnosticDataStore();
				var cmDiagnostic = new Ext.grid.ColumnModel([
					{header: " ", menuDisabled: true, width: 20, dataIndex: 'idx', resizable: false, sortable: false},
					{header: "Référence", menuDisabled: true, dataIndex: 'descRef', resizable: true, sortable: false, id: 'vous'}
				]);
				var storeExamens = this.getSolExamensDataStore();
				var cmExamens = new Ext.grid.ColumnModel([
					{header: "Référence", menuDisabled: true, dataIndex: 'descRef', sortable: false, resizable: true, id: 'vous'}
				]);
				var storeAnoCyto = this.getSolAnnoCytoDataStore();
				var cmAnoCyto = new Ext.grid.ColumnModel([
					{header: "Référence", menuDisabled: true, dataIndex: 'descRef', sortable: false, resizable: true, renderer: this.solAnoCytoRenderer, id: 'vous'}
				]);
				
			
			}
			
			
			var tabSolution = new Ext.FormPanel({
				id: 'tabSolution',
				frame: true,
				autoScroll: true,
				title: (this.initialConfig.type == 'training' ? "Solution" : "Atlas"),
				bodyStyle: 'padding:5px 5px 0',
				items: [
					{
						xtype: 'panel',
						id: 'head_solution',
						width: '100%',
						layout: 'column',
						header: false,
						items: [
							{
								layout: 'form',
								width: 150,
								items: [
									{
										xtype: 'textfield',
										fieldLabel: 'Dossier ',
										id: 'text_dossier3',
										width: 50,
										labelStyle: 'width: 50px',
										readOnly: true
									}
								]
							},
							{
								layout: 'form',
								columnWidth: 1,
								items: [{
									xtype: 'textfield',
									fieldLabel: 'Circonstances ',
									id: 'text_circonstances3',
									width: 585,
									readOnly: true,
									grow: true
								}]
							}
						]
						
					},
					{
						xtype: 'panel',
						layout: 'column',
						items: [
							{
								xtype: 'panel',
								width: 300,
								items: [
									// GRID NUMERATION
									{
										xtype: 'panel',
										title: 'Numération',
										frame: true,
										width:300,
										height: 200,
								        autoHeight: true, 
										stripeRows: true,
								        autoScroll:true,
										items: [{
											xtype: 'grid',
										 	id: 'grid_numeration2', 
									        ds: this.document.numeration.getDataStoreSolution(),
											hideHeaders: true,
									        columns: [
												{header: "Name", sortable: false, dataIndex: 'name1', renderer: this.numerationItemRenderer, width: 100},
												{header: "Val", sortable: false, dataIndex: 'value1', renderer: this.numerationRenderer, align: 'right', width: 35},
												{header: "Name2", sortable: false, dataIndex: 'name2', renderer: this.numerationItemRenderer, width: 100},
												{header: "Val2", sortable: false, dataIndex: 'value2', renderer: this.numerationRenderer, align: 'right', width: 35}
											]
										}]
										
							    	},
									// PANEL formule leucocytaire
									{
										xtype: 'panel',
										title: 'Formule leucocytaire',
										style: 'margin-top: '+ defaultCSSMargin,
										frame: true,
										items: [{
											xtype: 'grid',
											ds: storeFormLeuco,
									        cm: cmFormLeuco,
									        autoHeight: true, 
											stripeRows: true, 
									        autoScroll:true
										}]
									}
								]
					
							},
							
							// colonne 2
							{
								xtype: 'panel',
								id: 'panel_solCol2',
								columnWidth: 1,
								style: 'margin-left: '+ defaultCSSMargin,
								items: [
									{
										xtype: 'panel',
										title: 'Diagnostic',
										layout: 'fit',
										frame: true,
										items: [
											{
												xtype: 'grid',
												id: 'grid_liste_diag',
												width: '100%',
												height: 88,
												stripeRows: true,
												autoScroll:true,
												autoExpandColumn: 'vous',
												hideHeaders: (this.initialConfig.type == 'training' ? false : true),
												store: storeFormDiagnostic,
												cm: cmDiagnostic 
											}
										]								
									},
									{
										xtype: 'panel',
										id: 'panel_solHistCli',
										title: 'Histoire clinique et pathologie',
										frame: true,
										style: 'margin-top: '+ defaultCSSMargin,
										autoScroll: true,
										height:204,
										bodyStyle: 'background-color: #ffffff;padding: 3px;',
										cls: 'x-tool-left',
										html: document.currentFile.document.solComment1,
										tools: [{
											id: 'maximize',
											qtip: "Agrandir la fenêtre de visualisation",
											handler: function(event, toolEl, panel){
												if (Ext.getCmp('window_solHistCli') == null) {
													new Ext.Window({
														title: 'Histoire clinique et pathologie',
														id: 'window_solHistCli',
														width: defaultWindowWidth,
														height: defaultWindowHeight,
														modal: true,
														bodyStyle: 'background-color: #ffffff; padding: 3px;',
														maximizable: true,
														autoScroll: true,
														plain: true,
														html: document.currentFile.document.solComment1
													}).show();
												}
											}
										}]
									},
									{
										xtype: 'panel',
										title: 'Anomalies cytologiques',
										layout: 'fit',
										frame: true,
										style: 'margin-top: '+ defaultCSSMargin,
										items: [
											{
												xtype: 'grid',
												id: 'grid_liste_anoCyto2',
												width: '100%',
												height: 88,
												stripeRows: true,
												autoScroll:true,
												autoExpandColumn: 'vous',
												hideHeaders: (this.initialConfig.type == 'training' ? false : true),
												store: storeAnoCyto,
												cm: cmAnoCyto 
											}
										]
									},
									{
										xtype: 'panel',
										title: 'Examens complémentaires à réaliser',
										frame: true,
										layout: 'fit',
										style: 'margin-top: '+ defaultCSSMargin,
										items: [
											{
												xtype: 'grid',
												id: 'grid_liste_examens2',
												width: '100%',
												height: 88,
												stripeRows: true,
												autoScroll:true,
												autoExpandColumn: 'vous',
												hideHeaders: (this.initialConfig.type == 'training' ? false : true),
												store: storeExamens,
												cm: cmExamens 
											}
										]
									}
								]
							},
							// colonne 3
							{
								xtype: 'panel',
								width: imgWallDefaultTinyWidth,
								style: 'margin-left: '+ defaultCSSMargin,
								items: [this.imageWall.showGrid('Sol1', this.document.imageWall.imgWall.sol1, 1, 5)]	
							}
							
						]
					}
				]
			});
			
			return tabSolution;
			
		},

		getSolutionPanel2: function () {
			
			var tabSolution2 = new Ext.FormPanel ({
				id: 'tabSolution2',
				frame: true,
				autoScroll: true,
				title: (this.initialConfig.type == 'training' ? "Solution (suite)" : "Atlas (suite)"),
				bodyStyle: 'padding:5px 5px 0',
				items: [{
						xtype: 'panel',
						id: 'head_solution2',
						width: '100%',
						layout: 'column',
						header: false,
						items: [
							{
								layout: 'form',
								width: 150,
								items: [
									{
										xtype: 'textfield',
										fieldLabel: 'Dossier ',
										id: 'text_dossier4',
										width: 50,
										labelStyle: 'width: 50px',
										readOnly: true
									}
								]
							},
							{
								layout: 'form',
								columnWidth: 1,
								items: [{
									xtype: 'textfield',
									fieldLabel: 'Circonstances ',
									id: 'text_circonstances4',
									width: 585,
									readOnly: true,
									grow: true
								}]
							}
						]
					},
					{
						xtype: 'panel',
						layout: 'column',
						width: '100%',
						items: [{
							xtype: 'panel',
							id: 'panel_croquis',
							title: 'Illustrations',
							width: imgWallDefaultTinyWidth,
							items: [
								this.imageWall.showGrid('Crobar', this.document.imageWall.imgWall.crobar, 1, 2)
							]
						},
						{
							xtype: 'panel',
							id: 'panel_centre',
							columnWidth: 1,
							style: 'margin-left: '+ defaultCSSMargin,
							items: [{
								xtype: 'panel',
								title: 'Diagnostic',
								layout: 'fit',
								frame: true,
								items: [
									{
										xtype: 'grid',
										id: 'grid_liste_diag2',
										width: '100%',
										height: 88,
										stripeRows: true,
										autoScroll:true,
										autoExpandColumn: 'vous',
										store: this.getSolDiagnosticDataStore(),
										columns: [
											{header: " ", menuDisabled: true, width: 20, dataIndex: 'idx', resizable: false, sortable: false},
											{header: "Référence", menuDisabled: true, width: 280, dataIndex: 'descRef', resizable: true, sortable: false},
											{header: "Vous", menuDisabled: true, dataIndex: 'descRep', resizable: true, sortable: false, id: 'vous'}
										]
									}
								]								
							},
							{
								xtype: 'panel',
								id: 'panel_solHistCli2',
								title: 'Histoire clinique et pathologie',
								frame: true,
								style: 'margin-top: '+ defaultCSSMargin,
								autoScroll: true,
								height:445,
								bodyStyle: 'background-color: #ffffff;padding: 3px;',
								cls: 'x-tool-left',
								html: document.currentFile.document.solComment2,
								tools: [{
									id: 'maximize',
									qtip: "Agrandir la fenêtre de visualisation",
									handler: function(event, toolEl, panel){
										if (Ext.getCmp('window_solHistCli2') == null) {
											new Ext.Window({
												title: 'Histoire clinique et pathologie',
												id: 'window_solHistCli2',
												width: defaultWindowWidth,
												height: defaultWindowHeight,
												modal: true,
												bodyStyle: 'background-color: #ffffff; padding: 3px;',
												maximizable: true,
												autoScroll: true,
												plain: true,
												html: document.currentFile.document.solComment2
											}).show();
										}
									}
								}]
							}]
						},
						{
							xtype: 'panel',
							id: 'panel_imgWallSol2',
							width: imgWallDefaultTinyWidth,
							style: 'margin-left: '+ defaultCSSMargin,
							items: [
								this.imageWall.showGrid('Sol2', this.document.imageWall.imgWall.sol2, 1, 5)
							]
						}]
					}
				]
			});
			
			return tabSolution2;
			
		},

		/*
		 * Méthodes "utilitaires"
		 */
		destroy: function () {
			var tabPanel = this.initialConfig.tabPanel;
			
			this.removeTab('tabClinicPresentation');
			this.removeTab('tabMurImages');
			this.removeTab('tabMurImages2');
			this.removeTab('tabReponse');
			this.removeTab('tabSolution');
			this.removeTab('tabSolution2');
			this.removeTab('tabZoom_ImgWall1');
			this.removeTab('tabZoom_ImgWallX');

			return;
		},

		removeTab: function (tabId) {
			var tabPanel = this.initialConfig.tabPanel;
			var tab = tabPanel.findById(tabId);
			if (tab != null)
				tabPanel.remove(tabId);
		},
		 
		 
		/*
		 * Renderer pour les cellules des grid (mode solution) 
		 */
		numerationRenderer: function (value, metadata, record, rowIndex, colIndex, store) {
			var col = (colIndex < 3 ? '1' : '2');
			var colName = record.data['name'+col];
			if (colName == 'VS' || colName == 'Rét')
				return (record.get('value'+col) == '0' ? '---' : record.get('value'+col));
			else
				return record.get('value'+col);
			
		},
		
		numerationRenderer1: function  (value, metadata, record, rowIndex, colIndex, store) {
			var colName = record.data['name1'];
			if (colName == 'VS' || colName == 'Rét')
				return (value == '0' ? '---' : value);
			else
				return value;
			
		},
		
		numerationItemRenderer: function (value, metadata, record, rowIndex, colIndex, store) {
			var col = (colIndex < 3 ? '1' : '2');
			if (col == '2')
			metadata.attr = 'style="border-left: 1px solid #dddddd;"';
			return '<b>' + value + '</b> ('+record.get('unit'+col)+')';
			
		},
		
		solAnoCytoRenderer: function (value, metadata, record, rowIndex, colIndex, store) {
			if (colIndex == 0) {
				if (record.get('descRef') == '')
					return '';
				else
					return record.get('descCatRef') + ' - ' + record.get('descRef');
			}
			else {
				if (record.get('descRep') == '')
					return '';
				else
					return record.get('descCatRep') + ' - ' + record.get('descRep');
			}
		},
		
		/*
		 * Gestion des stores en mode solution 
		 */
		getSolDiagnosticDataStore: function () {
			var ref = this.document.diagnostics;
			var reponse = this.document.reponse.hypDiag;
			var liste = document.listes.liste_Diagnostics;
			var maxLength = (ref.length >= reponse.length ? ref.length : reponse.length);
			 
			var data = [];
			for (var i=0; i<maxLength; i++) {
				if (ref[i] == null)
					var iRef = new fcbm.model.Item ();
				else
					var iRef = liste.getItemById (ref[i]);
				if (reponse[i] == null)
					var iRep = new fcbm.model.Item ();
				else
					var iRep = liste.getItemById (reponse[i]);
				
				data.push ([(i+1), iRef.desc, iRep.desc]);
			}
			
			var ds = new Ext.data.Store({
				proxy: new Ext.data.MemoryProxy(data),
				reader: new Ext.data.ArrayReader({}, [{name: 'idx'}, {name: 'descRef'}, {name: 'descRep'}])
			});
			ds.load();
		
			return ds;
		},
		
		getSolAnnoCytoDataStore: function () {
			var ref = this.document.cytoSigns;
			var reponse = this.document.reponse.annoCyto;
			var liste = document.listes.liste_CytoSigns;
			var maxLength = (ref.length >= reponse.length ? ref.length : reponse.length);
			 
			var data = [];
			for (var i=0; i<maxLength; i++) {
				if (ref[i] == null)
					var iRef = new fcbm.model.Item ();
				else
					var iRef = liste.getItemById (ref[i]);
				if (reponse[i] == null)
					var iRep = new fcbm.model.Item ();
				else
					var iRep = liste.getItemById (reponse[i]);
				
				data.push ([iRef.descCat, iRef.desc, iRep.descCat, iRep.desc]);
			}
			
			var ds = new Ext.data.Store({
				proxy: new Ext.data.MemoryProxy(data),
				reader: new Ext.data.ArrayReader({}, [{name: 'descCatRef'}, {name: 'descRef'}, {name: 'descCatRep'}, {name: 'descRep'}])
			});
			ds.load();
		
			return ds;
		},
		
		getSolExamensDataStore: function () {
			var ref = this.document.investigations;
			var reponse = this.document.reponse.examens;
			var liste = document.listes.liste_Investigations;
			var maxLength = (ref.length >= reponse.length ? ref.length : reponse.length);
			 
			var data = [];
			for (var i=0; i<maxLength; i++) {
				if (ref[i] == null)
					var iRef = new fcbm.model.Item ();
				else
					var iRef = liste.getItemById (ref[i]);
				if (reponse[i] == null)
					var iRep = new fcbm.model.Item ();
				else
					var iRep = liste.getItemById (reponse[i]);
				
				data.push ([(i+1), iRef.desc, iRep.desc]);
			}
			
			var ds = new Ext.data.Store({
				proxy: new Ext.data.MemoryProxy(data),
				reader: new Ext.data.ArrayReader({}, [{name: 'idx'}, {name: 'descRef'}, {name: 'descRep'}])
			});
			ds.load();
		
			return ds;
		}
	}	
}

