/**
 * This source code is part of the Midnatt Content Management Framework.
 *
 * Copyright (c) Midnatt.org | http://www.midnatt.org | mail@midnatt.org
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Constructor.
 */
Ping_Controller = function() {
	var self = this;

}

/**
 * Loads a form template into a given element.
 * 
 * @param string name Name of the form.
 * @param string id Id of the target element.
 * @param function cb Optional callback function, called after the target 
 * 	element was filled with the form html.
 */
Ping_Controller.prototype.loadForm = function(name, id, callback) {
	var self = this;

	//$.post('/ajax//form/'+name, function(data) { // TODO IE?
	$.get('/ajax/form/'+name, function(data) {
		$('#'+id).html(data);
		//window.ping.app.loadLibraries();
		if ($.isFunction(callback)) callback();
	});
}

/**
 * Binds the form with the given id to an ajax call.
 * Uses jquery.form from http://malsup.com/jquery/form/
 * 
 * @param string id If of the form to bind.
 * @param function cb Optional callback function, called on ajaxForm success.
 */
Ping_Controller.prototype.bindForm = function(id, cb) {
	var self = this;

	$('#'+id).ajaxForm({
		beforeSubmit: function(arr, $form, options) {
			window.ping.app.setBusy(true);
		},
		success: function(responseText, statusText, xhr, $form) {
			if ($.isFunction(cb)) cb(responseText);
			window.ping.app.setBusy(false);
		}
	});
}


