bssimplefieldrenderer.class.inc.php 23 KB

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