File:  [mozdev] / banff / resources / content / Team.js
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Wed Feb 19 17:53:46 2003 UTC (15 years, 9 months ago) by mikep
Branches: MAIN
CVS tags: HEAD
Moving files.

include('chrome://hacktrack/content/jslib/io/io.js');
include('chrome://hacktrack/content/jslib/rdf/rdf.js');
include('chrome://hacktrack/content/jslib/rdf/rdfFile.js');

function Team()
{
	this.Id;
	this.Name;
	this.City;
	this.Province;
	this.Country;
	this.MyTeam; //true or false, do I play on this team?
	this.Players = new Array(); //an array of player objects.
}

function TeamDataSource( )
{
	this.observerList = new Array();
	
	var banffDir = new Dir((new DirUtils()).getPrefsDir());
  	banffDir.append("hacktrack");

  	if(!banffDir.exists()) {
   	banffDir.create(0755);
	}
   var rdffile = new File((new DirUtils()).getPrefsDir());
  	
   rdffile.append("hacktrack");
  	
  	rdffile.append("teams.rdf");
 	 
 	this.RDFDataSource = new RDFFile(rdffile.path, null);
   this.RDFDataSource = new RDFFile(rdffile.path);
   
   /* make sure we have a root node, if not we probably have an empty file */
   if( this.RDFDataSource.getRootContainers().length == 0 )
   {
      this.rootContainer = this.RDFDataSource.addRootSeq( "urn:teamcontainer" );
   }
   else
   {
      this.rootContainer = this.RDFDataSource.getRootContainers("seq")[0];
   }
   
   this.RDFDataSource.flush();
}

TeamDataSource.prototype.getDataSource = function()
{
	return( this.RDFDataSource.getDatasource() );
}

TeamDataSource.prototype.openTeamDialog = function( Team )
{
	var args = new Object();
	
	if( !Team )
	{
		args.Team = this.getNewTeam();
		
		args.mode = "add";
		
		var me = this;

		var callback = function( NewTeam ) { me.addTeam( NewTeam ); };
		
		args.onOK = callback;
	}
	else
	{
		args.Team = Team;
		
		args.mode = "edit";
		
		var me = this;
		
		var callback = function( NewTeam, OldTeam ) { me.modifyTeam( NewTeam, OldTeam ); };
		
		args.onOK = callback;
	}
		
	window.openDialog("chrome://hacktrack/content/teamDialog.xul","teamdialog","chrome", args);
}

TeamDataSource.prototype.getNewTeam = function()
{
	return( new Team() );
}

TeamDataSource.prototype.addTeam = function( NewTeam )
{
	var seq = this.rootContainer;
	
	var node = seq.addNode( "team"+new Date().getTime() );
		
	for( i in NewTeam )
	{
		node.setAttribute( "http://home.netscape.com/NC-rdf#"+i, NewTeam[i] );
	}
	this.RDFDataSource.flush();
}

TeamDataSource.prototype.modifyTeam = function( TeamToChange )
{
   for ( i in this.AllTeams ) 
   {
      if ( this.AllTeams[i].Id == TeamToChange.Id )
      {
         this.AllTeams[i] = TeamToChange;

         break;
      }
   }
   
   this.saveAllTeams();   

   this.respondModifyTeam( TeamToChange );
}

TeamDataSource.prototype.respondModifyTeam = function ( ModifiedTeam )
{

}

TeamDataSource.prototype.deleteTeam = function( Team )
{
   //through fileUtils, delete the category from the XML file.

   for ( i in this.AllTeams ) 
   {
      if ( this.AllTeams[i].Id == Team.Id ) 
      {
         this.AllTeams.splice( i, 1 );
         break;
      }
   }
   this.saveAllTeams();   

   this.respondDeleteTeam( Team );
}

TeamDataSource.prototype.respondDeleteTeam = function ( DeletedTeam )
{

}

TeamDataSource.prototype.addObserver = function( observer )
{
   if( observer )
   {
      // remove it first, that way no observer gets added twice
      
      this.removeObserver(  observer );
      
      // add it to the end.
      
      this.observerList[ this.observerList.length ] = observer;
      
      // if we have already loaded, call the observer's on load
      
      if( this.loaded  )
      {
         if( observer.onLoad )
         {
            observer.onLoad()
         }
      }
   }
}

TeamDataSource.prototype.removeObserver = function( observer )
{
   for( var index = 0; index < this.observerList.length; ++index )
   {
      if( observer === this.observerList[ index ] )
      {
         this.observerList.splice( index, 1 );
         
         return true;
      }
   }
   
   return false;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>