I have a pretty hard time to find out how to properly manage javascript in a page for different type of user.
Let me explain a bit: We have a page that's is visible for everyone but some have the right to edit content on the page directly and some just have a read-only access. This page is really javascript heavy. (4k+ lines or so) And inside this javascript, I have php conditions deciding, based on user rights, whether or not it should display this or this function. The problem is maintenance of the code.
Because I have many types of user rights and a file that is huge, I struggle with the process of refactoring some function including those right. And for security purposes, I have to be pretty precise about what I'm doing.
Since having a js file for each user right type is not maintainable at all in my case. I'd like to know if you guys have some kind of genius idea to help me make something readable and maintainable.
Along in this case, how could I include a system that minimize my JS including this right management.
Example of code I have :
<?if ( $right_to_invite ) { ?>
<div class="admin">
// Magic inside
</div>
<?}?>
// else i just don't display it
And since my javascript doesn't have to be displayed if you don't have right for it
<?if ( $right_to_invite ) { ?>
function invite(){
$.post(.......) // again magic ...
}
$(".invite").on("click",invite());
<?}?>
And it goes on and on and on ....