We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29635
    • 361 Posts
    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
      Need MODx Ecommerce? Try FoxyCart!
      • 22303 MODX Staff
      • 10,725 Posts
      That’s a very cool plugin Brett; jQuery looks very interesting... and just fyi, 0.9.7 alpha may get released today, but this will still be just as useful, as 0.9.7 simply will provide a new class to represent $modx and implement all it’s existing behavior (plus add new possibilities); the manager is still relatively the same.
        • 29635
        • 361 Posts
        Thanks for the compliment, Jason.
        If 0.9.7 doesn’t address this issue, I may extend it a bit, and I may switch it from jquery to mootools, as that seems to be the method of choice for the manager. Jquery is definitely interesting, though. I haven’t really come across anything that it can’t do.
          Need MODx Ecommerce? Try FoxyCart!
          • 6726
          • 7,075 Posts
          +1 very cool cool !

          I have been waiting for this to "dumb down" the interface for less technically minded users, that’s just perfect grin
          I am off to testing this right now !
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l&#39;outil id
            • 16311
            • 28 Posts
            This would seem to do exactly what I’ve been hoping, however I’m usure as to how to use it. I’ve installed it as per the instructions in the code comments. Does anyone have anymore tips?
              • 30223
              • 1,010 Posts
              Excellent! I really like the different criteria for hiding/changing fields. The changeover to mootools shouldn’t give you too many headaches. I’m an absolute jQuery fan but I’ve resigned to the fact that I’ve got start using mootools . There’s a nice mootools cheat sheet available at http://www.snook.ca/archives/javascript/mootools_r83_cheatsheet/
                • 29635
                • 361 Posts
                Thanks for that cheat sheet. That’ll definitely help.
                As far as making it easier to use and modify, my plan is to eventually turn it into a module, but that might take a while. (Our first child is due on Friday, so diapers are gonna take priority wink

                I just updated the code in the first post with a lot of comments that hopefully will help more people figure it out in the meantime.

                @kratos: Grab the latest version that I just posted. As far as "how to use it" in its current form, you just kind of have to go through the code with your favorite text editor and modify it to fit your needs manually. There are examples of everything I could think of, but you’ll need to know a little bit of PHP and jquery. The best thing may be to remove everything but one of the lines (like the first 2 lines that hide the longtitle), make sure that works, then add in additional parameters one at a time. You’ll probably also want to remove section 2 and 3 until you’re more comfortable with how it’s working.
                  Need MODx Ecommerce? Try FoxyCart!
                  • 30223
                  • 1,010 Posts
                  The beauty of this plugin is that you’re not limited to just hiding fields. It’s very easy for instance to automatically pre-fill the longtitle from the pagetitle value.

                  $("input[@name=pagetitle]").change( function(){ $("input[@name=longtitle]").val($(this).val()); });

                    • 26482
                    • 138 Posts
                    Could it be the case that this plugin works only on saved documents and not on new documents? The plugin gets loaded with OnDocFormRender with saved documents. However, when I create a new document, it doesn’t get loaded. Is there a separate event that is triggered for newly created documents?

                    Thanks.
                      • 27376
                      • 576 Posts
                      The OnDocFormRender System event is called after the Document input form is outputted, meaning it is called on new documents, loaded, documents, duplicated, whatever. Anytime the Document form is shown, this event is called.