'Render a filter manager widget
@param resource: the resource
@return: the widget'

def _render_filters(self, resource, form_id):

    SELECT_FILTER = current.T('Saved    Filters')
    ajaxurl = self.opts.get('saveurl', URL(args=['filter.json'], vars={}))
    auth = current.auth
    pe_id = (auth.user.pe_id if auth.s3_logged_in() else None)
    if (not pe_id):
        return None
    table = current.s3db.pr_filter
    query = ((table.deleted != True) & (table.pe_id == pe_id))
    if resource:
        query &= (table.resource == resource.tablename)
    else:
        query &= (table.resource == None)
    rows = current.db(query).select(table._id, table.title, table.query, orderby=table.title)
    options = [OPTION(SELECT_FILTER, _value='', _class='filter-manager-prompt', _disabled='disabled')]
    add_option = options.append
    filters = {}
    for row in rows:
        filter_id = row[table._id]
        add_option(OPTION(row.title, _value=filter_id))
        query = row.query
        if query:
            query = json.loads(query)
        filters[filter_id] = query
    widget_id = ('%s-fm' % form_id)
    widget = DIV(SELECT(options, _id=widget_id, _class='filter-manager-widget'), _class='filter-manager-container')
    T = current.T
    _t = (lambda s: s3_str(T(s)))
    settings = current.deployment_settings
    config = dict(filters=filters, ajaxURL=ajaxurl, allowDelete=settings.get_search_filter_manager_allow_delete(), createTooltip=_t('Save    current    options    as    new    filter'), loadTooltip=_t('Load    filter'), saveTooltip=_t('Update    saved    filter'), deleteTooltip=_t('Delete    saved    filter'), titleHint=_t('Enter    a    title...'), selectHint=s3_str(SELECT_FILTER), emptyHint=_t('No    saved    filters'), confirmUpdate=_t('Update    this    filter?'), confirmDelete=_t('Delete    this    filter?'))
    create_text = settings.get_search_filter_manager_save()
    if create_text:
        config['createText'] = _t(create_text)
    update_text = settings.get_search_filter_manager_update()
    if update_text:
        config['saveText'] = _t(update_text)
    delete_text = settings.get_search_filter_manager_delete()
    if delete_text:
        config['deleteText'] = _t(delete_text)
    load_text = settings.get_search_filter_manager_load()
    if load_text:
        config['loadText'] = _t(load_text)
    script = ('$("#%s").filtermanager(%s)' % (widget_id, json.dumps(config, separators=SEPARATORS)))
    current.response.s3.jquery_ready.append(script)
    return widget
