From ba9f2fce8d1a723f5b1d3c0cc87964a8942861fb Mon Sep 17 00:00:00 2001 From: wax100 Date: Fri, 5 Mar 2021 14:25:31 +0300 Subject: [PATCH 1/5] Enhancement #12 https://github.com/modxorg/DocsApp/issues/12 --- core/src/Revolution/modResource.php | 34 ++++++++++++++ .../assets/modext/sections/resource/update.js | 45 +++++++++++++++++++ .../resource/staticresource/update.class.php | 8 ++++ .../default/resource/symlink/update.class.php | 8 ++++ .../default/resource/update.class.php | 8 ++++ .../default/resource/weblink/update.class.php | 8 ++++ 6 files changed, 111 insertions(+) diff --git a/core/src/Revolution/modResource.php b/core/src/Revolution/modResource.php index 6eaeacbe071..7a7e86e858b 100644 --- a/core/src/Revolution/modResource.php +++ b/core/src/Revolution/modResource.php @@ -1584,4 +1584,38 @@ public function clearCache($context = '') $this->xpdo->invokeEvent('OnResourceCacheUpdate', ['id' => $this->get('id')]); } } + + /** + * Returns array with all neighborhood resources + * + * @return array $arr Array with neighborhood from left and right + */ + public function getNeighborhood() + { + $arr = array(); + + $q = $this->xpdo->newQuery('modResource', array('parent' => $this->parent)); + $q->sortby('menuindex', 'ASC'); + $q->select('id'); + if ($q->prepare() && $q->stmt->execute()) { + $ids = $q->stmt->fetchAll(PDO::FETCH_COLUMN); + $current = array_search($this->id, $ids); + + $right = $left = array(); + foreach ($ids as $k => $v) { + if ($k > $current) { + $right[] = $v; + } elseif ($k < $current) { + $left[] = $v; + } + } + + $arr = array( + 'left' => array_reverse($left), + 'right' => $right, + ); + } + + return $arr; + } } diff --git a/manager/assets/modext/sections/resource/update.js b/manager/assets/modext/sections/resource/update.js index 80a32954fd9..1587b85120f 100644 --- a/manager/assets/modext/sections/resource/update.js +++ b/manager/assets/modext/sections/resource/update.js @@ -227,6 +227,8 @@ Ext.extend(MODx.page.UpdateResource,MODx.Component,{ ,scope: this }); + btns.push(this.getAdditionalButtons(config)); + btns.push({ process: 'Resource/Update' ,text: _('save') + ' ' @@ -242,5 +244,48 @@ Ext.extend(MODx.page.UpdateResource,MODx.Component,{ return btns; } + + ,getAdditionalButtons: function (config) { + return [{ + text: '', + handler: this.prevPage, + disabled: !config['prev_page'], + scope: this, + tooltip: _('prev_page'), + keys: [{key: 37, alt: true, scope: this, fn: this.prevPage}] + }, { + text: '', + handler: this.upPage, + scope: this, + disabled: !config['up_page'], + tooltip: _('up_page'), + keys: [{key: 38, alt: true, scope: this, fn: this.upPage}] + }, { + text: '', + handler: this.nextPage, + disabled: !config['next_page'], + scope: this, + tooltip: _('next_page'), + keys: [{key: 39, alt: true, scope: this, fn: this.nextPage}] + }]; + } + + ,prevPage: function () { + if (this.config['prev_page'] > 0) { + MODx.loadPage('resource/update', 'id=' + this.config['prev_page']) + } + } + + ,nextPage: function () { + if (this.config['next_page'] > 0) { + MODx.loadPage('resource/update', 'id=' + this.config['next_page']) + } + } + + ,upPage: function () { + if (this.config['up_page'] > 0) { + MODx.loadPage('resource/update', 'id=' + this.config['up_page']) + } + } }); Ext.reg('modx-page-resource-update',MODx.page.UpdateResource); diff --git a/manager/controllers/default/resource/staticresource/update.class.php b/manager/controllers/default/resource/staticresource/update.class.php index 0d2f1757df7..c16a1883787 100644 --- a/manager/controllers/default/resource/staticresource/update.class.php +++ b/manager/controllers/default/resource/staticresource/update.class.php @@ -31,6 +31,7 @@ public function loadCustomCssJs() $this->addJavascript($mgrUrl . 'assets/modext/widgets/resource/modx.panel.resource.static.js'); $this->addJavascript($mgrUrl . 'assets/modext/sections/resource/update.js'); $this->addJavascript($mgrUrl . 'assets/modext/sections/resource/static/update.js'); + $neighborhood = $this->resource->getNeighborhood(); $data = [ 'xtype' => 'modx-page-static-update', 'resource' => $this->resource->get('id'), @@ -44,6 +45,13 @@ public function loadCustomCssJs() 'canCreate' => (int)$this->modx->hasPermission('new_document'), 'canDelete' => (int)$this->modx->hasPermission('delete_document'), 'show_tvs' => (int)!empty($this->tvCounts), + 'next_page' => !empty($neighborhood['right'][0]) + ? $neighborhood['right'][0] + : 0, + 'prev_page' => !empty($neighborhood['left'][0]) + ? $neighborhood['left'][0] + : 0, + 'up_page' => $this->resource->parent ]; $this->addHtml('