BxOAuthGrid.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 OAuth2 OAuth2 server
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxOAuthGrid extends BxTemplGrid
  12. {
  13. public function __construct ($aOptions, $oTemplate = false)
  14. {
  15. parent::__construct ($aOptions, $oTemplate);
  16. }
  17. /**
  18. * add js file for AJAX form submission
  19. */
  20. protected function _addJsCss()
  21. {
  22. parent::_addJsCss();
  23. $this->_oTemplate->addJs('jquery.form.min.js');
  24. $oForm = new BxTemplFormView(array());
  25. $oForm->addCssJs();
  26. }
  27. protected function _isVisibleGrid ($a)
  28. {
  29. return isAdmin();
  30. }
  31. protected function _getCellClientSecret($mixedValue, $sKey, $aField, $aRow)
  32. {
  33. return $this->_getCellSecret($mixedValue, $sKey, $aField, $aRow);
  34. }
  35. /**
  36. * 'add' action handler
  37. */
  38. public function performActionAdd()
  39. {
  40. $sAction = 'add';
  41. $oModule = BxDolModule::getInstance('bx_oauth');
  42. bx_import('FormAdd', $oModule->_aModule);
  43. $oForm = new BxOAuthFormAdd();
  44. $oForm->initChecker();
  45. if ($oForm->isSubmittedAndValid()) {
  46. $iNewId = $oForm->insert (array(), true);
  47. if ($iNewId)
  48. $aRes = array('grid' => $this->getCode(false), 'blink' => $iNewId);
  49. else
  50. $aRes = array('msg' => _t('_error occured'));
  51. return echoJson($aRes);
  52. }
  53. $s = BxTemplFunctions::getInstance()->transBox('', '
  54. <div class="bx-def-padding bx-def-color-bg-block">' . $oForm->getCode() . '</div>
  55. <script>
  56. $(document).ready(function () {
  57. $("#bx-oauth-' . $sAction . '").ajaxForm({
  58. dataType: "json",
  59. beforeSubmit: function (formData, jqForm, options) {
  60. bx_loading($("#' . $oForm->aFormAttrs['id'] . '"), true);
  61. },
  62. success: function (data) {
  63. $(".bx-popup-active").dolPopupHide();
  64. glGrids.' . $this->_sObject . '.processJson(data, "' . $sAction . '");
  65. }
  66. });
  67. });
  68. </script>');
  69. echoJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))));
  70. }
  71. /**
  72. * 'edit' action handler
  73. */
  74. public function performActionEdit()
  75. {
  76. $sAction = 'edit';
  77. $oModule = BxDolModule::getInstance('bx_oauth');
  78. $aIds = bx_get('ids');
  79. if(!$aIds || !is_array($aIds)) {
  80. $iId = (int)bx_get('id');
  81. if(!$iId) {
  82. echoJson(array());
  83. exit;
  84. }
  85. $aIds = array($iId);
  86. }
  87. $iId = $aIds[0];
  88. $aClient = $oModule->_oDb->getClientsBy(array('type' => 'id', 'id' => $iId));
  89. bx_import('FormEdit', $oModule->_aModule);
  90. $oForm = new BxOAuthFormEdit();
  91. $oForm->initChecker($aClient);
  92. if ($oForm->isSubmittedAndValid()) {
  93. if ($oForm->update($iId))
  94. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  95. else
  96. $aRes = array('msg' => _t('_error occured'));
  97. return echoJson($aRes);
  98. }
  99. $s = BxTemplFunctions::getInstance()->transBox('', '
  100. <div class="bx-def-padding bx-def-color-bg-block">' . $oForm->getCode() . '</div>
  101. <script>
  102. $(document).ready(function () {
  103. $("#bx-oauth-' . $sAction . '").ajaxForm({
  104. dataType: "json",
  105. beforeSubmit: function (formData, jqForm, options) {
  106. bx_loading($("#' . $oForm->aFormAttrs['id'] . '"), true);
  107. },
  108. success: function (data) {
  109. $(".bx-popup-active").dolPopupHide();
  110. glGrids.' . $this->_sObject . '.processJson(data, "' . $sAction . '");
  111. }
  112. });
  113. });
  114. </script>');
  115. echoJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))));
  116. }
  117. }
  118. /** @} */