BxDolStudioAgentsInstruments.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 UnaStudio UNA Studio
  7. * @{
  8. */
  9. class BxDolStudioAgentsInstruments extends BxTemplStudioGridAgents
  10. {
  11. protected $_oDb;
  12. protected $_sFieldName;
  13. public function __construct ($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct ($aOptions, $oTemplate);
  16. $this->_sDefaultSortingOrder = 'DESC';
  17. $this->_sFieldName = 'name';
  18. $this->_oDb = new BxDolStudioAgentsQuery();
  19. }
  20. public function getPageJsObject()
  21. {
  22. return 'oBxDolStudioPageAgents';
  23. }
  24. public function _performActionDuplicate($sMethodGetData, $sMethodInsertData)
  25. {
  26. $iId = $this->_getId();
  27. $aData = $this->_oDb->$sMethodGetData($iId);
  28. if (!empty($aData)) {
  29. unset($aData['id']);
  30. $aData['title'] .= ' (Copy)';
  31. $aData['duplicate'] = 1;
  32. $aData['changed'] = time();
  33. $aData['active'] = 0;
  34. $iNewId = $this->_oDb->$sMethodInsertData($aData);
  35. if ($iNewId) {
  36. $aRes = ['grid' => $this->getCode(false), 'blink' => $iNewId];
  37. return echoJson($aRes);
  38. }
  39. }
  40. $aRes = ['msg' => _t('_sys_txt_error_occured')];
  41. return echoJson($aRes);
  42. }
  43. protected function _performActionEdit($sMethodGetDataById, $sPopupTitleKey)
  44. {
  45. $sAction = 'edit';
  46. $iId = $this->_getId();
  47. $aData = $this->_oDb->$sMethodGetDataById($iId);
  48. $aForm = $this->_getFormEdit($sAction, $aData);
  49. $oForm = new BxTemplFormView($aForm);
  50. $oForm->initChecker();
  51. if($oForm->isSubmittedAndValid()) {
  52. if($oForm->update($iId, ['changed' => time()]) === false)
  53. return echoJson(['msg' => _t('_sys_txt_error_occured')]);
  54. return echoJson(['grid' => $this->getCode(false), 'blink' => $iId]);
  55. }
  56. $sFormId = $oForm->getId();
  57. $sForm = $oForm->getCode(true);
  58. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($sFormId . '_popup_' . $sAction, _t($sPopupTitleKey), $this->_oTemplate->parseHtmlByName('agents_automator_form.html', [
  59. 'form_id' => $sFormId,
  60. 'form' => $sForm,
  61. 'object' => $this->_sObject,
  62. 'action' => $sAction
  63. ]));
  64. return echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]]);
  65. }
  66. protected function _getFormEdit($sAction, $aData = [])
  67. {
  68. $aForm = $this->_getForm($sAction, $aData);
  69. $aForm['form_attrs']['action'] .= '&id=' . $aData['id'];
  70. return $aForm;
  71. }
  72. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  73. {
  74. if ($sType == 'single' && $aRow['duplicate'] == 0)
  75. return '';
  76. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  77. }
  78. }
  79. /** @} */