bssimplefieldrenderer.class.inc.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <?php
  2. // Copyright (C) 2010-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 \utils;
  20. use \Dict;
  21. use \UserRights;
  22. use \AttributeDateTime;
  23. use \AttributeText;
  24. use \InlineImage;
  25. use \Combodo\iTop\Renderer\FieldRenderer;
  26. use \Combodo\iTop\Renderer\RenderingOutput;
  27. use \Combodo\iTop\Form\Field\TextAreaField;
  28. /**
  29. * Description of BsSimpleFieldRenderer
  30. *
  31. * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
  32. */
  33. class BsSimpleFieldRenderer extends FieldRenderer
  34. {
  35. /**
  36. * Returns a RenderingOutput for the FieldRenderer's Field
  37. *
  38. * @return \Combodo\iTop\Renderer\RenderingOutput
  39. */
  40. public function Render()
  41. {
  42. $oOutput = new RenderingOutput();
  43. $sFieldClass = get_class($this->oField);
  44. $sFieldMandatoryClass = ($this->oField->GetMandatory()) ? 'form_mandatory' : '';
  45. // Rendering field in edition mode
  46. if (!$this->oField->GetReadOnly() && !$this->oField->GetHidden())
  47. {
  48. switch ($sFieldClass)
  49. {
  50. case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
  51. $oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '">');
  52. if ($this->oField->GetLabel() !== '')
  53. {
  54. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  55. }
  56. $oOutput->AddHtml('<div class="help-block"></div>');
  57. $oOutput->AddHtml('<div class="input-group date" id="datepicker_' . $this->oField->GetGlobalId() . '">');
  58. $oOutput->AddHtml('<input type="text" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetDisplayValue(), true)->AddHtml('" class="form-control" maxlength="255" />');
  59. $oOutput->AddHtml('<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>');
  60. $oOutput->AddHtml('</div>');
  61. $oOutput->AddHtml('</div>');
  62. $sJSFormat = json_encode($this->oField->GetJSDateTimeFormat());
  63. $oOutput->AddJs(
  64. <<<EOF
  65. $('#datepicker_{$this->oField->GetGlobalId()}').datetimepicker({format: $sJSFormat});
  66. EOF
  67. );
  68. break;
  69. case 'Combodo\\iTop\\Form\\Field\\PasswordField':
  70. $oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '">');
  71. if ($this->oField->GetLabel() !== '')
  72. {
  73. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  74. }
  75. $oOutput->AddHtml('<div class="help-block"></div>');
  76. $oOutput->AddHtml('<input type="password" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('" class="form-control" maxlength="255" autocomplete="off" />');
  77. $oOutput->AddHtml('</div>');
  78. break;
  79. case 'Combodo\\iTop\\Form\\Field\\StringField':
  80. $oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '">');
  81. if ($this->oField->GetLabel() !== '')
  82. {
  83. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  84. }
  85. $oOutput->AddHtml('<div class="help-block"></div>');
  86. $oOutput->AddHtml('<input type="text" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('" class="form-control" maxlength="255" />');
  87. $oOutput->AddHtml('</div>');
  88. break;
  89. case 'Combodo\\iTop\\Form\\Field\\TextAreaField':
  90. case 'Combodo\\iTop\\Form\\Field\\CaseLogField':
  91. $bRichEditor = ($this->oField->GetFormat() === TextAreaField::ENUM_FORMAT_HTML);
  92. $oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '">');
  93. if ($this->oField->GetLabel() !== '')
  94. {
  95. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  96. }
  97. $oOutput->AddHtml('<div class="help-block"></div>');
  98. // First the edition area
  99. $oOutput->AddHtml('<div>');
  100. $oOutput->AddHtml('<textarea id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" class="form-control" rows="8">' . $this->oField->GetCurrentValue() . '</textarea>');
  101. $oOutput->AddHtml('</div>');
  102. // Then the previous entries if necessary
  103. if ($sFieldClass === 'Combodo\\iTop\\Form\\Field\\CaseLogField')
  104. {
  105. $this->PreparingCaseLogEntries($oOutput);
  106. }
  107. $oOutput->AddHtml('</div>');
  108. // Some additional stuff if we are displaying it with a rich editor
  109. if ($bRichEditor)
  110. {
  111. $sEditorLanguage = strtolower(trim(UserRights::GetUserLanguage()));
  112. $oOutput->AddJs(
  113. <<<EOF
  114. $('#{$this->oField->GetGlobalId()}').addClass('htmlEditor');
  115. $('#{$this->oField->GetGlobalId()}').ckeditor(function(){}, {language: '$sEditorLanguage', contentsLanguage: '$sEditorLanguage'});
  116. EOF
  117. );
  118. if (($this->oField->GetObject() !== null) && ($this->oField->GetTransactionId() !== null))
  119. {
  120. $oOutput->AddJs(InlineImage::EnableCKEditorImageUpload($this->oField->GetObject(), utils::GetUploadTempId($this->oField->GetTransactionId())));
  121. }
  122. }
  123. break;
  124. case 'Combodo\\iTop\\Form\\Field\\SelectField':
  125. case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
  126. $oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '">');
  127. if ($this->oField->GetLabel() !== '')
  128. {
  129. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  130. }
  131. $oOutput->AddHtml('<div class="help-block"></div>');
  132. $oOutput->AddHtml('<select id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" ' . ( ($this->oField->GetMultipleValuesEnabled()) ? 'multiple' : '' ) . ' class="form-control">');
  133. foreach ($this->oField->GetChoices() as $sChoice => $sLabel)
  134. {
  135. // Note : The test is a double equal on purpose as the type of the value received from the XHR is not always the same as the type of the allowed values. (eg : string vs int)
  136. $sSelectedAtt = ($this->oField->GetCurrentValue() == $sChoice) ? 'selected' : '';
  137. $oOutput->AddHtml('<option value="' . $sChoice . '" ' . $sSelectedAtt . ' >')->AddHtml($sLabel)->AddHtml('</option>');
  138. }
  139. $oOutput->AddHtml('</select>');
  140. $oOutput->AddHtml('</div>');
  141. break;
  142. case 'Combodo\\iTop\\Form\\Field\\RadioField':
  143. case 'Combodo\\iTop\\Form\\Field\\CheckboxField':
  144. $sFieldType = ($sFieldClass === 'Combodo\\iTop\\Form\\Field\\RadioField') ? 'radio' : 'checkbox';
  145. $oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '" id="' . $this->oField->GetGlobalId() . '">');
  146. if ($this->oField->GetLabel() !== '')
  147. {
  148. $oOutput->AddHtml('<div><label class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label></div>');
  149. }
  150. $oOutput->AddHtml('<div class="help-block"></div>');
  151. $oOutput->AddHtml('<div class="btn-group" data-toggle="buttons">');
  152. $i = 0;
  153. foreach ($this->oField->GetChoices() as $sChoice => $sLabel)
  154. {
  155. // Note : The test is a double equal on purpose as the type of the value received from the XHR is not always the same as the type of the allowed values. (eg : string vs int)
  156. $sCheckedAtt = ($this->oField->IsAmongValues($sChoice)) ? 'checked' : '';
  157. $sCheckedClass = ($this->oField->IsAmongValues($sChoice)) ? 'active' : '';
  158. $oOutput->AddHtml('<label class="btn btn-default ' . $sCheckedClass . '"><input type="' . $sFieldType . '" name="' . $this->oField->GetId() . '" id="' . $this->oField->GetId() . $i . '" value="' . $sChoice . '" ' . $sCheckedAtt . ' />' . $sLabel . '</label>');
  159. $i++;
  160. }
  161. $oOutput->AddHtml('</div>');
  162. $oOutput->AddHtml('</div>');
  163. break;
  164. case 'Combodo\\iTop\\Form\\Field\\HiddenField':
  165. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('"/>');
  166. break;
  167. }
  168. }
  169. // ... and in read-only mode (or hidden)
  170. else
  171. {
  172. // ... specific rendering for fields with multiple values
  173. if (($this->oField instanceof Combodo\iTop\Form\Field\MultipleChoicesField) && ($this->oField->GetMultipleValuesEnabled()))
  174. {
  175. // TODO
  176. }
  177. // ... clasic rendering for fields with only one value
  178. else
  179. {
  180. switch ($sFieldClass)
  181. {
  182. case 'Combodo\\iTop\\Form\\Field\\LabelField':
  183. $oOutput->AddHtml('<div class="form-group">');
  184. // Showing label / value only if read-only but not hidden
  185. if (!$this->oField->GetHidden())
  186. {
  187. if ($this->oField->GetLabel() !== '')
  188. {
  189. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  190. }
  191. $oOutput->AddHtml('<div class="form-control-static">')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('</div>');
  192. }
  193. $oOutput->AddHtml('</div>');
  194. break;
  195. case 'Combodo\\iTop\\Form\\Field\\StringField':
  196. case 'Combodo\\iTop\\Form\\Field\\TextAreaField':
  197. $oOutput->AddHtml('<div class="form-group">');
  198. // Showing label / value only if read-only but not hidden
  199. if (!$this->oField->GetHidden())
  200. {
  201. if ($this->oField->GetLabel() !== '')
  202. {
  203. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  204. }
  205. if($sFieldClass === 'Combodo\\iTop\\Form\\Field\\TextAreaField')
  206. {
  207. $bEncodeHtmlEntities = false;
  208. $sDisplayValue = $this->oField->GetDisplayValue();
  209. }
  210. else
  211. {
  212. $bEncodeHtmlEntities = true;
  213. $sDisplayValue = $this->oField->GetCurrentValue();
  214. }
  215. $oOutput->AddHtml('<div class="form-control-static">')->AddHtml($sDisplayValue, $bEncodeHtmlEntities)->AddHtml('</div>');
  216. }
  217. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('" class="form-control" />');
  218. $oOutput->AddHtml('</div>');
  219. break;
  220. case 'Combodo\\iTop\\Form\\Field\\CaseLogField':
  221. $oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '">');
  222. if ($this->oField->GetLabel() !== '')
  223. {
  224. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  225. }
  226. // Entries if necessary
  227. $this->PreparingCaseLogEntries($oOutput);
  228. $oOutput->AddHtml('</div>');
  229. break;
  230. case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
  231. $oOutput->AddHtml('<div class="form-group">');
  232. // Showing label / value only if read-only but not hidden
  233. if (!$this->oField->GetHidden())
  234. {
  235. if ($this->oField->GetLabel() !== '')
  236. {
  237. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  238. }
  239. $oOutput->AddHtml('<div class="form-control-static">')->AddHtml($this->oField->GetDisplayValue(), true)->AddHtml('</div>');
  240. }
  241. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetDisplayValue(), true)->AddHtml('" class="form-control" />');
  242. $oOutput->AddHtml('</div>');
  243. break;
  244. case 'Combodo\\iTop\\Form\\Field\\DurationField':
  245. $oOutput->AddHtml('<div class="form-group">');
  246. // Showing label / value only if read-only but not hidden
  247. if (!$this->oField->GetHidden())
  248. {
  249. if ($this->oField->GetLabel() !== '')
  250. {
  251. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  252. }
  253. $oOutput->AddHtml('<div class="form-control-static">')->AddHtml($this->oField->GetDisplayValue(), true)->AddHtml('</div>');
  254. }
  255. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('" class="form-control" />');
  256. $oOutput->AddHtml('</div>');
  257. break;
  258. case 'Combodo\\iTop\\Form\\Field\\BlobField':
  259. $oOutput->AddHtml('<div class="form-group">');
  260. // Showing label / value only if read-only but not hidden
  261. if (!$this->oField->GetHidden())
  262. {
  263. if ($this->oField->GetLabel() !== '')
  264. {
  265. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  266. }
  267. $oOutput->AddHtml('<div class="form-control-static">')->AddHtml($this->oField->GetDisplayValue(), false)->AddHtml('</div>');
  268. }
  269. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('" class="form-control" />');
  270. $oOutput->AddHtml('</div>');
  271. break;
  272. case 'Combodo\\iTop\\Form\\Field\\RadioField':
  273. case 'Combodo\\iTop\\Form\\Field\\SelectField':
  274. case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
  275. $aFieldChoices = $this->oField->GetChoices();
  276. $sFieldValue = (isset($aFieldChoices[$this->oField->GetCurrentValue()])) ? $aFieldChoices[$this->oField->GetCurrentValue()] : Dict::S('UI:UndefinedObject');
  277. $oOutput->AddHtml('<div class="form-group">');
  278. // Showing label / value only if read-only but not hidden
  279. if (!$this->oField->GetHidden())
  280. {
  281. if ($this->oField->GetLabel() !== '')
  282. {
  283. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  284. }
  285. $oOutput->AddHtml('<div class="form-control-static">' . $sFieldValue . '</div>');
  286. }
  287. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="' . $this->oField->GetCurrentValue() . '" class="form-control" />');
  288. $oOutput->AddHtml('</div>');
  289. break;
  290. case 'Combodo\\iTop\\Form\\Field\\HiddenField':
  291. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('"/>');
  292. break;
  293. }
  294. }
  295. }
  296. // JS FieldChange trigger (:input are not always at the same depth)
  297. switch ($sFieldClass)
  298. {
  299. case 'Combodo\\iTop\\Form\\Field\\PasswordField':
  300. case 'Combodo\\iTop\\Form\\Field\\StringField':
  301. case 'Combodo\\iTop\\Form\\Field\\TextAreaField':
  302. case 'Combodo\\iTop\\Form\\Field\\CaseLogField':
  303. case 'Combodo\\iTop\\Form\\Field\\SelectField':
  304. case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
  305. case 'Combodo\\iTop\\Form\\Field\\HiddenField':
  306. $oOutput->AddJs(
  307. <<<EOF
  308. $("#{$this->oField->GetGlobalId()}").off("change keyup").on("change keyup", function(){
  309. var me = this;
  310. $(this).closest(".field_set").trigger("field_change", {
  311. id: $(me).attr("id"),
  312. name: $(me).closest(".form_field").attr("data-field-id"),
  313. value: $(me).val()
  314. });
  315. });
  316. EOF
  317. );
  318. break;
  319. case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
  320. // We need the focusout event has the datepicker widget seems to override the change event
  321. $oOutput->AddJs(
  322. <<<EOF
  323. $("#{$this->oField->GetGlobalId()}").off("change keyup focusout").on("change keyup focusout", function(){
  324. var me = this;
  325. $(this).closest(".field_set").trigger("field_change", {
  326. id: $(me).attr("id"),
  327. name: $(me).closest(".form_field").attr("data-field-id"),
  328. value: $(me).val()
  329. });
  330. });
  331. EOF
  332. );
  333. break;
  334. case 'Combodo\\iTop\\Form\\Field\\RadioField':
  335. case 'Combodo\\iTop\\Form\\Field\\CheckboxField':
  336. $oOutput->AddJs(
  337. <<<EOF
  338. $("#{$this->oField->GetGlobalId()} input").off("change").on("change", function(){
  339. var me = this;
  340. $(this).closest(".field_set").trigger("field_change", {
  341. id: $(me).closest("#{$this->oField->GetGlobalId()}").attr("id"),
  342. name: $(me).attr("name"),
  343. value: $(me).val()
  344. });
  345. });
  346. EOF
  347. );
  348. break;
  349. }
  350. // JS Form field widget construct
  351. $aValidators = array();
  352. foreach ($this->oField->GetValidators() as $oValidator)
  353. {
  354. $aValidators[$oValidator::GetName()] = array(
  355. 'reg_exp' => $oValidator->GetRegExp(),
  356. 'message' => Dict::S($oValidator->GetErrorMessage())
  357. );
  358. }
  359. $sFormFieldOptions = json_encode(array(
  360. 'validators' => $aValidators
  361. ));
  362. switch ($sFieldClass)
  363. {
  364. case 'Combodo\\iTop\\Form\\Field\\PasswordField':
  365. case 'Combodo\\iTop\\Form\\Field\\StringField':
  366. case 'Combodo\\iTop\\Form\\Field\\SelectField':
  367. case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
  368. case 'Combodo\\iTop\\Form\\Field\\HiddenField':
  369. case 'Combodo\\iTop\\Form\\Field\\RadioField':
  370. case 'Combodo\\iTop\\Form\\Field\\CheckboxField':
  371. case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
  372. $oOutput->AddJs(
  373. <<<EOF
  374. $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").portal_form_field($sFormFieldOptions);
  375. EOF
  376. );
  377. break;
  378. case 'Combodo\\iTop\\Form\\Field\\TextAreaField':
  379. case 'Combodo\\iTop\\Form\\Field\\CaseLogField':
  380. $bRichEditor = ($this->oField->GetFormat() === TextAreaField::ENUM_FORMAT_HTML);
  381. if($bRichEditor)
  382. {
  383. // Overloading $sFormFieldOptions to include the set_current_value_callback. It would have been nicer to refactor the variable for all field types, but as this is a fix for a maintenance release, we rather be safe.
  384. $sValidators = json_encode($aValidators);
  385. $oOutput->AddJs(
  386. <<<EOF
  387. $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").portal_form_field_html({
  388. validators: $sValidators,
  389. set_current_value_callback: function(me, oEvent, oData){ $(me.element).find('textarea').val(oData); }
  390. });
  391. EOF
  392. );
  393. // MagnificPopup on images
  394. $oOutput->AddJs(InlineImage::FixImagesWidth());
  395. }
  396. else
  397. {
  398. $oOutput->AddJs(
  399. <<<EOF
  400. $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").portal_form_field($sFormFieldOptions);
  401. EOF
  402. );
  403. }
  404. break;
  405. }
  406. return $oOutput;
  407. }
  408. protected function PreparingCaseLogEntries(RenderingOutput &$oOutput)
  409. {
  410. $aEntries = $this->oField->GetEntries();
  411. if (count($aEntries) > 0)
  412. {
  413. $oOutput->AddHtml('<div>');
  414. for ($i = 0; $i < count($aEntries); $i++)
  415. {
  416. $sEntryDate = AttributeDateTime::GetFormat()->Format($aEntries[$i]['date']);
  417. $sEntryUser = $aEntries[$i]['user_login'];
  418. $sEntryHeader = Dict::Format('UI:CaseLog:Header_Date_UserName', $sEntryDate, $sEntryUser);
  419. // Only the last 2 entries are expanded by default
  420. $sEntryContentExpanded = ($i < 2) ? 'true' : 'false';
  421. $sEntryHeaderButtonClass = ($i < 2) ? '' : 'collapsed';
  422. $sEntryContentClass = ($i < 2) ? 'in' : '';
  423. $sEntryContentId = 'caselog_field_entry_content-' . $this->oField->GetGlobalId() . '-' . $i;
  424. $sEntryHtml = AttributeText::RenderWikiHtml($aEntries[$i]['message_html'], true /* wiki only */);
  425. $sEntryHtml = InlineImage::FixUrls($sEntryHtml);
  426. // Note : We use CKEditor stylesheet to format this
  427. $oOutput->AddHtml(
  428. <<<EOF
  429. <div class="caselog_field_entry cke_inner">
  430. <div class="caselog_field_entry_header">
  431. {$sEntryHeader}
  432. <div class="pull-right">
  433. <span class="caselog_field_entry_button {$sEntryHeaderButtonClass}" data-toggle="collapse" href="#{$sEntryContentId}" aria-expanded="{$sEntryContentExpanded}" aria-controls="{$sEntryContentId}"></span>
  434. </div>
  435. </div>
  436. <div class="caselog_field_entry_content collapse {$sEntryContentClass}" id="{$sEntryContentId}">
  437. {$sEntryHtml}
  438. </div>
  439. </div>
  440. EOF
  441. );
  442. }
  443. $oOutput->AddHtml('</div>');
  444. }
  445. }
  446. }