ui.htmleditorwidget.class.inc.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Class UIHTMLEditorWidget
  18. * UI wdiget for displaying and editing one-way encrypted passwords
  19. *
  20. * @author Phil Eddies
  21. * @author Romain Quetiez <romain.quetiez@combodo.com>
  22. * @author Denis Flaven <denis.flaven@combodo.com>
  23. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  24. */
  25. class UIHTMLEditorWidget
  26. {
  27. protected $m_iId;
  28. protected $m_sAttCode;
  29. protected $m_sNameSuffix;
  30. protected $m_sFieldPrefix;
  31. protected $m_sHelpText;
  32. protected $m_sValidationField;
  33. protected $m_sValue;
  34. protected $m_sMandatory;
  35. public function __construct($iInputId, $sAttCode, $sNameSuffix, $sFieldPrefix, $sHelpText, $sValidationField, $sValue, $sMandatory)
  36. {
  37. $this->m_iId = $iInputId;
  38. $this->m_sAttCode = $sAttCode;
  39. $this->m_sNameSuffix = $sNameSuffix;
  40. $this->m_sHelpText = $sHelpText;
  41. $this->m_sValidationField = $sValidationField;
  42. $this->m_sValue = $sValue;
  43. $this->m_sMandatory = $sMandatory;
  44. $this->m_sFieldPrefix = $sFieldPrefix;
  45. }
  46. /**
  47. * Get the HTML fragment corresponding to the HTML editor widget
  48. * @param WebPage $oP The web page used for all the output
  49. * @param Hash $aArgs Extra context arguments
  50. * @return string The HTML fragment to be inserted into the page
  51. */
  52. public function Display(WebPage $oPage, $aArgs = array())
  53. {
  54. $iId = $this->m_iId;
  55. $sCode = $this->m_sAttCode.$this->m_sNameSuffix;
  56. $sValue = $this->m_sValue;
  57. $sHelpText = $this->m_sHelpText;
  58. $sValidationField = $this->m_sValidationField;
  59. $sHtmlValue = "<table><tr><td><textarea class=\"htmlEditor\" title=\"$sHelpText\" name=\"attr_{$this->m_sFieldPrefix}{$sCode}\" rows=\"10\" cols=\"10\" id=\"$iId\">$sValue</textarea></td><td>$sValidationField</td></tr></table>";
  60. // Replace the text area with CKEditor
  61. // To change the default settings of the editor,
  62. // a) edit the file /js/ckeditor/config.js
  63. // b) or override some of the configuration settings, using the second parameter of ckeditor()
  64. $sLanguage = strtolower(trim(UserRights::GetUserLanguage()));
  65. $oPage->add_ready_script("$('#$iId').ckeditor(function() { /* callback code */ }, { language : '$sLanguage' , contentsLanguage : '$sLanguage', extraPlugins: 'disabler' });"); // Transform $iId into a CKEdit
  66. // Please read...
  67. // ValidateCKEditField triggers a timer... calling itself indefinitely
  68. // This design was the quickest way to achieve the field validation (only checking if the field is blank)
  69. // because the ckeditor does not fire events like "change" or "keyup", etc.
  70. // See http://dev.ckeditor.com/ticket/900 => won't fix
  71. // The most relevant solution would be to implement a plugin to CKEdit, and handle the internal events like: setData, insertHtml, insertElement, loadSnapshot, key, afterUndo, afterRedo
  72. // Could also be bound to 'instanceReady.ckeditor'
  73. $oPage->add_ready_script("$('#$iId').bind('validate', function(evt, sFormId) { return ValidateCKEditField('$iId', '', {$this->m_sMandatory}, sFormId, '') } );\n");
  74. $oPage->add_ready_script("$('#$iId').bind('update', function() { BlockField('cke_$iId', $('#$iId').attr('disabled')); } );\n");
  75. return $sHtmlValue;
  76. }
  77. }
  78. ?>