BxOAuthGrid.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup OAuth2 OAuth2 server
  7. * @ingroup TridentModules
  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. $oModule = BxDolModule::getInstance('bx_oauth');
  37. bx_import('FormAdd', $oModule->_aModule);
  38. $oForm = new BxOAuthFormAdd($oModule);
  39. $oForm->initChecker();
  40. if ($oForm->isSubmittedAndValid()) { // if form is submitted and all fields are valid
  41. $iNewId = $oForm->insert (array(), true); // insert record to database
  42. if ($iNewId)
  43. $aRes = array('grid' => $this->getCode(false), 'blink' => $iNewId); // if record is successfully added, reload grid and highlight added row
  44. else
  45. $aRes = array('msg' => _t('_error occured')); // if record adding failed, display error message
  46. echoJson($aRes);
  47. } else { // if form is not submitted or some fields are invalid, display popup with form
  48. // we need to use 'transBox' function to properly display 'popup'
  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-add").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, "add");
  61. }
  62. });
  63. });
  64. </script>');
  65. echoJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))));
  66. }
  67. }
  68. }
  69. /** @} */