BxInvGrid.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 Invites Invites
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxInvGrid extends BxTemplGrid
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_sFilter1Name;
  16. protected $_sFilter1Value;
  17. protected $_aFilter1Values;
  18. protected $_sParamsDivider;
  19. public function __construct ($aOptions, $oTemplate = false)
  20. {
  21. parent::__construct ($aOptions, $oTemplate);
  22. $this->_sModule = 'bx_invites';
  23. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  24. $this->_sParamsDivider = '#-#';
  25. }
  26. public function getFormCallBackUrlAPI($sAction, $iId = 0)
  27. {
  28. return '/api.php?r=system/perfom_action_api/TemplServiceGrid/&params[]=&o=' . $this->_sObject . '&a=' . $sAction;
  29. }
  30. public function performActionAdd()
  31. {
  32. $sAction = 'add';
  33. $oForm = $this->_oModule->getFormObjectInvite();
  34. if(!$oForm)
  35. return $this->_getActionResult([]);
  36. $oForm->aInputs['text']['value'] = _t('_bx_invites_msg_invitation');
  37. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?' . bx_encode_url_params($_GET, array('ids', '_r'));
  38. $oForm->initChecker();
  39. $aResult = [];
  40. if($oForm->isSubmittedAndValid()) {
  41. $sResult = $this->_oModule->processFormObjectInvite($oForm);
  42. if($this->_bIsApi)
  43. $aResult = [bx_api_get_msg($sResult)];
  44. else
  45. $aResult = ['msg' => $sResult];
  46. }
  47. else {
  48. if($this->_bIsApi)
  49. $aResult = $this->getFormBlockAPI($oForm, $sAction);
  50. else
  51. $aResult = ['popup' => [
  52. 'html' => BxTemplFunctions::getInstance()->popupBox('_bx_invites_form_invite', _t('_bx_invites_form_invite'), $this->_oModule->_oTemplate->parseHtmlByName('popup_invite.html', [
  53. 'form_id' => $oForm->id,
  54. 'form' => $oForm->getCode(true),
  55. 'object' => $this->_sObject,
  56. 'action' => $sAction
  57. ])),
  58. 'options' => ['closeOnOuterClick' => true]
  59. ]];
  60. }
  61. return $this->_getActionResult($aResult);
  62. }
  63. protected function _getFilterControls ()
  64. {
  65. parent::_getFilterControls();
  66. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  67. }
  68. protected function _getSearchInput()
  69. {
  70. $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
  71. $aInputSearch = [
  72. 'type' => 'text',
  73. 'name' => 'search',
  74. 'attrs' => [
  75. 'id' => 'bx-grid-search-' . $this->_sObject,
  76. 'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter(this)',
  77. 'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter(this)',
  78. ]
  79. ];
  80. $oForm = new BxTemplFormView([]);
  81. return $oForm->genRow($aInputSearch);
  82. }
  83. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
  84. {
  85. if(empty($sFilterName) || empty($aFilterValues))
  86. return '';
  87. $CNF = &$this->_oModule->_oConfig->CNF;
  88. $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
  89. foreach($aFilterValues as $sKey => $sValue)
  90. $aFilterValues[$sKey] = _t($sValue);
  91. $aInputModules = [
  92. 'type' => 'select',
  93. 'name' => $sFilterName,
  94. 'attrs' => [
  95. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  96. 'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
  97. ],
  98. 'value' => $sFilterValue,
  99. 'values' => $aFilterValues
  100. ];
  101. $oForm = new BxTemplFormView([]);
  102. return $oForm->genRow($aInputModules);
  103. }
  104. protected function _getId()
  105. {
  106. $iId = 0;
  107. if(($aIds = bx_get('ids')) !== false) {
  108. if(!$aIds || !is_array($aIds))
  109. return 0;
  110. $iId = (int)array_shift($aIds);
  111. }
  112. else if(($iId = bx_get('id')) !== false)
  113. $iId = (int)$iId;
  114. return $iId;
  115. }
  116. protected function _getIds()
  117. {
  118. $aIds = [];
  119. if(($aIds = bx_get('ids')) !== false) {
  120. if(!$aIds || !is_array($aIds))
  121. return [];
  122. $aIds = bx_process_input($aIds, BX_DATA_INT);
  123. }
  124. else if(($iId = bx_get('id')) !== false)
  125. $aIds = [(int)$iId];
  126. return $aIds;
  127. }
  128. }
  129. /** @} */