Hi all.
So, I have a feeling this will all be taken care of in 0.9.7, but just in case somebody needs to hide document object fields (link attribute, longtitle, parent, menu title, etc.) in the manager before that happens, here’s a little plugin.
Notes:
- I have examples of hiding fields, disabling fields, changing the text of the labels, hiding the content box, etc.
- I have examples of hiding/showing/changing fields based on the template.
- I have an example of hiding/showing/changing based on the manager role. (ie. Alias is not disabled for Admin role users, but is disabled for all other roles.)
- Uses JQuery, because I don’t know Prototype.
- I’m posting it as I have it. I’d rework it to be a bit less "manual", but 0.9.7 is probably going to make this a moot plugin anyway.
Big thanks to Timon and Gildas for the inspiration with the HideContent plugin.
And with my luck, 0.9.7 will come out... right now! Haha, I hope this helps somebody in the meantime.
// <?php
/*
@name HideManagerFields
@version 0.1.2, 2007-02-18
@for MODx 0.9.5 (though it'll probably work for 0.9.2.x as well)
@author Brett @ The Man Can!
@INSTALLATION:
1. Grab jquery.js from http://jquery.com/src/jquery-latest.pack.js
2. Put it in /assets/js/
3. Paste this as a new plugin, check the OnDocFormRender checkbox
4. Make sure this comes after any other plugin that could effect the template, like InheritParentTemplate
5. Edit the code below. You may not need sections 2 or 3; delete them if that's the case.
@INSPIRATION:
HideEditor plugin by Timon Reinhard and Gildas
*/
// Set variables
global $content;
$template = $content['template'];
$output = '';
$role = $_SESSION['mgrRole'];
// Check the current event
$e = &$modx->Event;
// Check for the event, and to make sure there is a template specified
if (($e->name == 'OnDocFormRender') && ($template > 0)) {
// Include the JQuery call
$output .= '<!-- HideManagerFields Plugin :: Start -->
<!-- This document is using template: '. $template .' -->
<!-- You are logged into the following role: '. $role .' -->
<script src="/assets/js/jquery.js" type="text/javascript" charset="utf-8"></script>';
// SECTION 1: MAIN
// Hide all the stuff you want to hide for *all* templates and admin roles.
// This is probably the only section you'll need.
$output .= '
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Hide the longtitle
$("input[@name=longtitle]").parents("tr").hide();
// Change the "Summary (Introtext)" to "Summary"
$("input[@name=introtext]").parents("td").prev("td").children("span.warning").empty().prepend("Summary / Teaser");
// Change the "Document\'s Alias" to "Alias"
$("input[@name=alias]").parents("td").prev("td").children("span.warning").empty().prepend("Alias");
// Hide the link attributes
// $("input[@name=alias]").parents("tr").hide();
// Hide the template select box
$("input[@name=link_attributes]").parents("tr").hide();
// Hide the menutitle
$("input[@name=menutitle]").parents("tr").hide();
// Hide the "Show in menu" checkbox
$("input[@name=hidemenucheck]").parents("tr").empty();
// Hide the parent selector
$("input[@name=parent]").parents("tr").hide();';
// END SECTION 1
// SECTION 2: ADMIN ROLES
// REMOVE THIS BLOCK if you aren't going to be using it.
//
// Hide or modify certain elements based on the manager user's role.
// To determind the number of the role you're logged in with, create a page using the template,
// then view the source of the frame and look towards the bottom to see the HTML comments,
// which will say <!-- You are logged into the following role: 1 -->
// or something like that. (Default role is 1.)
if ($role != '1' ) {
$output .= '
// Disable the alias field
$("input[@name=alias]").attr("disabled","disabled").css({ background:"#ccc", color:"#666" });
// Hide the template selector dropdown
$("select[@name=template]").parents("tr").hide();';
}
// END SECTION 2
// SECTION 3: TEMPLATE SPECIFIC CODE
// REMOVE THIS BLOCK if you aren't going to be using it
//
// Hide or modify certain elements based on the template.
// To determind the number of the template you're using, create a page using the template,
// then view the source of the frame and look towards the bottom to see the HTML comments,
// which will say <!-- This document is using template: 1 -->
// or something like that.
switch ($template) {
case '4':
$output .= '
// Change the "Description" to "Sub-Heading"
$("input[@name=description]").parents("td").prev("td").children("span.warning").empty().prepend("Sub-Heading");';
break;
case '6':
$output .= '
// Hide the content area
$("#ta").parents("div").parents("div.sectionBody").hide().prev("div.sectionHeader").hide()';
break;
default:
break;
}
// END SECTION 3
// Do not remove the following lines.
$output .= '
});
</script>';
$output .= '
<!-- HideManagerFields Plugin :: End -->
';
}
$e->output($output);
// ?>
UPDATE:
This plugin has been updated. New thread here:
http://modxcms.com/forums/index.php?topic=12493