Alpha Framework alpha--view--widgets
[ class tree: alpha--view--widgets ] [ index: alpha--view--widgets ] [ all elements ]

Source for file DateBox.inc

Documentation is available at DateBox.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/model/types/Date.inc';
  4. require_once $config->get('sysRoot').'alpha/model/types/Timestamp.inc';
  5.  
  6. /**
  7.  * A HTML widget for rendering a text box with calendar icon for Date/Timestamp types
  8.  * 
  9.  * @package alpha::view::widgets
  10.  * @since 1.0
  11.  * @author John Collins <dev@alphaframework.org>
  12.  * @version $Id: DateBox.inc 1453 2011-12-04 15:12:54Z johnc $
  13.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  14.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  15.  *  All rights reserved.
  16.  * 
  17.  *  <pre>
  18.  *  Redistribution and use in source and binary forms, with or
  19.  *  without modification, are permitted provided that the
  20.  *  following conditions are met:
  21.  * 
  22.  *  * Redistributions of source code must retain the above
  23.  *    copyright notice, this list of conditions and the
  24.  *    following disclaimer.
  25.  *  * Redistributions in binary form must reproduce the above
  26.  *    copyright notice, this list of conditions and the
  27.  *    following disclaimer in the documentation and/or other
  28.  *    materials provided with the distribution.
  29.  *  * Neither the name of the Alpha Framework nor the names
  30.  *    of its contributors may be used to endorse or promote
  31.  *    products derived from this software without specific
  32.  *    prior written permission.
  33.  *   
  34.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  35.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  36.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  37.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  39.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  44.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  45.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  46.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47.  *  </pre>
  48.  *  
  49.  */
  50. class DateBox {    
  51.     /**
  52.      * The date or timestamp object for the widget.
  53.      * 
  54.      * @var Date/Timestamp 
  55.      * @since 1.0
  56.      */
  57.     var $dateObject = null;    
  58.     
  59.     /**
  60.      * The data label for the object
  61.      * 
  62.      * @var string 
  63.      * @since 1.0
  64.      */
  65.     var $label;
  66.     
  67.     /**
  68.      * The name of the HTML input box
  69.      * 
  70.      * @var string 
  71.      * @since 1.0
  72.      */
  73.     var $name;
  74.     
  75.     /**
  76.      * The constructor
  77.      * 
  78.      * @param Date/Timestamp $object The date or timestamp object that will be edited by this widget.
  79.      * @param string $label The data label for the object.
  80.      * @param string $name The name of the HTML input box.
  81.      * @since 1.0
  82.      * @throws IllegalArguementException
  83.      */
  84.     public function __construct($object$label=""$name=""{
  85.         
  86.         // check the type of the object passed
  87.         if($object instanceof Date || $object instanceof Timestamp{
  88.             $this->dateObject = $object;
  89.         }else{
  90.             throw new IllegalArguementException('DateBox widget can only accept a Date or Timestamp object!');
  91.         }
  92.         
  93.         $this->label = $label;
  94.         $this->name = $name;
  95.     }
  96.     
  97.     /**
  98.      * Renders the text box and icon to open the calendar pop-up
  99.      *
  100.      * @param boolean $tableTags 
  101.      * @return string 
  102.      * @since 1.0
  103.      */
  104.     public function render($tableTags=true{
  105.         global $config;
  106.         
  107.         $html '';        
  108.         
  109.         /*
  110.          * decide on the size of the text box and the height of the widget pop-up, 
  111.          * depending on the dateObject type
  112.          */
  113.         if(strtoupper(get_class($this->dateObject)) == "TIMESTAMP"{
  114.             $size 18;
  115.             $cal_height 230;
  116.         }else{
  117.             $size 10;
  118.             $cal_height 230;
  119.         }
  120.         
  121.         $value $this->dateObject->getValue();
  122.         if($value == '0000-00-00')
  123.             $value '';
  124.         
  125.         if($tableTags{
  126.             $html .= '<tr><th style="width:25%;">';
  127.             $html .= $this->label;
  128.             $html .= '</th>';
  129.  
  130.             $html .= '<td>';
  131.             $html .= '<input type="text" size="'.$size.'" class="readonly" name="'.$this->name.'" id="'.$this->name.'" value="'.$value.'" readonly/>';
  132.             $html .= '<script language="javascript">';
  133.             if($this->dateObject instanceof Timestamp)
  134.                 $html .= "$('#".$this->name."').datepicker({dateFormat:'yy-mm-dd HH:II:SS',showOn:'button',buttonImage:'".$config->get('sysURL')."alpha/images/icons/calendar.png'})";
  135.             else
  136.                 $html .= '$(document).ready(function(){$(\'#'.$this->name.'\').datepicker({dateFormat:\'yy-mm-dd\',defaultDate:\''.$value.'\',showOn:\'button\',buttonImageOnly:\'true\',buttonImage:\''.$config->get('sysURL').'alpha/images/icons/calendar.png\'})});';
  137.             $html .= '</script>';
  138.             $html .= '</td></tr>';
  139.         }else{
  140.             $html .= '<input type="text" size="'.$size.'" class="readonly" name="'.$this->name.'" id="'.$this->name.'" value="'.$value.'" readonly/>';
  141.             $html .= '<script language="javascript">';
  142.             if($this->dateObject instanceof Timestamp)
  143.                 $html .= "$('#".$this->name."').datepicker({dateFormat:'yy-mm-dd HH:II:SS',showOn:'button',buttonImage:'".$config->get('sysURL')."alpha/images/icons/calendar.png'})";
  144.             else
  145.                 $html .= '$(document).ready(function(){$(\'#'.$this->name.'\').datepicker({dateFormat:\'yy-mm-dd\',defaultDate:\''.$value.'\',showOn:\'button\',buttonImageOnly:\'true\',buttonImage:\''.$config->get('sysURL').'alpha/images/icons/calendar.png\'})});';
  146.             $html .= '</script>';
  147.         }
  148.         
  149.         return $html;
  150.     }
  151. }
  152.  
  153. ?>

Documentation generated on Tue, 13 Dec 2011 20:26:38 +0000 by phpDocumentor 1.4.3