/** 
 * This class is the base of all client-side actions
 * It provides a base behavior of a WAWAction
 * - Execution takes parameters which will be sended on the server-side
 * - A pre and post action may be declared (for bling-bling by example)
 * - A successfull execution is handled by default by the WAWController class
 */
var WAWAction = Class.create({
	
	params: new Hash(),
	
	/**
	 * Constructs a new WAWAction with a qPath
	 */
	initialize: function(qPath) {
		this.qPath = qPath;
	},
	
	/** 
	 * Executes the action with the parameters 
	 */
	execute: function(params) {
		this.params = new Hash(params);
		this.params = this.params.merge({'isAjaxRequest': 'true'});
		return new Ajax.Request(this.qPath, {
			method: 'post',
			parameters: this.params,
			onSuccess: function(response) {
				this.onPreSuccess(response);
			}.bind(this),
			onFailure: WAWController.error
		});
	},
	
	onSuccess: function(response) {
		WAWController.update(response);
		this.onPostSuccess();
	},
	
	onPostSuccess: function() {
	},
	
	onPreSuccess: function(response) {
		this.onSuccess(response);
	}
});

