<?php

	/**
	 * Template für die Liste der gewählten Zubehörprodukte (Backend)
	 */

?>
<br />
<?php if (sizeof($this->view['wpsg_mod_relatedproducts']['data']) <= 0) { ?>
<p><?php echo __('Noch keine Produkte zugeordnet', 'wpsg'); ?></p>
<?php } else { ?>
<?php foreach ($this->view['wpsg_mod_relatedproducts']['data'] as $p) { ?>
	<span id="wpsg_rp_<?php echo $p['id']; ?>">
		<?php if (!wpsg_isSizedString($this->get_option('wpsg_mod_relatedproducts_template')) || $this->get_option('wpsg_mod_relatedproducts_template') == '0') { ?>
		<?php echo wpsg_drawForm_Select('wpsg_mod_relatedproduct['.$p['id'].']', $p['name'], $this->view['wpsg_mod_relatedproducts']['arTemplates'], $p['template'], array('remove' => __('Zuordnung löschen', 'wpsg'), 'labellink' => WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Produkt&action=edit&edit_id='.$p['id'])); ?>
		<?php } else { ?>
		<a class="wpsg_icon wpsg_icon_right wpsg_icon_remove" href="#" title="<?php echo __('Zuordnung löschen', 'wpsg'); ?>"></a>
		<span style="line-height:25px;">
			<a href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=edit&edit_id=<?php echo $p['id']; ?>">
				<?php echo wpsg_hspc($p['name']); ?>
			</a>
		</span>		
		<?php } ?>
	</span>
	<div class="wpsg_clear"></div>
<?php } ?>
<?php } ?>

<script type="text/javascript">

	jQuery('#relatedproducts_list a.wpsg_icon_remove').bind('click', function() {

		var rel_id = jQuery(this).parents('span').attr('id').replace(/wpsg_rp_/, '');

		jQuery('#relatedproducts_list').html('<img src="<?php echo WPSG_URL; ?>views/gfx/ajax-loader.gif" alt="<?php echo __('Bitte warten ...', 'wpsg'); ?>" />');
		
		jQuery.ajax( {
			url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_relatedproducts&cmd=wpsg_rp_remove&noheader=1&edit_id=<?php echo $this->view['wpsg_mod_relatedproducts']['product_id']; ?>',
			data: {
				'rel_id': rel_id
			},
			success: function(data) {

				jQuery('#relatedproducts_list').html(data);
			}
		} );
		
		return false;
		
	} );

</script>