
/* ********************************************************************************************************** */
/* List Class */
/* ********************************************************************************************************** */

function joVMMDeviceClass (id, gui_parent_node_name, data_collection_name, data_name, source_data_types, destination_data_types)
{
	this.id								= id;

	this.gui_type						= "device";
	this.gui_parent_node_name		= gui_parent_node_name;
	this.gui_parent_node			= joFIND (gui_parent_node_name);

	this.data_collection_name		= data_collection_name;
	this.data_name						= data_name;
	
	this.data							= null;
	this.data_id						= "";
	
	this.form_node						= null;

	this.InitGui						= _joVMMDeviceClass_InitGui;
	this.AddButton						= _joVMMDeviceClass_AddButton;
	this.Action							= _joVMMDeviceClass_Action;
	this.ResetData						= function() {};
	this.ShowData						= function() {};
	this.SetActiveEntity 			= _joVMMDeviceClass_SetActiveEntity;
	this.ModelActiveEntity			= _joVMMDeviceClass_ModelActiveEntity;
	this.EditEntity					= _joVMMDeviceClass_EditEntity;


	// events
	this.OnEvent		 				= _joVMMDeviceClass_OnEvent;
	
	// do now
	this.InitGui();
}

/* ********************************************************************************************************** */

function _joVMMDeviceClass_InitGui()
{
	var button_node, title_node, container_node, footer_node, model_node, tr_node, td_node;

	this.form_node	 										= joAddHTMLChildNode (this.gui_parent_node, "FORM");
		joAddEvent 											(this.form_node, "submit", function (event) { void(0); });
		joDOM.SetAttribute								(this.form_node, "name", this.id + "_form");
			container_node									= joAddHTMLChildNode (this.form_node, "DIV", "vmm_list", "vmm_device_model");
				title_node									= joAddHTMLChildNode (container_node, "DIV", "title", "info_projectname");
					joVMMApp.AddTitle 					(title_node, "project");
				
				this.gui_list_node						= joAddHTMLChildNode (container_node, "DIV", "content", this.id + "_list");

					model_node 								= joFIND ("device_model");
					this.gui_list_node.appendChild 	(model_node);
					model_node.style.visibility 		= "visible";
					model_node.style.display	 		= "";
					
				footer_node						= joAddHTMLChildNode (container_node, "DIV", "footer");
					this.AddButton (footer_node, "edit");
}

/* ********************************************************************************************************** */

function _joVMMDeviceClass_AddButton (parent_node, button_type)
{
	button_node						= joAddHTMLChildNode (parent_node, "BUTTON", "joGfxButton");
	button_node.name				= "button_" + button_type;
	button_node.title				= joGUI.GetLocaleText (button_type);
	button_node.onclick			= function() 
										{ 
											joVMMApp.GetGuiObject (this.getAttribute ("vmm_data_obj")).Action (this.getAttribute ("name").substr ("button_".length)); return false; 
										};
	joDOM.SetAttribute (button_node, "vmm_data_obj", this.id);
	
	joAddImageChildNode (button_node, 	"images/button_" + button_type + ".gif");
}

/* ********************************************************************************************************** */

function _joVMMDeviceClass_SetActiveEntity (entity, call_modeller)
{
	if (this.data)
		this.data.style.backgroundColor 	= "";
	
	this.data_id 									= entity.id.substr (this.id.length + 1);
	this.data 										= entity;
	this.data.style.backgroundColor 		= "#DBD8C5";
	
	if (call_modeller)
	{
		this.ModelActiveEntity();
		joVMMApp.GuiObjectAction ("model", this);
	}
}

/* ********************************************************************************************************** */

function _joVMMDeviceClass_Action (action_type)
{
	joVMMApp.GuiObjectAction (action_type, this); 
	return false;
}

/* ********************************************************************************************************** */

function _joVMMDeviceClass_OnEvent (event_type, event_data_type)
{
}

/* ********************************************************************************************************** */

function _joVMMDeviceClass_EditEntity (entity)
{
	var data_id 		= entity.id.substr (this.id.length + 1);
	var data_entity 	= joVMM.entities["device"].FindNodeByAttribute ("", "id", data_id);
	var data_type		= data_entity.GetAttribute ("type");

	switch (data_type)
	{
		case "object":
			joVMMApp.GuiOpenDialog ("device", "device_vertical_frame", data_id);
			break;
		case "material":
			joVMMApp.GuiOpenDialog ("device", "device_spacer", data_id);
			break;
	}
}

/* ********************************************************************************************************** */

function _joVMMDeviceClass_ModelActiveEntity()
{
	joVMMApp.OnChangeDataSelection ("device", this.data_id, true); 
}


