bssubformfieldrenderer.class.inc.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // Copyright (C) 2016-2017 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. // Showing subform if there are visible fields
  29. if (!$this->oField->GetForm()->HasVisibleFields())
  30. {
  31. $oOutput->AddHtml('<div class="hidden">');
  32. }
  33. if (($this->oField->GetLabel() !== null) && ($this->oField->GetLabel() !== ''))
  34. {
  35. $oOutput->AddHtml('<fieldset><legend>' . $this->oField->GetLabel() . '</legend>');
  36. }
  37. $oOutput->AddHtml('<div id="fieldset_' . $this->oField->GetGlobalId() . '">');
  38. $oOutput->AddHtml('</div>');
  39. if (($this->oField->GetLabel() !== null) && ($this->oField->GetLabel() !== ''))
  40. {
  41. $oOutput->AddHtml('</fieldset>');
  42. }
  43. if (!$this->oField->GetForm()->HasVisibleFields())
  44. {
  45. $oOutput->AddHtml('</div>');
  46. }
  47. $oRenderer = new BsFormRenderer($this->oField->GetForm());
  48. $aRenderRes = $oRenderer->Render();
  49. $aFieldSetOptions = array(
  50. 'fields_list' => $aRenderRes,
  51. 'fields_impacts' => $this->oField->GetForm()->GetFieldsImpacts(),
  52. 'form_path' => $this->oField->GetForm()->GetId()
  53. );
  54. $sFieldSetOptions = json_encode($aFieldSetOptions);
  55. $oOutput->AddJs(
  56. <<<EOF
  57. $("#fieldset_{$this->oField->GetGlobalId()}").field_set($sFieldSetOptions);
  58. $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").subform_field({field_set: $("#fieldset_{$this->oField->GetGlobalId()}")});
  59. EOF
  60. );
  61. return $oOutput;
  62. }
  63. }