Instantly share code, notes, and snippets.
Last active
May 1, 2022 12:13
-
Save pepebe/10006991 to your computer and use it in GitHub Desktop.
ManagerQuickNav v:0.01i (BETA) ManagerQuickNav adds: - buttons with links to the previous or next resource in the current menuindex - a combobox with links the current parent resource and all siblings. - a button to quickly add a new resource with the same parent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ManagerQuickNav v:0.0.1j (BETA) | |
* Last edited: 2014-04-09 14:26 | |
* | |
* AUTHOR: | |
* info@pepebe.de | |
* | |
* DESCRIPTION: | |
* This plugin injects js to add new items to 'modx-action-buttons' | |
* (the button group in the top right corner of the update resource window). | |
* | |
* ManagerQuickNav adds: | |
* - buttons with links to the previous or next resource in the current menuindex | |
* - a combobox with links to the current parent resource and all siblings. | |
* | |
* The plugin is especially useful with other plugins that hide child resources like: | |
* - articles | |
* - collections | |
* - grid_class_key | |
* | |
* USAGE: | |
* 1. Create a new plugin and copy the content of this file into the plugin code textarea. | |
* 2. Check the 'OnDocFormRender' system event and make sure the plugin is not disabled. | |
* 3. Done. | |
* | |
* OPTIONS:. | |
* emptyText = (string) Placeholder text for combobox | |
* width = (int) width of comobox | |
* newTitle = (string) Tooltip text for the create new resource button | |
* | |
* hide_close = (bolean) Hide obsolete buttons | |
* | |
* IMPORTANT: | |
* This is just a proof of concept. | |
* | |
* 1. It assumes that the menuindex of a group of child resources looks like this: 0,1,2,3,... | |
* Im sure this is not always the case. The final version will handle this problem in a better way. | |
* If you have a good solution for this problem, send me a mail. | |
* | |
* CHANGELOG: | |
* v0.0.1a Initial Release | |
* v0.0.1b Customizazion options for combobox settings | |
* v0.0.1c Trigger MODx.releaseLock(MODx.request.id) before leaving current page. | |
* v0.0.1d Added ManagerQuickNav to root Elements | |
* v0.0.1e Added option to remove obolsolet buttons and and button to create a new resource with the same parent. | |
* v0.0.1f Language settings for en and de | |
* v0.0.1g New changelog | |
* v0.0.1h Now also (somewhat) working with articles. @treigh: Thanks for your feedback. | |
* v0.0.1i Now COMPLETELY working with articles! | |
* v0.0.1j Link generations completly rewritten.a | |
* v0.0.1k optimized css | |
* v0.0.1l minor code optimization | |
* | |
* extjs docs: https://docs.sencha.com/extjs/3.4.0/#!/api/Ext.Button | |
* | |
*/ | |
/**/ | |
$showQuickNav = array('22'); | |
/* Optional settings */ | |
$language = 'en'; | |
$lang['de']['emptyText'] = "Weiter mit..."; | |
$lang['de']['newText'] = "Neues Dokument"; | |
$lang['de']['newTooltip'] = "Erstelle ein neues Dokument mit dem selben Elternelement"; | |
$lang['en']['emptyText'] = "Quicknav"; | |
$lang['en']['newText'] = "New Document"; | |
$lang['en']['newTooltip'] = "Create a new Document with the same parent"; | |
$emptyText = $lang[$language]['emptyText']; | |
$newText = $lang[$language]['newText']; | |
$newTooltip = $lang[$language]['newTooltip']; | |
$prevTooltip = 'Previous Document'; | |
$prevText = '<i class="icon icon-angle-left"></i>'; | |
$nextTooltip = 'Next Document'; | |
$nextText = '<i class="icon icon-angle-right"></i>'; | |
$width = 150; /* Might be to small for your resource titles */ | |
$hide_close = 1; | |
/* Don't change anything below this comment if you don't know your code-fu... */ | |
$prevId = 0; | |
$prefTitle = ""; | |
$nextId = 0; | |
$nextTitle = ""; | |
$parentId = $resource->get('parent'); | |
$context_key = $resource->get('context_key'); | |
$currentId = $resource->get('id'); | |
$currentIndex = $resource->get('menuindex'); | |
$currentTitle = $resource->get('pagetitle'); | |
$currentTemplate = $resource->get('template'); | |
#if(!in_array($currentTemplate,$showQuickNav)) { return; } | |
if($currentIndex == 0) { $prev = 0;} | |
if($parentId == 0) { | |
/* All root elements... */ | |
$c = $modx->newQuery('modResource'); | |
$c->sortby('menuindex','ASC'); | |
$c->where(array( | |
'parent' => 0, | |
'context_key' => $context_key | |
)); | |
$children = $modx->getCollection('modResource', $c); | |
} | |
else { | |
$parent = $resource->getOne('Parent'); | |
$parent_class_key = $parent->get('class_key'); | |
if($parent_class_key == 'ArticlesContainer'){ | |
$settings = $parent->getProperties('articles'); | |
$articleTemplate = !empty($settings['articleTemplate']) ? $settings['articleTemplate'] : $modx->config[’articles.default_article_template’]; | |
} | |
$parentId = $parent->get('id'); | |
$parentTitle = $parent->get('pagetitle'); | |
$c = $modx->newQuery('modResource'); | |
$c->sortby('menuindex','ASC'); | |
$children = $parent->getMany('Children',$c); | |
} | |
if (!$children ) { return false; } | |
if($parentId != 0){ | |
$store[] = "['$parentId','$parentTitle ($parentId)']"; | |
} | |
foreach ($children as $child) { | |
$childId = $child->get('id'); | |
$childIndex = $child->get('menuindex'); | |
$childTitle = $child->get('pagetitle'); | |
if(($childIndex +1 ) == $currentIndex){ | |
$prevId = $childId; | |
$prevTitle = $childTitle; | |
} | |
if(($childIndex -1 ) == $currentIndex){ | |
$nextId = $childId; | |
$nextTitle = $childTitle; | |
} | |
if($id != $childId) { | |
$childTitle = " → $childTitle ($childId)"; | |
} | |
else { | |
$childTitle = " → <b>$childTitle ($childId)</b>"; | |
} | |
$store[] = "['$childId','$childTitle']"; | |
} | |
$store = implode(",",$store); | |
switch($modx->event->name){ | |
case 'OnDocFormRender': | |
$html = " | |
<style> | |
#modx-action-buttons .x-form-field-trigger-wrap { | |
margin-right: 0px!important; | |
} | |
#modx-action-buttons .x-btn { | |
padding: 0px; | |
} | |
#modx-action-buttons button { | |
height: auto; | |
padding: 11px; | |
} | |
#modx-action-buttons .x-item-disabled { | |
opacity: 0.2; | |
filter: alpha(opacity=60); | |
background-color: transparent; | |
} | |
#modx-action-buttons .x-item-disabled:hover { | |
background-color: transparent; | |
box-shadow: none; | |
border: transparent; | |
} | |
#nextResource.x-btn {margin-left: 0px;} | |
#prevResource.x-btn .icon, | |
#nextResource.x-btn .icon, | |
#newResource.x-btn .icon {margin-right: 0px;} | |
</style> | |
<!-- <script type='text/javascript' src='//code.jquery.com/jquery-1.10.2.min.js'></script> --> | |
<script type='text/javascript'> | |
Ext.onReady(function () { | |
console.log('ManagerQuickNav plugin loaded'); | |
var parent_class_key = '" . $parent_class_key . "'; | |
if(parent_class_key == 'ArticlesContainer'){ | |
var articleTemplate = '" . $articleTemplate . "'; | |
} | |
var hide_close = $hide_close; | |
var context_key = '$context_key'; | |
var parentId = $parentId; | |
var emptyText = '{$emptyText}'; | |
var width = $width; | |
var newText = '{$newText}'; | |
var newTooltip = '{$nexTooltip}'; | |
var prevId = $prevId; | |
var prevText = '{$prevText}'; | |
var prevTooltip = '{$prevTooltip}'; | |
var nextId = $nextId; | |
var nextText = '{$nextText}'; | |
var nextTooltip = '{$nextTooltip}'; | |
var currentId = $currentId; | |
var currentText = '{$currentText}'; | |
var currentTemplate = '{$currentTemplate}'; | |
var store = [$store]; | |
var modab = Ext.getCmp('modx-action-buttons'); | |
var modx_abtn_cancel = Ext.getCmp('modx-abtn-cancel'); | |
var modx_stay_menu = Ext.getCmp('modx-stay-menu'); | |
if(hide_close){ | |
if(modx_abtn_cancel) { | |
//modx_abtn_cancel.hide(); | |
} | |
if(modx_stay_menu){ | |
modx_stay_menu.hide(); | |
} | |
} | |
else { | |
modab.add('-'); | |
} | |
modab.add({ | |
xtype: 'button' | |
,disabled: true | |
,tooltip: prevTooltip | |
,tooltipType: 'title' | |
,text: prevText | |
,id: 'prevResource' | |
,handler: function(){ | |
MODx.releaseLock(MODx.request.id); | |
querystring = 'id=' + prevId; | |
MODx.loadPage(MODx.action['resource/update'], querystring); | |
} | |
}); | |
if(prevId != 0){ | |
Ext.getCmp('prevResource').enable(); | |
} | |
else { | |
Ext.getCmp('prevResource').disable(); | |
} | |
modab.add({ | |
xtype: 'combo' | |
,cls: 'siblingsCombo' | |
,width: width | |
,emptyText: emptyText | |
,id: 'siblings' | |
,mode: 'local' | |
,displayField: 'pagetitle' | |
,valueField: 'id' | |
,store: new Ext.data.ArrayStore({ | |
id: 0 | |
,fields: ['id','pagetitle'] | |
,data: store | |
}) | |
,listeners:{ | |
scope: this | |
,'select': function(combo,value){ | |
resource = combo.getValue(); | |
if(resource != currentId){ | |
MODx.releaseLock(MODx.request.id); | |
querystring = 'id=' + resource; | |
MODx.loadPage(MODx.action['resource/update'], querystring); | |
} | |
else { | |
combo.clearValue(); | |
combo.applyEmptyText(); | |
combo.getPicker().getSelectionModel().doMultiSelect([], false); | |
//alert(combo.getValue()); | |
} | |
} | |
} | |
,forceSelection: true | |
,triggerAction: 'all' | |
,selectOnFocus:true | |
,editable: false | |
,typeAhead: false | |
}); | |
modab.add({ | |
xtype: 'button' | |
,disabled: true | |
,text: nextText | |
,tooltip: nextTooltip | |
,tooltipType: 'title' | |
,id: 'nextResource' | |
,handler: function(){ | |
MODx.releaseLock(MODx.request.id); | |
querystring = 'id=' + nextId; | |
MODx.loadPage(MODx.action['resource/update'], querystring); | |
} | |
}); | |
if(nextId != 0){ | |
Ext.getCmp('nextResource').enable(); | |
} | |
else { | |
Ext.getCmp('nextResource').disable(); | |
} | |
modab.add({ | |
xtype: 'button' | |
,disabled: false | |
,tooltip: newTooltip | |
,text: newText | |
,id: 'newResource' | |
,handler: function(){ | |
MODx.releaseLock(MODx.request.id); | |
if(parent_class_key == 'ArticlesContainer'){ | |
querystring = 'class_key=Article&parent=' + parentId + '&context_key=' + context_key + '&template=' + articleTemplate; | |
MODx.loadPage(MODx.action['resource/create'], querystring); | |
} | |
else { | |
querystring = 'parent=' + parentId + '&context_key=' + context_key; | |
MODx.loadPage(MODx.action['resource/create'], querystring); | |
} | |
} | |
}); | |
modab.doLayout(); | |
}); | |
</script> | |
"; | |
$modx->regClientStartupHTMLBlock($html); | |
break; | |
default: | |
break; | |
} | |
/**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment