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

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework 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.