Webman-framework

Lightweight, Component-based, and Database-oriented Web Application Framework

About | Overview | Documentation

 

Documentation > Modules and APIs > webman_TLD_item_view_dynamic

webman_TLD_item_view_dynamic

 

Description:

Component-type module that provides dynamic control on item listing of Table_List_Data instance.

 

Dependencies:

Webman-framework's Core Modules:

  • HTML_Link_Menu (Composition)
  • HTML_Link_Menu_Paginate (Composition)
  • Select_Option (Composition)

Webman-framework's Component-type Modules:
  • CGI_Component::webman_CGI_component:webman_TLD_item_view (Inheritance)

 

1. View Template

  1 <html>                                                                      
  2 <body>                                                                      
  3 <!-- start_view_ //-->                                                      
  4 <!-- dynamic_content_ name=link_path //--> &gt; List Title                  
  5 <p />                                                                       
  6                                                                             
  7 <!-- dynamic_content_ name=tld_items_num_begin //--> -                      
  8 <!-- dynamic_content_ name=tld_items_num_end //--> of                       
  9 <!-- dynamic_content_ name=tld_items_num_total //--> Records.               
 10 <p />                                                                       
 11                                                                             
 12 <table border="1">                                                          
 13   <!-- start_menu_ name=caption //-->                                       
 14   <tr>                                                                      
 15     <th>Num.</th>                                                           
 16     <th>menu_item0_</th>                                                    
 17     <th>menu_item1_</th>                                                    
 18     <th>menu_item2_</th>                                                    
 19   </tr>                                                                     
 20   <!-- end_menu_ //-->                                                      
 21                                                                             
 22   <!-- start_list_ name=main //-->                                          
 23   <tr>                                                                      
 24     <td align="right">$tld_num_.</td>                                       
 25     <td>$tld_column_name_1_</td>                                            
 26     <td>$tld_column_name_2_</td>                                            
 27     <td>$tld_column_name_n_</td>                                            
 28   </tr>                                                                     
 29   <!-- end_list_ //-->                                                      
 30 </table>                                                                    
 31                                                                             
 32 <p />                                                                       
 33                                                                             
 34 <form name="tld_view_dynamic" method="post" action="index.cgi">             
 35   <!-- dynamic_content_ name=form_hidden_field //-->                        
 36                                                                             
 37   Items/List: <input name="inl" type="text" id="inl" value="$inl_" size="3">
 38   &nbsp;                                                                    
 39                                                                             
 40   <!-- start_menu_ name=list //-->                                          
 41     dynamic_menu_items_                                                     
 42   <!-- end_menu_ //-->                                                      
 43   &nbsp;                                                                    
 44                                                                             
 45   List Set Num. :                                                           
 46   <select name="lsn" onChange="document.tld_view_dynamic.submit()">         
 47     <!-- select_ name=lsn //-->                                             
 48   </select>                                                                 
 49 </form>                                                                     
 50 <!-- end_view_ //-->                                                        
 51 </body>                                                                     
 52 </html>                                                                     


 
2. Instantiation and Basic Parameter Setting

Lines 8-14 is the most practical way to create Table_List_Data instance by using JSON data entities retrieved from data interoperability service provided by webman_JSON component-type module. Values for the attributes of the entity can be a value from the CGI parameters: (attribute_2 => $cgi_param_name_). Manually create Table_List_Data instance is also possible as proposed at lines 17-19.

  1 my $component = new webman_TLD_item_view_dynamic;                                                                                                             
  2                                                                                                                                                               
  3 $component->set_CGI($cgi);                                                                                                                                    
  4 $component->set_DBI_Conn($db_conn);                                                                                                                           
  5                                                                                                                                                               
  6 ### Table_List_Data instance automatically created from the returned JSON                                                                                     
  7 ### formatted text.                                                                                                                                           
  8 $component->set_Web_Service_URL("http://app_URL_path/index_json.cgi");                                                                                        
  9                                                                                                                                                               
 10 $component->set_Web_Service_Entity("entity => entity_name,                                                                                                    
 11                                     attribute_1 => value_1,                                                                                                   
 12                                     attribute_2 => $cgi_param_name_,                                                                                          
 13                                     ...,                                                                                                                      
 14                                     attribute_n => value_n");                                                                                                 
 15                                                                                                                                                               
 16 ### Option to manually create an instance of Table_List_Data is also possible.                                                                                
 17 #my $tld = new Table_List_Data;                                                                                                                               
 18 #...;                                                                                                                                                         
 19 #$component->set_TLD($tld);                                                                                                                                   
 20                                                                                                                                                               
 21 #$component->set_List_Selection_Num($num); ### default is 15                                                                                                  
 22                                                                                                                                                               
 23 $component->set_Order_Field_CGI_Var("order_by_???");                                                                                                          
 24                                                                                                                                                               
 25 $component->set_Order_Field_Caption("Caption 1:Caption 2:...:Caption n");                                                                                     
 26 $component->set_Order_Field_Name("field_1:field_2 field_1:...:field_n");                                                                                      
 27                                                                                                                                                               
 28 #$component->set_Order_Field_Name_Opt("asc|desc:asc|desc asc|desc:...:asc|desc");                                                                             
 29 #$component->set_Order_Field_Mode("str|num:str|num str|num:...:str|num");                                                                                     
 30                                                                                                                                                               
 31 #$component->set_Order_Field_Name_Opt_Mode("field_1:field_2 field_1:...:field_n",                                                                             
 32 #                                          "asc|desc:asc|desc asc|desc:...:asc|desc",                                                                         
 33 #                                          "str|num:str|num str|num:...:str|num");                                                                            
 34                                                                                                                                                               
 35 #$component->set_Map_Caption_Field("caption_1_ => field_1_, ..., caption_n_ => field_n_"); ### it's only [1 to 1] mapping                                     
 36 #$component->set_Default_Order_Field_Selected($order_field_index_); ### default is 0                                                                          
 37                                                                                                                                                               
 38 #$component->set_Customize_TLD_After_Sort(1); ### default is 0                                                                                                
 39                                                                                                                                                               
 40 $component->set_Items_View_Num(50);                                                                                                                           
 41 $component->set_Items_Set_Num(1); ### set for default set num                                                                                                 
 42                                                                                                                                                               
 43 #$component->set_INL_Var_Name("???"); ### Items Num./List, default is "inl"                                                                                   
 44 #$component->set_LSN_Var_Name("???"); ### List Set Num., default is "lsn"                                                                                     
 45                                                                                                                                                               
 46 #$component->set_Items_Set_Num_Var("tldisn_???"); ### default is: "tldisn_" . $cgi->param("task");                                                            
 47 #$component->set_Dynamic_Menu_Items_Set_Number_Var("dmisn_???"); ### default is: "dmisn_" . $cgi->param("task");                                              
 48                                                                                                                                                               
 49 #$component->set_Carried_GET_Data("inl ..."); ### all possible get data except link_name, dmisn,                                                              
 50 #                                             ### link_id, app_name, and session_id                                                                           
 51                                                                                                                                                               
 52 #$component->set_Carried_Hidden_POST_Data("... "); ### all possible hidden post data except link_name, dmisn,                                                 
 53 #                                                  ### link_id, app_name, and session_id                                                                      
 54                                                                                                                                                               
 55                                                                                                                                                               
 56 #$component->set_Additional_GET_Data("get_data_1=get_value_1&...&get_data_n=get_value_n");                                                                    
 57 #$component->set_Additional_Hidden_POST_Data("post_data_1=post_value_1&...&post_data_n=post_value_n");                                                        
 58                                                                                                                                                               
 59 #$component->set_Link_Path_Carried_Get_Data("get_data_1_ ... get_data_n_"); ### all possible post data except link_name, link_id, dmisn, app_name & session_id
 60                                                                                                                                                               
 61 $component->set_Template_Default($template_file);                                                                                                             
 62                                                                                                                                                               


 
3. Component-type Generic Function Calls

 50 if ($component->auth_Link_Path && $component->authenticate) {
 51     $component->run_Task;                                    
 52     $component->process_Content;                             
 53     $component->end_Task;                                    
 54 }                                                            
 55                                                              
 56 my $content = $component->get_Content;                       


 
4. Child Module for Customization

  1 package child_module_name;                                                    
  2                                                                                                 
  3 use webman_TLD_item_view_dynamic;                                                               
  4                                                                                                 
  5 @ISA=("webman_TLD_item_view_dynamic");                                                          
  6                                                                                                 
  7 sub new {                                                                                       
  8     my $class = shift;                                                                          
  9                                                                                                 
 10     my $this = $class->SUPER::new();                                                            
 11                                                                                                 
 12     #$this->set_Debug_Mode(1, 1);                                                               
 13                                                                                                 
 14     bless $this, $class;                                                                        
 15                                                                                                 
 16     return $this;                                                                               
 17 }                                                                                               
 18                                                                                                 
 19 sub get_Name {                                                                                  
 20     my $this = shift @_;                                                                        
 21                                                                                                 
 22     return __PACKAGE__;                                                                         
 23 }                                                                                               
 24                                                                                                 
 25 sub get_Name_Full {                                                                             
 26     my $this = shift @_;                                                                        
 27                                                                                                 
 28     return $this->SUPER::get_Name_Full . "::" . __PACKAGE__;                                    
 29 }                                                                                               
 30                                                                                                 
 31 sub run_Task {                                                                                  
 32     my $this = shift @_;                                                                        
 33                                                                                                 
 34     my $cgi = $this->get_CGI;                                                                   
 35     my $dbu = $this->get_DBU;                                                                   
 36     my $db_conn = $this->get_DB_Conn;                                                           
 37                                                                                                 
 38     my $login_name = $this->get_User_Login;                                                     
 39     my @groups = $this->get_User_Groups;                                                        
 40                                                                                                 
 41     my $match_group = $this->match_Group($group_name_, @groups);                                
 42                                                                                                 
 43     ### Programmatically generate Table_List_Data instance                                      
 44     ### is highly possible to be done here.                                                     
 45     #my $tld = new Table_List_Data;                                                             
 46     #...;                                                                                       
 47     #...;                                                                                       
 48     #$this->set_TLD($tld);                                                                      
 49                                                                                                 
 50     $this->SUPER::run_Task();                                                                   
 51 }                                                                                               
 52                                                                                                 
 53 ### Example of handling view template with more than one DYNAMIC                                
 54 ### template-element. The standard DYNAMIC template element named "link_path"                   
 55 ### should be passed to the base module hook function. The new added DYNAMIC                    
 56 ### template-element ("other_new_dynamic") can be processed locally inside the                  
 57 ### child module hook function.                                                                 
 58 sub process_DYNAMIC {                                                                           
 59     my $this = shift @_;                                                                        
 60     my $te = shift @_;                                                                          
 61                                                                                                 
 62     my $cgi = $this->get_CGI;                                                                   
 63     my $dbu = $this->get_DBU;                                                                   
 64     my $db_conn = $this->get_DB_Conn;                                                           
 65                                                                                                 
 66     my $login_name = $this->get_User_Login;                                                     
 67     my @groups = $this->get_User_Groups;                                                        
 68                                                                                                 
 69     my $match_group = $this->match_Group($group_name_, @groups);                                
 70                                                                                                 
 71     my $te_content = $te->get_Content;                                                          
 72     my $te_type_num = $te->get_Type_Num;                                                        
 73     my $te_type_name = $te->get_Name;                                                           
 74                                                                                                 
 75     if ($te_type_name eq "link_path") {                                                         
 76         ### Just pass the DYNAMIC template-element instance to                                  
 77         ### parent's process_DYNAMIC function.                                                  
 78         $this->SUPER::process_DYNAMIC($te);                                                     
 79                                                                                                 
 80     } elsif ($te_type_name eq "other_new_dynamic") {                                            
 81         ### Process the new added LIST template-element                                         
 82         #$te_content = ...;                                                                     
 83         #...;                                                                                   
 84         #...;                                                                                   
 85         #return ($te_content);                                                                  
 86     }                                                                                           
 87 }                                                                                               
 88                                                                                                 
 89 sub customize_TLD {                                                                             
 90     my $this = shift @_;                                                                        
 91                                                                                                 
 92     my $tld = shift @_;                                                                         
 93                                                                                                 
 94     my $cgi = $this->get_CGI;                                                                   
 95     my $dbu = $this->get_DBU;                                                                   
 96     my $db_conn = $this->get_DB_Conn;                                                           
 97                                                                                                 
 98     my $caller_get_data = $cgi->generate_GET_Data("link_id");                                   
 99                                                                                                 
100     ### Add new column to represent HTML's CSS class to                                         
101     ### control the view presentation of HTML-table rows.                                       
102     $tld->add_Column("row_class");                                                              
103                                                                                                 
104     my $row_class = "row_odd";                                                                  
105                                                                                                 
106     for (my $i = 0; $i < $tld->get_Row_Num; $i++) {                                             
107         ### The below implementations assume that the CSS class "row_odd" and                   
108         ### "row_even" have been already defined and ready to be used inside                    
109         ### the view template. Refer back to section 2 (the proposed view                       
110         ### template) and see how the "$tld_row_class_" word pattern act as a                   
111         ### place-holder inside the main list template-element.                                 
112         $tld->set_Data($i, "row_class", "$row_class");                                          
113                                                                                                 
114         if ($row_class eq "row_odd") {                                                          
115             $row_class = "row_even";                                                            
116                                                                                                 
117         } else {                                                                                
118             $row_class = "row_odd";                                                             
119         }                                                                                       
120                                                                                                 
121         ### Other possible implementations of customization to manipulate the                   
122         ### existing column's data of Table_List_Data instance ($tld) to make                   
123         ### one of its column becomes an active hypertext links. The scalar                     
124         ### ($get_data) should be a list of additional CGI parameters written                   
125         ### in GET-data string format ("&param1=value1&param2=$value2&...").                    
126         ### The $link_properties is a string represent the attributes of the                    
127         ### HTML <a> tag: <a href="..." $link_properties>...</a>                                
128         #my $col_name = "...";                                                                  
129                                                                                                 
130         #my $get_data = $caller_get_data . "...";                                               
131         #my $link_properties = "...";                                                           
132                                                                                                 
133         #my $tld_data = $tld->get_Data($i, $col_name);                                          
134                                                                                                 
135         #$tld_data = "<font color=\"#0099FF\">$tld_data</font>";                                
136                                                                                                 
137         #$tld->set_Data($i, $col_name, $tld_data);                                              
138         #$tld->set_Data_Get_Link($i, $col_name, "index.cgi?$get_data", $link_properties);       
139                                                                                                 
140     }                                                                                           
141                                                                                                 
142     return $tld;                                                                                
143 }                                                                                               
144                                                                                                 
145 1;