<?php
/*
 *
 * @package		ARI Smart Content
 * @author		ARI Soft
 * @copyright	Copyright (c) 2011 www.ari-soft.com. All rights reserved
 * @license		GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
 * 
 */

(defined('_JEXEC') && defined('ARI_FRAMEWORK_LOADED')) or die;
?>

<div class="asc-modules-filter">
<?php echo $this->filterForm->render('filter'); ?>
</div>

<?php $this->dtModules->render(); ?>

<div><?php echo JText::_('COM_ARISMARTCONTENT_LABEL_MODULENOTE'); ?></div>

<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function() {
	var page = YAHOO.ARISoft.page,
		pageManager = page.pageManager,
		Dom = YAHOO.util.Dom,
		DTM = YAHOO.ARISoft.widgets.DataTableManager,
		dt = DTM.getTable('<?php echo $this->dtModules->id; ?>'),
		ds = dt.getDataSource(),
		oldHandler = ds.sendRequest;

	ds.sendRequest = function(oRequest, oCallback, oCaller) {
		var ctrlModuleType = Dom.get('filterModuleType');
		
		oRequest += '&moduleType=' + encodeURIComponent(ctrlModuleType.value);

		dt.showTableMessage(dt.get("MSG_LOADING"), dt.CLASS_LOADING);

		oldHandler.call(this, oRequest, oCallback, oCaller);
	};

	pageManager.registerAction('changeFilters', {
		onAction: function() {
			DTM.refresh("<?php echo $this->dtModules->id; ?>");
		}
	});

	pageManager.modulesManager = {
		moduleSelectedEvent: new YAHOO.util.CustomEvent('moduleSelected'),

		moduleSelected: function(id, name) {
			this.moduleSelectedEvent.fire({'Id': id, 'Name': name});
		},

		changeFilters: function() {
			pageManager.triggerAction("changeFilters");
		}
	};

	<?php
		if ($this->callback): 
	?>
	var context = (window.top != window.self) ? window.top : window.self;
	if (context["<?php echo $this->callback; ?>"])
		context["<?php echo $this->callback; ?>"](window.self);
	<?php
		endif; 
	?>
});
</script>