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 TIconView.php

Documentation is available at TIconView.php

  1. <?php
  2. namespace Adianti\Widget\Util;
  3.  
  4. use Adianti\Widget\Base\TElement;
  5. use Adianti\Widget\Base\TScript;
  6. use Adianti\Util\AdiantiTemplateHandler;
  7.  
  8. use stdClass;
  9.  
  10. /**
  11.  * TIconView Widget
  12.  *
  13.  * @version    7.4
  14.  * @package    widget
  15.  * @subpackage util
  16.  * @author     Pablo Dall'Oglio
  17.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  18.  * @license    http://www.adianti.com.br/framework-license
  19.  */
  20. class TIconView extends TElement
  21. {
  22.     protected $items;
  23.     protected $options;
  24.     protected $itemProperties;
  25.     protected $labelField;
  26.     protected $iconField;
  27.     protected $infoFields;
  28.     protected $popover;
  29.     protected $poptitle;
  30.     protected $popcontent;
  31.     protected $popside;
  32.     protected $popcondition;
  33.     protected $enableMoving;
  34.     protected $moveAction;
  35.     protected $dragSelector;
  36.     protected $dropSelector;
  37.     protected $itemTemplate;
  38.     protected $templateAttribute;
  39.     protected $doubleClickEnabled;
  40.     
  41.     /**
  42.      * Constructor Method
  43.      */
  44.     public function __construct()
  45.     {
  46.         parent::__construct('ul');
  47.         
  48.         $this->{'id'}    'ticonview_' mt_rand(10000000001999999999);
  49.         $this->{'class''ticonview';
  50.         $this->items   [];
  51.         $this->options [];
  52.         $this->popover FALSE;
  53.         $this->popside null;
  54.         $this->enableMoving FALSE;
  55.         $this->doubleClickEnabled FALSE;
  56.     }
  57.     
  58.     /**
  59.      * Enable double click
  60.      */
  61.     public function enableDoubleClick()
  62.     {
  63.         $this->doubleClickEnabled TRUE;
  64.     }
  65.     
  66.     /**
  67.      * Set item template for rendering
  68.      * @param  $template Template content
  69.      */
  70.     public function setItemTemplate($template)
  71.     {
  72.         $this->itemTemplate $template;
  73.     }
  74.     
  75.     /**
  76.      * Set template atribute for rendering
  77.      * @param  $attribute Template attribute
  78.      */
  79.     public function setTemplateAttribute($attribute)
  80.     {
  81.         $this->templateAttribute $attribute;
  82.     }
  83.     
  84.     /**
  85.      * Enable popover
  86.      * @param $title Title
  87.      * @param $content Content
  88.      */
  89.     public function enablePopover($title$content$popside null$popcondition null)
  90.     {
  91.         $this->popover TRUE;
  92.         $this->poptitle $title;
  93.         $this->popcontent $content;
  94.         $this->popside $popside;
  95.         $this->popcondition $popcondition;
  96.     }
  97.     
  98.     /**
  99.      * Enable move action
  100.      * @param $source_selector Source item selector
  101.      * @param $target_selector Target item selector
  102.      */
  103.     public function enableMoveAction$moveAction$source_selector$target_selector )
  104.     {
  105.         $this->enableMoving TRUE;
  106.         $this->moveAction   $moveAction;
  107.         $this->dragSelector $source_selector;
  108.         $this->dropSelector $target_selector;
  109.     }
  110.     
  111.     /**
  112.      * Set info fields
  113.      */
  114.     public function setInfoAttributes($fields)
  115.     {
  116.         $this->infoFields $fields;
  117.     }
  118.     
  119.     /**
  120.      * Add object item with data
  121.      */
  122.     public function addItem($object)
  123.     {
  124.         $this->items[$object;
  125.         
  126.         $itemProperties new StdClass;
  127.         $this->itemProperties[$itemProperties;
  128.         return $itemProperties;
  129.     }
  130.     
  131.     /**
  132.      * Define the field that will identify the icon
  133.      */
  134.     public function setIconAttribute$iconField )
  135.     {
  136.         $this->iconField $iconField;
  137.     }
  138.     
  139.     /**
  140.      * Define the field that will identify the label
  141.      */
  142.     public function setLabelAttribute$labelField )
  143.     {
  144.         $this->labelField $labelField;
  145.     }
  146.     
  147.     /**
  148.      * Add a context menu option
  149.      */
  150.     public function addContextMenuOption($label$action null$icon null/*Callable*/ $displayCondition null)
  151.     {
  152.         $this->options[[$label$action$icon$displayCondition];
  153.     }
  154.     
  155.     /**
  156.      * Show iconview items
  157.      */
  158.     public function show()
  159.     {
  160.         if ($this->items)
  161.         {
  162.             foreach ($this->items as $key => $object)
  163.             {
  164.                 $iconField      $this->iconField;
  165.                 $labelField     $this->labelField;
  166.                 $itemProperties $this->itemProperties[$key];
  167.                 $first_action null;
  168.                 
  169.                 $li new TElement('li');
  170.                 
  171.                 // set info data in the root element for things like fuse search
  172.                 if ($this->infoFields)
  173.                 {
  174.                     foreach ($this->infoFields as $infoField)
  175.                     {
  176.                         $li->$infoField = isset($object->{$infoField}$object->{$infoFieldNULL;
  177.                         $li->{"data-{$infoField}"= isset($object->{$infoField}$object->{$infoFieldNULL;
  178.                     }
  179.                 }
  180.                 
  181.                 if ($itemProperties)
  182.                 {
  183.                     foreach ($itemProperties as $item_prop_name => $item_prop_value)
  184.                     {
  185.                         $li->$item_prop_name $item_prop_value;
  186.                     }
  187.                 }
  188.                 
  189.                 if (empty($li->{'id'}))
  190.                 {
  191.                     $li->{'id''ticonitem_' mt_rand(10000000001999999999);
  192.                 }
  193.                 
  194.                 $id $li->{'id'};
  195.                 
  196.                 if ($this->popover && (empty($this->popconditionOR call_user_func($this->popcondition$object)))
  197.                 {
  198.                     $poptitle   $this->poptitle;
  199.                     $popcontent $this->popcontent;
  200.                     $poptitle   AdiantiTemplateHandler::replace($poptitle$object);
  201.                     $popcontent AdiantiTemplateHandler::replace($popcontent$objectnulltrue);
  202.                     
  203.                     $li->{'popover''true';
  204.                     $li->{'poptitle'$poptitle;
  205.                     $li->{'popcontent'htmlspecialchars(str_replace("\n"''nl2br($popcontent)));
  206.                     
  207.                     if ($this->popside)
  208.                     {
  209.                         $li->{'popside'$this->popside;
  210.                     }
  211.                 }
  212.                 
  213.                 if (!empty($object->{$this->templateAttribute}))
  214.                 {
  215.                     $item_content new TElement('div');
  216.                     $item_content->add(AdiantiTemplateHandler::replace($object->{$this->templateAttribute}$object));
  217.                     $li->add($item_content);
  218.                 }
  219.                 else if (!empty($this->itemTemplate))
  220.                 {
  221.                     $item_content new TElement('div');
  222.                     $item_content->add(AdiantiTemplateHandler::replace($this->itemTemplate$object));
  223.                     $li->add($item_content);
  224.                 }
  225.                 else
  226.                 {
  227.                     $item_wrapper new TElement('div');
  228.                     $item_wrapper->add(new TImage($object->$iconField));
  229.                     $item_wrapper->add(TElement::tag('span'$object->$labelField));
  230.                     
  231.                     $li->add($item_wrapper);
  232.                 }
  233.                 
  234.                 parent::add($li);
  235.                 
  236.                 if ($this->options)
  237.                 {
  238.                     $dropdown new TElement('ul');
  239.                     $dropdown->{'class''dropdown-menu pull-left dropdown-iconview';
  240.                     $dropdown->{'style''position:absolute; display:none;';
  241.                     
  242.                     foreach ($this->options as $index => $option)
  243.                     {
  244.                         $action_label     $option[0];
  245.                         $action_template  $option[1];
  246.                         $action_icon      $option[2];
  247.                         $action_condition $option[3];
  248.                         
  249.                         if ($action_template)
  250.                         {
  251.                             $item_action clone $action_template;
  252.                             
  253.                             if ($this->infoFields)
  254.                             {
  255.                                 foreach ($this->infoFields as $infoField)
  256.                                 {
  257.                                     $info_data = isset($object->{$infoField}$object->{$infoFieldNULL;
  258.                                     $item_action->setParameter($infoField"{$object->$infoField}");
  259.                                 }
  260.                             }
  261.                             $action $item_action->prepare($object);
  262.                             
  263.                             if (empty($action_conditionOR call_user_func($action_condition$object))
  264.                             {
  265.                                 $option_li new TElement('li');
  266.                                 $option_link new TElement('a');
  267.                                 $option_link->{'onclick'"__adianti_load_page('{$action->serialize()}');";
  268.                                 $option_link->{'style''cursor: pointer';
  269.                                 
  270.                                 if ($action_icon)
  271.                                 {
  272.                                     $image is_object($action_iconclone $action_icon new TImage($action_icon);
  273.                                     $image->{'style'.= ';padding: 4px';
  274.                                     $option_link->add($image);
  275.                                 }
  276.                                 
  277.                                 $span TElement::tag('span'$action_label);
  278.                                 $option_link->add($span);
  279.                                 $option_li->add($option_link);
  280.                                 
  281.                                 $dropdown->add($option_li);
  282.                                 
  283.                                 if (empty($first_action))
  284.                                 {
  285.                                     $first_action $action;
  286.                                 }
  287.                             }
  288.                         }
  289.                         else
  290.                         {
  291.                             if ($action_label)
  292.                             {
  293.                                 $dropdown->add(TElement::tag('li'$action_label['role'=>'presentation''class'=>'dropdown-header']));
  294.                             }
  295.                             else
  296.                             {
  297.                                 $dropdown->add(TElement::tag('li'''['class'=>'divider']));
  298.                             }
  299.                         }
  300.                     }
  301.                     
  302.                     parent::add($dropdown);
  303.                     $li->add(TScript::create("ticonview_contextmenu_start('{$id}')"false));
  304.                     
  305.                     if ($first_action)
  306.                     {
  307.                         if ($this->doubleClickEnabled)
  308.                         {
  309.                             $li->{'ondblclick'"__adianti_load_page('{$first_action->serialize()}');";
  310.                         }
  311.                         else
  312.                         {
  313.                             $li->{'href'}      $first_action->serialize();
  314.                         }
  315.                         $li->{'generator''adianti';
  316.                     }
  317.                 }
  318.             }
  319.         }
  320.         
  321.         if ($this->enableMoving)
  322.         {
  323.             $wrapper_id $this->{'id'};
  324.             $source_selectors [];
  325.             $source_not_selectors [];
  326.             $target_selectors [];
  327.             
  328.             if ($this->dragSelector)
  329.             {
  330.                 foreach ($this->dragSelector as $key => $value)
  331.                 {
  332.                     if (is_array($value))
  333.                     {
  334.                         foreach ($value as $val)
  335.                         {
  336.                             if (substr($val,0,1== '!')
  337.                             {
  338.                                 $val substr($val,1);
  339.                                 $source_not_selectors["[{$key}!=\"{$val}\"]";
  340.                             }
  341.                             else
  342.                             {
  343.                                 $source_selectors["[{$key}=\"{$val}\"]";
  344.                             }
  345.                         }
  346.                     }
  347.                     else
  348.                     {
  349.                         if (substr($value,0,1== '!')
  350.                         {
  351.                             $value substr($value,1);
  352.                             $source_not_selectors["[{$key}!=\"{$value}\"]";
  353.                         }
  354.                         else
  355.                         {
  356.                             $source_selectors["[{$key}=\"{$value}\"]";
  357.                         }
  358.                     }
  359.                 }
  360.             }
  361.             
  362.             if ($this->dropSelector)
  363.             {
  364.                 foreach ($this->dropSelector as $key => $value)
  365.                 {
  366.                     if (is_array($value))
  367.                     {
  368.                         foreach ($value as $val)
  369.                         {
  370.                             $target_selectors["[{$key}=\"{$val}\"]";
  371.                         }
  372.                     }
  373.                     else
  374.                     {
  375.                         $target_selectors["[{$key}=\"{$value}\"]";
  376.                     }
  377.                 }
  378.             }
  379.             
  380.             $source_not_selector_string implode(''$source_not_selectors);
  381.             $source_selector_string implode$source_not_selector_string ','$source_selectors$source_not_selector_string;
  382.             
  383.             $target_selector_string implode(','$target_selectors);
  384.             $move_action_string $this->moveAction->serialize();
  385.             
  386.             parent::add(TScript::create("ticonview_move_start( '{$wrapper_id}', '{$move_action_string}', '{$source_selector_string}', '{$target_selector_string}' )"false));
  387.         }
  388.         
  389.         parent::add(TScript::create('ticonview_bind_click()'false));
  390.         parent::show();
  391.     }
  392. }