BxBaseModGeneralGridAdministration.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup TridentModules
  8. * @{
  9. */
  10. bx_import('BxDolModule');
  11. bx_import('BxTemplGrid');
  12. class BxBaseModGeneralGridAdministration extends BxTemplGrid
  13. {
  14. protected $MODULE;
  15. protected $_oModule;
  16. protected $_sManageType;
  17. protected $_sParamsDivider;
  18. public function __construct ($aOptions, $oTemplate = false)
  19. {
  20. parent::__construct ($aOptions, $oTemplate);
  21. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  22. $this->_sManageType = 'administration';
  23. $this->_sParamsDivider = '#-#';
  24. }
  25. public function performActionDelete($aParams = array())
  26. {
  27. $CNF = &$this->_oModule->_oConfig->CNF;
  28. //TODO: remove this check when 'delete with content' feature will be realized in onDelete method.
  29. if(isset($aParams['with_content']) && $aParams['with_content'] === true) {
  30. $this->_echoResultJson(array('msg' => 'TODO: delete with content'));
  31. return;
  32. }
  33. $iAffected = 0;
  34. $aIds = bx_get('ids');
  35. if(!$aIds || !is_array($aIds)) {
  36. $this->_echoResultJson(array());
  37. exit;
  38. }
  39. $aIdsAffected = array ();
  40. foreach($aIds as $iId) {
  41. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
  42. if($this->_oModule->checkAllowedDelete($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  43. continue;
  44. if($this->_oModule->serviceDeleteEntity($iId) != '')
  45. continue;
  46. if(!$this->_onDelete($iId, $aParams))
  47. continue;
  48. $this->_oModule->checkAllowedDelete($aContentInfo, true);
  49. $aIdsAffected[] = $iId;
  50. $iAffected++;
  51. }
  52. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_delete'])));
  53. }
  54. protected function _getActionSettings($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  55. {
  56. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  57. $sMenuName = $this->_oModule->_oConfig->CNF['OBJECT_MENU_MANAGE_TOOLS'];
  58. bx_import('BxDolMenu');
  59. $sMenu = BxDolMenu::getObjectInstance($sMenuName)->getCode();
  60. if(empty($sMenu))
  61. return '';
  62. $a['attr'] = array_merge($a['attr'], array(
  63. "bx-popup-id" => $sMenuName . "-" . $aRow['id'],
  64. "onclick" => "$(this).off('click'); " . $sJsObject . ".onClickSettings('" . $sMenuName . "', this);"
  65. ));
  66. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  67. }
  68. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
  69. {
  70. if(empty($sFilterName) || empty($aFilterValues))
  71. return '';
  72. $CNF = &$this->_oModule->_oConfig->CNF;
  73. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  74. foreach($aFilterValues as $sKey => $sValue)
  75. $aFilterValues[$sKey] = _t($sValue);
  76. $aInputModules = array(
  77. 'type' => 'select',
  78. 'name' => $sFilterName,
  79. 'attrs' => array(
  80. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  81. 'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
  82. ),
  83. 'value' => $sFilterValue,
  84. 'values' => array_merge(array('' => _t($CNF['T']['filter_item_select_one_' . $sFilterName])), $aFilterValues)
  85. );
  86. bx_import('BxTemplFormView');
  87. $oForm = new BxTemplFormView(array());
  88. return $oForm->genRow($aInputModules);
  89. }
  90. protected function _getSearchInput()
  91. {
  92. $sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
  93. $aInputSearch = array(
  94. 'type' => 'text',
  95. 'name' => 'search',
  96. 'attrs' => array(
  97. 'id' => 'bx-grid-search-' . $this->_sObject,
  98. 'onKeyup' => 'javascript:$(this).off(\'keyup\'); ' . $sJsObject . '.onChangeFilter(this)'
  99. )
  100. );
  101. bx_import('BxTemplFormView');
  102. $oForm = new BxTemplFormView(array());
  103. return $oForm->genRow($aInputSearch);
  104. }
  105. protected function _onDelete($iId, $aParams = array())
  106. {
  107. return true;
  108. }
  109. }
  110. /** @} */