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 ).
- <?php
- /**
- * ProductForm Registration
- *
- * @version 1.0
- * @package samples
- * @subpackage library
- * @author Pablo DallOglio
- * @copyright Copyright (c) 2006-2011 Adianti Solutions Ltd. (http://www.adianti.com.br)
- * @license http://www.adianti.com.br/framework-license
- */
- class ProductFormLocal extends TPage
- {
- private $form; // form
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- //coloca o tab no 1 campo n1
- TScript::create('$("input[name=\'n1\']").focus()');
- //GOSTARIA DE HABILITAR a TECLA -> (flecha Direita) 39 para o botao onSave()
- //* não esta funcionando as linhas abaixo
- $script2 = new TElement('script');
- $script2->type = 'text/javascript';
- $javascript2 = "
- $(document).bind('keydown.right', function(e){$('#save').trigger('click')})
- ";
- /*
- $javascript2 = "
- $(document).bind('keydown.right', function(e){alert('Tecla de atalho com JQuery!')})
- ";
- */
- $script2->add($javascript2);
- TPage::add($script2);
- // 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;
- }
- });";
- $script->add($javascript);
- TPage::add($script);
- //loads easyzoom
- TPage::include_css('app/lib/jquery/easyzoom/css/example.css');
- TPage::include_css('app/lib/jquery/easyzoom/css/pygments.css');
- TPage::include_css('app/lib/jquery/easyzoom/css/easyzoom.css');
- TPage::include_js('app/lib/jquery/easyzoom/js/easyzoom.js');
- TPage::include_js('app/lib/jquery/jquery.hotkeys.js');
- // creates the form
- $this->form = new TForm('form_Product');
- // creates a table
- $table = new TTable;
- $table_buttons = new TTable;
- $table_numbers = new TTable;
- // add the table inside the form
- $this->form->add($table);
- // create the form fields
- $id = new TEntry('id');
- $name = new TEntry('name');
- $n1 = new TEntry('n1');
- $n2 = new TEntry('n2');
- $n3 = new TEntry('n3');
- $n4 = new TEntry('n4');
- $outros = new TCombo('outros');
- $items = array();
- $items['ni'] = 'Nao identificado';
- $items['cadeirante'] = 'Cadeirante';
- $items['bike'] = 'Bike';
- $items['po'] = 'Podium';
- $outros->addItems($items);
- $name->setSize(150);
- $name->setProperty("tabindex","-1");
- $id->setProperty("tabindex","-1");
- $n1->setSize(50);
- $n2->setSize(50);
- $n3->setSize(50);
- $n4->setSize(50);
- $id->setSize(50);
- $n1->setProperty("tabindex","1");
- $n2->setProperty("tabindex","2");
- $n3->setProperty("tabindex","3");
- $n4->setProperty("tabindex","4");
- $outros->setProperty("tabindex","5");
- $id->setEditable(FALSE);
- $name->setEditable(FALSE);
- $n1->setMask('99999'); // define numeric input
- $n2->setMask('99999'); // define numeric input
- $n3->setMask('99999'); // define numeric input
- $n4->setMask('99999');
- $table->border=1;
- $table->bgcolor='#f2f2f2';
- $easydiv = new TElement('div');
- $easydiv->id = "easyzoom easyzoom--overlay";
- $easydiv->class = "easyzoom easyzoom--overlay";
- $this->imgFoto = new TElement('img');
- $this->imgFoto->src = "";
- $this->imgFoto->style = "width:300px;height:450px";
- $this->linka = new TElement('a');
- $this->linka->href = "";
- $this->linka->add($this->imgFoto);
- $easydiv->add($this->linka);
- $script =new TElement('script');
- $script->type = 'text/javascript';
- $script->add('
- // Instantiate EasyZoom plugin
- var $easyzoom = $(".easyzoom").easyZoom();
- // Get the instance API
- var api = $easyzoom.data("easyZoom");
- ');
- // add the script to the table
- //$table->addRow()->addCell($script);
- $easydiv->add($script);
- //$this->form->add($script);
- // tabelas com numeros
- $row=$table_numbers->addRow();
- $row->addCell(new TLabel('Id:'));
- $cell=$row->addCell($id);
- $row=$table_numbers->addRow();
- $row->addCell(new TLabel('Nome:'));
- $cell=$row->addCell($name);
- $row=$table_numbers->addRow();
- $cell=$row->addCell('Numeros:');
- $cell->colspan=4;
- $row=$table_numbers->addRow();
- $cell=$row->addCell($n1);
- $cell->colspan=4;
- $row=$table_numbers->addRow();
- $cell=$row->addCell($n2);
- $cell->colspan=4;
- $row=$table_numbers->addRow();
- $cell=$row->addCell($n3);
- $cell->colspan=4;
- $row=$table_numbers->addRow();
- $cell=$row->addCell($n4);
- $cell->colspan=4;
- $row=$table_numbers->addRow();
- $cell=$row->addCell($outros);
- $cell->colspan=4;
- $row=$table_numbers->addRow();
- $cell=$row->addCell($table_buttons);
- $cell->colspan=4;
- // create an action button (save)
- $save_button=new TButton('save');
- // define the button action
- $save_button->setAction(new TAction(array($this, 'onSave')), 'Salvar e Mantem');
- $save_button->setImage('ico_save.png');
- $save_button->setProperty("tabindex","6");
- // create an action button (proximo)
- $proximo_button=new TButton('proximo');
- // define the button action
- $proximo_button->setAction(new TAction(array($this, 'onProximo')), 'Salva e Proximo');
- $proximo_button->setImage('ico_save.png');
- $proximo_button->setProperty("tabindex","7");
- // create an action button (go to list)
- $goto_button=new TButton('list');
- // define the button action
- $goto_button->setAction(new TAction(array('ProductDataGridView', 'onReload')), 'Listagem');
- $goto_button->setImage('ico_datagrid.png');
- $goto_button->setProperty("tabindex","-1");
- // create an action button (go to list)
- $anterior_button=new TButton('anterior');
- // define the button action
- $anterior_button->setAction(new TAction(array($this, 'onAnterior')), 'Anterior');
- $anterior_button->setImage('ico_anterior.png');
- $anterior_button->setProperty("tabindex","-1");
- // create an action button (go to list)
- $limpar_button=new TButton('limpar');
- // define the button action
- $limpar_button->setAction(new TAction(array($this, 'onLimpar')), 'Limpar');
- $limpar_button->setImage('ico_delete.png');
- $limpar_button->setProperty("tabindex","-1");
- // create an action button (go to list)
- $deletar_button=new TButton('excluir');
- // define the button action
- $deletar_button->setAction(new TAction(array($this, 'onDelete')), 'EXCLUIR');
- $deletar_button->setImage('ico_delete.png');
- $deletar_button->setProperty("tabindex","-1");
- // add a row for the form action
- $row=$table_buttons->addRow();
- $row->addCell($save_button);
- $row->addCell($proximo_button);
- $row->addCell($limpar_button);
- $row->addCell($anterior_button);
- //$row->addCell($deletar_button);
- $row->addCell($goto_button);
- // add a row for the form action
- //$row=$table->addRow();
- //$cell=$row->addCell($table_buttons);
- //$cell->colspan=3;
- $row=$table->addRow();
- //$row->addCell($this->divFoto);
- $row->addCell($easydiv);
- $row->addCell($table_numbers);
- // define wich are the form fields
- $this->form->setFields(array($id,$name,$n1,$n2,$n3,$n4,$outros,$save_button,$anterior_button,$proximo_button,$goto_button,$limpar_button,$deletar_button));
- // add the form to the page
- parent::add($this->form);
- }
- /**
- * method onSave()
- * Executed whenever the user clicks at the save button
- */
- function onSave()
- {
- try
- {
- // open a transaction with database 'library'
- TTransaction::open(TSession::getValue('iniciais'));
- // get the form data into an active record Book
- $object = $this->form->getData('Product');
- // stores the object
- $object->store();
- // fill the form with the active record data
- // mantem n1,n2,n3,n4
- //$this->form->setData($object);
- //avança para proximo
- $objectproximo = new Product($object->proximo);
- if ($objectproximo->n1 == "" and $objectproximo->outros == "") {
- $objectproximo->n1 = $object->n1;
- $objectproximo->n2 = $object->n2;
- $objectproximo->n3 = $object->n3;
- $objectproximo->n4 = $object->n4;
- }
- $this->form->setData($objectproximo);
- //$this->imgFoto->src = "app/images/".$objectproximo->corrida."/".$objectproximo->name.".jpg";
- $this->imgFoto->src = "chrome-extension://".TSession::getValue('chrome')."/".$objectproximo->name.".jpg";
- $this->linka->href = $this->imgFoto->src;
- // close the transaction
- TTransaction::close();
- // shows the success message
- //new TMessage('info', 'Registro Salvo');
- // reload the listing
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * method onEdit()
- * Executed whenever the user clicks at the edit button da datagrid
- */
- function onEdit($param)
- {
- try
- {
- if (isset($param['key']))
- {
- // get the parameter $key
- $key=$param['key'];
- // open a transaction with database 'fotos'
- TTransaction::open(TSession::getValue('iniciais'));
- // instantiates object Book
- $object = new Product($key);
- // fill the form with the active record data
- $this->form->setData($object);
- //$this->imgFoto->src = "../content/photopreupload/".TSession::getValue('iniciais')."/".$object->name.".jpg";
- $this->imgFoto->src = "chrome-extension://".TSession::getValue('chrome')."/".$object->name.".jpg";
- $this->linka->href = $this->imgFoto->src;
- // close the transaction
- TTransaction::close();
- }
- else
- {
- $this->form->clear();
- }
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- function onAnterior()
- {
- try
- {
- // open a transaction with database 'library'
- TTransaction::open(TSession::getValue('iniciais'));
- // get the form data into an active record Book
- $object = $this->form->getData('Product');
- // stores the object
- //$object->store();
- // fill the form with the active record data
- //$this->form->setData($object);
- //avança para proximo
- $objectanterior = new Product($object->anterior);
- $this->form->setData($objectanterior);
- //$this->imgFoto->src = "app/images/".$objectanterior->corrida."/".$objectanterior->name.".jpg";
- $this->imgFoto->src = "chrome-extension://".TSession::getValue('chrome')."/".$objectanterior->name.".jpg";
- //$this->imgFoto->src = "../content/photopreupload/".TSession::getValue('iniciais')."/".$objectanterior->name.".jpg";
- $this->linka->href = $this->imgFoto->src;
- // close the transaction
- TTransaction::close();
- // shows the success message
- //new TMessage('info', 'Registro Salvo');
- // reload the listing
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- function onProximo()
- {
- try
- {
- // open a transaction with database 'library'
- TTransaction::open(TSession::getValue('iniciais'));
- // get the form data into an active record Book
- $object = $this->form->getData('Product');
- // stores the object
- $object->store();
- // fill the form with the active record data
- //$this->form->setData($object);
- //avança para proximo
- $objectproximo = new Product($object->proximo);
- $this->form->setData($objectproximo);
- //$this->imgFoto->src = "app/images/".$objectproximo->corrida."/".$objectproximo->name.".jpg";
- $this->imgFoto->src = "chrome-extension://".TSession::getValue('chrome')."/".$objectproximo->name.".jpg";
- $this->linka->href = $this->imgFoto->src; //avança para proximo
- // close the transaction
- TTransaction::close();
- // shows the success message
- //new TMessage('info', 'Registro Salvo');
- // reload the listing
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- //new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- //new TMessage('info', $object->id);
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * method onEdit()
- * Executed whenever the user clicks at the edit button da datagrid
- */
- function onLimpar()
- {
- try
- {
- // instantiates object Book
- $object = $this->form->getData('Product');
- $object->n1="";
- $object->n2="";
- $object->n3="";
- $object->n4="";
- $object->outros="";
- // fill the form with the active record data
- $this->form->setData($object);
- //$this->imgFoto->src = "app/images/".$object->corrida."/".$object->name.".jpg";
- $this->imgFoto->src = "chrome-extension://".TSession::getValue('chrome')."/".$object->name.".jpg";
- $this->linka->href = $this->imgFoto->src;
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * method onDelete()
- * executed whenever the user clicks at the delete button
- * Ask if the user really wants to delete the record
- */
- function onDelete()
- {
- // get the parameter $key
- $object = $this->form->getData('Product');
- $key=$object->id;
- // define two actions
- $action = new TAction(array($this, 'Delete'));
- // define the action parameters
- $action->setParameter('key', $key);
- // shows a dialog to the user
- new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
- }
- /**
- * method Delete()
- * Delete a record
- */
- function Delete($param)
- {
- try
- {
- // get the parameter $key
- $key=$param['key'];
- // open a transaction with database 'changeman'
- TTransaction::open(TSession::getValue('iniciais'));
- // instantiates object Document
- $object = new Product($key);
- $objectproximo = new Product($object->proximo);
- //exclui a imagem
- //unlink("app/images/".$object->corrida."/".$object->name.".jpg");
- unlink("../content/photopreupload/".TSession::getValue('iniciais')."/".$object->name.".jpg");
- // deletes the object from the database
- $object->delete();
- // reload the listing
- //$this->onReload();
- // shows the success message
- new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted'));
- $this->form->setData($objectproximo);
- //$this->imgFoto->src = "app/images/".$objectproximo->corrida."/".$objectproximo->name.".jpg";
- $this->imgFoto->src = "chrome-extension://".TSession::getValue('chrome')."/".$objectproximo->name.".jpg";
- $this->linka->href = $this->imgFoto->src; //avança para proximo
- // close the transaction
- TTransaction::close();
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', '<b>Error</b> ' . $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- }
- ?>
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-
Deu certo , fiz assim:
Dica para saber o numero das teclas: keycode.info/
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 ?
quando atualizei o framework para a versao mais recente , funcionou corretamente.