Webman-framework

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

About | Overview | Documentation

 

Documentation > Modules and APIs > webman_TLD_item_view

webman_TLD_item_view

 

Description:

Component-type module that provides basic and simple item listing of Table_List_Data instance.

 

Dependencies:

Webman-framework's Core Modules:

  • TLD_HTML_Map (Composition)
  • Web_Service_Entity (Composition)

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

 

1. View Template

  1 <html>                                                    
  2 <body>                                                    
  3 <!-- start_view_ //-->                                    
  4 <!-- dynamic_content_ name=link_path //--> &gt; List Title
  5 <p />                                                     
  6 <table border="1">                                        
  7   <tr>                                                    
  8     <th>Num.</th>                                         
  9     <th>field_caption_1</th>                              
 10     <th>field_caption_2</th>                              
 11     <th>field_caption_n</th>                              
 12   </tr>                                                   
 13                                                           
 14   <!-- start_list_ name=main //-->                        
 15   <tr>                                                    
 16     <td align="right">$tld_num_.</td>                     
 17     <td>$tld_column_name_1_</td>                          
 18     <td>$tld_column_name_2_</td>                          
 19     <td>$tld_column_name_n_</td>                          
 20   </tr>                                                   
 21   <!-- end_list_ //-->                                    
 22 </table>                                                  
 23 <!-- end_view_ //-->                                      
 24 </body>                                                   
 25 </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;                                     
  2                                                                               
  3 $component->set_CGI($cgi);                                                    
  4 $component->set_DBI_Conn($db_conn); ### option 2                              
  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 ### Option to only show some of the part of the overall list items.           
 22 #$component->set_Items_View_Num(50);                                          
 23 #$component->set_Items_Set_Num(1);                                            
 24                                                                               
 25 $component->set_Template_Default($template_file);                             
 26                                                                               


 
3. Component-type Generic Function Calls

 13 if ($component->auth_Link_Path && $component->authenticate) {
 14     $component->run_Task;                                    
 15     $component->process_Content;                             
 16     $component->end_Task;                                    
 17 }                                                            
 18                                                              
 19 my $content = $component->get_Content;                       


 
4. Child Module for Customization

  1 package child_module_name;                                                    
  2                                                                                                 
  3 use webman_TLD_item_view;                                                                       
  4                                                                                                 
  5 @ISA=("webman_TLD_item_view");                                                                  
  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;