Webman-framework

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

About | Overview | Documentation

 

Documentation > Modules and APIs > webman_calendar_weekly

webman_calendar_weekly

 

Description:

Component-type module that provides interactive navigation (weekly) on calendar data.

 

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. CGI Parameters

Below are CGI parameters that provide control to and passed by webman_calendar_interactive instance at application run-time.

calendar_key_date => "yyyy-mm-dd"
calendar_ymd_selected => "yyyy-mm-dd"

Default active week selected is system's current active week. Changes on selected active week can be done by passing, any date ranges inside the intended week to the module via calendar_key_date CGI parameter. The CGI parameter calendar_ymd_selected is used to store the picked date when the module is used as calendar's date information picker through customization inside customize_TLD function (read section 5, code lines 126-139).

 
2. View Template

Generally the template contains DYNAMIC_CONTENT template-elements, LIST template-elements, and a single standard HTML-form.

The first two DYNAMIC_CONTENT template-elements (lines 12 and 14) named cal_prev_week and cal_prev_week are used as place-holders for HTTP-GET links attribute to navigate calendar's weeks forward and backward.

The next two LIST template-elements (lines 20 and 26) named col_view_day and col_view_content together with the word patterns $tld_week_day_, $tld_week_date_, and $tld_week_date_content_ are used as place-holders for selected week's days and date, and date's content. The word pattern $tld_column_style_ is used to control days/date and date's content columns presentation style using CSS.

The standard HTML-form (lines 31-40) can be used by users to quickly jump to specific week by passing week's key date to the module via calendar_key_date CGI parameter (line 34). Inside the HTML-form there is also CGI template-element (line 37) with the word pattern $cgi_link_id_ as a place-holder for the value of link_id input element. This input element is used as an entity to pass the parameter named link_id (via POST-method) which is the standard CGI parameter name used to refer nodes' IDs that construct the overall application's link structure. The logic is to use again node's link-id which is used to call webman_calendar_weekly component-type module previously.

  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 border="1">                                                                        
 10   <tr>                                                                                    
 11     <th colspan="7" align="center">                                                       
 12       <a href="<!-- dynamic_content_ name=cal_prev_week //-->">&lt;&lt;</a>               
 13       | Weekly Calendar Title |                                                           
 14       <a href="<!-- dynamic_content_ name=cal_next_week //-->">&gt;&gt;</a>               
 15     </th>                                                                                 
 16   </tr>                                                                                   
 17                                                                                           
 18   <tr>                                                                                    
 19     <!-- start_list_ name=col_view_day //-->                                              
 20     <td align="center" style="$tld_column_style_">$tld_week_day_<br />$tld_week_date_</td>
 21     <!-- end_list_ //-->                                                                  
 22   </tr>                                                                                   
 23                                                                                           
 24   <tr>                                                                                    
 25     <!-- start_list_ name=col_view_content //-->                                          
 26     <td valign="top" style="$tld_column_style_">$tld_week_date_content_</td>              
 27     <!-- end_list_ //-->                                                                  
 28   </tr>                                                                                   
 29                                                                                           
 30   <tr>                                                                                    
 31     <form method="POST" action="./index.cgi">                                             
 32     <th colspan="7" align="center">                                                       
 33         Week's Date (yyyy-mm-dd):                                                         
 34         <input type="text" size="10" name="calendar_key_date">                            
 35         <input type="submit" name="button_submit" value="Go">                             
 36         <!-- start_cgihtml_ //-->                                                         
 37         <input type="hidden" name="link_id" value="$cgi_link_id_">                        
 38         <!-- end_cgihtml_ //-->                                                           
 39     </th>                                                                                 
 40     </form>                                                                               
 41   </tr>                                                                                   
 42 </table>                                                                                  
 43 <!-- end_view_ //-->                                                                      
 44 </body>                                                                                   
 45 </html>                                                                                   


 
3. Instantiation and Basic Parameter Setting

The arguments $all, $odd, $even, $current, and $selected (lines 11-12) are CSS's strings code to control the presentation of HTML-table columns used to arrange week's days/date and date's content.

  1 my $component = new webman_calendar_weekly;                                           
  2                                                                                       
  3 $component->set_CGI($cgi);                                                            
  4 $component->set_DBI_Conn($db_conn);                                                   
  5                                                                                       
  6 #$component->set_Template_Default($template_file);                                    
  7                                                                                       
  8 ### if key date is ignored the default would be the the current date                  
  9 #$component->set_Key_Date("yyyy-mm-dd");                                              
 10                                                                                       
 11 #$component->set_Default_Date_Column_Style($all, $odd, $even, $current, $selected);   
 12 #$component->set_Default_Content_Column_Style($all, $odd, $even, $current, $selected);
 13                                                                                       
 14 #$component->add_Date_Content("yyyy-mm-dd", $content);                                


 
4. Component-type Generic Function Calls

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

my $content = $component->get_Content;



 
5. 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 49). 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 110) is actually Table_List_Data core module instance. There are two Table_List_Data instances involved since there are two LIST template-elements used inside the view template file (see section 2). These two instances are referred internally inside the module by $this->{tld_col_date} and $this->{tld_col_content} scalars. They are treated and manipulated differently inside the customize_TLD function as shown at lines 121-123, 127-140, and 142-149. To manipulate these two instances, customize_TLD function need to be called twice. For each call the argument is one of those mentioned instances. All these are done by base-module's run_Task hook function recalls while it was overriden (line 51).

Read the comments included inside the skeleton code to get more detailed explanations for all possible customizations that could be made.

  1 package child_module_name;                                                    
  2                                                                                                 
  3 use webman_calendar_weekly;                                                                     
  4                                                                                                 
  5 @ISA=("webman_calendar_weekly");                                                                
  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_Key_Date("yyyy-mm-dd");                                                         
 44                                                                                                 
 45     ### The CSS code $selected effects the implementation at lines 127-140.                     
 46     #$this->set_Default_Date_Column_Style($all, $odd, $even, $current, $selected);              
 47     #$this->set_Default_Content_Column_Style($all, $odd, $even, $current, $selected);           
 48                                                                                                 
 49     #$this->add_Date_Content("yyyy-mm-dd", "content_");                                         
 50                                                                                                 
 51     $this->SUPER::run_Task();                                                                   
 52                                                                                                 
 53     ### enable the next two lines to really know how the instances                              
 54     ### $this->{tld_col_date} & $this->{tld_col_content} are look like                          
 55     #$cgi->add_Debug_Text($this->{tld_col_date}->get_Table_List, __FILE__, __LINE__);           
 56     #$cgi->add_Debug_Text($this->{tld_col_content}->get_Table_List, __FILE__, __LINE__);        
 57 }                                                                                               
 58                                                                                                 
 59 sub process_Content {                                                                           
 60     $this = shift @_;                                                                           
 61                                                                                                 
 62     my $cgi = $this->get_CGI;                                                                   
 63     my $dbu = $this->get_DBU;                                                                   
 64     my $db_conn = $this->get_DB_Conn;                                                           
 65                                                                                                 
 66     $this->set_Template_File($this->{template_default});                                        
 67                                                                                                 
 68     #print "\$this->{template_default} = " . $this->{template_default} . "<br>";                
 69                                                                                                 
 70     $this->SUPER::process_Content;                                                              
 71 }                                                                                               
 72                                                                                                 
 73 sub process_so_type_ { ### so_type_ can be: VIEW, DYNAMIC, LIST, MENU, DBHTML, SELECT, DATAHTML 
 74     my $this = shift @_;                                                                        
 75     my $te = shift @_;                                                                          
 76                                                                                                 
 77     my $cgi = $this->get_CGI;                                                                   
 78     my $dbu = $this->get_DBU;                                                                   
 79     my $db_conn = $this->get_DB_Conn;                                                           
 80                                                                                                 
 81     my $login_name = $this->get_User_Login;                                                     
 82     my @groups = $this->get_User_Groups;                                                        
 83                                                                                                 
 84     my $match_group = $this->match_Group($group_name_, @groups);                                
 85                                                                                                 
 86     my $te_content = $te->get_Content;                                                          
 87     my $te_type_num = $te->get_Type_Num;                                                        
 88     my $te_type_name = $te->get_Name;                                                           
 89                                                                                                 
 90     $this->add_Content($te_content);                                                            
 91                                                                                                 
 92     #if ($this->get_Error eq "") {                                                              
 93     #   $this->add_Content($te_content);                                                        
 94                                                                                                 
 95     #} else {                                                                                   
 96     #   $this->add_Content($this->get_Error);                                                   
 97     #}                                                                                          
 98 }                                                                                               
 99                                                                                                 
100 ### The next function will customize both types of Table_List_Data                              
101 ### instance structure that are $this->{tld_col_date} and                                       
102 ### $this->{tld_col_content}. They have five identical column names which                       
103 ### are 'column_style', 'current_date', 'week_day', 'week_date' and 'date_iso'.                 
104 ### The $this->{tld_col_content} hase one extra column that is                                  
105 ### 'week_date_content'.                                                                        
106                                                                                                 
107 sub customize_TLD {                                                                             
108     my $this = shift @_;                                                                        
109                                                                                                 
110     my $tld = shift @_;                                                                         
111                                                                                                 
112     my $cgi = $this->get_CGI;                                                                   
113     my $dbu = $this->get_DBU;                                                                   
114     my $db_conn = $this->get_DB_Conn;                                                           
115                                                                                                 
116     my $std_get_data = $cgi->generate_GET_Data("link_id");                                      
117                                                                                                 
118     my $column_color = "#fbfbeb";                                                               
119                                                                                                 
120     ### Add other possible new column for the content.                                          
121     #if ($tld == $this->{tld_col_content}) {                                                    
122     #    $tld->add_Column("link");                                                              
123     #}                                                                                          
124                                                                                                 
125     for (my $i = 0; $i < $tld->get_Row_Num; $i++) {                                             
126         ### Make date columns are selectable via week_date link.                                
127         if ($tld eq $this->{tld_col_date}) {                                                    
128             ### Make week_date as links to select/deselect date.                                
129             my $date_iso = $tld->get_Data($i, "date_iso");                                      
130             my $link_properties = "title=\"Click to select date\"";                             
131                                                                                                 
132             if ($date_iso eq $cgi->param("calendar_ymd_selected")) {                            
133                 $date_iso = "";                                                                 
134                 $link_properties = "title=\"Click to deselect date\" style=\"color: #ff0000;\"";
135             }                                                                                   
136                                                                                                 
137             $tld->set_Data_Get_Link($i, "week_date",                                            
138                                     "index.cgi?$std_get_data&calendar_ymd_selected=$date_iso",  
139                                     "$link_properties");                                        
140         }                                                                                       
141                                                                                                 
142         ### Next possible operations on new column for the content.                             
143         #if ($tld == $this->{tld_col_content}) {                                                
144         #                                                                                       
145         #    $tld->set_Data($i, "link", "Link to...?");                                         
146         #    $tld->set_Data_Get_Link($i, "link",                                                
147         #                            "index.cgi?$std_get_data",                                 
148         #                            "$link_properties");                                       
149         #}                                                                                      
150     }                                                                                           
151                                                                                                 
152     #$cgi->add_Debug_Text($tld->get_Table_List, __FILE__, __LINE__);                            
153                                                                                                 
154     return $tld;                                                                                
155 }                                                                                               
156                                                                                                 
157 1;