Webman-framework

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

About | Overview | Documentation

 

Documentation > Modules and APIs > webman_calendar

webman_calendar

 

Description:

Component-type module used to render basic calendar information of system's current active month.

 

Dependencies:

Webman-framework's Core Modules:

  • Calendar (Composition)
  • Table_List_Data (Composition)
  • TLD_HTML_Map (Composition)

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

 

1. View Template

The main part of view template content for webman_calendar module is actually a LIST template-element (23-31), passed to process_LIST hook function and processed by TLD_HTML_Map core module. The LIST template-element contains the formation of word patterns $tld_date1_, ..., $tld_date7_ and $tld_date1_content_, ..., $tld_date1_content_ as place-holders for calendar's date and date's content.

  1 <html>                                                                                               
  2 <head>                                                                                               
  3 <title>Untitled Document</title>                                                                     
  4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">                             
  5 </head>                                                                                              
  6                                                                                                      
  7 <body>                                                                                               
  8 <!-- start_view_ //-->                                                                               
  9 <table width="315" border="1">                                                                       
 10   <tr>                                                                                               
 11     <td width="45" colspan="7" align="center">$active_month_ &nbsp;&nbsp; $active_year_</td>         
 12   </tr>                                                                                              
 13   <tr>                                                                                               
 14     <td align="center" width="45">Mon</td>                                                           
 15     <td align="center" width="45">Tue</td>                                                           
 16     <td align="center" width="45">Wed</td>                                                           
 17     <td align="center" width="45">Thu</td>                                                           
 18     <td align="center" width="45">Fri</td>                                                           
 19     <td align="center" width="45">Sat</td>                                                           
 20     <td align="center" width="45">Sun</td>                                                           
 21   </tr>                                                                                              
 22   <!-- start_list_ //-->                                                                             
 23   <tr>                                                                                               
 24     <td align="center" valign="top" width="45" $tld_cell1_color_>$tld_date1_ $tld_date1_content_</td>
 25     <td align="center" valign="top" width="45" $tld_cell2_color_>$tld_date2_ $tld_date2_content_</td>
 26     <td align="center" valign="top" width="45" $tld_cell3_color_>$tld_date3_ $tld_date3_content_</td>
 27     <td align="center" valign="top" width="45" $tld_cell4_color_>$tld_date4_ $tld_date4_content_</td>
 28     <td align="center" valign="top" width="45" $tld_cell5_color_>$tld_date5_ $tld_date5_content_</td>
 29     <td align="center" valign="top" width="45" $tld_cell6_color_>$tld_date6_ $tld_date6_content_</td>
 30     <td align="center" valign="top" width="45" $tld_cell7_color_>$tld_date7_ $tld_date7_content_</td>
 31   </tr>                                                                                              
 32   <!-- end_list_ //-->                                                                               
 33 </table>                                                                                             
 34 <!-- end_view_ //-->                                                                                 
 35 </body>                                                                                              
 36 </html>                                                                                              


 
2. Instantiation and Basic Parameter Setting

The arguments $normal, $current, $odd, and $even are strings represent HTML color codes in hexadecimal fromat number ("#RRGGBB").

my $component = new webman_calendar;

$component->set_CGI($cgi);
$component->set_DBI_Conn($db_conn);

#$component->set_Default_Text_Colors($normal, $current);

#$component->set_Default_Cell_Colors($normal, $current);

#$component->set_Default_Column_Color($odd, $even);
#$component->set_Default_Row_Color($odd, $even);

#$component->add_Date_Content("yyyy-mm-dd", $content);

#$component->set_Template_Default($template_file);



 
3. Component-type Generic Function Calls

$component->run_Task;
$component->process_Content;
$component->end_Task;

my $content = $component->get_Content;



 
4. Child Module for Customization

Most basic customization is to add content into specific calendar's date-cell, done inside the overriden run_Task hook function (line 54). Other more advanced and complex customization tasks are involving calendar's data-structure manipulations inside customize_TLD function.

Calendar's data-structure instance ($tld) passed to customize_TLD function (line 109) is actually Table_List_Data core module instance.

  1 package child_module_name;                                                            
  2                                                                                                         
  3 use webman_calendar;                                                                                    
  4                                                                                                         
  5 @ISA=("webman_calendar");                                                                               
  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     #$this->set_Error("???");                                                                           
 44                                                                                                         
 45     $this->SUPER::run_Task();                                                                           
 46                                                                                                         
 47     #$this->set_Default_Text_Colors("#all_", "#current_");                                              
 48                                                                                                         
 49     #$this->set_Default_Cell_Colors("#all_", "#current_");                                              
 50                                                                                                         
 51     #$this->set_Default_Column_Color(#odd_, #even_");                                                   
 52     #$this->set_Default_Row_Color(#odd_, #even_");                                                      
 53                                                                                                         
 54     #$this->add_Date_Content("yyyy-mm-dd", "content_");                                                 
 55 }                                                                                                       
 56                                                                                                         
 57 sub process_Content {                                                                                   
 58     $this = shift @_;                                                                                   
 59                                                                                                         
 60     my $cgi = $this->get_CGI;                                                                           
 61     my $dbu = $this->get_DBU;                                                                           
 62     my $db_conn = $this->get_DB_Conn;                                                                   
 63                                                                                                         
 64     $this->set_Template_File($this->{template_default});                                                
 65                                                                                                         
 66     #print "\$this->{template_default} = " . $this->{template_default} . "<br>";                        
 67                                                                                                         
 68     $this->SUPER::process_Content;                                                                      
 69 }                                                                                                       
 70                                                                                                         
 71 ### The skeleton of "hook" function to be redefined to process template                                 
 72 ### elements content. TE_TYPE_ can be: VIEW, DYNAMIC, LIST, MENU, DBHTML,                               
 73 ### SELECT, DATAHTML, CGIHTML, etc.                                                                     
 74 sub process_TE_TYPE_ {                                                                                  
 75     my $this = shift @_;                                                                                
 76     my $te = shift @_;                                                                                  
 77                                                                                                         
 78     my $cgi = $this->get_CGI;                                                                           
 79     my $dbu = $this->get_DBU;                                                                           
 80     my $db_conn = $this->get_DB_Conn;                                                                   
 81                                                                                                         
 82     my $login_name = $this->get_User_Login;                                                             
 83     my @groups = $this->get_User_Groups;                                                                
 84                                                                                                         
 85     my $match_group = $this->match_Group($group_name_, @groups);                                        
 86                                                                                                         
 87     my $te_content = $te->get_Content;                                                                  
 88     my $te_type_num = $te->get_Type_Num;                                                                
 89     my $te_type_name = $te->get_Name;                                                                   
 90                                                                                                         
 91     $this->add_Content($te_content);                                                                    
 92                                                                                                         
 93     #if ($this->get_Error eq "") {                                                                      
 94     #   $this->add_Content($te_content);                                                                
 95                                                                                                         
 96     #} else {                                                                                           
 97     #   $this->add_Content($this->get_Error);                                                           
 98     #}                                                                                                  
 99 }                                                                                                       
100                                                                                                         
101 sub customize_TLD {                                                                                     
102     my $this = shift @_;                                                                                
103                                                                                                         
104     ### The $tld instance has the column names and structure as follows:                                
105     ### 'date1', ..., 'date7',                                                                          
106     ### 'cell1_color', ..., 'cell7_color',                                                              
107     ### 'date1_iso', ..., 'date7_iso',                                                                  
108     ### 'date1_content', ..., 'date7_content'                                                           
109     my $tld = shift @_;                                                                                 
110                                                                                                         
111     my $cgi = $this->get_CGI;                                                                           
112     my $dbu = $this->get_DBU;                                                                           
113     my $db_conn = $this->get_DB_Conn;                                                                   
114                                                                                                         
115     ### The "link_id" is CGI parameter which is used to make the main controller run this this module   
116     my $std_get_data = $cgi->generate_GET_Data("link_id");                                              
117                                                                                                         
118     ### Add other possible new columns (link1, ..., link7).                                             
119     #for (my $cell_num = 1; $cell_num <= 7; $cell_num++) {                                              
120     #    $tld->add_Column("link" . $cell_num);                                                          
121     #}                                                                                                  
122                                                                                                         
123     for (my $i = 0; $i < $tld->get_Row_Num; $i++) {                                                     
124         ### Next possible operations on new columns (link1, ..., link7).                                
125         #for (my $cell_num = 1; $cell_num <= 7; $cell_num++) {                                          
126         #    my $date_iso = $tld->get_Data($i, "date" . $cell_num . "_iso");                            
127         #    my $link_properties = "title=\"Click to do something...\"";                                
128         #                                                                                               
129         #    if ($date_iso ne "") {                                                                     
130         #        $tld->set_Data($i, "link" . $cell_num, "Link...?");                                    
131         #        $tld->set_Data_Get_Link($i, "link" . $cell_num,                                        
132         #                                    "index.cgi?$std_get_data&calendar_ymd_selected=$date_iso", 
133         #                                    "$link_properties");                                       
134         #    }                                                                                          
135         #}                                                                                              
136     }                                                                                                   
137                                                                                                         
138     $cgi->add_Debug_Text($tld->get_Table_List, __FILE__, __LINE__);                                     
139                                                                                                         
140     return $tld;                                                                                        
141 }                                                                                                       
142                                                                                                         
143 1;