PrintButton.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ aJteemRg60wI3Lzfqv7wS0PdBYuYFKsnJSVJhpXTMyQ=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2014 Online Ventures Software LTD & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.0
  11. */
  12. /**
  13. * print button form element
  14. */
  15. namespace Ppb\Form\Element;
  16. use Cube\Form\Element,
  17. Cube\Controller\Front;
  18. class PrintButton extends Element
  19. {
  20. const BTN_CLASS = 'print-button';
  21. /**
  22. *
  23. * type of element - override the variable from the parent class
  24. *
  25. * @var string
  26. */
  27. protected $_element = 'submit';
  28. /**
  29. *
  30. * base url of the application
  31. *
  32. * @var string
  33. */
  34. protected $_baseUrl;
  35. /**
  36. *
  37. * class constructor
  38. *
  39. * @param string $name
  40. */
  41. public function __construct($name)
  42. {
  43. parent::__construct($this->_element, $name);
  44. $this->_baseUrl = Front::getInstance()->getRequest()->getBaseUrl();
  45. $this->setHeaderCode('<link href="' . $this->_baseUrl . '/js/printarea/print.css" media="print" rel="stylesheet" type="text/css">')
  46. ->setBodyCode('<script type="text/javascript" src="' . $this->_baseUrl . '/js/printarea/jquery.printarea.js"></script>')
  47. ->setBodyCode("<script type=\"text/javascript\">
  48. $(document).ready(function() {
  49. $('." . self::BTN_CLASS . "').click(function () {
  50. var container = $(this).attr('rel');
  51. $('#' + container).printArea();
  52. return false;
  53. });
  54. });
  55. </script>");
  56. $this->addAttribute('class', self::BTN_CLASS);
  57. }
  58. }