Example of sitetree randomlinks filter - button with filter text field (can be usefull for huge number of items in tree).
RandomLinksAdmin_left.ss:
<div id="treepanes" style="overflow-y: auto;">
<ul id="TreeActions">
<li class="action" ><button id="filterlink">Filtruj</button>
<form class="actionparams" id="filterlink_options" style="display: block" action="admin/randomlinks/filterlink">
<input type="text" name="filter"/>
</form>
</li>
<li class="action" id="addlink"><button><% _t('CREATENL','Create New Link xXx') %></button></li>
<li class="action" id="deletelink"><button><% _t('DEL','Delete Link xXx') %></button></li>
</ul>
...
RandomLinksAdmin_left.js:
_HANDLER_FORMS['filterlink'] = 'filterlink_options';
filterlink = {
button_onclick : function() {
filterlink.form_submit();
return false;
},
form_submit : function() {
Ajax.SubmitForm('filterlink_options', null, {
onSuccess : function(response) {
$('sitetree').innerHTML = response.responseText;
$$('#sitetree li').each(function(n) {
$('sitetree').SiteSubTree.castAsTreeNode(n);
});
},
onFailure : function(response) {
errorMessage('Error filtering', response);
}
});
return false;
}
};
Behaviour.addLoader(function () {
Observable.applyTo($('filterlink_options'));
$('filterlink').onclick = filterlink.button_onclick;
$('filterlink').getElementsByTagName('button')[0].onclick = function() {return false;};
...
RandomLinksAdmin.php
public function filterlink() {
$filter = 'ALL';
if (isset($_POST['filter']) && $_POST['filter'] != '')
$filter = $_POST['filter'];
$siteTree = $this->SiteTreeAsUL($filter);
return $siteTree;
}
public function SiteTreeAsUL($filter = null) {
$siteTree = "";
if ($filter && $filter != 'ALL')
$randomlinks = DataObject::get("RandomLinks", "LinkTitle LIKE '%".$filter."%'");
else
$randomlinks = DataObject::get("RandomLinks");
if ($randomlinks) {
foreach($randomlinks as $ID => $data) {
$siteTree .= "<li id=\"record-" . $data->ID . "\" class=\"" . $data->class . " " .
($data->Locked ? " nodelete" : "") . "\" >" .
"<a href=\"" . Director::link("randomlinks", "show", $data->ID) . "\" >" . $data->LinkTitle . "</a>";
}
}
if ($filter)
$siteTree =
"<li id=\"record-0\" class=\"Root nodelete\">" .
"<a href=\"admin/randomlinks/show/0\" ><strong>"._t('RandomLinksAdmin.CURLINKS',"Current Links xXx")."</strong></a>"
. $siteTree .
"</li>";
else
$siteTree = "<ul id=\"sitetree\" class=\"tree unformatted\">" .
"<li id=\"record-0\" class=\"Root nodelete\">" .
"<a href=\"admin/randomlinks/show/0\" ><strong>"._t('RandomLinksAdmin.CURLINKS',"Current Links xXx")."</strong></a>"
. $siteTree .
"</li>" .
"</ul>";
return $siteTree;
}