APEX上自制菜單

雖然APEX的THEME提供了很好的菜單功能,有時候還是需要自制菜單。

這裏提供一個自制菜單的PL/SQL Procedure及使用實例。

 

比如,要做出這樣的兩級菜單:

 

顯示菜單的兩個Region:

Display Point: Page Template Body (1)
  Tabs PL/SQL  

Display Point: Page Template Body (3)
  REVENUE/COST計算書 PL/SQL  

 

第二個Region使用的PL/SQL代碼(例):

begin
 SUP_TABS_HTML(title=>'#年度#第1年#第2年#第3年#第4年#第5年',
          selected_no=>2,
          ws_image=>'#WORKSPACE_IMAGES#',
          slct_gif=>'bg-select1.gif',
          unslct_gif=>'bg-unselect1.gif',
          href=>'javascript:void(0);#f?p=104:91:::NO::P7_NENDO:1#f?p=104:91:::NO::P7_NENDO:2#f?p=104:91:::NO::P7_NENDO:3#f?p=104:91:::NO::P7_NENDO:4#f?p=104:91:::NO::P7_NENDO:5');

end;

 

注意事項:這裏選擇的是“第1年”,如果選擇的是“第2年”(當然是另一頁了),上例中要改爲 selected_no=>3.

 

PL/SQL Procedure

 

create or replace procedure "SUP_TABS_HTML"
(title IN VARCHAR2 ,
href IN VARCHAR2,
selected_no IN NUMBER default 1,
separator IN CHAR default '#',
ws_image IN VARCHAR2,
slct_gif IN VARCHAR2 default 'bg-select.gif',
unslct_gif IN VARCHAR2 default 'bg-unselect.gif'
)
is

--- Internal variables, constant
width number := 1200;
head varchar2(500) :=
'<table border=0 cellspacing=0 cellpadding=1>
    <tr bgcolor="#FFFFFF">
     <td style="border-left:.5pt solid;width:20px;height:25px;
                background:url(#WORKSPACE_IMAGES##UNSLCT_GIF#);"></td>';

selected varchar2(500) :=
'     <td style="border-left:.5pt solid;width:100px;
                background:url(#WORKSPACE_IMAGES##SLCT_GIF#);
                color: SteelBlue;text-align:center;
                vertical-align:bottom">#TITLE#</td>';

unselected varchar2(500) :=
'     <td style="border-left:.5pt solid;width:100px;
                background:url(#WORKSPACE_IMAGES##UNSLCT_GIF#);
                text-align:center;">
                <a href="#HREF#" style="color:white;">#TITLE#</a></td>';

foot  varchar2(500) :=
'     <td style="border-left:.5pt solid;width:#WIDTH#px;
                background:url(#WORKSPACE_IMAGES##UNSLCT_GIF#);"> 
                </td>
    </tr>
</table>';

--- Internal variables
i number;
title_now varchar2(500);
href_now varchar2(500);
--ws_image varchar2(200);

begin

--select '#WORKSPACE_IMAGES#' into ws_image from dual;
--htp.p('**************'||ws_image);
head       := replace(head,'#WORKSPACE_IMAGES#', ws_image);
selected   := replace(selected,'#WORKSPACE_IMAGES#', ws_image);
unselected := replace(unselected,'#WORKSPACE_IMAGES#', ws_image);
foot       := replace(foot,'#WORKSPACE_IMAGES#', ws_image);

head       := replace(head,'#UNSLCT_GIF#', unslct_gif);
selected   := replace(selected,'#UNSLCT_GIF#', unslct_gif);
unselected := replace(unselected,'#UNSLCT_GIF#', unslct_gif);
foot       := replace(foot,'#UNSLCT_GIF#', unslct_gif);

head       := replace(head,'#SLCT_GIF#', slct_gif);
selected   := replace(selected,'#SLCT_GIF#', slct_gif);
unselected := replace(unselected,'#SLCT_GIF#', slct_gif);
foot       := replace(foot,'#SLCT_GIF#', slct_gif);

htp.p(head);
i:=1;
loop

  title_now := regexp_substr(title, '[^'||separator||']+', 1, i);
  href_now := regexp_substr(href, '[^'||separator||']+', 1, i);
  if (title_now is null) or (href is null) then
     exit;
  end if;

/******* debug **
htp.p(i);
htp.p(title_now);
htp.p(href_now);
************/

href_now := APEX_UTIL.PREPARE_URL(href_now);
if (i = selected_no) then
  htp.p(replace(selected,'#TITLE#',title_now));
else
 htp.p(replace(replace(unselected,'#TITLE#',title_now),'#HREF#',href_now));
end if;

  i := i+1;
end loop;
 
 htp.p(replace(foot,'#WIDTH#',width-(i*120)));
 htp.p('<br>');
end;

 

 

注意:

title變量是菜單的文字串,用#分割(可給separator指定不同字符,默認爲#)。

href變量是URL的文字串,默認用#分割。

 

用到的GIF文件(要上傳到APEX的Workspace)

 

想照樣使用的可下載

    

 

   

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章