'Helper method to inject the init script for a particular agent,
usually called by widget() method.
@param agent_id: the agent ID
@param version: the config version key
@param widget_class: the widget class to instantiate
@param options: JSON-serializable dict of options to pass
to the widget instance'

@classmethod
def inject_script(cls, agent_id, version=None, widget_class='dashboardWidget', options=None):

    s3 = current.response.s3
    if ((not agent_id) or (not widget_class)):
        return
    if (not options):
        options = {}
    title = cls.title
    if title:
        options['title'] = s3_str(current.T(title))
    dashboard_url = URL(args=[], vars={})
    options['dashboardURL'] = dashboard_url
    options['version'] = version
    script = ('$("#%(agent_id)s").%(widget_class)s(%(options)s)' % {'agent_id': agent_id, 'widget_class': widget_class, 'options': json.dumps(options)})
    s3.jquery_ready.append(script)
