<![CDATA[ [Tip] Control TVs order when editing a document - My Forums]]> https://forums.modx.com/thread/?thread=19727 <![CDATA[Re: [Tip] Control TVs order when editing a document]]> https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109801 ]]> davidm Sep 22, 2006, 06:06 AM https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109801 <![CDATA[Re: [Tip] Control TVs order when editing a document]]> https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109800 Quote from: davidm at Sep 22, 2006, 10:16 AM

You’ll be able to enjoy this feature with 0.9.5 thanks to the DocManager module smiley
This isn’t in the DocManager module (yet!), Menu Index is but not TV sorting - it slipped off the radar. I will work on getting it added in tonight, hopefully should be ready for the 0.9.5 beta 3.

And, nice work heliotrope! smiley]]>
garryn Sep 22, 2006, 06:04 AM https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109800
<![CDATA[Re: [Tip] Control TVs order when editing a document]]> https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109799
thanks wink]]>
banzai Sep 22, 2006, 05:38 AM https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109799
<![CDATA[Re: [Tip] Control TVs order when editing a document]]> https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109798 ]]> davidm Sep 22, 2006, 05:16 AM https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109798 <![CDATA[Re: [Tip] Control TVs order when editing a document]]> https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109797
I’ll test this right now !!!

Edit : It seems to work fine !

This is exactly what I had in mind, thanks a ton Heliotrope for the time-saver grin
]]>
davidm Jun 26, 2006, 07:46 AM https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109797
<![CDATA[Re: [Tip] Control TVs order when editing a document]]> https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109796
here is a quick and dirty mod of Mark Kaplan script "Ajax Menu Index Editor".
It allows to sort tv associated to a specific template.

Code needs some clean up (some js functions are no more used) but seems to work.

You ’ll have to check that in manager  and FCK the sql statement "order by" to get TV is set to  rank asc.

To make it work, install "Ajax Menu Index Editor" to get "SLLists.class.php" in the right place.
Then create a new module "sortTVorder" for instance, copy and paste the code below.

Hope that helps

// +----------------------------------------------------------------------+

// | Ajax Menu Index Editor                                               |

// +----------------------------------------------------------------------+

// | Created January 2006                                                 |

// +----------------------------------------------------------------------+

// | ALL credits go to Mark Kaplan                                        |

// +----------------------------------------------------------------------+
// 
// qq modifs pour ordonner TV (heliotrope) a partir du script Ajax Menu Index Editor
// le code a besoin d'etre nettoye des fonctions js inutiles mais ...



$template= isset($_POST['template'])? $_POST['template']: 0;

$actionkey = isset($_POST['actionkey'])? $_POST['actionkey']: 0;

if(isset($_POST['sortableListsSubmitted'])) {$actionkey =1;}



$header = '

<html>

<head>

	<title>Module : ordonner les TV</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

	<link rel="stylesheet" type="text/css" href="media/style/MODx/style.css?" />

	

	<link rel="stylesheet" type="text/css" href="media/style/MODx/coolButtons2.css?" />

<style type="text/css">



input.button {

display: none;



}



ul.sortableList {

	padding-left: 20px;

	margin: 0px;

	width: 300px;

	font-family: Arial, sans-serif;

}

ul.sortableList li {

	font-weight: bold;

	cursor: move;

	color: white;

	padding: 2px 2px;

	margin: 2px 0px;

	border: 1px solid #000000;

	background-image: url(media/style/MODx/images/grid_hdr.gif);

	background-repeat: repeat-x;

}

#bttn .bttnheight {

	height: 25px !important;

	padding: 0px; 

	padding-top: 6px;

	float: left;

	vertical-align:		middle !important;



}

#bttn a{

	cursor: 			default !important;

	font: 				icon !important;

	color:				black !important;

	border:				0px !important;

	padding:			5px 5px 7px 5px!important;

	white-space:		nowrap !important;

	vertical-align:		middle !important;

	background:	transparent !important;

}



#bttn a:hover {

	border:		1px solid darkgreen !important;

	padding:			4px 4px 6px 4px !important;		

	background-image:	url("media/style/MODx/images/button_dn.gif") !important;

	text-decoration: none;

}

#bttn a img {

	vertical-align: middle !important;

}

</style>



	<script type="text/javascript" language="JavaScript" src="media/script/modx.js"></script>

	<script type="text/javascript" language="JavaScript" src="media/script/cb2.js"></script>



	<script type="text/javascript" language="JavaScript">

	function reset()

	

	{

	document.resetform.submit();

	}

	

	';

if ($actionkey == 1){

$header .= '



	function save()

	{

	populateHiddenVars();

	if (document.getElementById("updated")) {new Effect.Fade(\'updated\',{duration:0});}

	new Effect.Appear(\'updating\',{duration:0.5});

	setTimeout("document.sortableListForm.submit()",1000);

	}

	';

}else {

$header .= '



	function save()

	{

	document.newdocumentparent.submit();

	}

	



parent.menu.ca = "move";



function setMoveValue(pId, pName) {

	if (pId==0 || checkParentChildRelation(pId, pName)) {

		document.newdocumentparent.new_parent.value=pId;

		document.getElementById(\'parentName\').innerHTML = "Parent: <b>" + pId + "</b> (" + pName + ")";

	}

}



// check if the selected parent is a child of this document

function checkParentChildRelation(pId, pName) {

	var sp;

	var id = document.newdocumentparent.id.value;

	var tdoc = parent.menu.document;

	var pn = (tdoc.getElementById) ? tdoc.getElementById("node"+pId) : tdoc.all["node"+pId];

	if (!pn) return;

		while (pn.p>0) {

			pn = (tdoc.getElementById) ? tdoc.getElementById("node"+pn.p) : tdoc.all["node"+pn.p];

			if (pn.id.substr(4)==id) {

				alert("Illegal Parent");

				return;

			}

		}

	

	return true;

}





	';

}

$header .= '	

</script>

</head>

<body>

<form action="" method="post" name="resetform" style="display: none;">



<input name="actionkey" type="hidden" value="0" />



</form>



<div class="subTitle" id="bttn">

	<span class="right"><img src="media/images/_tx_.gif" width="1" height="5"><br />Gestion du rang d\'affichage TV</span>



';



if ($actionkey == 1){



$header .= '<div class="bttnheight"><a id="Button1" onclick="save();"><img src="media/images/icons/save.gif"> Save</a></div>

<div class="bttnheight"><a id="Button4" onclick="reset();"><img src="media/images/icons/sort.gif"> Sort Another</a></div>';



}else {



$header .= '<div class="bttnheight"><a id="Button1" onclick="save();"><img src="media/images/icons/save.gif"> Go</a></div>';



}

$header .= '

		

		

		<div class="bttnheight"><a id="Button5" onclick="document.location.href=\'index.php?a=106\';"><img src="media/images/icons/cancel.gif"> Cancel</a></div>



	<div class="stay">   

	</div>

</div>



<div class="sectionHeader"><img src="media/images/misc/dot.gif" alt="." /> ';

$middle = '</div><div class="sectionBody">';

$footer = ' 

	</div>

	</body>

	</html>

';

echo $header."Menu Index Editor".$middle;



switch ($actionkey) {

case 0:

   echo '

<form method="post" action="" name=\'newdocumentparent\'>

<span id="parentName" class="warning">Please select the template that you\'d like to sort TV.</span><br>

<input name="actionkey" type="hidden" value="1" />

<!-- <input type="hidden" name="new_parent" value="" class="inputBox"> -->

<br />';

 $sql = "select distinct  a.id,a.templatename,c.rank from modx_site_templates a, modx_site_tmplvar_templates b, modx_site_tmplvars c where a.id = b.templateid group by a.id order by a.id";
 //$sql = "select * from modx_site_content";
  if (!$rs= $modx->db->query($sql)) {
            echo "vide";
				return '';

			}

			while ($row= $modx->db->getRow($rs)) {

				$result[]= $row;

			}
//print_r($result);


$total = count($result);
echo "total:$total";
echo '<select name="template">';
foreach ($result as $item) {

echo '<option value="'.$item['id'].'">'.$item['templatename'].'</option>';



}   
echo"</select>";             
echo'
<input type=\'save\' value="save" style="display:none">

</form>
';

   echo $footer;

   break;

   

case 1:

	$basePath = $modx->config['base_path'];

	$siteURL = $modx->config['site_url'];

	$include = $basePath.'assets/modules/menuindex/SLLists.class.php';

	

require_once($include);

$sortableLists = new SLLists($siteURL.'manager/media/script/scriptaculous/');

$sortableLists->addList('categories','categoriesListOrder');

$sortableLists->debug = false;



echo "<span class=\"warning\" style=\"display:none;\" id=\"updating\">Updating...<br /><br /> </span>";

$sortableLists->printTopJS();

$tblContent= $modx->getFullTableName('site_tmplvars');

if(isset($_POST['sortableListsSubmitted'])) {

echo "<span class=\"warning\" id=\"updated\">Updated!<br /><br /> </span>";

	//$tbl = $modx->getFullTableName("site_content");

	$orderArray = $sortableLists->getOrderArray($_POST['categoriesListOrder'],'categories');

	foreach($orderArray as $item) {

		$sql = "UPDATE $tblContent set rank=".$item['order']." WHERE id=".$item['element'];
		echo $sql ."<br />";

		$modx->db->query($sql);

	}



}



			//$query= "SELECT * FROM modx_site_content WHERE parent = $id ORDER BY menuindex ASC";
            //
            $query = "select a.id, a.templatename, b.templateid, b.tmplvarid, c.name as tvname, c.id as tvid from modx_site_templates a, modx_site_tmplvar_templates b,  modx_site_tmplvars c ".
                     "where a.id=b.templateid and a.id=".$template." and c.id=b.tmplvarid order by c.rank asc";
		
//echo "template:".$_POST['template'];
			if (!$rs= $modx->db->query($query)) {

				return '';

			}

			while ($row= $modx->db->getRow($rs)) {

				$resource[]= $row;

			}



echo '<ul id="categories" class="sortableList">';



$cnt = count($resource);

if ($cnt < 1) {echo "Opèration terminé"; die;} else {



foreach ($resource as $item) {

echo '<li id="item_'.$item['tvid'].'">'.$item['tvname'].'</li>';



}

}

echo '</ul>';







$sortableLists->printForm('', 'POST', 'Submit', 'button');



echo '<br>';



$sortableLists->printBottomJS();



echo $footer;

break;

}



]]>
heliotrope Jun 26, 2006, 07:32 AM https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109796
<![CDATA[ [Tip] Control TVs order when editing a document]]> https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109795
How do you do that ? A quick look into manager/actions/dynamic/mutate_content.dynamic.action.php, and more particularly at line 977, will give you the answer : you have to edit the rank field in the modx_site_tmplvars table with phpMyAdmin.

You’ll notice it has a default value of "0".
Set ranks according to the order you want your TVs displayed (rank 0 is before rank 1, rank 1 is before rank 2 and so on) when editing a document containing TVs -> you’re set !

(For reference, here is the related support thread :
http://modxcms.com/forums/index.php/topic,5386.0.html
And also the Feature Request I filed in FlySpray :
http://modxcms.com/bugs/task/444 )

]]>
davidm Jun 26, 2006, 04:16 AM https://forums.modx.com/thread/19727/tip-control-tvs-order-when-editing-a-document#dis-post-109795