Explorar el Código

#100 - unified content deletion.

AntonLV hace 12 años
padre
commit
925a006736

+ 48 - 0
modules/base/general/classes/BxBaseModGeneralGridAdministration.php

@@ -29,6 +29,49 @@ class BxBaseModGeneralGridAdministration extends BxTemplGrid
         $this->_sParamsDivider = '#-#';
     }
 
+	public function performActionDelete($aParams = array())
+    {
+    	$sPrefixLang = $this->_oModule->_oConfig->getPrefix('lang');
+    	$sPrefixClass = $this->_oModule->_oConfig->getClassPrefix();
+
+    	//TODO: remove this check when 'delete with content' feature will be realized in onDelete method.
+    	if(isset($aParams['with_content']) && $aParams['with_content'] === true) {
+			$this->_echoResultJson(array('msg' => 'TODO: delete with content'));
+	    	return;
+    	}
+
+        $iAffected = 0;
+        $aIds = bx_get('ids');
+        if(!$aIds || !is_array($aIds)) {
+            $this->_echoResultJson(array());
+            exit;
+        }
+
+        bx_import('FormsEntryHelper', $this->_oModule->_aModule);
+        $sClass = $sPrefixClass . 'FormsEntryHelper';
+        $oFormsHelper = new $sClass($this->_oModule);
+
+        $aIdsAffected = array ();
+        foreach($aIds as $iId) {
+			$aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
+	    	if($this->_oModule->checkAllowedDelete($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
+	    		continue;
+
+        	if($oFormsHelper->deleteData($iId) != '')
+                continue;
+
+			if(!$this->_onDelete($iId, $aParams))
+				continue;
+
+			$this->_oModule->checkAllowedDelete($aContentInfo, true);
+
+            $aIdsAffected[] = $iId;
+            $iAffected++;
+        }
+
+        $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($sPrefixLang . '_grid_action_err_delete')));
+    }
+
     protected function _getActionSettings($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
     {
     	$sJsObject = $this->_oModule->_oConfig->getJsObject('manage_tools');
@@ -92,6 +135,11 @@ class BxBaseModGeneralGridAdministration extends BxTemplGrid
         $oForm = new BxTemplFormView(array());
         return $oForm->genRow($aInputSearch);
     }
+
+    protected function _onDelete($iId, $aParams = array())
+    {
+    	return true;
+    }
 }
 
 /** @} */

+ 28 - 44
modules/base/profile/classes/BxBaseModProfileGridAdministration.php

@@ -34,20 +34,31 @@ class BxBaseModProfileGridAdministration extends BxBaseModGeneralGridAdministrat
     	$aIds = bx_get('ids');
         if(!$aIds || !is_array($aIds) || !$oMenu) {
             $this->_echoResultJson(array());
-            exit;
+            return;
         }
 
-        foreach($aIds as $iKey => $iId)
-        	$aIds[$iKey] = $this->_getProfileId($iId);
+        $aIdsResult = array();
+        foreach($aIds as $iId) {
+        	$aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
+	    	if($this->_oModule->checkAllowedSetMembership($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
+	    		continue;
 
-		if(count($aIds) == 1)
-			$aIds = $aIds[0];
+        	$aIdsResult[] = $this->_getProfileId($iId);
+        }
+
+        if(empty($aIdsResult)) {
+            $this->_echoResultJson(array());
+            return;
+        }
+
+		if(count($aIdsResult) == 1)
+			$aIdsResult = $aIdsResult[0];
 
 		$sContent = $this->_oTemplate->parseHtmlByName('bx_div.html', array(
 			'bx_repeat:attrs' => array(
 				array('key' => 'class', 'value' => 'bx-def-padding')
 			),
-			'content' => $oMenu->getCode($aIds)
+			'content' => $oMenu->getCode($aIdsResult)
 		));
 
     	bx_import('BxTemplFunctions');
@@ -56,46 +67,9 @@ class BxBaseModProfileGridAdministration extends BxBaseModGeneralGridAdministrat
     	$this->_echoResultJson(array('popup' => $sContent), true);
     }
 
-	public function performActionDelete($bWithContent = false)
-    {
-    	$sPrefixLang = $this->_oModule->_oConfig->getPrefix('lang');
-
-    	if($bWithContent) {
-			$this->_echoResultJson(array('msg' => 'TODO: delete with content'));
-	    	return;
-    	}
-
-        $iAffected = 0;
-        $aIds = bx_get('ids');
-        if(!$aIds || !is_array($aIds)) {
-            $this->_echoResultJson(array());
-            exit;
-        }
-
-        $aIdsAffected = array ();
-        foreach($aIds as $iId) {
-        	$oProfile = $this->_getProfileObject(iId);
-
-        	if((int)$this->_delete($iId) == 0)
-                continue;
-
-        	if(!$oProfile->delete())
-        		continue;
-
-        	if($bWithContent)	{
-        		//TODO: delete content after profile deletion
-        	}
-
-            $aIdsAffected[] = $iId;
-            $iAffected++;
-        }
-
-        $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($sPrefixLang . '_grid_action_err_delete')));
-    }
-
 	public function performActionDeleteWithContent()
     {
-    	$this->performActionDelete(true);
+    	$this->performActionDelete(array('with_content' => true));
     }
 
 	protected function _switcherChecked2State($isChecked)
@@ -177,6 +151,16 @@ class BxBaseModProfileGridAdministration extends BxBaseModGeneralGridAdministrat
     {
     	return $this->_getProfileObject($iId)->id();
     }
+
+    protected function _onDelete($iId, $aParams = array())
+    {
+    	if(isset($aParams['with_content']) && $aParams['with_content'] === true)	{
+			//TODO: delete content after profile deletion
+		}
+
+		return parent::_onDelete($iId, $aParams);
+    }
+    
 }
 
 /** @} */

+ 0 - 23
modules/base/text/classes/BxBaseModTextGridAdministration.php

@@ -26,29 +26,6 @@ class BxBaseModTextGridAdministration extends BxBaseModGeneralGridAdministration
         }
     }
 
-	public function performActionDelete()
-    {
-    	$sPrefixLang = $this->_oModule->_oConfig->getPrefix('lang');
-
-        $iAffected = 0;
-        $aIds = bx_get('ids');
-        if(!$aIds || !is_array($aIds)) {
-            $this->_echoResultJson(array());
-            exit;
-        }
-
-        $aIdsAffected = array ();
-        foreach($aIds as $iId) {
-        	if((int)$this->_delete($iId) == 0)
-                continue;
-
-            $aIdsAffected[] = $iId;
-            $iAffected++;
-        }
-
-        $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($sPrefixLang . '_grid_action_err_delete')));
-    }
-
     protected function _switcherChecked2State($isChecked)
     {
         return $isChecked ? 'active' : 'hidden';

+ 2 - 0
modules/boonex/organizations/js/manage_tools.js

@@ -41,6 +41,8 @@ BxOrgsManageTools.prototype.onClickSettings = function(sMenuObject, oButton) {
 };
 
 BxOrgsManageTools.prototype.onClickDeleteWithContent = function(iContentId) {
+	$('.bx-popup-applied:visible').dolPopupHide();
+
 	glGrids[this._sObjNameGrid].actionWithId(iContentId, 'delete_with_content', {}, '', false, 1);
 };
 

+ 2 - 0
modules/boonex/persons/js/manage_tools.js

@@ -41,6 +41,8 @@ BxPersonsManageTools.prototype.onClickSettings = function(sMenuObject, oButton)
 };
 
 BxPersonsManageTools.prototype.onClickDeleteWithContent = function(iContentId) {
+	$('.bx-popup-applied:visible').dolPopupHide();
+
 	glGrids[this._sObjNameGrid].actionWithId(iContentId, 'delete_with_content', {}, '', false, 1);
 };