This discussion is archived
5 Replies Latest reply: Nov 26, 2012 5:18 AM by 974630 RSS

JS function to generate HTML list for standard tabs

Mahmoud_Rabie Journeyer
Currently Being Moderated
Dear Experts

Given:
Two-Tabs Theme

Required :
I need to do the following:
1) Write PL/SQL on-demand process generates HTML list for standard tabs under parent tab id passed.
2) Write JS function to call the above process when the parent tab clicked (inside the parent tab template)

What are the steps?

Best Regards
Mahmoud
  • 1. Re: JS function to generate HTML list for standard tabs
    974630 Newbie
    Currently Being Moderated
    Mahmoud
    Mahmoud_Rabie wrote:
    What are the steps?
    Read the documentation and search the forum on "ondemand process";

    For the pl/sql code to render the standerd tabs belonging to a parent tabs see [url http://www.apex-plugin.com/oracle-apex-plugins/region-plugin/tab-menu_203.html"] Tab menu 
    The basic functionality of the function render_tab_region is too render the standerd tabs of a parent tab with all the correct html.
    Exactly what your ondemand process needs.
    Of which the sql statements to link the standerd tabs to the parent tab is the most important one.

    For the javascript code this forum holds many examples.

    Set up a very basic application on apex.oracle.com, with some empty pages some parent and standerd tabs.
    And the pl/sql and javascript you have come up on your own.

    Then we can help you putting the puzzle pieces together or point you to more information.

    We are all voluntary helping others with there problems. Nobody is going to write the complete solution for you.

    Especially because this tread {thread:id=2465193} already gives you a complete solution to your original problem.
    And as already mentioned in that thread without something to work with on apex.oracle.com we can only guess what the actual missing link is.

    Nicolette
  • 2. Re: JS function to generate HTML list for standard tabs
    Mahmoud_Rabie Journeyer
    Currently Being Moderated
    Dear Nicolette

    Thank you for you help and interest.

    As you referred to the other thread, please note that we have 2 options.

    I would like to concentrate here on the Option 1 (Without Plugin)

    The other thread will be concerned with Option 2 (With Plugin)

    As I agree with you that we are sharing the knowledge here and trying to help each other. So, there are some friends either prefer option 1 or option 2

    Regarding  render_tab_region
    I have prepared on-demand PL/SQL anonymous block as following
    -- Application Process: DisplayStandardTabs
    -- On Demand...
    -- Purpose: Called by JS function in the page template to display drop-down menu for standard tabs under current parent tab
    DECLARE
      cursor c_pag(b_app_id  in number
                  ,b_page_id in number
                  )
      is
        select pag.tab_set
        from   apex_application_pages     pag
        where  pag.page_id = b_page_id
        and    pag.application_id = b_app_id
      ;
      
      cursor c_tem(b_app_id       in number
                  ,b_temp_name    in varchar2
                  ,b_theme_number in number
                  )
      is
        select tep.current_tab
        ,      tep.non_current_tab
        ,      tep.current_parent_tab
        ,      tep.noncurrent_parent_tab
        from   apex_application_temp_page tep
        where  tep.application_id = b_app_id
        and    tep.template_name  = b_temp_name
        and    tep.theme_number   = b_theme_number 
      ;
      
      cursor c_pat(b_app_id in number
                  ,b_tabset in varchar2
                  )
      is
        select pat.tab_set
        ,      pat.current_for_tabset
        ,      pat.tab_name
        ,      pat.tab_label
        ,      pat.authorization_scheme
        ,      pat.condition_type
        ,      pat.condition_expression1
        ,      pat.condition_expression2
        ,      pat.build_option
        ,      pat.tab_target
        ,      pat.when_current_image
        ,      pat.when_non_current_image
        from   apex_application_parent_tabs pat
        where      pat.application_id = b_app_id
        and   (pat.tab_set = b_tabset
               or
               b_tabset is null
               )
        order by pat.display_sequence
      ;
      
      cursor c_tab(b_app_id in number
                  ,b_tab_set in varchar2
                  )
      is
        select tab.tab_set
        ,      tab.tab_name
        ,      tab.tab_label
        ,      tab.condition_type
        ,      tab.condition_expression1
        ,      tab.condition_expression2
        ,      tab.authorization_scheme
        ,      tab.build_option
        ,      tab.parent_tabset
        ,      tab.tab_also_current_for_pages
        ,      tab.tab_page
        ,      tab.when_current_tab_image
        ,      tab.when_not_current_tab_image
        from      apex_application_tabs tab
        where      tab.application_id = b_app_id
        and    tab.tab_set        = b_tab_set
        order by tab.display_sequence
      ;
      
      type v_table_pat is table of c_pat%rowtype
      index by pls_integer;
      v_pat_table  v_table_pat;
      r_pat   c_pat%rowtype;
      
      type v_table_tab is table of c_tab%rowtype
      index by pls_integer;
      v_tab_table  v_table_tab;
      r_tab   c_tab%rowtype;
      
      l_current_tab_set                         apex_application_pages.tab_set%type;
      l_html_current_tab                    apex_application_temp_page.current_tab%type;
      l_html_non_current_tab          apex_application_temp_page.non_current_tab%type;
      l_html_current_p_tab               apex_application_temp_page.current_parent_tab%type;     
      l_html_non_current_p_tab     apex_application_temp_page.noncurrent_parent_tab%type;
    
    l_html_tab               varchar2(32767);
      l_html_parent          varchar2(32767);
      l_has_parent    boolean := false;
      l_has_tab       boolean := true;
      l_url           varchar2(2000);
      l_code          varchar2(4000);
      l_debug_char    varchar2(3);
      i               number;
    
    BEGIN
      /*Determine the current tab set*/
      open c_pag(wwv_flow.g_flow_id,wwv_flow.g_flow_step_id);
      fetch c_pag
      into  l_current_tab_set;
      close c_pag;
    
    /*Get the parent tabs*/
      open c_pat(wwv_flow.g_flow_id,l_tabset);
      fetch c_pat bulk collect
      into  v_pat_table;
      close c_pat;
      
      for k in v_pat_table.first .. v_pat_table.last
      loop
        r_pat := v_pat_table(k);
        /*Check if the parent tab should be displayed*/
        if auth_condition_check(r_pat.condition_type
                               ,r_pat.condition_expression1
                               ,r_pat.condition_expression2
                               ,r_pat.authorization_scheme
                               ,r_pat.build_option
                               )
        then
          apex_debug_message.log_message('parent tab: '||r_pat.tab_name);
          if not l_has_parent
          then
            /*It's the first parent tab*/
            sys.htp.p(l_before_html);
            l_has_parent := true;
          end if; 
          /*Check if the parent tab is current*/
          if r_pat.current_for_tabset = l_current_tab_set
          then
            l_html_parent := l_html_current_p_tab;
            l_html_parent := replace(l_html_parent,'#TAB_IMAGE#',r_pat.when_current_image);
          else
            l_html_parent := l_html_non_current_p_tab;
            l_html_parent := replace(l_html_parent,'#TAB_IMAGE#',r_pat.when_non_current_image);
          end if;
          l_url := apex_util.prepare_url(apex_application.do_substitutions(r_pat.tab_target));
          /*replace different tags*/
          l_html_parent := replace(l_html_parent,'#TAB_LABEL#',r_pat.tab_label);
          l_html_parent := replace(l_html_parent,'#TAB_NAME#',r_pat.tab_name);
     
          /*Standard tabs belonging to the parent tab*/
          l_html_tab := null;
          i:=0;
          open  c_tab(wwv_flow.g_flow_id,r_pat.current_for_tabset);
          fetch c_tab bulk collect
          into  v_tab_table;
          close c_tab;
          for h in v_tab_table.first .. v_tab_table.last
          loop 
            r_tab := v_tab_table(h);
            if auth_condition_check(r_tab.condition_type
                                   ,r_tab.condition_expression1
                                   ,r_tab.condition_expression2
                                   ,r_tab.authorization_scheme
                                   ,r_tab.build_option
                                   )
            then                                       
              apex_debug_message.log_message('tab: '||r_tab.tab_name);
              i := i + 1;
              /*Check if standard tab is current*/
              if r_tab.tab_page = wwv_flow.g_flow_step_id
                 or
                 instr(','||r_tab.tab_also_current_for_pages||',',','||wwv_flow.g_flow_step_id||',') > 0
              then
                /*Standard tab is current for this page*/
                l_html_tab := l_html_tab||l_html_current_tab;
                l_html_tab := replace(l_html_tab,'#TAB_IMAGE#',r_tab.when_current_tab_image);
              else
                /*Standard tab is not current for this page*/
                l_html_tab := l_html_tab||l_html_non_current_tab;
                l_html_tab := replace(l_html_tab,'#TAB_IMAGE#',r_tab.when_not_current_tab_image);
              end if;
              l_html_tab := replace(l_html_tab,'#TAB_LABEL#',r_tab.tab_label);
              l_html_tab := replace(l_html_tab,'#TAB_NAME#',r_tab.tab_name);
              if r_pat.current_for_tabset = l_current_tab_set
              then
                /*Standard tab belongs to current parent tab*/
                l_html_tab := replace(l_html_tab,'#TAB_LINK#','javascript:doSubmit('''||r_tab.tab_name||''');');
              else
                /*Standard tab does not belong to current parent tab
                **standard submit doesn't work so a url is used
                */
                l_url := 'f?p='||wwv_flow.g_flow_alias||':'||r_tab.tab_page||':'||wwv_flow.g_instance||'::'||l_debug_char;
                l_url := apex_application.do_substitutions(l_url);
                l_html_tab := replace(l_html_tab,'#TAB_LINK#',l_url);
              end if;
    
              /*Now, render the drop-down menu of the standard tabs under the current parent tab using sys.htp */
              --
             --    HOW ?
             --- 
          end loop;
    END;
    Now, I would like to ask
    1) Does the code above miss something other than part of generating li's of the drop-down menu?
    2) What about the JS function?

    Best Regards
    Mahmoud
  • 3. Re: JS function to generate HTML list for standard tabs
    974630 Newbie
    Currently Being Moderated
    Mahmoud

    Is the function auth_condition_check available? It is also supplied with the plugin. If you don't plan have any conditions on the tabs you could leave it out.
    You don't set the name of the tab set and the page template. Without them nothing will be renderd.

    Do you plan on rendering 1 set of standerd tabs at a time or all of them in one go?
    As the code is now you're not only rendering the standerd tabs but also all the parent tabs.

    As for the javascript code this depends on when you want to call it and what is being returned.
    For the ajax part of the code have a look at htmldb_Get.

    Nicolette
  • 4. Re: JS function to generate HTML list for standard tabs
    Mahmoud_Rabie Journeyer
    Currently Being Moderated
    Dear Nicolette
    Is the function auth_condition_check available? It is also supplied with the plugin. If you don't plan have any conditions on the tabs you could leave it out.
    You don't set the name of the tab set and the page template. Without them nothing will be renderd
    I don't need it because I will perform authorization on the level of parent tabs
    Do you plan on rendering 1 set of standerd tabs at a time or all of them in one go?
    As the code is now you're not only rendering the standerd tabs but also all the parent tabs.
    Only I need to render drop-down menu of standard tabs under a parent tab selected (calling JS function)
    As for the javascript code this depends on when you want to call it and what is being returned.
    For the ajax part of the code have a look at htmldb_Get.
    Would you give me an example for that

    TIA
    Mahmoud Rabie
  • 5. Re: JS function to generate HTML list for standard tabs
    974630 Newbie
    Currently Being Moderated
    Mahmoud_Rabie wrote:
    As for the javascript code this depends on when you want to call it and what is being returned.
    For the ajax part of the code have a look at htmldb_Get.
    Would you give me an example for that
    This is the closest to [url http://apex.oracle.com/pls/otn/f?p=11933:63:13921925846638::NO:::]documentation on htmldb_Get  that I know of.

    And have a look at [url http://ora-00001.blogspot.nl/]this dynamic action plugin. I haven't tried it yet but it seems to be just what you need.

    Nicolette

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points