1
0

BxDolStudioApiKeys.php 5.4 KB

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