|
|
@@ -26,6 +26,30 @@ class BxBaseModGroupsGridPricesManage extends BxBaseModGroupsGridPrices
|
|
|
$this->setRoleId($iRoleId);
|
|
|
}
|
|
|
|
|
|
+ public function getFormBlockTitleAPI($sAction, $iId = 0)
|
|
|
+ {
|
|
|
+ $CNF = &$this->_oModule->_oConfig->CNF;
|
|
|
+
|
|
|
+ $sResult = '';
|
|
|
+
|
|
|
+ switch($sAction) {
|
|
|
+ case 'add':
|
|
|
+ $sResult = _t($CNF['T']['popup_title_price_add']);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'edit':
|
|
|
+ $sResult = _t($CNF['T']['popup_title_price_edit']);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $sResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getFormCallBackUrlAPI($sAction, $iId = 0)
|
|
|
+ {
|
|
|
+ return '/api.php?r=system/perfom_action_api/TemplServiceGrid/¶ms[]=&o=' . $this->_sObject . '&a=' . $sAction . '&profile_id=' . $this->_iGroupProfileId . '&role_id=' . $this->_iRoleId . '&id=' . $iId;
|
|
|
+ }
|
|
|
+
|
|
|
public function setRoleId($iRoleId)
|
|
|
{
|
|
|
$this->_iRoleId = (int)$iRoleId;
|
|
|
@@ -56,12 +80,12 @@ class BxBaseModGroupsGridPricesManage extends BxBaseModGroupsGridPrices
|
|
|
|
|
|
public function performActionAdd()
|
|
|
{
|
|
|
- $CNF = &$this->_oModule->_oConfig->CNF;
|
|
|
+ $CNF = &$this->_oModule->_oConfig->CNF;
|
|
|
|
|
|
- $sAction = 'add';
|
|
|
+ $sAction = 'add';
|
|
|
|
|
|
if(($mixedResult = $this->_oModule->checkAllowedEdit($this->_aGroupContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
|
|
|
- return echoJson(['msg' => $mixedResult]);
|
|
|
+ return $this->_bIsApi ? [bx_api_get_msg($mixedResult)] : echoJson(['msg' => $mixedResult]);
|
|
|
|
|
|
$sFilter = bx_get('filter');
|
|
|
if(strpos($sFilter, $this->_sParamsDivider) !== false)
|
|
|
@@ -71,8 +95,8 @@ class BxBaseModGroupsGridPricesManage extends BxBaseModGroupsGridPrices
|
|
|
$this->_iRoleId = (int)$iRoleId;
|
|
|
|
|
|
$sForm = $CNF['OBJECT_FORM_PRICE_DISPLAY_ADD'];
|
|
|
- $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_PRICE'], $CNF['OBJECT_FORM_PRICE_DISPLAY_ADD']);
|
|
|
- $oForm->setId($sForm);
|
|
|
+ $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_PRICE'], $CNF['OBJECT_FORM_PRICE_DISPLAY_ADD']);
|
|
|
+ $oForm->setId($sForm);
|
|
|
$oForm->setName($sForm);
|
|
|
$oForm->setAction(BX_DOL_URL_ROOT . bx_append_url_params('grid.php', array('o' => $this->_sObject, 'a' => $sAction, 'profile_id' => $this->_iGroupProfileId, 'role_id' => $this->_iRoleId)));
|
|
|
$oForm->setRoleId($this->_iRoleId);
|
|
|
@@ -83,77 +107,80 @@ class BxBaseModGroupsGridPricesManage extends BxBaseModGroupsGridPrices
|
|
|
$sPeriodUnit = $oForm->getCleanValue('period_unit');
|
|
|
|
|
|
if(!empty($iPeriod) && empty($sPeriodUnit))
|
|
|
- return echoJson(array('msg' => _t($CNF['T']['err_period_unit'])));
|
|
|
+ return ($sMsg = _t($CNF['T']['err_period_unit'])) && $this->_bIsApi ? [bx_api_get_msg($sMsg)] : echoJson(['msg' => $sMsg]);
|
|
|
|
|
|
- $aPrice = $this->_oModule->_oDb->getPrices(array('type' => 'by_prpp', 'profile_id' => $this->_iGroupProfileId, 'role_id' => $this->_iRoleId, 'period' => $iPeriod, 'period_unit' => $sPeriodUnit));
|
|
|
+ $aPrice = $this->_oModule->_oDb->getPrices(['type' => 'by_prpp', 'profile_id' => $this->_iGroupProfileId, 'role_id' => $this->_iRoleId, 'period' => $iPeriod, 'period_unit' => $sPeriodUnit]);
|
|
|
if(!empty($aPrice) && is_array($aPrice))
|
|
|
- return echoJson(array('msg' => _t($CNF['T']['err_price_duplicate'])));
|
|
|
+ return ($sMsg = _t($CNF['T']['err_price_duplicate'])) && $this->_bIsApi ? [bx_api_get_msg($sMsg)] : echoJson(['msg' => $sMsg]);
|
|
|
|
|
|
- $iId = (int)$oForm->insert(array('profile_id' => $this->_iGroupProfileId, 'order' => $this->_oModule->_oDb->getPriceOrderMax($this->_iRoleId) + 1));
|
|
|
+ $iId = (int)$oForm->insert(['profile_id' => $this->_iGroupProfileId, 'order' => $this->_oModule->_oDb->getPriceOrderMax($this->_iRoleId) + 1]);
|
|
|
if($iId != 0)
|
|
|
- $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
|
|
|
+ $aRes = ['grid' => $this->getCode(false), 'blink' => $iId];
|
|
|
else
|
|
|
- $aRes = array('msg' => _t($CNF['T']['err_cannot_perform']));
|
|
|
+ $aRes = ['msg' => _t($CNF['T']['err_cannot_perform'])];
|
|
|
|
|
|
- echoJson($aRes);
|
|
|
- return;
|
|
|
+ return $this->_bIsApi ? [] : echoJson($aRes);
|
|
|
}
|
|
|
|
|
|
+ if($this->_bIsApi)
|
|
|
+ return $this->getFormBlockAPI($oForm, $sAction);
|
|
|
+
|
|
|
bx_import('BxTemplFunctions');
|
|
|
- $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('popup_price'), _t($CNF['T']['popup_title_price_add']), $this->_oModule->_oTemplate->parseHtmlByName('popup_price.html', array(
|
|
|
+ $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('popup_price'), _t($CNF['T']['popup_title_price_add']), $this->_oModule->_oTemplate->parseHtmlByName('popup_price.html', [
|
|
|
'form_id' => $oForm->getId(),
|
|
|
'form' => $oForm->getCode(true),
|
|
|
'object' => $this->_sObject,
|
|
|
'action' => $sAction
|
|
|
- )));
|
|
|
+ ]));
|
|
|
|
|
|
- echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
|
|
|
+ echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]]);
|
|
|
}
|
|
|
|
|
|
public function performActionEdit()
|
|
|
{
|
|
|
- $CNF = &$this->_oModule->_oConfig->CNF;
|
|
|
+ $CNF = &$this->_oModule->_oConfig->CNF;
|
|
|
|
|
|
$sAction = 'edit';
|
|
|
|
|
|
if(($mixedResult = $this->_oModule->checkAllowedEdit($this->_aGroupContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
|
|
|
- return echoJson(['msg' => $mixedResult]);
|
|
|
+ return $this->_bIsApi ? [bx_api_get_msg($mixedResult)] : echoJson(['msg' => $mixedResult]);
|
|
|
|
|
|
$aIds = $this->_getIds();
|
|
|
if($aIds === false)
|
|
|
- return echoJson(array());
|
|
|
+ return $this->_bIsApi ? [] : echoJson([]);
|
|
|
|
|
|
- $aItem = $this->_oModule->_oDb->getPrices(array('type' => 'by_id', 'value' => array_shift($aIds)));
|
|
|
+ $aItem = $this->_oModule->_oDb->getPrices(['type' => 'by_id', 'value' => array_shift($aIds)]);
|
|
|
if(!is_array($aItem) || empty($aItem))
|
|
|
- return echoJson(array());
|
|
|
+ return $this->_bIsApi ? [] : echoJson([]);
|
|
|
|
|
|
$sForm = $CNF['OBJECT_FORM_PRICE_DISPLAY_EDIT'];
|
|
|
$oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_PRICE'], $CNF['OBJECT_FORM_PRICE_DISPLAY_EDIT']);
|
|
|
$oForm->setId($sForm);
|
|
|
$oForm->setName($sForm);
|
|
|
- $oForm->setAction(BX_DOL_URL_ROOT . bx_append_url_params('grid.php', ['o' => $this->_sObject, 'a' => $sAction, 'profile_id' => $this->_iGroupProfileId, 'role_id' => $this->_iRoleId]));
|
|
|
+ $oForm->setAction(BX_DOL_URL_ROOT . bx_append_url_params('grid.php', ['o' => $this->_sObject, 'a' => $sAction, 'profile_id' => $this->_iGroupProfileId, 'role_id' => $this->_iRoleId]));
|
|
|
|
|
|
$oForm->initChecker($aItem);
|
|
|
if($oForm->isSubmittedAndValid()) {
|
|
|
if($oForm->update($aItem['id']) !== false)
|
|
|
- $aRes = array('grid' => $this->getCode(false), 'blink' => $aItem['id']);
|
|
|
+ $aRes = ['grid' => $this->getCode(false), 'blink' => $aItem['id']];
|
|
|
else
|
|
|
- $aRes = array('msg' => _t($CNF['T']['err_cannot_perform']));
|
|
|
+ $aRes = ['msg' => _t($CNF['T']['err_cannot_perform'])];
|
|
|
|
|
|
- return echoJson($aRes);
|
|
|
+ return $this->_bIsApi ? [] : echoJson($aRes);
|
|
|
}
|
|
|
|
|
|
+ if($this->_bIsApi)
|
|
|
+ return $this->getFormBlockAPI($oForm, $sAction, $iItem);
|
|
|
+
|
|
|
bx_import('BxTemplFunctions');
|
|
|
- $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('popup_price'), _t($CNF['T']['popup_title_price_edit']), $this->_oModule->_oTemplate->parseHtmlByName('popup_price.html', array(
|
|
|
+ $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('popup_price'), _t($CNF['T']['popup_title_price_edit']), $this->_oModule->_oTemplate->parseHtmlByName('popup_price.html', [
|
|
|
'form_id' => $oForm->getId(),
|
|
|
'form' => $oForm->getCode(true),
|
|
|
'object' => $this->_sObject,
|
|
|
'action' => $sAction
|
|
|
- )));
|
|
|
-
|
|
|
- $aRes = array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false)));
|
|
|
+ ]));
|
|
|
|
|
|
- return echoJson($aRes);
|
|
|
+ return echoJson(['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]]);
|
|
|
}
|
|
|
|
|
|
public function performActionDelete()
|