bssimplefieldrenderer.class.inc.php 21 KB

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