﻿/**
*	@class GeneralControl
*
*	Houses all general control methods used by the application
*
*	@author			Daniel Ivanovic dan@anti-blanks.co.uk
*
*	@param c		Model instance
*/
var GeneralControl = AbstractControl.extend(
	{
		/**
		*   init
		*
		*   Class constructor for the control instance
		*
		*	@param	c - model instance
		*/
		init: function(c)
		{
			this._super( "GeneralControl", c );
			this.delay = null;
		},
		
		/**
		*   changePage
		*
		*   Changes the page to a passed URL
		*
		*	@param	url - target url
		*/
		changePage: function(url)
		{
			window.location = url;
		},
		
		/**
		*   changePageOnDelay
		*
		*   Changes the page to a passed URL after a passed delay
		*
		*	@param	url - target url
		*	@param	d - delay ( in seconds )
		*/
		changePageOnDelay: function(url, d)
		{
			//alert( "delayed page change : " + url );
			
			if ( this.delay != null )
				clearTimeout( this.delay );
				
			this.delay = setTimeout( 'app.generalControl.changePage( "' + url + '" );', d*1000 );
		},
		
		/**
		*   showMessage / hideMessage
		*
		*   Shows a new message to the user
		*
		*	@param	m - message data object
		*/
		/*showMessage: function(m)
		{
			this.getCore().broadcast( 'onMessageShow', m );
		},
		
		hideMessage: function(m)
		{
			this.getCore().broadcast( 'onMessageHide', m );
		},*/
		
		/**
		*   showDialogueMessage / hideDialogueMessage
		*
		*   Shows a new dialogue message to the user
		*
		*	@param	m - message data object
		*/
		/*showDialogueMessage: function(m)
		{
			this.getCore().broadcast( 'onDialogueMessageShow', m );
		},
		
		hideDialogueMessage: function(m)
		{
			this.getCore().broadcast( 'onDialogueMessageHide', m );
		},*/
		
		/**
		*   openDialogue / closeDialogue
		*
		*   Broadcasts event - Opens / Closes a passed dialogue
		*
		*	@param	id - dialogue id
		*	@param	s - solo boolean
		*	@param	c - content data
		*/
		openDialogue: function(id, s, c)
		{
			//alert( "opening dialogue " + id + " : " + s + " : " + c );
			
			/*var toOpen = new DialogueData();
				toOpen.setDialogId( id );
				toOpen.setSolo( s );
				toOpen.setContentData( c );
				
			this.getCore().broadcast( 'onDialogueOpened', toOpen );*/
		},
		
		closeDialogue: function(id)
		{
			//alert( "closing dialogue " + id );
			
			/*var toClose = new DialogueData();
				toClose.setDialogId( id );
				
			this.getCore().broadcast( 'onDialogueClosed', toClose );*/
		}
	}
);

/**
*	@class ActivationsControl
*
*	Houses all activation control methods used by the application
*
*	@author			Daniel Ivanovic dan@anti-blanks.co.uk
*
*	@param c		Model instance
*/
var ActivationsControl = AbstractControl.extend(
	{
		/**
		*   init
		*
		*   Class constructor for the control instance
		*
		*	@param	c - model instance
		*/
		init: function(c)
		{
			this._super( "ActivationsControl", c );
		},
		
		/**
		*   addActivationCodes
		*
		*   Adds a series of activation codes to the database
		*
		*	@param	s - scope (of caller)
		*	@param	v - vendor id
		*	@param	p - plugin id
		*	@param	c - activation codes array
		*/
		addActivationCodes: function(s, v, p, c)
		{
			this.getCore().makeAjaxRequest(
				s, "ajax_activations.php", "add_activation_codes", {
					vendorId: v,
					pluginId: p,
					activationCodes: c
				},
				ActivationsEvent_ADD_CODES_SUCCESS,
				ActivationsEvent_ADD_CODES_FAILED
			);
			// return false
			return false;
		}
	}
);

/**
*	@class VendorsControl
*
*	Houses all vendor control methods used by the application
*
*	@author			Daniel Ivanovic dan@anti-blanks.co.uk
*
*	@param c		Model instance
*/
var VendorsControl = AbstractControl.extend(
	{
		/**
		*   init
		*
		*   Class constructor for the control instance
		*
		*	@param	c - model instance
		*/
		init: function(c)
		{
			this._super( "VendorsControl", c );
		},
		
		/**
		*   addVendor
		*
		*   Adds a new vendor record to the database
		*
		*	@param	s - scope (of caller)
		*	@param	v - vendor name
		*/
		addVendor: function(s, v)
		{
			//this.debug( "adding vendor " + v );
			
			this.getCore().makeAjaxRequest(
				s, "ajax_vendors.php", "add_vendor", {
					vendorName: v
				},
				VendorsEvent_ADD_VENDOR_SUCCESS,
				VendorsEvent_ADD_VENDOR_FAILED
			);
			// return false
			return false;
		}
	}
);
