LinkedTextarea.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ pa5vRUJo6k3fbeZS4uXnKzMRGD9i7nicpA4WTwflljM=
  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. * linked textarea custom element
  14. *
  15. * used specifically for the languages editor admin page
  16. */
  17. namespace Ppb\Form\Element;
  18. use Cube\Form\Element,
  19. Cube\Controller\Front;
  20. class LinkedTextarea extends Element
  21. {
  22. const ELEMENT_CLASS = 'linked-textarea';
  23. /**
  24. *
  25. * type of element - override the variable from the parent class
  26. *
  27. * @var string
  28. */
  29. protected $_element = 'linkedTextarea';
  30. /**
  31. *
  32. * class constructor
  33. *
  34. * @param string $name
  35. */
  36. public function __construct($name)
  37. {
  38. parent::__construct($this->_element, $name);
  39. $baseUrl = Front::getInstance()->getRequest()->getBaseUrl();
  40. $this->setHeaderCode('<link href="' . $baseUrl . '/js/linedtextarea/linedtextarea.css" media="screen" rel="stylesheet" type="text/css">')
  41. ->setBodyCode('<script type="text/javascript" src="' . $baseUrl . '/js/linedtextarea/linedtextarea.js"></script>');
  42. $this->setBodyCode(
  43. "<script type=\"text/javascript\">" . "\n"
  44. . " $(document).ready(function() { " . "\n"
  45. . " $('." . self::ELEMENT_CLASS . "').linedtextarea();" . "\n"
  46. . " }); " . "\n"
  47. . "</script>"
  48. );
  49. $this->addAttribute('class', self::ELEMENT_CLASS);
  50. }
  51. // /**
  52. // *
  53. // * set script code in case the element is not part of a form
  54. // *
  55. // * @return $this
  56. // */
  57. // public function setScriptCode()
  58. // {
  59. // $view = Front::getInstance()->getBootstrap()->getResource('view');
  60. //
  61. // /* @var \Cube\View\Helper\Script $helper */
  62. // $helper = $view->getHelper('script');
  63. //
  64. // $headerCode = $this->getHeaderCode();
  65. // foreach ($headerCode as $code) {
  66. // $helper->addHeaderCode($code);
  67. // }
  68. // $bodyCode = $this->getBodyCode();
  69. // foreach ($bodyCode as $code) {
  70. // $helper->addBodyCode($code);
  71. // }
  72. //
  73. // return $this;
  74. // }
  75. /**
  76. *
  77. * render the form element
  78. *
  79. * @return string
  80. */
  81. public function render()
  82. {
  83. $value = $this->getValue();
  84. return '<div class="row">'
  85. . '<div class="col-sm-6">'
  86. . '<textarea name="' . $this->_name . 'Keys" readonly="readonly" '
  87. . $this->renderAttributes() . '>'
  88. . implode("\n", array_keys($value))
  89. . '</textarea>'
  90. . '</div>'
  91. . '<div class="col-sm-6">'
  92. . '<textarea name="' . $this->_name . '" '
  93. . $this->renderAttributes() . '>'
  94. . implode("\n", array_values($value))
  95. . '</textarea>'
  96. . '</div>'
  97. . '</div>';
  98. }
  99. }