bssimplefieldrenderer.class.inc.php 26 KB

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