فهرست منبع

#2304 Wiki functionality: blocks adding

Alex Trofimov 6 سال پیش
والد
کامیت
6b1a504a71

+ 5 - 0
inc/classes/BxDolPage.php

@@ -252,6 +252,11 @@ class BxDolPage extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
     	return (int)$this->_aObject['type_id'];
     }
 
+    public function getModule ()
+    {
+    	return (int)$this->_aObject['module'];
+    }
+
     /**
      * Add replace markers. Markers are replaced in raw, html, lang blocks and page title, description, keywords and block titles.
      * @param $a array of markers as key => value

+ 32 - 1
inc/classes/BxDolWiki.php

@@ -279,6 +279,37 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
         }
     }
 
+    public function actionAdd ()
+    {
+        $iCellId = (int)bx_get('cell_id');
+        $sPage = bx_get('page');
+        $oPage = BxDolPage::getObjectInstance($sPage);
+        if (!$oPage)
+            return array('code' => 4, 'actions' => array('ShowMsg'), 'msg' => _t('_sys_txt_error_occured'));
+
+        if ($this->_aObject['module'] != $oPage->getModule())
+            return array('code' => 5, 'actions' => array('ShowMsg'), 'msg' => _t('_sys_txt_access_denied'));
+
+        $aBlock = array(
+            'object' => $sPage,
+            'cell_id' => $iCellId,
+            'module' => $this->_aObject['module'],
+            'title_system' => '',
+            'title' => '',
+            'designbox_id' => 0, // TODO: add to params
+            'visible_for_levels' => 2147483647, 
+            'type' => 'wiki',
+            'deletable' => 1,
+            'copyable' => 0,
+            'active' => 1,
+        );
+        $oQueryPageBuilder = new BxDolStudioBuilderPageQuery();
+        if (!($iBlockId = $oQueryPageBuilder->insertBlock($aBlock)))
+            return array('code' => 6, 'actions' => array('ShowMsg'), 'msg' => _t('_sys_txt_error_occured'));
+
+        return array('code' => 0, 'block_id' => $iBlockId, 'cell_id' => $iCellId);
+    }
+
     public function actionDeleteBlock ()
     {
         $iBlockId = (int)bx_get('block_id');
@@ -289,7 +320,7 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
 
         $this->_oQuery->deleteAllRevisions($iBlockId);
 
-        return array('code' => 0, 'actions' => array('Reload', 'ShowMsg'), 'block_id' => $iBlockId, 'msg' => _t('_sys_wiki_block_deleted'));
+        return array('code' => 0, 'actions' => array('DeleteBlock', 'ShowMsg'), 'block_id' => $iBlockId, 'msg' => _t('_sys_wiki_block_deleted'));
     }
     public function actionHistory ()
     {

+ 27 - 7
inc/js/classes/BxDolWiki.js

@@ -99,13 +99,12 @@ BxDolWiki.prototype.onDeleteVersion = function () {
 };
 
 BxDolWiki.prototype.onDeleteBlock = function () {
-    if (!confirm(this._oOptions.t_confirm_block_deletion))
-        return;
-
     var self = this;
-    $.post(this._sActionUrl + 'delete-block', {block_id: this._oOptions.block_id}, function (oData) {
-        self.processResponce(oData);
-    }, 'json');
+    bx_confirm(this._oOptions.t_confirm_block_deletion, function () {
+        $.post(self._sActionUrl + 'delete-block', {block_id: self._oOptions.block_id}, function (oData) {
+            self.processResponce(oData);
+        }, 'json');
+    });
 };
 
 BxDolWiki.prototype.onHistory = function () {
@@ -130,7 +129,7 @@ BxDolWiki.prototype.processResponce = function (oResponce) {
 }
 
 BxDolWiki.prototype.actionShowMsg = function (oResponce) {
-    alert(oResponce.msg);
+    bx_alert(oResponce.msg);
 }
 
 BxDolWiki.prototype.actionClosePopup = function (oResponce) {
@@ -146,6 +145,10 @@ BxDolWiki.prototype.actionReload = function (oResponce) {
     loadDynamicBlock(oResponce.block_id, document.location.href);
 }
 
+BxDolWiki.prototype.actionDeleteBlock = function (oResponce) {
+    $('#bx-page-block-' + oResponce.block_id).remove();
+}
+
 BxDolWiki.prototype.popup = function (sAction) {
     
     var self = this;
@@ -161,4 +164,21 @@ BxDolWiki.prototype.popup = function (sAction) {
     $(window).dolPopupAjax({url: sActionUrl, closeOnOuterClick: false});
 };
 
+function bx_wiki_add_block(e, sPage, iCellId, sActionUri) {
+    var sActionUrl = sUrlRoot + 'r.php?_q=' + sActionUri + '-action/';
+    bx_loading($(e), true);
+    $.post(sActionUrl + 'add', {page: sPage, cell_id: iCellId}, function (oData) {
+        bx_loading($(e), false);
+        if ('undefined' !== typeof(oData.code)) {
+            if (0 == oData.code) {
+                $(e).parents('.bx-wiki-add-block').before('<div class="bx-page-block-container bx-def-padding-sec-topbottom" id="bx-page-block-' + oData.block_id + '">');
+                loadDynamicBlock(oData.block_id, document.location.href);
+            }
+            else {
+                bx_alert(oData.msg);
+            }
+        }
+    }, 'json');
+}
+
 /** @} */

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -3123,5 +3123,6 @@ If it is not enabled then please consider implement this optimization, since it
     <string name="_sys_wiki_revisions_deleted"><![CDATA[{0} revisions were deleted]]></string>
     <string name="_sys_wiki_confirm_block_deletion"><![CDATA[Are you sure you want to permanently delete this block with all revisions and translations?]]></string>
     <string name="_sys_wiki_block_deleted"><![CDATA[Block was successfully deleted]]></string>
+    <string name="_sys_wiki_add_block"><![CDATA[Add Block]]></string>
 	
 </resources>

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -3103,5 +3103,6 @@
     <string name="_sys_wiki_revisions_deleted"><![CDATA[{0} ревизий было удалено]]></string>
     <string name="_sys_wiki_confirm_block_deletion"><![CDATA[Подтвердите удаление блока со всей историей и переводами?]]></string>
     <string name="_sys_wiki_block_deleted"><![CDATA[Блок был успешно удален]]></string>
+    <string name="_sys_wiki_add_block"><![CDATA[Добавить блок]]></string>
 
 </resources>

+ 1 - 1
modules/boonex/wiki/install/sql/enable.sql

@@ -2,7 +2,7 @@
 -- Wiki object
 
 INSERT INTO `sys_objects_wiki` (`object`, `uri`, `title`, `module`, `allow_add_for_levels`, `allow_edit_for_levels`, `allow_delete_for_levels`, `allow_translate_for_levels`, `allow_unsafe_for_levels`, `override_class_name`, `override_class_file`) VALUES
-('bx_wiki', 'wiki', '_bx_wiki_object_title', 'system', 192, 192, 192, 192, 0, '', '');
+('bx_wiki', 'wiki', '_bx_wiki_object_title', 'bx_wiki', 192, 192, 192, 192, 0, '', '');
 
 -- Permalinks
 

+ 3 - 1
studio/classes/BxDolStudioBuilderPageQuery.php

@@ -383,7 +383,9 @@ class BxDolStudioBuilderPageQuery extends BxDolStudioPageQuery
         $aFields['order'] = $this->getBlockOrderMax($aFields['object']) + 1;
 
         $sSql = "INSERT INTO `sys_pages_blocks` SET " . $this->arrayToSQL($aFields);
-        return (int)$this->query($sSql) > 0;
+        if (!$this->query($sSql))
+            return false;
+        return $this->lastId();
     }
 
     function updateBlock($iId, $aFields)

+ 4 - 0
template/css/wiki.css

@@ -39,3 +39,7 @@
 .bx-wiki-history-cell-rev {
     text-align:center;
 }
+.bx-wiki-add-block {
+    border:1px dashed #aaa; 
+    text-align:center;
+}

+ 2 - 2
template/scripts/BxBasePageWiki.php

@@ -22,11 +22,11 @@ class BxBasePageWiki extends BxTemplPage
         $aVars = parent::_getPageCodeVars ();
         
         $oWiki = BxDolWiki::getObjectInstance($this->_aObject['module']);
-        if ($oWiki->isAllowed('add')) {
+        if ($oWiki && $oWiki->isAllowed('add')) {
             foreach ($aVars as $sKey => $sCell) {
                 if (0 !== strncmp('cell_', $sKey, 5))
                     continue;
-                $aVars[$sKey] = $sCell . '<div class="bx-def-margin-top bx-def-padding" style="border:1px dashed #aaa; text-align:center;"><a href="javascript:void(0);" onclick="alert(\'TODO: wiki block add form\')"><i class="sys-icon plus"></i> Add Block</a></div>';
+                $aVars[$sKey] = $sCell . bx_srv('system', 'wiki_add_block', array($oWiki, $this->_sObject, $sKey), 'TemplServiceWiki');
             }
         }
         return $aVars;

+ 34 - 10
template/scripts/BxBaseServiceWiki.php

@@ -73,7 +73,7 @@ class BxBaseServiceWiki extends BxDol
      * @code bx_srv('system', 'wiki_action', [...], 'TemplServiceWiki'); @endcode
      * 
      * Perform WIKI action.
-     * @param $sUri categories object name
+     * @param $sWikiObjectUri wiki object URI
      * 
      * @see BxBaseServiceWiki::serviceWikiAction
      */
@@ -105,19 +105,14 @@ class BxBaseServiceWiki extends BxDol
      * @page service Service Calls
      * @section bx_system_general System Services 
      * @subsection bx_system_general-wiki Wiki
-     * @subsubsection bx_system_general-wiki_page wiki_page
+     * @subsubsection bx_system_general-wiki_controls wiki_controls
      * 
-     * @code bx_srv('system', 'wiki_page', ["index"], 'TemplServiceWiki'); @endcode
-     * @code {{~system:wiki_page:TemplServiceWiki["index"]~}} @endcode
+     * Get wiki block controls panel
      * 
-     * Add controls for edit, delete, translate, history, etc content
-     * @param $sUri categories object name
-     * 
-     * @see BxBaseServiceWiki::serviceWikiPage
-     * @param $iBlockId block ID
+     * @see BxBaseServiceWiki::serviceWikiControls
      */
     /** 
-     * @ref bx_system_general-wiki_page "wiki_page"
+     * @ref bx_system_general-wiki_controls "wiki_controls"
      */
     public function serviceWikiControls ($oWikiObject, $aWikiVer, $aWikiVerLatest, $sBlockId)
     {
@@ -153,6 +148,35 @@ class BxBaseServiceWiki extends BxDol
         ));
     }
 
+    /**
+     * @page service Service Calls
+     * @section bx_system_general System Services 
+     * @subsection bx_system_general-wiki Wiki
+     * @subsubsection bx_system_general-wiki_add_block wiki_add_block
+     * 
+     * Get "add wiki block" panel
+     * 
+     * @see BxBaseServiceWiki::serviceWikiAddBlock
+     */
+    /** 
+     * @ref bx_system_general-wiki_add_block "wiki_add_block"
+     */
+    public function serviceWikiAddBlock ($oWikiObject, $sPageObject, $sCellId)
+    {
+        $this->_addCssJs ();
+        if (!preg_match("/cell_(\d+)/", $sCellId, $aMatches))
+            return '';
+        $iCellId = $aMatches[1];
+
+        $o = BxDolTemplate::getInstance();        
+        return $o->parseHtmlByName('wiki_add_block.html', array(
+            'add_block' => _t('_sys_wiki_add_block'),
+            'page' => $sPageObject,
+            'cell_id' => $iCellId,
+            'action_uri' => $oWikiObject->getWikiUri(),
+        ));
+    }
+
     protected function _addCssJs ()
     {
         if ($this->_bJsCssAdded)

+ 3 - 0
template/wiki_add_block.html

@@ -0,0 +1,3 @@
+<div class="bx-wiki-add-block bx-def-margin-top bx-def-padding">
+    <a href="javascript:void(0);" onclick="bx_wiki_add_block(this, '__page__', '__cell_id__', '__action_uri__')"><i class="sys-icon plus"></i> __add_block__</a>
+</div>