Browse Source

#52 - Get rid of duplicates in code.

AntonLV 12 years ago
parent
commit
798e5899da

+ 18 - 47
modules/boonex/developer/classes/BxDevBuilderPage.php

@@ -32,53 +32,8 @@ class BxDevBuilderPage extends BxTemplStudioBuilderPage {
     }
 
     function getBlockPanelTop($aParams = array()) {
-        $sJsObject = $this->getPageJsObject();
-
-        $oForm = new BxTemplStudioFormView(array());
-
-        $aInputPages = array(
-            'type' => 'select',
-            'name' => 'page',
-            'attrs' => array(
-            	'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
-            ),
-            'value' => $this->sPage,
-            'values' => array(
-                array('key' => '', 'value' => _t('_adm_bp_txt_select_page'))
-            )
-        );
-
-        $aPages = $aCounter = array();
-        $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType), $aPages, false);
-        $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
-        foreach($aPages as $aPage)
-            $aInputPages['values'][] = array('key' => $aPage['object'], 'value' => _t($aPage['title_system']) . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")");
-
-        bx_import('BxDolPermalinks');
-        $oPermalinks = BxDolPermalinks::getInstance();
-
-        $aTmplVarsActions = array();
-        if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
-            $aTmplVarsActions = array(
-                'js_object' => $sJsObject,
-        		'url_view' => BX_DOL_URL_ROOT . $oPermalinks->permalink($this->aPageRebuild['url']),
-                'action_page_export' => $this->sActionPageExport,
-            	'action_page_edit' => $this->sActionPageEdit,
-                'action_block_create' => $this->sActionBlockCreate,
-            );
-
-        $aTmplVars = array(
-        	'js_object' => $this->getPageJsObject(),
-            'selector' => $oForm->genRow($aInputPages),
-        	'action_page_create' => $this->sActionPageCreate,
-            'bx_if:show_actions' => array(
-                'condition' => $this->sPage != '',
-                'content' => $aTmplVarsActions
-            )
-        );
-
-        return BxBaseStudioPage::getBlockPanelTop(
-            array('panel_top' => $this->oModule->_oTemplate->parseHtmlByName('bp_block_panel_top.html', $aTmplVars))
+         return BxBaseStudioPage::getBlockPanelTop(
+            array('panel_top' => $this->oModule->_oTemplate->parseHtmlByName('bp_block_panel_top.html', $this->_getTmplVarsBlockPanelTop()))
         );
     }
 
@@ -435,5 +390,21 @@ class BxDevBuilderPage extends BxTemplStudioBuilderPage {
             BxDolForm::setSubmittedValue('content', $sValue, $oForm->aFormAttrs['method']);
         }
     }
+
+	protected function _getTmplVarsBlockPanelTopActions()
+    {
+    	$sJsObject = $this->getPageJsObject();
+
+    	bx_import('BxDolPermalinks');
+        $oPermalinks = BxDolPermalinks::getInstance();
+
+    	return array(
+			'js_object' => $sJsObject,
+        	'url_view' => BX_DOL_URL_ROOT . $oPermalinks->permalink($this->aPageRebuild['url']),
+            'action_page_export' => $this->sActionPageExport,
+            'action_page_edit' => $this->sActionPageEdit,
+            'action_block_create' => $this->sActionBlockCreate,
+		);
+    }
 }
 /** @} */

+ 5 - 19
modules/boonex/developer/classes/BxDevFormsPreLists.php

@@ -58,22 +58,8 @@ class BxDevFormsPreLists extends BxTemplStudioFormsPreLists {
     public function performActionEdit() {
         $sAction = 'edit';
 
-        $aIds = bx_get('ids');
-        if(!$aIds || !is_array($aIds)) {
-            $iId = (int)bx_get('id');
-            if(!$iId) {
-                $this->_echoResultJson(array());
-                exit;
-            }
-
-            $aIds = array($iId);
-        }
-
-        $iId = $aIds[0];
-
-        $aList = array();
-        $this->oDb->getLists(array('type' => 'by_id', 'value' => $iId), $aList, false);
-        if(!is_array($aList) || empty($aList)){
+    	$aList = $this->_getItem('getLists');
+        if($aList === false) {
             $this->_echoResultJson(array());
             exit;
         }
@@ -86,8 +72,8 @@ class BxDevFormsPreLists extends BxTemplStudioFormsPreLists {
 
         $oForm->initChecker($aList);
         if($oForm->isSubmittedAndValid()) {
-            if($oForm->update($iId) !== false)
-                $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
+            if($oForm->update($aList['id']) !== false)
+                $aRes = array('grid' => $this->getCode(false), 'blink' => $aList['id']);
             else
                 $aRes = array('msg' => _t('_bx_dev_frm_err_prelists_edit'));
 
@@ -95,7 +81,7 @@ class BxDevFormsPreLists extends BxTemplStudioFormsPreLists {
         }
         else {
             bx_import('BxTemplStudioFunctions');
-            $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx-dev-frm-prelist-edit-popup', _t('_bx_dev_frm_txt_prelists_edit_popup'), $this->oModule->_oTemplate->parseHtmlByName('form_add_list.html', array(
+            $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx-dev-frm-prelist-edit-popup', _t('_bx_dev_frm_txt_prelists_edit_popup', _t($aList['title'])), $this->oModule->_oTemplate->parseHtmlByName('form_add_list.html', array(
                 'form_id' => $oForm->aFormAttrs['id'],
                 'form' => $oForm->getCode(true),
                 'object' => $this->_sObject,

+ 4 - 18
modules/boonex/developer/classes/BxDevFormsPreValues.php

@@ -69,22 +69,8 @@ class BxDevFormsPreValues extends BxTemplStudioFormsPreValues {
     public function performActionEdit() {
         $sAction = 'edit';
 
-        $aIds = bx_get('ids');
-        if(!$aIds || !is_array($aIds)) {
-            $iId = (int)bx_get('id');
-            if(!$iId) {
-                $this->_echoResultJson(array());
-                exit;
-            }
-
-            $aIds = array($iId);
-        }
-
-        $iId = $aIds[0];
-
-        $aValue = array();
-        $this->oDb->getValues(array('type' => 'by_id', 'value' => $iId), $aValue, false);
-        if(!is_array($aValue) || empty($aValue)){
+    	$aValue = $this->_getItem('getValues');
+        if($aValue === false) {
             $this->_echoResultJson(array());
             exit;
         }
@@ -97,9 +83,9 @@ class BxDevFormsPreValues extends BxTemplStudioFormsPreValues {
 
         $oForm->initChecker($aValue);
         if($oForm->isSubmittedAndValid()) {
-            if($oForm->update($iId) !== false) {
+            if($oForm->update($aValue['id']) !== false) {
                 $this->onSave($oForm);
-                $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
+                $aRes = array('grid' => $this->getCode(false), 'blink' => $aValue['id']);
             }
             else
                 $aRes = array('msg' => _t('_bx_dev_frm_err_prevalues_edit'));

+ 61 - 50
studio/template/scripts/BxBaseStudioBuilderPage.php

@@ -185,58 +185,9 @@ class BxBaseStudioBuilderPage extends BxDolStudioBuilderPage {
 
     function getBlockPanelTop($aParams = array()) {
         $oTemplate = BxDolStudioTemplate::getInstance();
-        $sJsObject = $this->getPageJsObject();
-
-        $oForm = new BxTemplStudioFormView(array());
-
-        $aInputPages = array(
-            'type' => 'select',
-            'name' => 'page',
-            'attrs' => array(
-            	'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
-            ),
-            'value' => $this->sPage,
-            'values' => array(
-                array('key' => '', 'value' => _t('_adm_bp_txt_select_page'))
-            )
-        );
-
-        $aPages = $aCounter = array();
-        $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType), $aPages, false);
-        $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
-        foreach($aPages as $aPage)
-            $aInputPages['values'][] = array('key' => $aPage['object'], 'value' => _t($aPage['title_system']) . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")");
-
-        bx_import('BxDolPermalinks');
-        $oPermalinks = BxDolPermalinks::getInstance();
-
-        $aTmplVarsActions = array();
-        if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
-            $aTmplVarsActions = array(
-                'js_object' => $sJsObject,
-        		'url_view' => BX_DOL_URL_ROOT . $oPermalinks->permalink($this->aPageRebuild['url']),
-            	'action_page_edit' => $this->sActionPageEdit,
-                'bx_if:can_delete' => array(
-                    'condition' => (int)$this->aPageRebuild['deletable'] == 1,
-                    'content' => array(
-                        'js_object' => $sJsObject
-                    )
-                ),
-                'action_block_create' => $this->sActionBlockCreate,
-            );
-
-        $aTmplVars = array(
-        	'js_object' => $this->getPageJsObject(),
-            'selector' => $oForm->genRow($aInputPages),
-        	'action_page_create' => $this->sActionPageCreate,
-            'bx_if:show_actions' => array(
-                'condition' => $this->sPage != '',
-                'content' => $aTmplVarsActions
-            )
-        );
 
         return parent::getBlockPanelTop(
-            array('panel_top' => $oTemplate->parseHtmlByName('bp_block_panel_top.html', $aTmplVars))
+            array('panel_top' => $oTemplate->parseHtmlByName('bp_block_panel_top.html', $this->_getTmplVarsBlockPanelTop()))
         );
     }
 
@@ -1537,5 +1488,65 @@ class BxBaseStudioBuilderPage extends BxDolStudioBuilderPage {
 
     	return $aBlocks;
     }
+
+	protected function _getTmplVarsBlockPanelTop()
+    {
+    	$sJsObject = $this->getPageJsObject();
+
+        $oForm = new BxTemplStudioFormView(array());
+
+        $aInputPages = array(
+            'type' => 'select',
+            'name' => 'page',
+            'attrs' => array(
+            	'onChange' => 'javascript:' . $this->getPageJsObject() . '.onChangePage(this)'
+            ),
+            'value' => $this->sPage,
+            'values' => array(
+                array('key' => '', 'value' => _t('_adm_bp_txt_select_page'))
+            )
+        );
+
+        $aPages = $aCounter = array();
+        $this->oDb->getPages(array('type' => 'by_module', 'value' => $this->sType), $aPages, false);
+        $this->oDb->getBlocks(array('type' => 'counter_by_pages'), $aCounter, false);
+        foreach($aPages as $aPage)
+            $aInputPages['values'][] = array('key' => $aPage['object'], 'value' => _t($aPage['title_system']) . " (" . (isset($aCounter[$aPage['object']]) ? $aCounter[$aPage['object']] : "0") . ")");
+
+        $aTmplVarsActions = array();
+        if(($this->sPage != '' && !empty($this->aPageRebuild)) !== false)
+            $aTmplVarsActions = $this->_getTmplVarsBlockPanelTopActions();
+
+        return array(
+        	'js_object' => $this->getPageJsObject(),
+            'selector' => $oForm->genRow($aInputPages),
+        	'action_page_create' => $this->sActionPageCreate,
+            'bx_if:show_actions' => array(
+                'condition' => $this->sPage != '',
+                'content' => $aTmplVarsActions
+            )
+        );
+    }
+
+    protected function _getTmplVarsBlockPanelTopActions()
+    {
+    	$sJsObject = $this->getPageJsObject();
+
+    	bx_import('BxDolPermalinks');
+        $oPermalinks = BxDolPermalinks::getInstance();
+
+    	return array(
+			'js_object' => $sJsObject,
+        	'url_view' => BX_DOL_URL_ROOT . $oPermalinks->permalink($this->aPageRebuild['url']),
+            'action_page_edit' => $this->sActionPageEdit,
+            'bx_if:can_delete' => array(
+            	'condition' => (int)$this->aPageRebuild['deletable'] == 1,
+                'content' => array(
+                	'js_object' => $sJsObject
+				)
+			),
+			'action_block_create' => $this->sActionBlockCreate,
+		);
+    }
 }
 /** @} */

+ 5 - 19
studio/template/scripts/BxBaseStudioFormsPreLists.php

@@ -131,22 +131,8 @@ class BxBaseStudioFormsPreLists extends BxDolStudioFormsPreLists {
     public function performActionEdit() {
         $sAction = 'edit';
 
-        $aIds = bx_get('ids');
-        if(!$aIds || !is_array($aIds)) {
-            $iId = (int)bx_get('id');
-            if(!$iId) {
-                $this->_echoResultJson(array());
-                exit;
-            }
-
-            $aIds = array($iId);
-        }
-
-        $iId = $aIds[0];
-
-        $aList = array();
-        $this->oDb->getLists(array('type' => 'by_id', 'value' => $iId), $aList, false);
-        if(!is_array($aList) || empty($aList)){
+        $aList = $this->_getItem('getLists');
+        if($aList === false) {
             $this->_echoResultJson(array());
             exit;
         }
@@ -170,7 +156,7 @@ class BxBaseStudioFormsPreLists extends BxDolStudioFormsPreLists {
             	'id' => array(
                     'type' => 'hidden',
                     'name' => 'id',
-                    'value' => $iId,
+                    'value' => $aList['id'],
                     'db' => array (
                         'pass' => 'Int',
                     ),
@@ -216,8 +202,8 @@ class BxBaseStudioFormsPreLists extends BxDolStudioFormsPreLists {
         $oForm->initChecker();
 
         if($oForm->isSubmittedAndValid()) {
-            if($oForm->update($iId) !== false)
-                $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
+            if($oForm->update($aList['id']) !== false)
+                $aRes = array('grid' => $this->getCode(false), 'blink' => $aList['id']);
             else
                 $aRes = array('msg' => _t('_adm_form_err_pre_lists_edit'));
 

+ 5 - 19
studio/template/scripts/BxBaseStudioFormsPreValues.php

@@ -152,22 +152,8 @@ class BxBaseStudioFormsPreValues extends BxDolStudioFormsPreValues {
     public function performActionEdit() {
         $sAction = 'edit';
 
-        $aIds = bx_get('ids');
-        if(!$aIds || !is_array($aIds)) {
-            $iId = (int)bx_get('id');
-            if(!$iId) {
-                $this->_echoResultJson(array());
-                exit;
-            }
-
-            $aIds = array($iId);
-        }
-
-        $iId = $aIds[0];
-
-        $aValue = array();
-        $this->oDb->getValues(array('type' => 'by_id', 'value' => $iId), $aValue, false);
-        if(!is_array($aValue) || empty($aValue)){
+	    $aValue = $this->_getItem('getValues');
+        if($aValue === false) {
             $this->_echoResultJson(array());
             exit;
         }
@@ -195,7 +181,7 @@ class BxBaseStudioFormsPreValues extends BxDolStudioFormsPreValues {
             	'id' => array(
                     'type' => 'hidden',
                     'name' => 'id',
-                    'value' => $iId,
+                    'value' => $aValue['id'],
                     'db' => array (
                         'pass' => 'Int',
                     ),
@@ -270,8 +256,8 @@ class BxBaseStudioFormsPreValues extends BxDolStudioFormsPreValues {
                 }
             }
 
-            if($oForm->update($iId, $aAdd) !== false)
-                $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
+            if($oForm->update($aValue['id'], $aAdd) !== false)
+                $aRes = array('grid' => $this->getCode(false), 'blink' => $aValue['id']);
             else
                 $aRes = array('msg' => _t('_adm_form_err_pre_values_edit'));
 

+ 21 - 0
studio/template/scripts/BxBaseStudioGrid.php

@@ -19,5 +19,26 @@ class BxBaseStudioGrid extends BxDolStudioGrid {
     function getJsObject() {
         return '';
     }
+
+	protected function _getItem($sDbMethod = '')
+    {
+    	$aIds = bx_get('ids');
+        if(!$aIds || !is_array($aIds)) {
+            $iId = (int)bx_get('id');
+            if(!$iId) 
+            	return false;
+
+            $aIds = array($iId);
+        }
+
+        $iId = $aIds[0];
+
+        $aItem = array();
+        $this->oDb->$sDbMethod(array('type' => 'by_id', 'value' => $iId), $aItem, false);
+        if(!is_array($aItem) || empty($aItem))
+        	return false; 
+
+        return $aItem;
+    }
 }
 /** @} */