BxBaseModGeneralGrid.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. * @{
  9. */
  10. class BxBaseModGeneralGrid extends BxTemplGrid
  11. {
  12. protected $MODULE;
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_sParamsDivider;
  16. protected $_sJsObject;
  17. public function __construct ($aOptions, $oTemplate = false)
  18. {
  19. $this->MODULE = $this->MODULE ?: $this->_sModule;
  20. $this->_sModule = $this->_sModule ?: $this->MODULE;
  21. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  22. parent::__construct ($aOptions, $oTemplate ?: $this->_oModule->_oTemplate);
  23. $this->_sParamsDivider = '#-#';
  24. }
  25. protected function _getFilterOnChange()
  26. {
  27. return '';
  28. }
  29. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, $bAddSelectOne = true)
  30. {
  31. if(empty($sFilterName))
  32. return '';
  33. $CNF = &$this->_oModule->_oConfig->CNF;
  34. $aInputValues = [];
  35. if($bAddSelectOne)
  36. $aInputValues[''] = _t($CNF['T']['filter_item_select_one_' . $sFilterName] ?? '_Select_one');
  37. foreach($aFilterValues as $mixedKey => $mixedValue)
  38. if(is_array($mixedValue) && isset($mixedValue['key'], $mixedValue['value']))
  39. $aInputValues[$mixedValue['key']] = _t($mixedValue['value']);
  40. else
  41. $aInputValues[$mixedKey] = _t($mixedValue);
  42. $aInputModules = [
  43. 'type' => 'select',
  44. 'name' => $sFilterName,
  45. 'attrs' => [
  46. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  47. 'onChange' => 'javascript:' . $this->_getFilterOnChange()
  48. ],
  49. 'value' => $sFilterValue,
  50. 'values' => $aInputValues
  51. ];
  52. $oForm = new BxTemplFormView([]);
  53. return $oForm->genRow($aInputModules);
  54. }
  55. protected function _getSearchInput()
  56. {
  57. $sOnChange = $this->_getFilterOnChange();
  58. $aInputSearch = [
  59. 'type' => 'text',
  60. 'name' => 'search',
  61. 'attrs' => [
  62. 'id' => 'bx-grid-search-' . $this->_sObject,
  63. 'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sOnChange,
  64. 'onBlur' => 'javascript:' . $sOnChange,
  65. ]
  66. ];
  67. $oForm = new BxTemplFormView([]);
  68. return $oForm->genRow($aInputSearch);
  69. }
  70. }
  71. /** @} */