Refactoring Phenotype

Generic Selector

We once had a “generic selector” within Page components (used within the Midray project e.g. for selecting ringtones). I have removed it from the component class, since it was beta all the time. Here’s some code for inspiration, if it will be implemented properly one day: (It should be done completely different with AJAX nowaday, but just to remember)

function form_genericselector($name,$text_add,$text_reset,$text_select,$status,$js_add,$js_select,$js_reset,$html_hidden,$html_form,$html_start="",$html_select="",$html_reset="")
	{
		// Status 0 = leer
		// Status 1 = gefüllt
		// Derzeit nicht aus der Layoutklasse
  	?>
 
  	<?php if ($status==0){ ?>
  	<table width="408" border="0" cellpadding="0" cellspacing="0" >
    <tr>
    <td nowrap>
    <a class="bausteineLink" href="javascript:<?php echo $js_add ?>"><img src="img/b_plus_tr.gif" width="18" height="18" border="0" align="absmiddle"><?php echo $text_add ?></a>
    </td>
    </tr>
    </table>
    <?php } ?>
    <table id="<?php echo $this->formid ?><?php echo $name ?>select" width="408" border="0" cellpadding="0" cellspacing="0" <?php if($status==0){ ?>style="visibility: hidden;display:none"<?php } ?>>
    <tr>
    <td nowrap>
    <a class="bausteineLink" href="javascript:<?php echo $js_select ?>"><img src="img/b_edit_s.gif" width="18" height="18" border="0" align="absmiddle"><?php echo $text_select ?></a>
    </td>
    </tr>
    </table>
    <?php if ($status==1){ ?>
    <table id="<?php echo $this->formid ?><?php echo $name ?>reset" width="408" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td nowrap>
    <a href="javascript:<?php echo $js_reset ?>" class="bausteineLink"><img src="img/b_minus_tr.gif" width="18" height="18" border="0" align="absmiddle"><?php echo $text_reset ?></a>
    </td>
    </tr>
    </table>    
    <?php } ?>
    <table id="<?php echo $this->formid ?><?php echo $name ?>panel_form" <?php if($html_form==""){ ?>style="visibility: hidden;display:none"<?php } ?> width="408" border="0" cellpadding="0" cellspacing="0" class="tableBausteineBackground" >
    <tr >
    <td>
    <?php echo $html_form ?>
    </td>
    </tr>
    </table>    
    <table id="<?php echo $this->formid ?><?php echo $name ?>panel_start" <?php if($html_start==""){ ?>style="visibility: hidden;display:none"<?php } ?> width="408" border="0" cellpadding="0" cellspacing="0" class="tableBausteineBackground" >
    <tr >
    <td >
    <?php echo $html_start ?>
    </td>
    </tr>
    </table>
    <table id="<?php echo $this->formid ?><?php echo $name ?>panel_select" style="visibility: hidden;display:none" width="408" border="0" cellpadding="0" cellspacing="0" class="tableBausteineBackground" >
    <tr >
    <td>
    <?php echo $html_select ?>
    </td>
    </tr>
    </table>
    <table id="<?php echo $this->formid ?><?php echo $name ?>panel_reset" style="visibility: hidden;display:none" width="408" border="0" cellpadding="0" cellspacing="0" class="tableBausteineBackground" >
    <tr >
    <td>
    <?php echo $html_reset ?>
    </td>
    </tr>
    </table>    
    </br>
    <table style="visibility: hidden;display:none" width="408" border="0" cellpadding="0" cellspacing="0" class="tableBausteineBackground" >
    <tr >
    <td>
    <?php echo $html_hidden ?>
    </td>
    </tr>
    </table><br clear="all">
 
  	<?php
	}

form_document_upload for Page Components

removed when changing form_xy behaviour of components, must be reimplemented someday

	function form_documentupload($name,$med_id)
	{
		if ($this->myLayout==-1)
		{
			$this->myLayout = new PhenotypeAdminLayout();
		}
		$name = $this->formid . $name;
		echo $this->myLayout->workarea_form_document($name,$med_id);
	}
	function form_download($name,$med_id)
	{
		$this->form_document($name,$med_id);
	}

Drag & Drop within Page Component

I removed code for this rarely used feature during reimplementation of form_xy methods of page components. Currently no time to reimplement that.


	function form_ddpositioner($name,$val, $quantity, $methodname,$background=1)
	{
		?>
		<p>
		 <?php
		 $anzahl = $quantity;
		 $token = $this->formid.$name;
		 $kette = "";
		 for ($j = 1; $j <= $anzahl; $j ++)
		 {
		 	$kette .= ",".$j;
		 }
		 if (strpos($val,","))
		 {
		 	$_position = explode(",",$val);
		 }
		 else
		 {
		 	$_position = Array();
		 }

		 if (count($_position)!=$anzahl) // Array an die neue Anzahl anpassen
		 {
		 	$_newposition = Array();
		 	foreach ($_position AS $k => $v)
		 	{
		 		if ($v<=$anzahl)
		 		{
		 			$_newposition[]=$v;
		 		}
		 	}
		 	for ($j = 1; $j <= $anzahl; $j ++)
		 	{
		 		if (!in_array($j,$_newposition))
		 		{
		 			$_newposition[] = $j;
		 		}
		 	}
		 	$_position = $_newposition;
		 }

			 ?>
			 
			 <input type="hidden" name="<?php echo $token ?>" value="<?php echo implode(",",$_position) ?>"/>
			 <input type="hidden" name="<?php echo $token ?>_posstart" value="<?php echo implode(",",$_position) ?>"/>
			 <?php
			 $this->displayDHtmlWZJavascript($token, $anzahl,16);

			 $mname = $methodname;
			 for ($j = 1; $j <= $anzahl; $j ++)
			 {
			 ?>
			 <div id="<?php echo $token.$j ?>" style="width:404px;position:relative;background:url(img/moveit.gif) top left no-repeat">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:<?php echo $token ?>movedown(<?php echo $j ?>)"><img src="img/b_down2.gif" width="18" height="18" border="0"></a>
        	 <a href="javascript:<?php echo $token ?>moveup(<?php echo $j ?>)"><img src="img/b_up2.gif" width="18" height="18" border="0"></a><br/>
        	 <?php if ($background==1)
        	 {
        	 ?>
        	 <div style="background-color:#D1D6DB;padding:2px;width:404px;"><p><?php echo $this->$mname($_position[$j-1]); ?></p></div></div><br/>
        	 <?php
        	 }else{
			 ?>
        	 <p><?php echo $this->$mname($_position[$j-1]); ?></p></div><br/>
        	 <?php
        	 }
        	 ?>
			 <script type="text/javascript">ADD_DHTML("<?php echo $token ?><?php echo $j ?>"+VERTICAL+TRANSPARENT);</script>
			 <?php
			 }
			 ?>
			 <script type="text/javascript">
			 <?php
			 for ($j = 1; $j <= $anzahl; $j ++)
			 {
			 	?>
			 	dd.elements.<?php echo $token ?><?php echo $j ?>.setDropFunc(<?php echo $token ?>dropTopListItem);
			 	<?php
			 }
			 ?>
			 </script>
			 </p>
			 <?php
	}


	function displayDHtmlWZJavascript($token, $anzahl,$spacer)
	{
		global $myLayout;

		if ($myLayout->dhtmlwz_init == 0)
		{
?>
			 <script type="text/javascript">
			 SET_DHTML(CURSOR_MOVE);
			 </script>
			 <?php


			 $myLayout->dhtmlwz_init = 1;
		}
?>
  	<script type="text/javascript">
  	function <?php echo $token ?>moveup(item)
  	{

  		order = <?php echo $token ?>determineOrder();
  		currentpos = item;
  		for (i=0;i<<?php echo $anzahl ?>;i++)
  		{
  			if(order[i]==item)
  			{
  				currentpos =i+1;
  			}
  		}
  		if (currentpos>1)
  		{
  			// Item an der übergeordneten Position bestimmen
  			changepos = currentpos-1;
  			changeitem = order[changepos-1];

  			citem ="<?php echo $token ?>" + item;
  			y = dd.elements[citem].y;
  			x = dd.elements[citem].x;

  			citem2 ="<?php echo $token ?>" + changeitem;
  			y2 = dd.elements[citem2].y;
  			x2 = dd.elements[citem2].x;

  			dd.elements[citem].moveTo(x2,y2);
  			dd.elements[citem2].moveTo(x,y);
  		}

  		<?php echo $token ?>dropTopListItem();
  	}

  	function <?php echo $token ?>movedown(item)
  	{
  		order = <?php echo $token ?>determineOrder();
  		currentpos = item;
  		for (i=0;i<<?php echo $anzahl ?>;i++)
  		{
  			if(order[i]==item)
  			{
  				currentpos =i+1;
  			}
  		}
  		if (currentpos<<?php echo $anzahl ?>)
  		{
  			// Item an der übergeordneten Position bestimmen
  			changepos = currentpos+1;
  			changeitem = order[changepos-1];

  			citem ="<?php echo $token ?>" + item;
  			y = dd.elements[citem].y;
  			x = dd.elements[citem].x;

  			citem2 ="<?php echo $token ?>" + changeitem;
  			y2 = dd.elements[citem2].y;
  			x2 = dd.elements[citem2].x;

  			dd.elements[citem].moveTo(x2,y2);
  			dd.elements[citem2].moveTo(x,y);
  		}
  		<?php echo $token ?>dropTopListItem();
  	}

  	function <?php echo $token ?>determineOrder()
  	{
  		order = new Array();

  		for (i=1;i<=<?php echo $anzahl ?>;i++)
  		{
  			citem ='<?php echo $token ?>' + i;
  			y = dd.elements[citem].y;
  			order[i-1]=y + "#" + i;

  		}

  		order.sort
  		(
  		function(a,b)
  		{
  			return (parseInt(a)-parseInt(b));
  		}
  		);

  		for (i=0;i<<?php echo $anzahl ?>;i++)
  		{
  			p = order[i].indexOf("#")
  			order[i]=order[i].substr(p+1);
  		}
  		return (order);
  	}

  	function <?php echo $token ?>storeOrder()
  	{
  		posstart = document.forms.editform.<?php echo $token ?>_posstart.value;
  		startorder = posstart.split(",");


  		order = <?php echo $token ?>determineOrder();

  		s="";
  		for (i=0;i<<?php echo $anzahl ?>;i++)
  		{
  			s = s+ "," + startorder[order[i]-1];
  		}

  		document.forms.editform.<?php echo $token ?>.value=s.substr(1);
  	}



  	function  <?php echo $token ?>dropTopListItem()
  	{

  		order = <?php echo $token ?>determineOrder();

  		citem ="<?php echo $token ?>1";
  		y = dd.elements[citem].defy;
  		for (i=1;i<=<?php echo $anzahl ?>;i++)
  		{
  			citem ="<?php echo $token ?>" + order[i-1];
  			x = dd.elements[citem].x;
  			h = dd.elements[citem].h;
  			dd.elements[citem].moveTo(x,y);
  			y=y+h+<?php echo $spacer ?>;
  		}
  		<?php echo $token ?>storeOrder();

  	}


  	//-->

    </script>
    <?php


	}

You think Phenotype Wiki/Documentation could be better?
We too. Please contribute: Edit this page

Bookmark and Share