Changeset 1062


Ignore:
Timestamp:
Mar 3, 2006, 2:57:39 AM (18 years ago)
Author:
rvelices
Message:

improvement: calendar navigation now uses at maximum one navigation bar
together with a next/previous date links

improvement: calendar view styles now shown in DIV.titrePage (I still need
to move padding from H2 to DIV.titrePage ...)

fix: moved all calendar css colors from template to the theme

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/calendar_base.class.php

    r1059 r1062  
    4141  var $calendar_levels;
    4242
     43  var $has_nav_bar;
     44
    4345  /**
    4446   * Initialize the calendar
     
    5254    $this->inner_sql = $inner_sql;
    5355    $this->date_components = $date_components;
     56    $this->has_nav_bar = false;
    5457  }
    5558
     
    99102    }
    100103    return $label;
     104  }
     105
     106  /**
     107   * Gets a nice display name for a date to be shown in previos/next links.
     108   */
     109  function get_date_nice_name($date)
     110  {
     111    $date_components = explode('-', $date);
     112    $res = '';
     113    for ($i=count($date_components)-1; $i>=0; $i--)
     114    {
     115      if ($date_components[$i]!='any')
     116      {
     117        $label = $date_components[$i];
     118        if (isset($this->calendar_levels[$i]['labels'][$date_components[$i]]))
     119        {
     120          $label = $this->calendar_levels[$i]['labels'][$date_components[$i]];
     121        }
     122        $res .= $label.' ';
     123      }
     124    }
     125    return $res;
    101126  }
    102127
     
    212237    }
    213238
    214     if ( count($level_items)==1 )
     239    if ( count($level_items)==1 and
     240         count($this->date_components)<count($this->calendar_levels)-1)
    215241    {
    216242      if ( ! isset($this->date_components[$level]) )
     
    218244        list($key) = array_keys($level_items);
    219245        $this->date_components[$level] = (int)$key;
    220       }
    221     }
    222 
    223     if ( $conf['calendar_multi_bar']==false )
    224     {
    225       if ( $level<count($this->date_components) and
    226            $level!=count($this->calendar_levels)-1 )
    227       {
    228         return;
     246
     247        if ( $level<count($this->date_components) and
     248             $level!=count($this->calendar_levels)-1 )
     249        {
     250          return;
     251        }
    229252      }
    230253    }
     
    237260        $url_base .= $this->date_components[$i].'-';
    238261      }
    239     }
    240     $selected = null;
    241     if ( isset($this->date_components[$level]) )
    242     {
    243       $selected = $this->date_components[$level];
    244262    }
    245263    $nav_bar = $this->get_nav_bar_from_items(
    246264      $url_base,
    247265      $level_items,
    248       $selected,
     266      null,
    249267      'calItem',
    250268      true,
     
    256274      'calendar.navbar',
    257275      array(
    258         'BAR' => $nav_bar
     276        'BAR' => $nav_bar,
    259277        )
    260278      );
     279    $this->has_nav_bar = true;
     280  }
     281
     282  /**
     283   * Assigns the next/previous link to the template with regards to
     284   * the currently choosen date.
     285   */
     286  function build_next_prev()
     287  {
     288    global $template;
     289    $prev = $next =null;
     290    if ( empty($this->date_components) )
     291      return;
     292
     293    $current = '';
     294    $query = 'SELECT CONCAT_WS("-"';
     295    for ($i=0; $i<count($this->date_components); $i++)
     296    {
     297      if ( $this->date_components[$i] != 'any' )
     298      {
     299        $query .= ','.$this->calendar_levels[$i]['sql'];
     300      }
     301      else
     302      {
     303        $query .= ','.'"any"';
     304      }
     305      $current .= '-' . $this->date_components[$i];
     306    }
     307    $current = substr($current, 1);
     308
     309    $query.=') as period' . $this->inner_sql .'
     310AND ' . $this->date_field . ' IS NOT NULL
     311GROUP BY period';
     312    $upper_items = array_from_query( $query, 'period');
     313    usort($upper_items, 'version_compare');
     314    //echo ('<pre>'. var_export($upper_items, true) . '</pre>');
     315    $upper_items_rank = array_flip($upper_items);
     316    $current_rank = $upper_items_rank[$current];
     317    if (!$this->has_nav_bar and
     318        ($current_rank>0 or $current_rank < count($upper_items)-1 ) )
     319    {
     320      $template->assign_block_vars( 'calendar.navbar', array() );
     321    }
     322
     323    if ( $current_rank>0 )
     324    { // has previous
     325      $prev = $upper_items[$current_rank-1];
     326      $template->assign_block_vars(
     327        'calendar.navbar.prev',
     328        array(
     329          'LABEL' => $this->get_date_nice_name($prev),
     330          'URL' => $this->url_base . $prev,
     331          )
     332        );
     333    }
     334    if ( $current_rank < count($upper_items)-1 )
     335    {
     336      // has next
     337      $next = $upper_items[$current_rank+1];
     338      $template->assign_block_vars(
     339        'calendar.navbar.next',
     340        array(
     341          'LABEL' => $this->get_date_nice_name($next),
     342          'URL' => $this->url_base . $next,
     343          )
     344        );
     345    }
    261346  }
    262347}
  • trunk/include/calendar_monthly.class.php

    r1061 r1062  
    9494    {//case C: year+month given - display a nice month calendar
    9595      $this->build_month_calendar();
     96      //$this->build_nav_bar(CYEAR); // years
     97      //$this->build_nav_bar(CMONTH); // month
     98      $this->build_next_prev();
     99      return true;
     100    }
     101  }
     102
     103  if ($view_type==CAL_VIEW_LIST or count($this->date_components)==3)
     104  {
     105    $has_nav_bar = false;
     106    if ( count($this->date_components)==0 )
     107    {
    96108      $this->build_nav_bar(CYEAR); // years
     109    }
     110    if ( count($this->date_components)==1)
     111    {
    97112      $this->build_nav_bar(CMONTH); // month
    98       return true;
    99     }
    100   }
    101 
    102   if ($view_type==CAL_VIEW_LIST or count($this->date_components)==3)
    103   {
    104     if ( count($this->date_components)>=0 )
    105     {
    106       $this->build_nav_bar(CYEAR); // years
    107     }
    108     if ( count($this->date_components)>=1)
    109     {
    110       $this->build_nav_bar(CMONTH); // month
    111     }
    112     if ( count($this->date_components)>=2 )
    113     {
    114       $this->build_nav_bar(
    115           CDAY,
    116           range( 1, $this->get_all_days_in_month(
    117               $this->date_components[CYEAR] ,$this->date_components[CMONTH] )
    118               )
    119         ); // days
    120     }
     113    }
     114    if ( count($this->date_components)==2 )
     115    {
     116      $day_labels = range( 1, $this->get_all_days_in_month(
     117              $this->date_components[CYEAR] ,$this->date_components[CMONTH] ) );
     118      array_unshift($day_labels, 0);
     119      unset( $day_labels[0] );
     120      $this->build_nav_bar( CDAY, $day_labels ); // days
     121    }
     122    $this->build_next_prev();
    121123  }
    122124  return false;
     
    294296    list($m) = array_keys($items);
    295297    $this->date_components[CMONTH] = $m;
    296     if (count($items[$m]['children'])==1)
    297     { // or even to day view if everything occured in one day
    298       list($d) = array_keys($items[$m]['children']);
    299       $this->date_components[CDAY] = $d;
    300     }
    301298    return false;
    302299  }
  • trunk/include/calendar_weekly.class.php

    r1059 r1062  
    8181  assert($view_type==CAL_VIEW_LIST);
    8282
    83   $this->build_nav_bar(CYEAR); // years
    84   if ( count($this->date_components)>=1 )
     83  if ( count($this->date_components)==0 )
     84  {
     85    $this->build_nav_bar(CYEAR); // years
     86  }
     87  if ( count($this->date_components)==1 )
    8588  {
    8689    $this->build_nav_bar(CWEEK); // week nav bar 1-53
    8790  }
    88   if ( count($this->date_components)>=2 )
     91  if ( count($this->date_components)==2 )
    8992  {
    9093    $this->build_nav_bar(CDAY); // days nav bar Mon-Sun
    9194  }
     95  $this->build_next_prev();
    9296  return false;
    9397}
  • trunk/include/config_default.inc.php

    r1061 r1062  
    9191$conf['calendar_datefield'] = 'date_creation';
    9292
    93 // calendar_multi_bar : the calendar shows a maximum number of
    94 // year/month/week/day navigation bars
    95 $conf['calendar_multi_bar'] = true;
    96 
    9793// calendar_show_any : the calendar shows an aditional 'any' button in the
    9894// year/month/week/day navigation bars
  • trunk/include/functions_calendar.inc.php

    r1059 r1062  
    261261      }
    262262    }
     263    $calendar_title =
     264        '<a href="'.$url_base.$cal_style.'-'.$cal_view.'">'
     265        .$fields[$cal_field]['label'].'</a>';
     266    $calendar_title.= $calendar->get_display_name();
     267    //this should be an assign_block_vars, but I need to assign 'calendar'
     268    //above and at that point I don't have the title yet.
     269    $template->_tpldata['calendar.'][0]['TITLE'] = $calendar_title;
    263270  } // end category calling
    264271
    265   $calendar_title =
    266       '<a href="'.$url_base.$cal_style.'-'.$cal_view.'">'
    267       .$fields[$cal_field]['label'].'</a>';
    268   $calendar_title.= $calendar->get_display_name();
    269   $template->assign_block_vars(
    270     'calendar',
    271     array(
    272       'TITLE' => '<br/>'.$calendar_title,
    273       )
    274     );
    275 
    276272  if ($must_show_list)
    277273  {
    278274    $query = 'SELECT DISTINCT(id)';
    279     $query .= $calendar->inner_sql;
    280     $query .= $calendar->get_date_where();
     275    $query .= $calendar->inner_sql.'
     276  '.$calendar->get_date_where();
    281277    if ( isset($page['super_order_by']) )
    282278    {
     
    290286        'ORDER BY '.$calendar->date_field.' DESC,', $conf['order_by']
    291287        );
    292       $query .= $order_by;
     288      $query .= '
     289  '.$order_by;
    293290    }
    294291
  • trunk/template/yoga/category.tpl

    r1061 r1062  
    142142    </ul>
    143143
    144   <h2>{TITLE}
     144  <h2>{TITLE}</h2>
    145145  <!-- BEGIN calendar -->
    146   {calendar.TITLE}
     146  <!-- BEGIN views -->
     147  <div class="calendarViews">{lang:calendar_view}:
     148    <select onchange="document.location = this.options[this.selectedIndex].value;">
     149    <!-- BEGIN view -->
     150      <option value="{calendar.views.view.VALUE}" {calendar.views.view.SELECTED}>{calendar.views.view.CONTENT}</option>
     151    <!-- END view -->
     152    </select>
     153  </div>
     154  <!-- END views -->
    147155  <!-- END calendar -->
    148   </h2>
     156
     157  <!-- BEGIN calendar -->
     158  <h2>{calendar.TITLE}
     159</h2>
     160  <!-- END calendar -->
     161
    149162  </div> <!-- content -->
    150163
    151164<!-- BEGIN calendar -->
    152 <!-- BEGIN views -->
    153 <div class="calendarViews">
    154 {lang:calendar_view}: <select onchange="document.location = this.options[this.selectedIndex].value;">
    155 <!-- BEGIN view -->
    156   <option value="{calendar.views.view.VALUE}" {calendar.views.view.SELECTED}>{calendar.views.view.CONTENT}</option>
    157 <!-- END view -->
    158 </select>
     165<!-- BEGIN navbar -->
     166<div class="calendarBar">
     167<!-- BEGIN prev -->
     168        <div style="float:left">&laquo; <a href="{calendar.navbar.prev.URL}">{calendar.navbar.prev.LABEL}</a></div>
     169<!-- END prev -->
     170<!-- BEGIN next -->
     171        <div style="float:right"><a href="{calendar.navbar.next.URL}">{calendar.navbar.next.LABEL}</a> &raquo;</div>
     172<!-- END next -->
     173        {calendar.navbar.BAR}&nbsp;
    159174</div>
    160 <!-- END views -->
    161 
    162 <!-- BEGIN navbar -->
    163 <div class="calendarBar">{calendar.navbar.BAR}</div>
    164175<!-- END navbar -->
    165176
  • trunk/template/yoga/content.css

    r1061 r1062  
    183183#content DIV.calendarViews {
    184184  display: block;
    185   text-align: left;
    186   margin: 5px 0;
    187 }
    188 
    189 #content DIV.calendarBar {
    190   margin: 8px 4px;
    191 }
    192 
    193 SPAN.calItem {
     185  float: right;
     186  margin: 2px 2px;
     187}
     188
     189#content DIV.calendarBar { margin: 8px 4px; }
     190
     191SPAN.calItem, SPAN.calItemEmpty {
    194192  font-weight: bold;
    195   margin: 0 2px;
    196   border: 1px solid gray;
    197 }
    198 
    199 SPAN.calItemSel {
    200   font-weight: bold;
    201   margin: 0 2px;
    202   border: 1px solid gray;
    203 }
    204 
    205 SPAN.calItemEmpty {
    206   font-weight: bold;
    207   margin: 0 2px;
    208   border: 1px solid gray;
    209 }
     193  margin: 0 1px;
     194}
     195
     196SPAN.calItem A { border:0 }
    210197
    211198#content DIV.calendarCalBar {
     
    220207}
    221208
    222 SPAN.calCal {
    223   margin: 0 2px;
    224 }
     209SPAN.calCal { margin: 0 2px; }
    225210
    226211/* nice looking month calendar*/
  • trunk/template/yoga/theme/clear/theme.css

    r1061 r1062  
    7979
    8080/*calendar elements*/
    81 SPAN.calItemSel { color: dark-gray; }
     81SPAN.calItemEmpty { color: silver; }
    8282
    83 SPAN.calItemEmpty { color: lightgray; }
    84 
     83SPAN.calItem, SPAN.calItemEmpty
     84{
     85  border: 1px solid silver;
     86}
    8587
    8688/* nice looking month calendar*/
    8789TD.calDayCellEmpty, TD.calDayCellFull { border: 1px solid #7E7262;}
    8890
    89 TD.calDayCellEmpty { color: lightgray; }
     91TD.calDayCellEmpty { color: silver; }
    9092
    9193.calBackDate { color: #000; }
  • trunk/template/yoga/theme/dark/theme.css

    r1061 r1062  
    116116
    117117/*calendar elements*/
    118 SPAN.calItemSel { color: #fff48e; }
     118SPAN.calItemEmpty { color: silver; }
    119119
    120 SPAN.calItemEmpty { color: darkgray; }
     120SPAN.calItem, SPAN.calItemEmpty
     121{
     122  border: 1px solid gray;
     123}
    121124
    122125/* nice looking month calendar*/
    123126TD.calDayCellEmpty, TD.calDayCellFull { border: 1px solid gray;}
    124127
    125 TD.calDayCellEmpty { color: lightgray; }
     128TD.calDayCellEmpty { color: silver; }
    126129
    127130.calBackDate { color: #000; }
Note: See TracChangeset for help on using the changeset viewer.