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

Source for file TextBox.inc

Documentation is available at TextBox.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/util/InputFilter.inc';
  4. require_once $config->get('sysRoot').'alpha/model/types/Text.inc';
  5.  
  6. /**
  7.  * Text HTML input box custom widget
  8.  * 
  9.  * @package alpha::view::widgets
  10.  * @since 1.0
  11.  * @author John Collins <dev@alphaframework.org>
  12.  * @version $Id: TextBox.inc 1341 2011-03-17 15:02:02Z 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 TextBox {
  51.     /**
  52.      * The text object that will be edited by this text box
  53.      * 
  54.      * @var Text 
  55.      * @since 1.0
  56.      */
  57.     public $textObject;
  58.     
  59.     /**
  60.      * The data label for the text object
  61.      * 
  62.      * @var string 
  63.      * @since 1.0
  64.      */
  65.     public $label;
  66.     
  67.     /**
  68.      * The name of the HTML input box
  69.      * 
  70.      * @var string 
  71.      * @since 1.0
  72.      */
  73.     public $name;
  74.     
  75.     /**
  76.      * The amount of rows to display by default
  77.      * 
  78.      * @var integer 
  79.      * @since 1.0
  80.      */
  81.     public $rows;
  82.     
  83.     /**
  84.      * An optional additional idenitfier to append to the id of the text box where many are on one page
  85.      * 
  86.      * @var integer 
  87.      * @since 1.0
  88.      */
  89.     public $identifier;
  90.     
  91.     /**
  92.      * The constructor
  93.      * 
  94.      * @param Text $text The text object that will be edited by this text box.
  95.      * @param string $label The data label for the text object.
  96.      * @param string $name The name of the HTML input box.
  97.      * @param integer $rows The display size (rows).
  98.      * @param integer $identifier An additional idenitfier to append to the id of the text box.
  99.      * @since 1.0
  100.      * @throws IllegalArguementException
  101.      */
  102.     public function __construct($text$label$name$rows=5$identifier=0{
  103.         if($text instanceof Text)
  104.             $this->textObject = $text;
  105.         else
  106.             throw new IllegalArguementException('Text object passed ['.var_export($texttrue).'] is not a valid Text object!');
  107.             
  108.         $this->label = $label;
  109.         $this->name = $name;
  110.         $this->rows = $rows;        
  111.         $this->identifier = $identifier;
  112.     }
  113.     
  114.     /**
  115.      * Renders the HTML and javascript for the text box
  116.      * 
  117.      * @param bool $tableTags Determines if table tags are also rendered for the TextBox
  118.      * @param bool $markdown Set to true when rendering Markdown text content fields
  119.      * @return string 
  120.      * @since 1.0
  121.      */
  122.     public function render($tableTags=true$markdown=false{
  123.         global $config;
  124.         
  125.         $html '';
  126.         
  127.         if($tableTags{
  128.             $html .= '<tr><th colspan="2" style="text-align:center;">';
  129.             $html .= $this->label;
  130.             $html .= '</th></tr>';    
  131.             
  132.             $html .= '<tr><td colspan="2">';
  133.         }
  134.         
  135.         if($markdown{
  136.             $html .= '<input type="hidden" id="markdownTextBoxRows" name="markdownTextBoxRows" value=""/>';
  137.         }
  138.         $html .= '<textarea id="text_field_'.$this->name.'_'.$this->identifier.'" style="width:100%;" rows="'.$this->rows.'" name="'.$this->name.'">';
  139.         
  140.         if($this->textObject->getAllowHTML())
  141.             $html .= InputFilter::decode($this->textObject->getValue()true);
  142.         else
  143.             $html .= InputFilter::decode($this->textObject->getValue());
  144.             
  145.         $html .= '</textarea><br>';
  146.         
  147.         if($tableTags{
  148.             $html .= '</td></tr>';
  149.             $html .= '<tr><td colspan="2">';
  150.         }
  151.         
  152.         if($markdown{
  153.             $increaseTextArea new button("document.getElementById('text_field_".$this->name."_".$this->identifier."').rows = ".
  154.                 "(parseInt(document.getElementById('text_field_".$this->name."_".$this->identifier."').rows) + 10);".
  155.                 "document.getElementById('markdownTextBoxRows').value = (parseInt(document.getElementById('text_field_".$this->name."_".$this->identifier."').rows));",
  156.                  "Increase text area"$this->name."IncBut"$config->get('sysURL')."/alpha/images/icons/arrow_down.png");
  157.         }else{
  158.             $increaseTextArea new button("document.getElementById('text_field_".$this->name."_".$this->identifier."').rows = ".
  159.                 "(parseInt(document.getElementById('text_field_".$this->name."_".$this->identifier."').rows) + 10);",
  160.                  "Increase text area"$this->name."IncBut"$config->get('sysURL')."/alpha/images/icons/arrow_down.png");
  161.         }
  162.                 
  163.         $html .= $increaseTextArea->render();
  164.         
  165.         if($markdown{
  166.             $decreaseTextArea new button("if(document.getElementById('text_field_".$this->name."_".$this->identifier."').rows > 10) ".
  167.                 "{document.getElementById('text_field_".$this->name."_".$this->identifier."').rows = (parseInt(document.getElementById('text_field_".
  168.                 $this->name."_".$this->identifier."').rows) - 10)};".
  169.                 "document.getElementById('markdownTextBoxRows').value = (parseInt(document.getElementById('text_field_".$this->name."_".$this->identifier."').rows));",
  170.                 "Decrease text area"$this->name."DecBut"$config->get('sysURL')."/alpha/images/icons/arrow_up.png");
  171.         }else{
  172.             $decreaseTextArea new button("if(document.getElementById('text_field_".$this->name."_".$this->identifier."').rows > 10) ".
  173.                 "{document.getElementById('text_field_".$this->name."_".$this->identifier."').rows = (parseInt(document.getElementById('text_field_".
  174.                 $this->name."_".$this->identifier."').rows) - 10)};",
  175.                 "Decrease text area"$this->name."DecBut"$config->get('sysURL')."/alpha/images/icons/arrow_up.png");
  176.         }
  177.         
  178.         $html .= $decreaseTextArea->render();
  179.         
  180.         if($tableTags)
  181.             $html .= '</td></tr>';
  182.  
  183.         if($this->textObject->getRule(!= ''{
  184.             $html .= '<input type="hidden" id="'.$this->name.'_msg" value="'.$this->textObject->getHelper().'"/>';
  185.             $html .= '<input type="hidden" id="'.$this->name.'_rule" value="'.$this->textObject->getRule().'"/>';
  186.         }
  187.         
  188.         return $html;
  189.     }
  190.     
  191.     /**
  192.      * Setter for text object
  193.      * 
  194.      * @param string $text 
  195.      * @since 1.0
  196.      * @throws IllegalArguementException
  197.      */
  198.     public function setTextObject($text{
  199.         if($text instanceof Text)
  200.             $this->text $text;
  201.         else
  202.             throw new IllegalArguementException('Text object passed ['.var_export($texttrue).'] is not a valid Text object!');
  203.     }
  204.  
  205.     /**
  206.      * Getter for text object
  207.      * 
  208.      * @return Text 
  209.      * @since 1.0
  210.      */
  211.     function getTextObject({
  212.         return $this->textObject;
  213.     }
  214. }
  215.  
  216. ?>

Documentation generated on Thu, 17 Mar 2011 16:45:00 +0000 by phpDocumentor 1.4.3