bssimplefieldrenderer.class.inc.php 24 KB

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