Monday, September 24, 2007

Displaying Subpages as TABs

I've found that a lot of companies have issues when they have too many tabs and subtabs in the same page, one of my usual recommendations is to change the structure to sub pages (folders), this way they can use some additional features like WEBDAV and the security and administration becomes a bit simpler.

However, some people still want to have the tabs functionality even if the structure behind it is different, here is a simple example of how to display a tab-like menu of sub-pages.

The script doesn't work well on a portlet so it's better to just add it as a PLSQL item to the template of the pages, it will pick up which page the user is viewing and display the tabs accordingly.

create or replace
create or replace
Procedure JBMENU (p_parent_id in varchar2)
IS
v_page varchar2(200);
v_page_id varchar2(200);
lv_temp number;
lv_sub number:=0;
temp2 number:=1;
lv_select boolean;
lv_align varchar2(50):='right';
begin
v_page := portal.wwpro_api_parameters.get_value( '_pageid','a');
v_page_id:=substr(v_page,(instr(v_page, ',')+1));


lv_temp:=p_parent_id;
htp.p('<table width="100%" cellpading="0" cellspacing="0" border="0" align="'||lv_align||'">');

while true loop


select count(*) into lv_sub from portal.wwv_user_corners where parentid=lv_temp;

if lv_sub >0 then
htp.p('<tr><td><table cellpading="0" cellspacing="0" align="'||lv_align||'"><tr align="'||lv_align||'">');
temp2:=0;
for lv_rec in (select * from portal.wwv_user_corners where parentid=lv_temp) loop

lv_select:=false;
for lv_page in (select id, parentid from portal.wwv_user_corners where id >= p_parent_id START WITH id=v_page_id CONNECT BY PRIOR parentid =id) loop
if lv_page.id = lv_rec.id then
lv_select:=true;
end if;
end loop;

if lv_select then
htp.p('<td><table border="0" width="100%" cellpadding="0" cellspacing="0"><tr>
<td class="LeftTabForeSlantid32529siteid0" valign="top" align="left" width="10" height="19" nowrap=""> </td>
<td valign="middle" class="TabForegroundColorid32529siteid0"> <span class="TabForegroundTextid32529siteid0">
<a href="/portal/page?_pageid='||lv_rec.siteid||','||lv_rec.id||'&_dad=portal&_schema=PORTAL">'||lv_rec.title||'</a>
</span> </td><td align="right" class="RightTabForeCurveid32529siteid0" width="8" nowrap=""> </td></tr></table></td>');
lv_temp:=lv_rec.id;
temp2:=1;
else
htp.p('<td><table border="0" width="100%" cellpadding="0" cellspacing="0"><tr>
<td class="LeftTabBgSlantid32529siteid0" valign="top" align="left" width="10" height="19" nowrap=""> </td>
<td valign="middle" class="TabBackgroundColorid32529siteid0">
<a href="/portal/page?_pageid='||lv_rec.siteid||','||lv_rec.id||'&_dad=portal&_schema=PORTAL">'||lv_rec.title||'</a>
</td><td align="right" class="RightTabBgCurveid32529siteid0" width="8" nowrap=""> </td></tr></table></td>');
end if;
end loop;

htp.p('</tr></table></td></tr>');
if temp2 = 0 then lv_temp:=0; exit; end if;
else
exit;
end if;
end loop;
htp.p('</table>');
end;
/</div>

To call it, just add the following code in a PLSQL item, passign the ID of the TOP page in the structure:
<div class="graydiv">
begin
jbmenu('3888216');
end;/


To call it, just add the following code in a PLSQL item, passign the ID of the TOP page in the structure:

begin
jbmenu('3888216');
end;

1 comment:

Anonymous said...
This comment has been removed by a blog administrator.