1
0
Эх сурвалжийг харах

Ticket #2176 - Issue with submit after previous error was fixed.

AntonLV 7 жил өмнө
parent
commit
011ae116e7

+ 8 - 1
modules/base/files/classes/BxBaseModFilesFormsEntryHelper.php

@@ -27,7 +27,14 @@ class BxBaseModFilesFormsEntryHelper extends BxBaseModTextFormsEntryHelper
         if (false === $sDisplay)
         if (false === $sDisplay)
             $sDisplay = $this->_sDisplayForFormAdd;
             $sDisplay = $this->_sDisplayForFormAdd;
 
 
-        return BxDolForm::getObjectInstance($this->_sObjectNameForFormAdd, $sDisplay, $this->_oModule->_oTemplate);
+        $oForm = BxDolForm::getObjectInstance($this->_sObjectNameForFormAdd, $sDisplay, $this->_oModule->_oTemplate);
+        if($this->_bAjaxMode)
+            $oForm->setAjaxMode($this->_bAjaxMode);
+
+        if($this->_bAbsoluteActionUrl)
+            $this->_setAbsoluteActionUrl('add', $oForm);
+
+        return $oForm;
     }
     }
     
     
     protected function addDataFormAction ($sDisplay = false, $sCheckFunction = false)
     protected function addDataFormAction ($sDisplay = false, $sCheckFunction = false)

+ 57 - 9
modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php

@@ -24,6 +24,12 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
      */
      */
     protected $_bAjaxMode;
     protected $_bAjaxMode;
 
 
+    /**
+     * Use absolute Action URL in generated form object. 
+     * It's needed in Ajax Mode.
+     */
+    protected $_bAbsoluteActionUrl;
+
     protected $_bDynamicMode;
     protected $_bDynamicMode;
 
 
     public function __construct($oModule)
     public function __construct($oModule)
@@ -36,14 +42,24 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
         $this->_bAjaxMode = false;
         $this->_bAjaxMode = false;
         $mixedAjaxMode = bx_get('ajax_mode');
         $mixedAjaxMode = bx_get('ajax_mode');
         if($mixedAjaxMode !== false)
         if($mixedAjaxMode !== false)
-        	$this->setAjaxMode($mixedAjaxMode);
+            $this->setAjaxMode($mixedAjaxMode);
+
+        $this->_bAbsoluteActionUrl = false;
+        $mixedAbsoluteActionUrl = bx_get('absolute_action_url');
+        if($mixedAbsoluteActionUrl !== false)
+            $this->setAbsoluteActionUrl($mixedAbsoluteActionUrl);
     }
     }
 
 
     public function setAjaxMode($bAjaxMode)
     public function setAjaxMode($bAjaxMode)
     {
     {
         $this->_bAjaxMode = (bool)$bAjaxMode;
         $this->_bAjaxMode = (bool)$bAjaxMode;
         if($this->_bAjaxMode)
         if($this->_bAjaxMode)
-        	$this->setDynamicMode(true);
+            $this->setDynamicMode(true);
+    }
+
+    public function setAbsoluteActionUrl($bAbsoluteActionUrl)
+    {
+        $this->_bAbsoluteActionUrl = (bool)$bAbsoluteActionUrl;
     }
     }
 
 
     public function setDynamicMode($bDynamicMode)
     public function setDynamicMode($bDynamicMode)
@@ -60,23 +76,37 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
     {
     {
     	$CNF = &$this->_oModule->_oConfig->CNF;
     	$CNF = &$this->_oModule->_oConfig->CNF;
 
 
-        if (false === $sDisplay)
+        if(false === $sDisplay)
             $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'];
             $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'];
-        
-        return BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
+
+        $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
+        if($this->_bAjaxMode)
+            $oForm->setAjaxMode($this->_bAjaxMode);
+
+        if($this->_bAbsoluteActionUrl)
+            $this->_setAbsoluteActionUrl('add', $oForm);
+
+        return $oForm; 
     }
     }
 
 
     public function getObjectFormEdit ($sDisplay = false)
     public function getObjectFormEdit ($sDisplay = false)
     {
     {
     	$CNF = &$this->_oModule->_oConfig->CNF;
     	$CNF = &$this->_oModule->_oConfig->CNF;
 
 
-        if (false === $sDisplay)
+        if(false === $sDisplay)
             $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
             $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
 
 
-        return BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
+        $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
+        if($this->_bAjaxMode)
+            $oForm->setAjaxMode($this->_bAjaxMode);
+
+        if($this->_bAbsoluteActionUrl)
+            $this->_setAbsoluteActionUrl('edit', $oForm);
+
+        return $oForm;
     }
     }
 
 
-	public function getObjectFormView ($sDisplay = false)
+    public function getObjectFormView ($sDisplay = false)
     {
     {
     	$CNF = &$this->_oModule->_oConfig->CNF;
     	$CNF = &$this->_oModule->_oConfig->CNF;
 
 
@@ -93,7 +123,14 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
         if (false === $sDisplay)
         if (false === $sDisplay)
             $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_DELETE'];
             $sDisplay = $CNF['OBJECT_FORM_ENTRY_DISPLAY_DELETE'];
 
 
-        return BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
+        $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
+        if($this->_bAjaxMode)
+            $oForm->setAjaxMode($this->_bAjaxMode);
+
+        if($this->_bAbsoluteActionUrl)
+            $this->_setAbsoluteActionUrl('delete', $oForm);
+
+        return $oForm;
     }
     }
 
 
     public function viewDataEntry ($iContentId)
     public function viewDataEntry ($iContentId)
@@ -525,6 +562,17 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
 
 
         return $aResponse;
         return $aResponse;
     }
     }
+    
+    protected function _setAbsoluteActionUrl($sType, &$oForm)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        $sKeyUri = 'URI_' . strtoupper($sType) . '_ENTRY';
+        if(empty($CNF[$sKeyUri]))
+            return;
+
+        $oForm->setAbsoluteActionUrl(BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF[$sKeyUri]));
+    }
 }
 }
 
 
 /** @} */
 /** @} */

+ 8 - 11
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -451,22 +451,19 @@ class BxBaseModGeneralModule extends BxDolModule
         $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
         $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
         $oFormsHelper = new $sClass($this);
         $oFormsHelper = new $sClass($this);
 
 
+        $sParamsKey = 'ajax_mode';
+        if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
+            $oFormsHelper->setAjaxMode((bool)$aParams[$sParamsKey]);
+
+        $sParamsKey = 'absolute_action_url';
+        if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
+            $oFormsHelper->setAbsoluteActionUrl((bool)$aParams[$sParamsKey]);
+
         $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
         $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
 
 
         $sFunc = 'getObjectForm' . ucfirst($sType);
         $sFunc = 'getObjectForm' . ucfirst($sType);
         $oForm = $oFormsHelper->$sFunc($sDisplay);
         $oForm = $oFormsHelper->$sFunc($sDisplay);
 
 
-        $sParamsKey = 'absolute_action_url';
-        if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true) {
-            $sKeyUri = 'URI_' . strtoupper($sType) . '_ENTRY';
-            if(!empty($this->_oConfig->CNF[$sKeyUri]))
-                $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF[$sKeyUri]);
-        }
-
-        $sParamsKey = 'ajax_mode';
-        if(isset($aParams[$sParamsKey]) && is_bool($aParams[$sParamsKey]))
-        	$oForm->setAjaxMode((bool)$aParams[$sParamsKey]);
-
         $sKey = 'FIELD_ALLOW_VIEW_TO';
         $sKey = 'FIELD_ALLOW_VIEW_TO';
         if(!empty($aParams['context_id']) && !empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]])) {
         if(!empty($aParams['context_id']) && !empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]])) {
             foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $aValue)
             foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $aValue)

+ 31 - 12
template/scripts/BxBaseFormView.php

@@ -58,6 +58,11 @@ class BxBaseFormView extends BxDolForm
      * Form is submitted dynamically (using Ajax Submit).
      * Form is submitted dynamically (using Ajax Submit).
      */
      */
     protected $_bAjaxMode = false;
     protected $_bAjaxMode = false;
+    
+    /**
+     * Use absolute Action URL which is needed in Ajax Mode.
+     */
+    protected $_bAbsoluteActionUrl = false;
 
 
     /**
     /**
      * Form is displayed in view mode.
      * Form is displayed in view mode.
@@ -99,29 +104,33 @@ class BxBaseFormView extends BxDolForm
     {
     {
         parent::__construct($aInfo, $oTemplate);
         parent::__construct($aInfo, $oTemplate);
 
 
-        if(isset($this->aParams['ajax_mode']))
-        	$this->setAjaxMode($this->aParams['ajax_mode']);
-
-        $mixedAjaxMode = bx_get('ajax_mode');
-        if($mixedAjaxMode !== false)
-        	$this->setAjaxMode($mixedAjaxMode);
-
+        $this->_bAjaxMode = isset($this->aParams['ajax_mode']) && $this->aParams['ajax_mode'];
         $this->_bViewMode = isset($this->aParams['view_mode']) && $this->aParams['view_mode'];
         $this->_bViewMode = isset($this->aParams['view_mode']) && $this->aParams['view_mode'];
 
 
-        if ($this->_bViewMode) {
+        if($this->_bViewMode) {
             $this->_sSectionClose = 'getCloseSectionViewMode';
             $this->_sSectionClose = 'getCloseSectionViewMode';
             $this->_sSectionOpen = 'getOpenSectionViewMode';
             $this->_sSectionOpen = 'getOpenSectionViewMode';
         }
         }
     }
     }
 
 
-	function setAjaxMode($bAjaxMode)
+    function setAjaxMode($bAjaxMode)
     {
     {
-		$this->_bAjaxMode = (bool)$bAjaxMode;
+        $this->_bAjaxMode = (bool)$bAjaxMode;
     }
     }
 
 
     function isAjaxMode()
     function isAjaxMode()
     {
     {
-    	return $this->_bAjaxMode;
+        return $this->_bAjaxMode;
+    }
+
+    function setAbsoluteActionUrl($sUrl)
+    {
+        if(empty($sUrl))
+            return;
+
+        $this->aFormAttrs['action'] = $sUrl;
+
+        $this->_bAbsoluteActionUrl = true;
     }
     }
 
 
     /**
     /**
@@ -226,7 +235,7 @@ BLAH;
 
 
         // add 'Ajax Mode' flag
         // add 'Ajax Mode' flag
         if($this->_bAjaxMode)
         if($this->_bAjaxMode)
-        	$this->aInputs['ajax_mode'] = array(
+            $this->aInputs['ajax_mode'] = array(
                 'type' => 'hidden',
                 'type' => 'hidden',
                 'name' => 'ajax_mode',
                 'name' => 'ajax_mode',
                 'value' => 1,
                 'value' => 1,
@@ -234,6 +243,16 @@ BLAH;
                 'visible_for_levels' => PHP_INT_MAX,
                 'visible_for_levels' => PHP_INT_MAX,
             );
             );
 
 
+        // add 'Absolute Action Url' flag
+        if($this->_bAbsoluteActionUrl)
+            $this->aInputs['absolute_action_url'] = array(
+                'type' => 'hidden',
+                'name' => 'absolute_action_url',
+                'value' => 1,
+                'db' => array ('pass' => 'Int'),
+                'visible_for_levels' => PHP_INT_MAX,
+            );
+
         // check if we need to generate open section clause
         // check if we need to generate open section clause
         $sOpenSection = '';
         $sOpenSection = '';
         foreach ($this->aInputs as $aInput) {
         foreach ($this->aInputs as $aInput) {