/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/

#ifndef SXPAGEFAQSCATEGORY_H
#define SXPAGEFAQSCATEGORY_H

#include <sxpage.h>


/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/


class ddwebdossiermap;

/// sxpagefaqdossier : Hilfsklasse, die ein Dossier abbildet.
/**
	Kiss: eine direktabbildung der DB Inhalte der Dossier-Tabelle
*/

struct ddwebdossier : public ddbaseobject
{

	ddstring 		id;
	ddstring 		subject;
	
	ddstringrow	entries;
	ddstringrow	subjects;
	
	ddwebdossier( const ddstring& aid, const ddstring& asubject, const ddstring& akeys )
	: id( aid ), subject( asubject )
	{
		entries.create( akeys, "," );	
		// auf gleiche größe bringen
		subjects.resize( entries.size() );
			
	}
	
	ddstring render_dossier_box( const ddstring& id, dditem& item );
	void		 render_dossier_editor( const ddstring& id, dditem& item );
	
	inline ddstring to_string() const
	{
		return "-- ID: " + id; // + " Subject: " +  subject + " Entries: " + keys;
	}
	
	void add_at_key( const ddstring& id, const ddstring& subject );
	
	void action_at_key( const ddstring& id, const ddstring& subject, const ddstring& actionstr );
	
	inline ddstring get_entries() const
	{
		return entries.join( "," );
	}
		
	inline bool is_modified()
	{
		return _changed;
	}
	
	inline void dump() const
	{
		cout << to_string() << endl; //" Title: " << title << endl;
	}
	
protected: 

	void swap_elements( size_t oldidx, size_t newidx );
	
	bool _changed;
	
};


/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/


/// ddwebdossiermap: Hilfsklasse, die Dossiers speichert.
/**
	ddwebdossiermap: Hilfsklasse, die Dossiers speichert.
	
	Erstmal muss ermittelt werden, ob ein Tipp überhaupt Teil eines Dossiers,
	daher wird eine Abbildung von Tipp-ID auf Dossiers benötigt.
	
	Die IDs der in Dossiers befindlichen Faqs zeigen auf die (interne) ID
	des Dossiers.
	
*/

class ddwebdossiermap : public ddstringmap
{

friend class ddwebdossier;

public:

	void init_dossier_data( const ddwebview& table, ddwebview& dossiertable );
	
	ddwebdossier& get_entry( const ddstring& key )
	{
		return _dossiers.get_entry( (*this)[key] );
	}
	
	void render_dossier_box( const ddstring& id, dditem& item, ddstring& result )
	{
		if( contains_key( id ) )
			result = get_entry( id ).render_dossier_box( id, item );
	}
	
	inline void render_dossier_editor( const ddstring& id, dditem& item )
	{
		if( _dossiers.contains_key( id ) )
			get_dossier( id ).render_dossier_editor( id, item );
	}
	
	void get_neighbors( const ddstring& id, ddstring& lst, ddstring& nxt );
	
	ddwebdossier& get_dossier( const ddstring& id  )
	{
		return _dossiers.get_entry( id );
	}
	
	void dump() const
	{		
		
		ddwebdossiermap::const_iterator pos = begin();
		for( ; pos != end(); ++pos )
			cout << (*pos).first << ": " << (*pos).second << endl;
			
	}
	
	
protected:

	ddmapptr<ddwebdossier> _dossiers;
	
};


#endif
