|
|
@@ -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))));
|
|
|
}
|
|
|
}
|
|
|
|