bssimplefieldrenderer.class.inc.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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. // JS Form field widget construct
  247. $aValidators = array();
  248. foreach ($this->oField->GetValidators() as $oValidator)
  249. {
  250. $aValidators[$oValidator::GetName()] = array(
  251. 'reg_exp' => $oValidator->GetRegExp(),
  252. 'message' => Dict::S($oValidator->GetErrorMessage())
  253. );
  254. }
  255. $sFormFieldOptions = json_encode(array(
  256. 'validators' => $aValidators
  257. ));
  258. switch ($sFieldClass)
  259. {
  260. case 'Combodo\\iTop\\Form\\Field\\PasswordField':
  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\\SelectField':
  265. case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
  266. case 'Combodo\\iTop\\Form\\Field\\HiddenField':
  267. case 'Combodo\\iTop\\Form\\Field\\RadioField':
  268. case 'Combodo\\iTop\\Form\\Field\\CheckboxField':
  269. case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
  270. $oOutput->AddJs(
  271. <<<EOF
  272. $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").portal_form_field($sFormFieldOptions);
  273. EOF
  274. );
  275. break;
  276. case 'Combodo\\iTop\\Form\\Field\\TextAreaField':
  277. case 'Combodo\\iTop\\Form\\Field\\CaseLogField':
  278. $bRichEditor = ($this->oField->GetFormat() === TextAreaField::ENUM_FORMAT_HTML);
  279. if($bRichEditor)
  280. {
  281. // 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.
  282. $sValidators = json_encode($aValidators);
  283. $oOutput->AddJs(
  284. <<<EOF
  285. $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").portal_form_field_html({
  286. validators: $sValidators,
  287. set_current_value_callback: function(me, oEvent, oData){ $(me.element).find('textarea').val(oData); }
  288. });
  289. EOF
  290. );
  291. // MagnificPopup on images
  292. $oOutput->AddJs(InlineImage::FixImagesWidth());
  293. }
  294. else
  295. {
  296. $oOutput->AddJs(
  297. <<<EOF
  298. $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").portal_form_field($sFormFieldOptions);
  299. EOF
  300. );
  301. }
  302. break;
  303. }
  304. }
  305. // ... and in read-only mode (or hidden)
  306. else
  307. {
  308. // ... specific rendering for fields with multiple values
  309. if (($this->oField instanceof Combodo\iTop\Form\Field\MultipleChoicesField) && ($this->oField->GetMultipleValuesEnabled()))
  310. {
  311. // TODO
  312. }
  313. // ... clasic rendering for fields with only one value
  314. else
  315. {
  316. switch ($sFieldClass)
  317. {
  318. case 'Combodo\\iTop\\Form\\Field\\LabelField':
  319. case 'Combodo\\iTop\\Form\\Field\\StringField':
  320. case 'Combodo\\iTop\\Form\\Field\\UrlField':
  321. case 'Combodo\\iTop\\Form\\Field\\EmailField':
  322. case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
  323. case 'Combodo\\iTop\\Form\\Field\\DurationField':
  324. // Opening container
  325. $oOutput->AddHtml('<div class="form-group form_group_small">');
  326. // Showing label / value only if read-only but not hidden
  327. if (!$this->oField->GetHidden())
  328. {
  329. // Label
  330. $oOutput->AddHtml('<div class="form_field_label">');
  331. if ($this->oField->GetLabel() !== '')
  332. {
  333. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  334. }
  335. $oOutput->AddHtml('</div>');
  336. // Value
  337. $bEncodeHtmlEntities = ($sFieldClass === 'Combodo\\iTop\\Form\\Field\\UrlField') ? false : true;
  338. $oOutput->AddHtml('<div class="form_field_control">');
  339. $oOutput->AddHtml('<div class="form-control-static">')->AddHtml($this->oField->GetDisplayValue(), $bEncodeHtmlEntities)->AddHtml('</div>');
  340. $oOutput->AddHtml('</div>');
  341. }
  342. // Adding hidden input if not a label
  343. if($sFieldClass !== 'Combodo\\iTop\\Form\\Field\\LabelField')
  344. {
  345. $sValueForInput = ($sFieldClass === 'Combodo\\iTop\\Form\\Field\\DateTimeField') ? $this->oField->GetDisplayValue() : $this->oField->GetCurrentValue();
  346. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($sValueForInput, true)->AddHtml('" class="form-control" />');
  347. }
  348. // Closing container
  349. $oOutput->AddHtml('</div>');
  350. break;
  351. case 'Combodo\\iTop\\Form\\Field\\TextAreaField':
  352. // Opening container
  353. $oOutput->AddHtml('<div class="form-group">');
  354. // Showing label / value only if read-only but not hidden
  355. if (!$this->oField->GetHidden())
  356. {
  357. // Label
  358. $oOutput->AddHtml('<div class="form_field_label">');
  359. if ($this->oField->GetLabel() !== '')
  360. {
  361. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  362. }
  363. $oOutput->AddHtml('</div>');
  364. // Value
  365. $oOutput->AddHtml('<div class="form_field_control">');
  366. $oOutput->AddHtml('<div class="form-control-static">')->AddHtml($this->oField->GetDisplayValue(), false)->AddHtml('</div>');
  367. $oOutput->AddHtml('</div>');
  368. }
  369. // Adding hidden input
  370. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('" class="form-control" />');
  371. // Closing container
  372. $oOutput->AddHtml('</div>');
  373. break;
  374. case 'Combodo\\iTop\\Form\\Field\\CaseLogField':
  375. // Opening container
  376. $oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '">');
  377. // Label
  378. $oOutput->AddHtml('<div class="form_field_label">');
  379. if ($this->oField->GetLabel() !== '')
  380. {
  381. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  382. }
  383. $oOutput->AddHtml('</div>');
  384. // Value
  385. $oOutput->AddHtml('<div class="form_field_control">');
  386. // - Entries if necessary
  387. $this->PreparingCaseLogEntries($oOutput);
  388. $oOutput->AddHtml('</div>');
  389. // Closing container
  390. $oOutput->AddHtml('</div>');
  391. break;
  392. case 'Combodo\\iTop\\Form\\Field\\BlobField':
  393. case 'Combodo\\iTop\\Form\\Field\\ImageField':
  394. // Opening container
  395. $oOutput->AddHtml('<div class="form-group">');
  396. // Showing label / value only if read-only but not hidden
  397. if (!$this->oField->GetHidden())
  398. {
  399. // Label
  400. $oOutput->AddHtml('<div class="form_field_label">');
  401. if ($this->oField->GetLabel() !== '')
  402. {
  403. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  404. }
  405. $oOutput->AddHtml('</div>');
  406. // Value
  407. $oOutput->AddHtml('<div class="form_field_control">');
  408. $oOutput->AddHtml('<div class="form-control-static">');
  409. if($sFieldClass === 'Combodo\\iTop\\Form\\Field\\ImageField')
  410. {
  411. $oOutput->AddHtml('<img src="' . $this->oField->GetDisplayUrl() . '" />', false);
  412. }
  413. else
  414. {
  415. $oOutput->AddHtml($this->oField->GetDisplayValue(), false);
  416. }
  417. $oOutput->AddHtml('</div>');
  418. $oOutput->AddHtml('</div>');
  419. }
  420. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('" class="form-control" />');
  421. // Closing container
  422. $oOutput->AddHtml('</div>');
  423. break;
  424. case 'Combodo\\iTop\\Form\\Field\\RadioField':
  425. case 'Combodo\\iTop\\Form\\Field\\SelectField':
  426. case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
  427. $aFieldChoices = $this->oField->GetChoices();
  428. $sFieldValue = (isset($aFieldChoices[$this->oField->GetCurrentValue()])) ? $aFieldChoices[$this->oField->GetCurrentValue()] : Dict::S('UI:UndefinedObject');
  429. // Opening container
  430. $oOutput->AddHtml('<div class="form-group form_group_small">');
  431. // Showing label / value only if read-only but not hidden
  432. if (!$this->oField->GetHidden())
  433. {
  434. // Label
  435. $oOutput->AddHtml('<div class="form_field_label">');
  436. if ($this->oField->GetLabel() !== '')
  437. {
  438. $oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
  439. }
  440. $oOutput->AddHtml('</div>');
  441. // Value
  442. $oOutput->AddHtml('<div class="form_field_control">');
  443. $oOutput->AddHtml('<div class="form-control-static">' . $sFieldValue . '</div>');
  444. $oOutput->AddHtml('</div>');
  445. }
  446. // Adding hidden value
  447. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="' . $this->oField->GetCurrentValue() . '" class="form-control" />');
  448. // Closing container
  449. $oOutput->AddHtml('</div>');
  450. break;
  451. case 'Combodo\\iTop\\Form\\Field\\HiddenField':
  452. $oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('"/>');
  453. break;
  454. }
  455. }
  456. }
  457. return $oOutput;
  458. }
  459. protected function PreparingCaseLogEntries(RenderingOutput &$oOutput)
  460. {
  461. $aEntries = $this->oField->GetEntries();
  462. if (count($aEntries) > 0)
  463. {
  464. $oOutput->AddHtml('<div>');
  465. for ($i = 0; $i < count($aEntries); $i++)
  466. {
  467. $sEntryDate = AttributeDateTime::GetFormat()->Format($aEntries[$i]['date']);
  468. $sEntryUser = $aEntries[$i]['user_login'];
  469. $sEntryHeader = Dict::Format('UI:CaseLog:Header_Date_UserName', $sEntryDate, $sEntryUser);
  470. // Only the last 2 entries are expanded by default
  471. $sEntryContentExpanded = ($i < 2) ? 'true' : 'false';
  472. $sEntryHeaderButtonClass = ($i < 2) ? '' : 'collapsed';
  473. $sEntryContentClass = ($i < 2) ? 'in' : '';
  474. $sEntryContentId = 'caselog_field_entry_content-' . $this->oField->GetGlobalId() . '-' . $i;
  475. $sEntryHtml = AttributeText::RenderWikiHtml($aEntries[$i]['message_html'], true /* wiki only */);
  476. $sEntryHtml = InlineImage::FixUrls($sEntryHtml);
  477. // Note : We use CKEditor stylesheet to format this
  478. $oOutput->AddHtml(
  479. <<<EOF
  480. <div class="caselog_field_entry cke_inner">
  481. <div class="caselog_field_entry_header">
  482. {$sEntryHeader}
  483. <div class="pull-right">
  484. <span class="caselog_field_entry_button {$sEntryHeaderButtonClass}" data-toggle="collapse" href="#{$sEntryContentId}" aria-expanded="{$sEntryContentExpanded}" aria-controls="{$sEntryContentId}"></span>
  485. </div>
  486. </div>
  487. <div class="caselog_field_entry_content collapse {$sEntryContentClass}" id="{$sEntryContentId}">
  488. {$sEntryHtml}
  489. </div>
  490. </div>
  491. EOF
  492. );
  493. }
  494. $oOutput->AddHtml('</div>');
  495. }
  496. }
  497. }