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

Documentation is available at TJQueryDialog.php

  1. <?php
  2. namespace Adianti\Widget\Container;
  3.  
  4. use Adianti\Control\TAction;
  5. use Adianti\Widget\Base\TElement;
  6. use Adianti\Widget\Base\TScript;
  7. use Adianti\Core\AdiantiCoreTranslator;
  8. use Exception;
  9.  
  10. /**
  11.  * JQuery dialog container
  12.  *
  13.  * @version    7.4
  14.  * @package    widget
  15.  * @subpackage container
  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 TJQueryDialog extends TElement
  21. {
  22.     private $actions;
  23.     private $width;
  24.     private $height;
  25.     private $top;
  26.     private $left;
  27.     private $modal;
  28.     private $draggable;
  29.     private $resizable;
  30.     private $useOKButton;
  31.     private $stackOrder;
  32.     private $closeAction;
  33.     private $closeEscape;
  34.     private $dialogClass;
  35.     
  36.     /**
  37.      * Class Constructor
  38.      * @param $name Name of the widget
  39.      */
  40.     public function __construct()
  41.     {
  42.         parent::__construct('div');
  43.         $this->useOKButton TRUE;
  44.         $this->top NULL;
  45.         $this->left NULL;
  46.         $this->modal 'true';
  47.         $this->draggable 'true';
  48.         $this->resizable 'true';
  49.         $this->stackOrder 2000;
  50.         $this->closeEscape true;
  51.         $this->dialogClass '';
  52.         
  53.         $this->{'id''jquery_dialog_'.mt_rand(10000000001999999999);
  54.         $this->{'style'"overflow:auto";
  55.     }
  56.     
  57.     /**
  58.      * Disable close on escape
  59.      */
  60.     public function disableEscape()
  61.     {
  62.         $this->closeEscape false;
  63.     }
  64.     
  65.     /**
  66.      * Disable scrolling
  67.      */
  68.     public function disableScrolling()
  69.     {
  70.         $this->{'style'"overflow: hidden";
  71.     }
  72.     
  73.     /**
  74.      * Set Dialog class
  75.      * @param $class Class name
  76.      */
  77.     public function setDialogClass($class)
  78.     {
  79.         $this->dialogClass $class;
  80.     }
  81.     
  82.     /**
  83.      * Set close action
  84.      */
  85.     public function setCloseAction(TAction $action)
  86.     {
  87.         if ($action->isStatic())
  88.         {
  89.             $this->closeAction $action;
  90.         }
  91.         else
  92.         {
  93.             $string_action $action->toString();
  94.             throw new Exception(AdiantiCoreTranslator::translate('Action (^1) must be static to be used in ^2'$string_action__METHOD__));
  95.         }
  96.     }
  97.     
  98.     /**
  99.      * Define if will use OK Button
  100.      * @param $bool boolean
  101.      */
  102.     public function setUseOKButton($bool)
  103.     {
  104.         $this->useOKButton $bool;
  105.     }
  106.     
  107.     /**
  108.      * Define the dialog title
  109.      * @param $title title
  110.      */
  111.     public function setTitle($title)
  112.     {
  113.         $this->{'title'$title;
  114.     }
  115.     
  116.     /**
  117.      * Turn on/off modal
  118.      * @param $modal Boolean
  119.      */
  120.     public function setModal($bool)
  121.     {
  122.         $this->modal $bool 'true' 'false';
  123.     }
  124.     
  125.     /**
  126.      * Turn on/off resizeable
  127.      * @param $bool Boolean
  128.      */
  129.     public function setResizable($bool)
  130.     {
  131.         $this->resizable $bool 'true' 'false';
  132.     }
  133.     
  134.     /**
  135.      * Turn on/off draggable
  136.      * @param $bool Boolean
  137.      */
  138.     public function setDraggable($bool)
  139.     {
  140.         $this->draggable $bool 'true' 'false';
  141.     }
  142.     
  143.     /**
  144.      * Returns the element ID
  145.      */
  146.     public function getId()
  147.     {
  148.         return $this->{'id'};
  149.     }
  150.     
  151.     /**
  152.      * Define the dialog size
  153.      * @param $width width
  154.      * @param $height height
  155.      */
  156.     public function setSize($width$height)
  157.     {
  158.         $this->width  $width  "\$(window).width() * $width$width;
  159.         
  160.         if (is_null($height))
  161.         {
  162.             $this->height "'auto'";
  163.         }
  164.         else
  165.         {
  166.             $this->height $height "\$(window).height() * $height$height;
  167.         }
  168.     }
  169.     
  170.     /**
  171.      * Define the window's min width between percent and absolute
  172.      * @param  $percent width
  173.      * @param  $absolute width
  174.      */
  175.     public function setMinWidth($percent$absolute)
  176.     {
  177.         $this->width  "Math.min(\$(window).width() * $percent$absolute)";
  178.     }
  179.     
  180.     /**
  181.      * Define the dialog position
  182.      * @param $left left
  183.      * @param $top top
  184.      */
  185.     public function setPosition($left$top)
  186.     {
  187.         $this->left $left;
  188.         $this->top  $top;
  189.     }
  190.     
  191.     /**
  192.      * Add a JS button to the dialog
  193.      * @param $label button label
  194.      * @param $action JS action
  195.      */
  196.     public function addAction($label$action)
  197.     {
  198.         $this->actions[array($label$action);
  199.     }
  200.     
  201.     /**
  202.      * Define the stack order (zIndex)
  203.      * @param $order Stack order
  204.      */
  205.     public function setStackOrder($order)
  206.     {
  207.         $this->stackOrder $order;
  208.     }
  209.     
  210.     /**
  211.      * Shows the widget at the screen
  212.      */
  213.     public function show()
  214.     {
  215.         $action_code '';
  216.         if ($this->actions)
  217.         {
  218.             foreach ($this->actions as $action_array)
  219.             {
  220.                 $label  $action_array[0];
  221.                 $action $action_array[1];
  222.                 $action_code .= "\"{$label}\": function() {  $action },";
  223.             }
  224.         }
  225.         
  226.         $ok_button '';
  227.         if ($this->useOKButton)
  228.         {
  229.             $ok_button '  OK: function() { $( this ).remove(); }';
  230.         }
  231.         
  232.         $left $this->left $this->left 0;
  233.         $top  $this->top  $this->top  0;
  234.         
  235.         $pos_string '';
  236.         $id $this->{'id'};
  237.         
  238.         $close_action 'undefined'// cannot be function, because it is tested inside tjquerydialog.js
  239.         
  240.         if (isset($this->closeAction))
  241.         {
  242.             $string_action $this->closeAction->serialize(FALSE);
  243.             $close_action "function() { __adianti_ajax_exec('{$string_action}') }";
  244.         }
  245.         
  246.         $close_on_escape $this->closeEscape 'true' 'false';
  247.         parent::add(TScript::create("tjquerydialog_start( '#{$id}', {$this->modal}, {$this->draggable}, {$this->resizable}, {$this->width}, {$this->height}, {$top}, {$left}, {$this->stackOrder}, { {$action_code} {$ok_button} }, $close_action$close_on_escape, '{$this->dialogClass}' ); "FALSE));
  248.         parent::show();
  249.     }
  250.     
  251.     /**
  252.      * Closes the dialog
  253.      */
  254.     public function close()
  255.     {
  256.         parent::add(TScript::create('$( "#' $this->{'id''" ).remove();'false));
  257.     }
  258.     
  259.     /**
  260.      * Close window by id
  261.      */
  262.     public static function closeById($id)
  263.     {
  264.         TScript::create('$( "#' $id '" ).remove();');
  265.     }
  266.     
  267.     /**
  268.      * Close all TJQueryDialog
  269.      */
  270.     public static function closeAll()
  271.     {
  272.         if (!isset($_REQUEST['ajax_lookup']OR $_REQUEST['ajax_lookup'!== '1')
  273.         {
  274.             // it has to be inline (not external function call)
  275.             TScript::create' $(\'[widget="TWindow"]\').remove(); ' );
  276.         }
  277.     }
  278.     
  279.     /**
  280.      * Close all TJQueryDialog
  281.      */
  282.     public static function closeLatest()
  283.     {
  284.         if (!isset($_REQUEST['ajax_lookup']OR $_REQUEST['ajax_lookup'!== '1')
  285.         {
  286.             // it has to be inline (not external function call)
  287.             TScript::create' $(\'[role=window-wrapper]\').last().remove(); ' );
  288.         }
  289.     }
  290. }