AntonLV %!s(int64=9) %!d(string=hai) anos
pai
achega
6194b21a5c

+ 10 - 0
modules/boonex/oauth2/classes/BxOAuthDb.php

@@ -22,6 +22,16 @@ class BxOAuthDb extends BxDolModuleDb
         $sSelectClause = $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause = "";
 
         switch($aParams['type']) {
+            case 'id':
+                $aMethod['name'] = 'getRow';
+                $aMethod['params'][1] = array(
+                	'id' => $aParams['id']
+                );
+
+                $sWhereClause .= "AND `tc`.`id`=:id";
+                $sLimitClause .= "LIMIT 1";
+                break;
+
             case 'client_id':
                 $aMethod['name'] = 'getRow';
                 $aMethod['params'][1] = array(

+ 10 - 10
modules/boonex/oauth2/classes/BxOAuthFormAdd.php

@@ -11,20 +11,24 @@
 
 class BxOAuthFormAdd extends BxTemplFormView
 {
-     protected static $LENGTH_ID = 10;
-     protected static $LENGTH_SECRET = 32;
+    protected static $LENGTH_ID = 10;
+    protected static $LENGTH_SECRET = 32;
 
-    function __construct ($oModule)
+    protected $_sModule;
+    protected $_oModule;
+
+    function __construct($aCustomForm = array())
     {
-        $aCustomForm = array(
+        $this->_sModule = 'bx_oauth';
+    	$this->_oModule = BxDolModule::getInstance($this->_sModule);
 
+        $aCustomForm = array_replace_recursive(array(
             'form_attrs' => array(
                 'id' => 'bx-oauth-add',
                 'name' => 'bx-oauth-add',
                 'action' => BX_DOL_URL_ROOT . 'grid.php?' . bx_encode_url_params($_GET, array('ids', '_r')),
                 'method' => 'post',
             ),
-
             'params' => array (
                 'db' => array(
                     'table' => 'bx_oauth_clients',
@@ -32,9 +36,7 @@ class BxOAuthFormAdd extends BxTemplFormView
                     'submit_name' => 'client_add',
                 ),
             ),
-
             'inputs' => array(
-
                 'title' => array(
                     'type' => 'text',
                     'name' => 'title',
@@ -48,7 +50,6 @@ class BxOAuthFormAdd extends BxTemplFormView
                         'pass' => 'Xss',
                     ),
                 ),
-
                 'redirect_uri' => array(
                     'type' => 'text',
                     'name' => 'redirect_uri',
@@ -63,7 +64,6 @@ class BxOAuthFormAdd extends BxTemplFormView
                         'pass' => 'Xss',
                     ),
                 ),
-
                 'Submit' => array (
                     'type' => 'input_set',
                     0 => array (
@@ -82,7 +82,7 @@ class BxOAuthFormAdd extends BxTemplFormView
                     ),
                 ),
             ),
-        );
+        ), $aCustomForm);
 
         parent::__construct ($aCustomForm);
     }

+ 39 - 0
modules/boonex/oauth2/classes/BxOAuthFormEdit.php

@@ -0,0 +1,39 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    OAuth2 OAuth2 server
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+require_once('BxOAuthFormAdd.php');
+
+class BxOAuthFormEdit extends BxOAuthFormAdd
+{
+    function __construct ($aCustomForm = array())
+    {
+        $aCustomForm = array_replace_recursive(array(
+        	'form_attrs' => array(
+        		'id' => 'bx-oauth-edit',
+                'name' => 'bx-oauth-edit',
+            ),
+            'inputs' => array(
+                'id' => array(
+                    'type' => 'hidden',
+                    'name' => 'id',
+                    'value' => '',
+                    'db' => array (
+                        'pass' => 'Int',
+                    ),
+                ),
+            )
+        ), $aCustomForm);
+
+        parent::__construct($aCustomForm);
+    }
+}
+
+/** @} */

+ 80 - 28
modules/boonex/oauth2/classes/BxOAuthGrid.php

@@ -38,45 +38,97 @@ class BxOAuthGrid extends BxTemplGrid
      */
     public function performActionAdd()
     {
+        $sAction = 'add';
         $oModule = BxDolModule::getInstance('bx_oauth');
 
         bx_import('FormAdd', $oModule->_aModule);
-        $oForm = new BxOAuthFormAdd($oModule);
+        $oForm = new BxOAuthFormAdd();
         $oForm->initChecker();
 
-        if ($oForm->isSubmittedAndValid()) { // if form is submitted and all fields are valid
-
-            $iNewId = $oForm->insert (array(), true); // insert record to database
+        if ($oForm->isSubmittedAndValid()) {
+            $iNewId = $oForm->insert (array(), true);
             if ($iNewId)
-                $aRes = array('grid' => $this->getCode(false), 'blink' => $iNewId); // if record is successfully added, reload grid and highlight added row
+                $aRes = array('grid' => $this->getCode(false), 'blink' => $iNewId);
             else
-                $aRes = array('msg' => _t('_error occured')); // if record adding failed, display error message
-
-            echoJson($aRes);
-
-        } else { // if form is not submitted or some fields are invalid, display popup with form
-
-            // we need to use 'transBox' function to properly display 'popup'
-            $s = BxTemplFunctions::getInstance()->transBox('', '
-                <div class="bx-def-padding bx-def-color-bg-block">' . $oForm->getCode() . '</div>
-                <script>
-                    $(document).ready(function () {
-                        $("#bx-oauth-add").ajaxForm({
-                            dataType: "json",
-                            beforeSubmit: function (formData, jqForm, options) {
-                                bx_loading($("#' . $oForm->aFormAttrs['id'] . '"), true);
-                            },
-                            success: function (data) {
-                                $(".bx-popup-active").dolPopupHide();
-                                glGrids.' . $this->_sObject . '.processJson(data, "add");
-                            }
-                        });
+                $aRes = array('msg' => _t('_error occured'));
+
+           return echoJson($aRes);
+
+        }
+
+        $s = BxTemplFunctions::getInstance()->transBox('', '
+            <div class="bx-def-padding bx-def-color-bg-block">' . $oForm->getCode() . '</div>
+            <script>
+                $(document).ready(function () {
+                    $("#bx-oauth-' . $sAction . '").ajaxForm({
+                        dataType: "json",
+                        beforeSubmit: function (formData, jqForm, options) {
+                            bx_loading($("#' . $oForm->aFormAttrs['id'] . '"), true);
+                        },
+                        success: function (data) {
+                            $(".bx-popup-active").dolPopupHide();
+                            glGrids.' . $this->_sObject . '.processJson(data, "' . $sAction . '");
+                        }
                     });
-                </script>');
+                });
+            </script>');
 
-            echoJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))));
+        echoJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))));
+    }
+
+	/**
+     * 'edit' action handler
+     */
+    public function performActionEdit()
+    {
+        $sAction = 'edit';
+        $oModule = BxDolModule::getInstance('bx_oauth');
 
+        $aIds = bx_get('ids');
+        if(!$aIds || !is_array($aIds)) {
+            $iId = (int)bx_get('id');
+            if(!$iId) {
+                echoJson(array());
+                exit;
+            }
+
+            $aIds = array($iId);
         }
+
+        $iId = $aIds[0];
+        $aClient = $oModule->_oDb->getClientsBy(array('type' => 'id', 'id' => $iId));
+
+        bx_import('FormEdit', $oModule->_aModule);
+        $oForm = new BxOAuthFormEdit();
+
+        $oForm->initChecker($aClient);
+        if ($oForm->isSubmittedAndValid()) {
+            if ($oForm->update($iId))
+                $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
+            else
+                $aRes = array('msg' => _t('_error occured'));
+
+            return echoJson($aRes);
+        } 
+
+        $s = BxTemplFunctions::getInstance()->transBox('', '
+            <div class="bx-def-padding bx-def-color-bg-block">' . $oForm->getCode() . '</div>
+            <script>
+                $(document).ready(function () {
+                    $("#bx-oauth-' . $sAction . '").ajaxForm({
+                        dataType: "json",
+                        beforeSubmit: function (formData, jqForm, options) {
+                            bx_loading($("#' . $oForm->aFormAttrs['id'] . '"), true);
+                        },
+                        success: function (data) {
+                            $(".bx-popup-active").dolPopupHide();
+                            glGrids.' . $this->_sObject . '.processJson(data, "' . $sAction . '");
+                        }
+                    });
+                });
+            </script>');
+
+        echoJson(array('popup' => array('html' => $s, 'options' => array('closeOnOuterClick' => false))));
     }
 }
 

+ 8 - 6
modules/boonex/oauth2/install/sql/enable.sql

@@ -8,12 +8,14 @@ INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `params`, `or
 ('bx_oauth', 'checkbox', 'Select', '2%', '', 10),
 ('bx_oauth', 'title', '_Title', '20%', '', 20),
 ('bx_oauth', 'client_id', '_bx_oauth_client_id', '15%', '', 30),
-('bx_oauth', 'client_secret', '_bx_oauth_client_secret', '30%', '', 40),
-('bx_oauth', 'redirect_uri', '_bx_oauth_url', '33%', '', 50);
-
-INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `confirm`, `order`) VALUES
-('bx_oauth', 'bulk', 'delete', '_Delete', 1, 1),
-('bx_oauth', 'independent', 'add', '_bx_oauth_add', 0, 1);
+('bx_oauth', 'client_secret', '_bx_oauth_client_secret', '20%', '', 40),
+('bx_oauth', 'redirect_uri', '_bx_oauth_url', '25%', '', 50),
+('bx_oauth', 'actions', '', '18%', '', 60);
+
+INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `icon_only`, `confirm`, `order`) VALUES
+('bx_oauth', 'bulk', 'delete', '_Delete', '', 0, 1, 1),
+('bx_oauth', 'single', 'edit', '_Edit', 'pencil', 1, 0, 1),
+('bx_oauth', 'independent', 'add', '_bx_oauth_add', '', 0, 0, 1);
 
 -- SETTINGS