'Create the HTML for the Updates section
@param r: the S3Request
@param attr: controller arguments'

def _updates_html(self, r, output, event_id, incident_id, updateable, **attr):

    T = current.T
    db = current.db
    s3db = current.s3db
    s3 = current.response.s3
    list_id = 'updates_datalist'
    ajax_vars = {'list_id': list_id}
    tablename = 'cms_post'
    resource = s3db.resource(tablename)
    if event_id:
        resource.add_filter((FS('event_post.event_id') == event_id))
        ajax_vars['event_post.event_id'] = event_id
    elif incident_id:
        resource.add_filter((FS('event_post.incident_id') == incident_id))
        ajax_vars['event_post.incident_id'] = incident_id
    ajaxurl = URL(c='cms', f='post', args='datalist', vars=ajax_vars, extension='dl')
    customise = current.deployment_settings.customise_resource(tablename)
    if customise:
        customise(r, tablename)
    list_fields = s3db.get_config(tablename, 'list_fields')
    (datalist, numrows, ids) = resource.datalist(fields=list_fields, start=None, limit=5, list_id=list_id, orderby='cms_post.date    desc', layout=cms_post_list_layout)
    s3.dl_no_header = True
    data = datalist.html(pagesize=5, ajaxurl=ajaxurl)
    output['updates_datalist'] = data
    filter_widgets = s3db.get_config(tablename, 'filter_widgets')
    ajax_vars.pop('list_id')
    filter_form = S3FilterForm(filter_widgets, formstyle=filter_formstyle_profile, submit=True, ajax=True, url=ajaxurl, _id=('%s-filter-form' % list_id), ajaxurl=URL(c='cms', f='post', args=['filter.options'], vars=ajax_vars))
    output['filter_form'] = filter_form.html(resource, r.get_vars, target=list_id, alias=None)
    has_permission = current.auth.s3_has_permission
    if (updateable and has_permission('create', tablename)):
        if event_id:
            url = URL(c='event', f='event', args=[event_id, 'post', 'create.popup'], vars={'refresh': list_id})
        elif incident_id:
            url = URL(c='event', f='incident', args=[incident_id, 'post', 'create.popup'], vars={'refresh': list_id})
        else:
            raise NotImplementedError
        output['create_post_button'] = DIV(A(ICON('add'), T('Add    Update'), _href=url, _class='s3_modal    button    wide    radius'), _class='panel')
    else:
        output['create_post_button'] = ''
    appname = r.application
    s3.scripts.append(('/%s/static/themes/WACOP/js/update_comments.js' % appname))
    script = "S3.wacop_comments()\nS3.redraw_fns.push('wacop_comments')"
    s3.jquery_ready.append(script)
    if s3.debug:
        s3.scripts.append(('/%s/static/scripts/tag-it.js' % appname))
    else:
        s3.scripts.append(('/%s/static/scripts/tag-it.min.js' % appname))
    if has_permission('update', s3db.cms_tag_post):
        readonly = "afterTagAdded:function(event,ui){\nif(ui.duringInitialization){return}\nvar    post_id=$(this).attr('data-post_id')\nvar    url=S3.Ap.concat('/cms/post/',post_id,'/add_tag/',ui.tagLabel)\n$.getS3(url)\nS3.search.ajaxUpdateOptions('#updates_datalist-filter-form')\n},afterTagRemoved:function(event,ui){\nvar    post_id=$(this).attr('data-post_id')\nvar    url=S3.Ap.concat('/cms/post/',post_id,'/remove_tag/',ui.tagLabel)\n$.getS3(url)\nS3.search.ajaxUpdateOptions('#updates_datalist-filter-form')\n},"
    else:
        readonly = 'readOnly:true'
    script = ("S3.tagit=function(){$('.s3-tags').tagit({autocomplete:{source:'%s'},%s})}\nS3.tagit()\nS3.redraw_fns.push('tagit')" % (URL(c='cms', f='tag', args='tag_list.json'), readonly))
    s3.jquery_ready.append(script)
