BxDolStudioAgentsInstruments.php 3.0 KB

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