Lançado Adianti Framework 7.6!
Clique aqui para saber mais
tecla de atalho para botao Pessoal, to querendo criar um js para ter uma tecla de atalho (flecha para direita no meu botao save ). ...
LJ
tecla de atalho para botao  
Pessoal, to querendo criar um js para ter uma tecla de atalho (flecha para direita no meu botao save ).
  1. <?php
  2. /**
  3.  * ProductForm Registration
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage library
  8.  * @author     Pablo DallOglio
  9.  * @copyright  Copyright (c) 2006-2011 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class ProductFormLocal extends TPage
  13. {
  14.     private $form// form
  15.     /**
  16.      * Class constructor
  17.      * Creates the page and the registration form
  18.      */
  19.     function __construct()
  20.     {
  21.         parent::__construct();
  22.         //coloca o tab no 1 campo n1
  23.         TScript::create('$("input[name=\'n1\']").focus()');
  24.         
  25.         //GOSTARIA DE HABILITAR a TECLA -> (flecha Direita) 39 para o botao onSave()
  26.         //* não esta funcionando as linhas abaixo
  27.         $script2 = new TElement('script'); 
  28.         $script2->type 'text/javascript'
  29.         $javascript2 "
  30.         $(document).bind('keydown.right', function(e){$('#save').trigger('click')})
  31.         ";
  32.         /*
  33.         $javascript2 = "
  34.         $(document).bind('keydown.right', function(e){alert('Tecla de atalho com JQuery!')})
  35.         ";
  36.         */
  37.         $script2->add($javascript2);
  38.         TPage::add($script2);
  39.         
  40.         
  41.         // habilita o tab no enter
  42.         $script = new TElement('script'); 
  43.         $script->type 'text/javascript'
  44.         $javascript "     
  45.         $('body').on('keydown', 'input, select, textarea', function(e) {
  46.         var self = $(this)
  47.       , form = self.parents('form:eq(0)')
  48.       , focusable
  49.       , next
  50.       ;
  51.     if (e.keyCode == 13) {
  52.         focusable = form.find('input,a,select,button,textarea').filter(':visible');
  53.         next = focusable.eq(focusable.index(this)+1);
  54.         if (next.length) {
  55.             next.focus();
  56.         } else {
  57.             form.submit();
  58.         }
  59.         return false;
  60.     }
  61. });";
  62.         $script->add($javascript);
  63.         TPage::add($script);
  64.             
  65.         
  66.         
  67.         //loads easyzoom
  68.         TPage::include_css('app/lib/jquery/easyzoom/css/example.css');
  69.         TPage::include_css('app/lib/jquery/easyzoom/css/pygments.css');
  70.         TPage::include_css('app/lib/jquery/easyzoom/css/easyzoom.css');
  71.         
  72.         TPage::include_js('app/lib/jquery/easyzoom/js/easyzoom.js');
  73.         
  74.         TPage::include_js('app/lib/jquery/jquery.hotkeys.js');
  75.         
  76.            
  77.         
  78.         // creates the form
  79.         $this->form = new TForm('form_Product');
  80.         // creates a table
  81.         $table = new TTable;
  82.         $table_buttons = new TTable;
  83.         $table_numbers = new TTable;
  84.         
  85.          // add the table inside the form
  86.         $this->form->add($table);       
  87.    
  88.         // create the form fields
  89.         $id                     = new TEntry('id');
  90.         $name                   = new TEntry('name');
  91.         $n1            = new TEntry('n1');
  92.         $n2            = new TEntry('n2');
  93.         $n3            = new TEntry('n3');
  94.         $n4            = new TEntry('n4');
  95.         $outros               = new TCombo('outros');
  96.         
  97.        
  98.         $items      = array();
  99.         $items['ni'] = 'Nao identificado';
  100.         $items['cadeirante'] = 'Cadeirante';
  101.         $items['bike'] = 'Bike';
  102.         $items['po'] = 'Podium';
  103.         $outros->addItems($items);       
  104.         
  105.         $name->setSize(150);
  106.         $name->setProperty("tabindex","-1");
  107.         $id->setProperty("tabindex","-1");
  108.         $n1->setSize(50);
  109.         $n2->setSize(50);
  110.         $n3->setSize(50);
  111.         $n4->setSize(50);
  112.         $id->setSize(50);
  113.         $n1->setProperty("tabindex","1");
  114.         $n2->setProperty("tabindex","2");
  115.         $n3->setProperty("tabindex","3");
  116.         $n4->setProperty("tabindex","4");
  117.         $outros->setProperty("tabindex","5");
  118.         $id->setEditable(FALSE);
  119.     $name->setEditable(FALSE);
  120.     $n1->setMask('99999'); // define numeric input
  121.     $n2->setMask('99999'); // define numeric input
  122.     $n3->setMask('99999'); // define numeric input
  123.     $n4->setMask('99999');
  124.         $table->border=1;
  125.         $table->bgcolor='#f2f2f2';
  126.   
  127.       
  128.     $easydiv = new TElement('div');
  129.     $easydiv->id "easyzoom easyzoom--overlay";
  130.     $easydiv->class "easyzoom easyzoom--overlay";        
  131.         $this->imgFoto = new TElement('img');
  132.         $this->imgFoto->src "";
  133.         $this->imgFoto->style "width:300px;height:450px";
  134.         
  135.         
  136.         $this->linka = new TElement('a');
  137.         $this->linka->href "";
  138.         $this->linka->add($this->imgFoto);
  139.         
  140.         
  141.         $easydiv->add($this->linka);
  142.         
  143.         $script =new TElement('script');
  144.         $script->type 'text/javascript';
  145.         $script->add('
  146.         // Instantiate EasyZoom plugin
  147.         var $easyzoom = $(".easyzoom").easyZoom();
  148.         // Get the instance API
  149.         var api = $easyzoom.data("easyZoom");
  150.         ');
  151.         // add the script to the table
  152.         //$table->addRow()->addCell($script);
  153.         $easydiv->add($script);
  154.     //$this->form->add($script);        
  155.         
  156.     
  157.         
  158.     // tabelas com numeros
  159.     $row=$table_numbers->addRow();
  160.     $row->addCell(new TLabel('Id:'));
  161.         $cell=$row->addCell($id);
  162.         
  163.         $row=$table_numbers->addRow();
  164.     $row->addCell(new TLabel('Nome:'));
  165.     $cell=$row->addCell($name);
  166.         $row=$table_numbers->addRow();        
  167.     $cell=$row->addCell('Numeros:');
  168.         $cell->colspan=4;    
  169.     $row=$table_numbers->addRow();
  170.     $cell=$row->addCell($n1);
  171.         $cell->colspan=4;    
  172.     $row=$table_numbers->addRow();
  173.     $cell=$row->addCell($n2);
  174.         $cell->colspan=4;    
  175.     $row=$table_numbers->addRow();
  176.     $cell=$row->addCell($n3);
  177.         $cell->colspan=4;    
  178.     $row=$table_numbers->addRow();
  179.     $cell=$row->addCell($n4);
  180.         $cell->colspan=4;    
  181.     $row=$table_numbers->addRow();
  182.     $cell=$row->addCell($outros);
  183.         $cell->colspan=4;    
  184.     $row=$table_numbers->addRow();
  185.     $cell=$row->addCell($table_buttons);
  186.         $cell->colspan=4;    
  187.         // create an action button (save)
  188.         $save_button=new TButton('save');
  189.         // define the button action
  190.         $save_button->setAction(new TAction(array($this'onSave')), 'Salvar e Mantem');
  191.         $save_button->setImage('ico_save.png');
  192.     $save_button->setProperty("tabindex","6");
  193.         
  194.         
  195.          // create an action button (proximo)
  196.         $proximo_button=new TButton('proximo');
  197.         // define the button action
  198.         $proximo_button->setAction(new TAction(array($this'onProximo')), 'Salva e Proximo');
  199.         $proximo_button->setImage('ico_save.png'); 
  200.         $proximo_button->setProperty("tabindex","7");
  201.         
  202.         // create an action button (go to list)
  203.         $goto_button=new TButton('list');
  204.         // define the button action
  205.         $goto_button->setAction(new TAction(array('ProductDataGridView''onReload')), 'Listagem');
  206.         $goto_button->setImage('ico_datagrid.png');
  207.         $goto_button->setProperty("tabindex","-1");
  208.         
  209.         // create an action button (go to list)
  210.         $anterior_button=new TButton('anterior');
  211.         // define the button action
  212.         $anterior_button->setAction(new TAction(array($this'onAnterior')), 'Anterior');
  213.         $anterior_button->setImage('ico_anterior.png');  
  214.         $anterior_button->setProperty("tabindex","-1");
  215.         // create an action button (go to list)
  216.         $limpar_button=new TButton('limpar');
  217.         // define the button action
  218.         $limpar_button->setAction(new TAction(array($this'onLimpar')), 'Limpar');
  219.         $limpar_button->setImage('ico_delete.png');  
  220.         $limpar_button->setProperty("tabindex","-1");
  221.    
  222.         // create an action button (go to list)
  223.         $deletar_button=new TButton('excluir');
  224.         // define the button action
  225.         $deletar_button->setAction(new TAction(array($this'onDelete')), 'EXCLUIR');
  226.         $deletar_button->setImage('ico_delete.png');  
  227.         $deletar_button->setProperty("tabindex","-1");   
  228.         // add a row for the form action
  229.         $row=$table_buttons->addRow();
  230.         $row->addCell($save_button);
  231.         $row->addCell($proximo_button);
  232.         $row->addCell($limpar_button);
  233.         $row->addCell($anterior_button);
  234.         //$row->addCell($deletar_button);
  235.         $row->addCell($goto_button);
  236.         
  237.         
  238.         // add a row for the form action
  239.         //$row=$table->addRow();
  240.         //$cell=$row->addCell($table_buttons);
  241.         //$cell->colspan=3;
  242.         $row=$table->addRow();        
  243.         //$row->addCell($this->divFoto);
  244.         $row->addCell($easydiv);
  245.         $row->addCell($table_numbers);
  246.         // define wich are the form fields
  247.         $this->form->setFields(array($id,$name,$n1,$n2,$n3,$n4,$outros,$save_button,$anterior_button,$proximo_button,$goto_button,$limpar_button,$deletar_button));
  248.         // add the form to the page
  249.         parent::add($this->form);
  250.     }
  251.     /**
  252.      * method onSave()
  253.      * Executed whenever the user clicks at the save button
  254.      */
  255.     function onSave()
  256.     {
  257.         try
  258.         {
  259.             // open a transaction with database 'library'
  260.             TTransaction::open(TSession::getValue('iniciais'));
  261.             // get the form data into an active record Book
  262.             $object $this->form->getData('Product');
  263.             // stores the object
  264.             $object->store();
  265.             // fill the form with the active record data
  266.             // mantem n1,n2,n3,n4
  267.             //$this->form->setData($object);
  268.             
  269.             //avança para proximo
  270.             
  271.             $objectproximo = new Product($object->proximo);
  272.             if ($objectproximo->n1 == "" and $objectproximo->outros == "") {
  273.                 $objectproximo->n1 $object->n1;
  274.                 $objectproximo->n2 $object->n2;
  275.                 $objectproximo->n3 $object->n3;
  276.                 $objectproximo->n4 $object->n4;
  277.                 
  278.                 }
  279.             $this->form->setData($objectproximo);
  280.          //$this->imgFoto->src = "app/images/".$objectproximo->corrida."/".$objectproximo->name.".jpg"; 
  281.          $this->imgFoto->src "chrome-extension://".TSession::getValue('chrome')."/".$objectproximo->name.".jpg";      
  282.         $this->linka->href $this->imgFoto->src;
  283.         
  284.             // close the transaction
  285.             TTransaction::close();
  286.             // shows the success message
  287.             //new TMessage('info', 'Registro Salvo');
  288.             // reload the listing
  289.             
  290.             
  291.             
  292.             
  293.         }
  294.         catch (Exception $e// in case of exception
  295.         {
  296.             // shows the exception error message
  297.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  298.             // undo all pending operations
  299.             TTransaction::rollback();
  300.         }
  301.     }
  302.     
  303.     /**
  304.      * method onEdit()
  305.      * Executed whenever the user clicks at the edit button da datagrid
  306.      */
  307.     function onEdit($param)
  308.     {
  309.         try
  310.         {
  311.                         
  312.             if (isset($param['key']))
  313.             {
  314.                 // get the parameter $key
  315.                 $key=$param['key'];
  316.                 // open a transaction with database 'fotos'
  317.                 TTransaction::open(TSession::getValue('iniciais'));
  318.                 // instantiates object Book
  319.                 $object = new Product($key);
  320.                 // fill the form with the active record data
  321.                 $this->form->setData($object);
  322.                 
  323.                 
  324.         //$this->imgFoto->src = "../content/photopreupload/".TSession::getValue('iniciais')."/".$object->name.".jpg"; 
  325.         $this->imgFoto->src "chrome-extension://".TSession::getValue('chrome')."/".$object->name.".jpg"
  326.         $this->linka->href $this->imgFoto->src;
  327.         
  328.                 // close the transaction
  329.                 TTransaction::close();
  330.             }
  331.             else
  332.             {
  333.                 $this->form->clear();
  334.             }
  335.         }
  336.         catch (Exception $e// in case of exception
  337.         {
  338.             // shows the exception error message
  339.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  340.             // undo all pending operations
  341.             TTransaction::rollback();
  342.         }
  343.     }
  344.     function onAnterior()
  345.     {
  346.         try
  347.         {
  348.             // open a transaction with database 'library'
  349.             TTransaction::open(TSession::getValue('iniciais'));
  350.             // get the form data into an active record Book
  351.             $object $this->form->getData('Product');
  352.             // stores the object
  353.             //$object->store();
  354.             // fill the form with the active record data
  355.             //$this->form->setData($object);
  356.             
  357.             //avança para proximo
  358.             
  359.             $objectanterior = new Product($object->anterior);
  360.             $this->form->setData($objectanterior);
  361.          //$this->imgFoto->src = "app/images/".$objectanterior->corrida."/".$objectanterior->name.".jpg"; 
  362.          $this->imgFoto->src "chrome-extension://".TSession::getValue('chrome')."/".$objectanterior->name.".jpg";    
  363.          //$this->imgFoto->src = "../content/photopreupload/".TSession::getValue('iniciais')."/".$objectanterior->name.".jpg";                
  364.         $this->linka->href $this->imgFoto->src;
  365.                 
  366.             // close the transaction
  367.             TTransaction::close();
  368.             // shows the success message
  369.             //new TMessage('info', 'Registro Salvo');
  370.             // reload the listing
  371.         }        
  372.         catch (Exception $e// in case of exception
  373.         {
  374.             // shows the exception error message
  375.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  376.             // undo all pending operations
  377.             TTransaction::rollback();
  378.         }   
  379.     }    
  380.     function onProximo()
  381.     {
  382.         try
  383.         {
  384.             // open a transaction with database 'library'
  385.             TTransaction::open(TSession::getValue('iniciais'));
  386.             // get the form data into an active record Book
  387.             $object $this->form->getData('Product');
  388.             // stores the object
  389.             $object->store();
  390.             // fill the form with the active record data
  391.             //$this->form->setData($object);
  392.             
  393.             //avança para proximo
  394.             
  395.             $objectproximo = new Product($object->proximo);
  396.             $this->form->setData($objectproximo);
  397.          //$this->imgFoto->src = "app/images/".$objectproximo->corrida."/".$objectproximo->name.".jpg";
  398.          $this->imgFoto->src "chrome-extension://".TSession::getValue('chrome')."/".$objectproximo->name.".jpg";       
  399.         $this->linka->href $this->imgFoto->src;           //avança para proximo
  400.             
  401.                 
  402.             // close the transaction
  403.             TTransaction::close();
  404.             // shows the success message
  405.             //new TMessage('info', 'Registro Salvo');
  406.             // reload the listing
  407.             
  408.             
  409.             
  410.             
  411.         }        
  412.         catch (Exception $e// in case of exception
  413.         {
  414.             // shows the exception error message
  415.             //new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  416.             //new TMessage('info', $object->id);
  417.             
  418.             // undo all pending operations
  419.             TTransaction::rollback();
  420.         }
  421.     }
  422.  /**
  423.      * method onEdit()
  424.      * Executed whenever the user clicks at the edit button da datagrid
  425.      */
  426.     function onLimpar()
  427.     {
  428.         try
  429.         {
  430.                 // instantiates object Book
  431.             $object $this->form->getData('Product');
  432.         $object->n1="";
  433.         $object->n2="";
  434.         $object->n3="";
  435.         $object->n4="";
  436.         $object->outros="";
  437.         
  438.             // fill the form with the active record data
  439.             $this->form->setData($object);
  440.         //$this->imgFoto->src = "app/images/".$object->corrida."/".$object->name.".jpg"; 
  441.         $this->imgFoto->src "chrome-extension://".TSession::getValue('chrome')."/".$object->name.".jpg"
  442.         $this->linka->href $this->imgFoto->src;
  443.         }
  444.         catch (Exception $e// in case of exception
  445.         {
  446.             // shows the exception error message
  447.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  448.             // undo all pending operations
  449.             TTransaction::rollback();
  450.         }
  451.     } 
  452.     /**
  453.      * method onDelete()
  454.      * executed whenever the user clicks at the delete button
  455.      * Ask if the user really wants to delete the record
  456.      */
  457.     function onDelete()
  458.     {
  459.         // get the parameter $key
  460.         $object $this->form->getData('Product');
  461.         
  462.         $key=$object->id;
  463.         
  464.         // define two actions
  465.         $action = new TAction(array($this'Delete'));
  466.         
  467.         // define the action parameters
  468.         $action->setParameter('key'$key);
  469.         
  470.         // shows a dialog to the user
  471.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  472.     }
  473.     
  474.     /**
  475.      * method Delete()
  476.      * Delete a record
  477.      */
  478.     function Delete($param)
  479.     {
  480.         try
  481.         {
  482.             // get the parameter $key
  483.             $key=$param['key'];
  484.             // open a transaction with database 'changeman'
  485.             TTransaction::open(TSession::getValue('iniciais'));
  486.             
  487.             // instantiates object Document
  488.             $object = new Product($key);
  489.             
  490.             $objectproximo = new Product($object->proximo);
  491.             
  492.             //exclui a imagem
  493.             //unlink("app/images/".$object->corrida."/".$object->name.".jpg");
  494.             unlink("../content/photopreupload/".TSession::getValue('iniciais')."/".$object->name.".jpg");
  495.              
  496.             // deletes the object from the database
  497.             $object->delete();
  498.             
  499.             
  500.             // reload the listing
  501.             //$this->onReload();
  502.             // shows the success message
  503.   
  504.             
  505.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted'));
  506.             
  507.             
  508.             $this->form->setData($objectproximo);
  509.          //$this->imgFoto->src = "app/images/".$objectproximo->corrida."/".$objectproximo->name.".jpg"; 
  510.          $this->imgFoto->src "chrome-extension://".TSession::getValue('chrome')."/".$objectproximo->name.".jpg";      
  511.         $this->linka->href $this->imgFoto->src;           //avança para proximo    
  512.         
  513.             // close the transaction
  514.             TTransaction::close();        
  515.             
  516.         }
  517.         catch (Exception $e// in case of exception
  518.         {
  519.             // shows the exception error message
  520.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  521.             
  522.             // undo all pending operations
  523.             TTransaction::rollback();
  524.         }
  525.     } 
  526. }
  527. ?>

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (4)


LJ

em um post antigo o pablo me deu uma dica, mas não consegui aplicar:

https://www.adianti.com.br/forum/pt/view_669?tbutton-com-tecla-de-atalho-
LJ



Deu certo , fiz assim:

// habilita o tab no enter $script = new TElement('script'); $script->type = 'text/javascript'; $javascript = " $('body').on('keydown', 'input, select, textarea', function(e) { var self = $(this) , form = self.parents('form:eq(0)') , focusable , next ; if (e.keyCode == 13) { focusable = form.find('input,a,select,button,textarea').filter(':visible'); next = focusable.eq(focusable.index(this)+1); if (next.length) { next.focus(); } else { form.submit(); } return false; } if (e.keyCode == 70) { $('#tbutton_proximo').click(); return false; } if (e.keyCode == 71) { $('#tbutton_proximo').click(); return false; } if (e.keyCode == 65) { $('#tbutton_anterior').click(); return false; } if (e.keyCode == 109) { $('input[name=\'n1\'').val(''); $('input[name=\'n2\'').val(''); $('input[name=\'n3\'').val(''); $('input[name=\'n4\'').val(''); $('input[name=\'outros\'').val(''); return false; } if (e.keyCode == 111) { $('input[name=\'outros\'').val('ni'); return false; } });"; $script->add($javascript); TPage::add($script);


Dica para saber o numero das teclas: keycode.info/
LJ

DEU UM PROBLEMA:
quando inseri este javascript nesta página, alterando as teclas, quando vou para um outro form, as teclas de atalho continuam ativas no outro form ?????
como resolver isso ?
LJ

quando atualizei o framework para a versao mais recente , funcionou corretamente.