// Copyright 2008 ProjectWizards GmbH. All rights reserved.

//console.log("UtilizationView");

var UtilizationView = ActivitiesView.extend({
	constructor: function(outlineController, domNode, columns, styleList, ganttRuler, viewOptions, environment, controlsContainer, managedObjectContext, showPrintView, delegate){
		this.base(outlineController, domNode, columns, styleList, ganttRuler, viewOptions, environment, controlsContainer, managedObjectContext, showPrintView, delegate);
		this.outlineView.outlineColumnPadding = 13;
	},

	rootObjectsInManagedObjectContext: function(moc){
		var result = [];
		if(moc){
			for(var key in moc.registeredObjects){
				var object = moc.registeredObjects[key]; 
				if(object.className() == "MEProject" && !object.valueForKey("linkedParentActivity") && !object.valueForKey("projectLink")) {
					result = object.valueForKey("masterResources");
					break;
				}
			}
		}
		return result;
	},
	
	outlineShouldDragRows: function(outline, rows){
		return false;
	},
	
	outlineViewDidCreateDisclosureButtonForRow: function(outline, button, row){
	
	},
	
	outlineHeightForRow: function(outline, row){
		var height = this.base(outline, row);
		if(!height)
			height = 24;
		return height;
	},

	outlineDidCreateCellInRow: function(outline, cell, row, editMode){
		if(cell.column == outline.outlineColumn){
			if(row.object.className() == "MEAssignment" || row.object.className() == "MEActivity"){
				this.base(outline, cell, row, editMode);
				cell.style.paddingLeft = (parseInt(cell.style.paddingLeft)+9)+'px';
				cell.style.width = (parseInt(cell.style.width)-9)+'px';
			}else if(row.object.className() == "MEMasterResource"){
				var imagePath = row.object.valueForKey('resources').length ? this.environment.images.Resource : this.environment.images.Activity;
//				var style = "vertical-align:middle; margin-left:"+(3+(row.object.isLeaf() ? 9 : 0))+"px; margin-right:2px;";
				var style = "vertical-align:middle; margin-left:"+ 3 +"px; margin-right:2px;";
				var image = IMG({width:15, height:14, src:imagePath, style:style});
				cell.appendChild(image);
				cell.style.fontWeight='bold';
			}
		}
	},
	
	setColumns: function(columns){
		this.columns = columns;
		this.outlineView.setColumnsAndOutlineColumnKey(columns, "utilizationTitle");
	},
	
	outlineHeightForRow: function(outline, row){
		var height = this.base(outline, row);
		return Math.max(height, 18);
	},
	
	displayGraphs: function(){
		return true;
	},
	
	refresh: function(refreshSelection){
		this.setRootActivities(this.rootObjectsInManagedObjectContext(this.moc), true);
		this.base(refreshSelection);	
	}
				
	
});