Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TNotebook.php

Documentation is available at TNotebook.php

  1. <?php
  2. namespace Adianti\Widget\Container;
  3.  
  4. use Adianti\Control\TAction;
  5. use Adianti\Widget\Base\TElement;
  6. use Adianti\Widget\Container\TTable;
  7. use Adianti\Widget\Container\TFrame;
  8.  
  9. /**
  10.  * Notebook
  11.  *
  12.  * @version    7.4
  13.  * @package    widget
  14.  * @subpackage container
  15.  * @author     Pablo Dall'Oglio
  16.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  17.  * @license    http://www.adianti.com.br/framework-license
  18.  */
  19. class TNotebook extends TElement
  20. {
  21.     private $width;
  22.     private $height;
  23.     private $currentPage;
  24.     private $pages;
  25.     private $counter;
  26.     private $id;
  27.     private $tabAction;
  28.     private $tabsVisibility;
  29.     private $tabsSensibility;
  30.     private $container;
  31.     private static $noteCounter;
  32.     
  33.     /**
  34.      * Class Constructor
  35.      * @param $width   Notebook's width
  36.      * @param $height  Notebook's height
  37.      */
  38.     public function __construct($width null$height null)
  39.     {
  40.         parent::__construct('div');
  41.         $this->id 'tnotebook_' mt_rand(10000000001999999999);
  42.         $this->counter = ++ self::$noteCounter;
  43.         
  44.         // define some default values
  45.         $this->pages [];
  46.         $this->width $width;
  47.         $this->height $height;
  48.         $this->currentPage 0;
  49.         $this->tabsVisibility TRUE;
  50.         $this->tabsSensibility TRUE;
  51.     }
  52.     
  53.     /**
  54.      * Define if the tabs will be visible or not
  55.      * @param $visible If the tabs will be visible
  56.      */
  57.     public function setTabsVisibility($visible)
  58.     {
  59.         $this->tabsVisibility $visible;
  60.     }
  61.     
  62.     /**
  63.      * Define the tabs click sensibility
  64.      * @param $sensibility If the tabs will be sensible to click
  65.      */
  66.     public function setTabsSensibility($sensibility)
  67.     {
  68.         $this->tabsSensibility $sensibility;
  69.     }
  70.     
  71.     /**
  72.      * Returns the element ID
  73.      */
  74.     public function getId()
  75.     {
  76.         return $this->id;
  77.     }
  78.     
  79.     /**
  80.      * Set the notebook size
  81.      * @param $width  Notebook's width
  82.      * @param $height Notebook's height
  83.      */
  84.     public function setSize($width$height)
  85.     {
  86.         // define the width and height
  87.         $this->width  $width;
  88.         $this->height $height;
  89.     }
  90.     
  91.     /**
  92.      * Returns the frame size
  93.      * @return array(width, height)
  94.      */
  95.     public function getSize()
  96.     {
  97.         return array($this->width$this->height);
  98.     }
  99.     
  100.     /**
  101.      * Define the current page to be shown
  102.      * @param $i An integer representing the page number (start at 0)
  103.      */
  104.     public function setCurrentPage($i)
  105.     {
  106.         // atribui a página corrente
  107.         $this->currentPage $i;
  108.     }
  109.     
  110.     /**
  111.      * Returns the current page
  112.      */
  113.     public function getCurrentPage()
  114.     {
  115.         return $this->currentPage;
  116.     }
  117.     
  118.     /**
  119.      * Add a tab to the notebook
  120.      * @param $title   tab's title
  121.      * @param $object  tab's content
  122.      */
  123.     public function appendPage($title$object)
  124.     {
  125.         $this->pages[$title$object;
  126.     }
  127.  
  128.     /**
  129.      * Return the Page count
  130.      */
  131.     public function getPageCount()
  132.     {
  133.         return count($this->pages);
  134.     }
  135.     
  136.     /**
  137.      * Define the action for the Notebook tab
  138.      * @param $action Action taken when the user
  139.      *  clicks over Notebook tab (A TAction object)
  140.      */
  141.     public function setTabAction(TAction $action)
  142.     {
  143.         $this->tabAction $action;
  144.     }
  145.     
  146.     /**
  147.      * Render the notebook
  148.      */
  149.     public function render()
  150.     {
  151.         // count the pages
  152.         $pages $this->getPageCount();
  153.         
  154.         $this->container new TElement('div');
  155.         if ($this->width)
  156.         {
  157.             $this->container->{'style'";min-width:{$this->width}px";
  158.         }
  159.         $this->container->{'class'} = 'tnotebook';
  160.         
  161.         $ul = new <a href="widget/base/TElement.html">TElement</a>('ul');
  162.         $ul->{'class'} = 'nav nav-tabs';
  163.         $this->container->add($ul);
  164.         
  165.         $space = new TElement('div');
  166.         if ($this->width)
  167.         {
  168.             $space->{'style'} = "min-width:{$this->width}px";
  169.         }
  170.         $space->{'class'} = 'spacer';
  171.         $this->container->add($space);
  172.         
  173.         $i = 0;
  174.         $id = $this->id;
  175.         
  176.         
  177.         if ($this->pages)
  178.         {
  179.             // iterate the tabs, showing them
  180.             foreach ($this->pages as $title => $content)
  181.             {
  182.                 // verify if the current page is to be shown
  183.                 $classe = ($i == $this->currentPage) ? 'active' : '';
  184.                 
  185.                 // add a cell for this tab
  186.                 if ($this->tabsVisibility)
  187.                 {
  188.                     $item = new <a href="widget/base/TElement.html">TElement</a>('li');
  189.                     $link = new <a href="widget/base/TElement.html">TElement</a>('a');
  190.                     $link->{'aria-controls'} = "home";
  191.                     $link->{'role'} = "tab";
  192.                     $link->{'data-toggle'} = "tab";
  193.                     $link->{'href'} = "#"."panel_{$id}_{$i}";
  194.                     $link->{'class'} = $classe . " nav-link";
  195.                     
  196.                     if (!$this->tabsSensibility)
  197.                     {
  198.                         $link->{'style'} = "pointer-events:none";
  199.                     }
  200.                     
  201.                     $item->add($link);
  202.                     $link->add("$title");
  203.                     $item->{'class'} = $classe . " nav-item";
  204.                     $item->{'role'} = "presentation";
  205.                     $item->{'id'} = "tab_{$id}_{$i}";
  206.                     
  207.                     if ($this->tabAction)
  208.                     {
  209.                         $this->tabAction->setParameter('current_page', $i+1);
  210.                         $string_action = $this->tabAction->serialize(FALSE);
  211.                         $link-> onclick = "__adianti_ajax_exec('$string_action')";
  212.                     }
  213.                     
  214.                     $ul->add($item);
  215.                     $i ++;
  216.                 }
  217.             }
  218.         }
  219.         
  220.         // creates a <div> around the content
  221.         $quadro = new TElement('div');
  222.         $quadro->{'class'} = 'frame tab-content';
  223.         
  224.         $width = $this->width;
  225.         $height$this->height;// -30;
  226.         
  227.         if ($width)
  228.         {
  229.             $quadro->{'style'} .= ";min-width:{$width}px";
  230.         }
  231.         
  232.         if($height)
  233.         {
  234.             $quadro->{'style'} .= ";min-height:{$height}px";
  235.         }
  236.         
  237.         $i = 0;
  238.         // iterate the tabs again, now to show the content
  239.         if ($this->pages)
  240.         {
  241.             foreach ($this->pages as $title => $content)
  242.             {
  243.                 $panelClass = ($i == $this->currentPage) ? 'active''';
  244.                 
  245.                 // creates a <div> for the contents
  246.                 $panel = new <a href="widget/base/TElement.html">TElement</a>('div');
  247.                 $panel->{'role'}  = "tabpanel";
  248.                 $panel->{'class'} = "tab-pane " . $panelClass;
  249.                 $panel->{'id'}    = "panel_{$id}_{$i}"; // ID
  250.                 $quadro->add($panel);
  251.                 
  252.                 // check if the content is an object
  253.                 if (is_object($content))
  254.                 {
  255.                     $panel->add($content);
  256.                 }
  257.                 
  258.                 $i ++;
  259.             }
  260.         }
  261.         
  262.         $this->container->add($quadro);
  263.         return $this->container;
  264.     }
  265.     
  266.     /**
  267.      * Show the notebook
  268.      */
  269.     public function show()
  270.     {
  271.         if (empty($this->container))
  272.         {
  273.             $this->container = $this->render();
  274.         }
  275.         parent::add($this->container);
  276.         parent::show();
  277.     }