bssimplefieldrenderer.class.inc.php 25 KB

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