import posixpath

from django.conf import settings

RL_ADMIN_SCRIPTS = {}

def registerJsAdminScript(modelFieldClass, pathname):
    RL_ADMIN_SCRIPTS.setdefault(modelFieldClass, []).append(pathname)

def rlAdminExtraHead(opts):
    html = []
    for modelFieldClass, paths in RL_ADMIN_SCRIPTS.items():
        if opts.has_field_type(modelFieldClass):
            for path in paths:
                fullPath = posixpath.join(settings.APP_ADMIN_MEDIA_PREFIX, path)
                headLine = '<script type="text/javascript" src="%s"></script>' % fullPath
                html.append(headLine)
    return '\n'.join(html)
