BxOAuthGrid.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. /**
  32. * 'add' action handler
  33. */
  34. public function performActionAdd()
  35. {
  36. $sAction = 'add';
  37. $oModule = BxDolModule::getInstance('bx_oauth');
  38. bx_import('FormAdd', $oModule->_aModule);
  39. $oForm = new BxOAuthFormAdd();
  40. $oForm->initChecker();
  41. if ($oForm->isSubmittedAndValid()) {
  42. $iNewId = $oForm->insert (array(), true);
  43. if ($iNewId)
  44. $aRes = array('grid' => $this->getCode(false), 'blink' => $iNewId);
  45. else
  46. $aRes = array('msg' => _t('_error occured'));
  47. return echoJson($aRes);
  48. }
  49. $s = BxTemplFunctions::getInstance()->transBox('', '
  50. <div class="bx-def-padding bx-def-color-bg-block">' . $oForm->getCode() . '</div>
  51. <script>
  52. $(document).ready(function () {
  53. $("#bx-oauth-' . $sAction . '").ajaxForm({
  54. dataType: "json",
  55. beforeSubmit: function (formData, jqForm, options) {
  56. bx_loading($("#' . $oForm->aFormAttrs['id'] . '"), true);
  57. },
  58. success: function (data) {
  59. $(".bx-popup-active").dolPopupHide();
  60. glGrids.' . $this->_sObject . '.processJson(data, "' . $sAction . '");
  61. }
  62. });
  63. });
  64. </script>');
  65. echoJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))));
  66. }
  67. /**
  68. * 'edit' action handler
  69. */
  70. public function performActionEdit()
  71. {
  72. $sAction = 'edit';
  73. $oModule = BxDolModule::getInstance('bx_oauth');
  74. $aIds = bx_get('ids');
  75. if(!$aIds || !is_array($aIds)) {
  76. $iId = (int)bx_get('id');
  77. if(!$iId) {
  78. echoJson(array());
  79. exit;
  80. }
  81. $aIds = array($iId);
  82. }
  83. $iId = $aIds[0];
  84. $aClient = $oModule->_oDb->getClientsBy(array('type' => 'id', 'id' => $iId));
  85. bx_import('FormEdit', $oModule->_aModule);
  86. $oForm = new BxOAuthFormEdit();
  87. $oForm->initChecker($aClient);
  88. if ($oForm->isSubmittedAndValid()) {
  89. if ($oForm->update($iId))
  90. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  91. else
  92. $aRes = array('msg' => _t('_error occured'));
  93. return echoJson($aRes);
  94. }
  95. $s = BxTemplFunctions::getInstance()->transBox('', '
  96. <div class="bx-def-padding bx-def-color-bg-block">' . $oForm->getCode() . '</div>
  97. <script>
  98. $(document).ready(function () {
  99. $("#bx-oauth-' . $sAction . '").ajaxForm({
  100. dataType: "json",
  101. beforeSubmit: function (formData, jqForm, options) {
  102. bx_loading($("#' . $oForm->aFormAttrs['id'] . '"), true);
  103. },
  104. success: function (data) {
  105. $(".bx-popup-active").dolPopupHide();
  106. glGrids.' . $this->_sObject . '.processJson(data, "' . $sAction . '");
  107. }
  108. });
  109. });
  110. </script>');
  111. echoJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))));
  112. }
  113. }
  114. /** @} */