Disable rename of a core doctype

Hi all,

this is a hack that might be useful to some of you: consider you have a core doctype like the project, which can be renamed. Now, you would like to prevent renaming this (e.g. see Disable Rename Item). Unfortunately, allow_rename cannot be customised; so either you fork the core, which is certainly not a good option. Or, you add a custom script with something like

/* remove rename handler from title */
var elements = document.getElementsByClassName("title-text");
var old_element = elements[0];
var new_element = old_element.cloneNode(true);
old_element.parentNode.replaceChild(new_element, old_element);
/* remove the remove option from the menu */
$("span[data-label='Rename']").parent().parent().remove();

Hopefully this is helpful to someone else (other than me :wink: )

3 Likes

Thanks for the script. Works!

Only problem: clicking directly on the name of a doc also opens the rename dialog… So there is some more needed here.
Any tips?

This is more a hack than anything else, but include this in your refresh trigger:

var e = document.getElementsByClassName("title-text");
for (var i = 0; i < e.length; i++) { e[i].outerHTML = e[i].outerHTML; } 

It will prevent the rename dialog from coming up (by removing the event listener)…

Hope this helps.