'Main entry point, configuration'

def __call__(self):

    logged_in = current.auth.s3_logged_in()
    if logged_in:
        fn = 'alert'
    else:
        fn = 'public'
    T = current.T
    s3db = current.s3db
    request = current.request
    output = {}
    ftable = s3db.gis_layer_feature
    query = ((ftable.controller == 'cap') & (ftable.function == fn))
    layer = current.db(query).select(ftable.layer_id, limitby=(0, 1)).first()
    try:
        layer_id = layer.layer_id
    except:
        from s3 import s3_debug
        s3_debug('Cannot    find    Layer    for    Map')
        layer_id = None
    time_filter = (request.utcnow + timedelta((-7)))
    map_filter = ('~.external=True&~.status=Actual&~.info.expires__gt=%s' % time_filter)
    feature_resources = [{'name': T('Alerts'), 'id': 'search_results', 'layer_id': layer_id, 'filter': map_filter, 'active': False}]
    _map = current.gis.show_map(callback='S3.search.s3map()', catalogue_layers=True, collapsed=True, feature_resources=feature_resources, save=False, search=True, toolbar=True)
    output['_map'] = _map
    resource = s3db.resource('cap_alert')
    resource.add_filter((FS('is_template') == False))
    if (not logged_in):
        resource.add_filter((FS('scope') == 'Public'))
    resource.add_filter((FS('info.expires') >= time_filter))
    resource.add_filter((FS('external') == True))
    resource.add_filter((FS('status') == 'Actual'))
    resource.table.status.represent = None
    list_id = 'cap_alert_datalist'
    list_fields = ['msg_type', 'info.headline', 'area.name', 'info.sender_name', 'info.priority', 'status', 'scope', 'info.event_type_id', 'info.severity', 'info.certainty', 'info.urgency', 'sent']
    orderby = 'cap_alert.sent    desc'
    (datalist, numrows, ids) = resource.datalist(fields=list_fields, limit=None, list_id=list_id, orderby=orderby, layout=s3db.cap_alert_list_layout)
    if (numrows == 0):
        current.response.s3.crud_strings['cap_alert'].msg_no_match = T('No    Current    Alerts    match    these    filters.')
    ajax_url = URL(c='cap', f=fn, args='datalist.dl', vars={'list_id': list_id, 'info.expires__gt': time_filter, '~.external': True, '~.status': 'Actual'})
    output[list_id] = datalist.html(ajaxurl=ajax_url, pagesize=0)
    filter_widgets = [S3OptionsFilter('info.event_type_id'), S3DateFilter('info.expires', label='', hide_time=True)]
    filter_form = S3FilterForm(filter_widgets, ajax=True, submit=True, url=ajax_url)
    output['alert_filter_form'] = filter_form.html(resource, request.get_vars, list_id)
    output['title'] = s3_str(current.deployment_settings.get_cap_alert_hub_title())
    datalist_btn = A(T('View    Datalist'), _href=URL(c='cap', f=fn, vars={'~.external': True}), _class='action-btn    button    tiny')
    output['datalist_btn'] = datalist_btn
    self._view(THEME, 'alert_hub.html')
    s3 = current.response.s3
    s3.stylesheets.append('../themes/SAMBRO/style.css')
    s3.scripts.append(('/%s/static/themes/SAMBRO/js/homepage.js' % request.application))
    return output
