BxBaseLabelForm.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. class BxBaseLabelForm extends BxTemplFormView
  10. {
  11. protected $_oObject;
  12. public function __construct($aInfo, $oTemplate)
  13. {
  14. parent::__construct($aInfo, $oTemplate);
  15. $this->_oObject = BxDolLabel::getInstance();
  16. switch($this->aParams['display']) {
  17. case 'sys_labels_select':
  18. $this->aInputs['action']['value'] = 'select_labels';
  19. break;
  20. }
  21. }
  22. public function initChecker($aValues = array(), $aSpecificValues = array())
  23. {
  24. return parent::initChecker($aValues, $aSpecificValues);
  25. }
  26. public function getFormElement($aInput = array())
  27. {
  28. $sName = !empty($aInput['name']) ? $aInput['name'] : 'labels';
  29. $sHtmlId = !empty($aInput['attrs']['id']) ? $aInput['attrs']['id'] : 'bx-form-element-labels';
  30. $sValue = '';
  31. if(!empty($aInput['value']) && is_array($aInput['value']))
  32. foreach($aInput['value'] as $sLabel)
  33. $sValue .= $this->_oObject->getLabel($sName, $sLabel);
  34. $sKeyPlaceholder = $aInput['caption_src'] . '_placeholder';
  35. if(strcmp($sKeyPlaceholder, _t($sKeyPlaceholder)) != 0)
  36. $sValue .= $this->_oObject->getLabelPlaceholder($sKeyPlaceholder);
  37. $aInputLabels = array(
  38. 'type' => 'custom',
  39. 'name' => $sName,
  40. 'caption' => '',
  41. 'value' => $sValue,
  42. 'ajax_get_suggestions' => BX_DOL_URL_ROOT . bx_append_url_params('label.php', array(
  43. 'action' => 'labels_list',
  44. )),
  45. 'attrs' => array(
  46. 'class' => 'bx-form-input-labels',
  47. 'disabled' => 'disabled'
  48. )
  49. );
  50. return $this->oTemplate->parseHtmlByName('label_select_field.html', array(
  51. 'js_object' => $this->_oObject->getJsObjectName(),
  52. 'js_code' => $this->_oObject->getJsCodeForm(),
  53. 'html_id' => $sHtmlId,
  54. 'name' => $sName,
  55. 'input_labels' => $this->genCustomInputUsernamesSuggestions($aInputLabels)
  56. ));
  57. }
  58. protected function genCustomInputSearch($aInput)
  59. {
  60. $aInput = array_merge($aInput, array(
  61. 'custom' => array(
  62. 'b_img' => false
  63. ),
  64. 'ajax_get_suggestions' => BX_DOL_URL_ROOT . bx_append_url_params('label.php', array(
  65. 'action' => 'labels_list',
  66. ))
  67. ));
  68. return $this->genCustomInputUsernamesSuggestions($aInput);
  69. }
  70. protected function genCustomInputList($aInput)
  71. {
  72. return $this->_oObject->getLabelsList($aInput, $this);
  73. }
  74. }
  75. /** @} */