BxDolStudioApiKeys.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 BxDolStudioApiKeys extends BxTemplStudioGrid
  10. {
  11. public function __construct ($aOptions, $oTemplate = false)
  12. {
  13. parent::__construct ($aOptions, $oTemplate);
  14. }
  15. protected function _getCellKey($mixedValue, $sKey, $aField, $aRow)
  16. {
  17. return $this->_getCellSecret($mixedValue, $sKey, $aField, $aRow);
  18. }
  19. public function _performActionAdd($aForm, $aCustomValues = [])
  20. {
  21. $oForm = new BxTemplFormView($aForm);
  22. $oForm->initChecker();
  23. if ($oForm->isSubmittedAndValid()) { // if form is submitted and all fields are valid
  24. $iRecentId = $oForm->insert ($aCustomValues, true); // insert new record
  25. if ($iRecentId)
  26. $aRes = array('grid' => $this->getCode(false), 'blink' => $iRecentId); // if record is successfully added, reload grid and highlight added row
  27. else
  28. $aRes = array('msg' => _t('_sys_txt_error_occured')); // if record adding failed, display error message
  29. echoJson($aRes);
  30. } else { // if form is not submitted or some fields are invalid, display popup with form
  31. $s = BxTemplStudioFunctions::getInstance()->popupBox($oForm->getId() . '_form', '', $oForm->getCode() . '
  32. <script>
  33. $(document).ready(function () {
  34. $("#' . $oForm->getId() . '").ajaxForm({
  35. dataType: "json",
  36. beforeSubmit: function (formData, jqForm, options) {
  37. bx_loading($("#' . $oForm->getId() . '"), true);
  38. },
  39. success: function (data) {
  40. $(".bx-popup-applied:visible").dolPopupHide();
  41. glGrids.' . $this->_sObject . '.processJson(data, "add");
  42. }
  43. });
  44. });
  45. </script>');
  46. echoJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))));
  47. }
  48. }
  49. public function performActionAdd()
  50. {
  51. $aForm = array(
  52. 'form_attrs' => array(
  53. 'id' => 'bx_studio_api_keys',
  54. 'action' => BX_DOL_URL_ROOT . 'grid.php?o=sys_studio_api_keys&a=add',
  55. 'method' => 'post',
  56. ),
  57. 'params' => array (
  58. 'db' => array(
  59. 'table' => 'sys_api_keys',
  60. 'key' => 'id',
  61. 'submit_name' => 'do_submit',
  62. ),
  63. ),
  64. 'inputs' => array(
  65. 'title' => array(
  66. 'type' => 'text',
  67. 'name' => 'title',
  68. 'caption' => _t('_Name'),
  69. 'db' => array (
  70. 'pass' => 'Xss',
  71. ),
  72. ),
  73. 'submit' => array(
  74. 'type' => 'input_set',
  75. 0 => array (
  76. 'type' => 'submit',
  77. 'name' => 'do_submit',
  78. 'value' => _t('_sys_submit'),
  79. ),
  80. 1 => array (
  81. 'type' => 'reset',
  82. 'name' => 'close',
  83. 'value' => _t('_sys_close'),
  84. 'attrs' => array('class' => 'bx-def-margin-sec-left', 'onclick' => '$(\'.bx-popup-applied:visible\').dolPopupHide();'),
  85. ),
  86. ),
  87. ),
  88. );
  89. $aCustomValues = array(
  90. 'key' => genRndPwd(48),
  91. );
  92. return $this->_performActionAdd($aForm, $aCustomValues);
  93. /*
  94. $oForm = new BxTemplFormView($aForm);
  95. $oForm->initChecker();
  96. if ($oForm->isSubmittedAndValid()) { // if form is submitted and all fields are valid
  97. $aCustomValues = array(
  98. 'key' => genRndPwd(48),
  99. );
  100. $iRecentId = $oForm->insert ($aCustomValues, true); // insert new record
  101. if ($iRecentId)
  102. $aRes = array('grid' => $this->getCode(false), 'blink' => $iRecentId); // if record is successfully added, reload grid and highlight added row
  103. else
  104. $aRes = array('msg' => _t('_sys_txt_error_occured')); // if record adding failed, display error message
  105. echoJson($aRes);
  106. } else { // if form is not submitted or some fields are invalid, display popup with form
  107. $s = BxTemplFunctions::getInstance()->popupBox($oForm->getId() . '_form', '', $oForm->getCode() . '
  108. <script>
  109. $(document).ready(function () {
  110. $("#' . $oForm->getId() . '").ajaxForm({
  111. dataType: "json",
  112. beforeSubmit: function (formData, jqForm, options) {
  113. bx_loading($("#' . $oForm->getId() . '"), true);
  114. },
  115. success: function (data) {
  116. $(".bx-popup-applied:visible").dolPopupHide();
  117. glGrids.' . $this->_sObject . '.processJson(data, "add");
  118. }
  119. });
  120. });
  121. </script>');
  122. echoJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))));
  123. }
  124. */
  125. }
  126. }
  127. /** @} */