bssubformfieldrenderer.class.inc.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. // Copyright (C) 2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. namespace Combodo\iTop\Renderer\Bootstrap\FieldRenderer;
  19. use \Dict;
  20. use Combodo\iTop\Renderer\Bootstrap\BsFormRenderer;
  21. use Combodo\iTop\Renderer\FieldRenderer;
  22. use Combodo\iTop\Renderer\RenderingOutput;
  23. class BsSubFormFieldRenderer extends FieldRenderer
  24. {
  25. public function Render()
  26. {
  27. $oOutput = new RenderingOutput();
  28. if (($this->oField->GetLabel() !== null) && ($this->oField->GetLabel() !== ''))
  29. {
  30. $oOutput->AddHtml('<fieldset><legend>' . $this->oField->GetLabel() . '</legend>');
  31. }
  32. $oOutput->AddHtml('<div id="fieldset_' . $this->oField->GetGlobalId() . '">');
  33. $oOutput->AddHtml('</div>');
  34. if (($this->oField->GetLabel() !== null) && ($this->oField->GetLabel() !== ''))
  35. {
  36. $oOutput->AddHtml('</fieldset>');
  37. }
  38. $oRenderer = new BsFormRenderer($this->oField->GetForm());
  39. $aRenderRes = $oRenderer->Render();
  40. $aFieldSetOptions = array(
  41. 'fields_list' => $aRenderRes,
  42. 'fields_impacts' => $this->oField->GetForm()->GetFieldsImpacts(),
  43. 'form_path' => $this->oField->GetForm()->GetId()
  44. );
  45. $sFieldSetOptions = json_encode($aFieldSetOptions);
  46. $oOutput->AddJs(
  47. <<<EOF
  48. $("#fieldset_{$this->oField->GetGlobalId()}").field_set($sFieldSetOptions);
  49. $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").subform_field({field_set: $("#fieldset_{$this->oField->GetGlobalId()}")});
  50. EOF
  51. );
  52. return $oOutput;
  53. }
  54. }