Tuesday, January 24, 2012

How to hide Add Repository browser tree node in Webtop

Probably many developers faced the problem: how to hide the 'Add repository' node from the browser tree? No, there's no OOTB configuration for this.
The WDK development Guide says you have to make your custom component, with your class, jsp and even a tld. That's cumbersome!
There's a trick that will hide that node faster: just copy the browsertree.jsp into your custom layer, add a browsertree_component.xml definition (perhaps you already have it) extending it from the webtop layer and set your custom browsertree.jsp page. Now open your custom browsertree.jsp file and add at the end of it, inside the last javascript tag, the following JS code:

var addRepository = findMatchingElements('selectrepository','div');
addRepository.style.visibility='hidden';

function findMatchingElements(toMatch, tagname) {
var reMatch = new RegExp( toMatch, "i" ); // match and ignore case
if ( tagname == null ) tagname = "*"; // if not tagname passed, search all
var elems = document.getElementsByTagName(tagname);
for ( var e = 0; e < elems.length; ++e ) {
if (elems[e].id.match(reMatch))
return elems[e];
}
}

That's all! Deploy and see it ... hidden.