pepebe
4/15/2014 - 1:06 PM

Hide TVs from root resources in MODX Manager

Hide TVs from root resources in MODX Manager

<?php
/**
 * Hide TVs for root elements... 
 */ 
 
    /* Set option(s) here */
    
    $tvs_to_hide = '1,2';
    
    /* ---------------------------------- */
    
    $parentId    = $resource->get('parent');
    
    if($parentId == 0){

        switch($modx->event->name){
        case 'OnDocFormRender':
            $html = "
                <script type='text/javascript'>
                Ext.onReady(function () {
                    
                    console.log('Parent id is 0 - Hide some TVs from user');
                    
                    var tvs_to_hide = [".$tvs_to_hide."];
                    
                    Ext.each(
                        tvs_to_hide, 
                        function(tv_to_hide, index) {
                            var tv = Ext.get('tv' + tv_to_hide + '-tr');
                            if(tv){
                                console.log('tv' + tv_to_hide + ' found and hidden');
                                tv.setVisibilityMode(Ext.Element.DISPLAY).hide();
                            }
                            else{
                                console.log('tv' + tv_to_hide + ' cannot be found');
                            }
                        }
                    );
                });
                </script>
            ";
            
            $modx->regClientStartupHTMLBlock($html);
            break;
        default:
            break;
}
    return;
}
else {
    return;
}
/**/