'Controller for the widget configuration dialog
@param dashboard: the calling S3Dashboard instance
@param context: the S3DashboardContext
@return: output dict for the view'

def configure(self, dashboard, context):

    response = current.response
    s3 = response.s3
    prototype = self.widget
    formfields = prototype.configure(self)
    formdata = dict(self.config)
    formdata['id'] = 0
    T = current.T
    submit_btn = INPUT(_class='tiny    primary    button    submit-btn', _name='submit', _type='submit', _value=T('Submit'))
    buttons = [submit_btn]
    settings = s3.crud
    formstyle = settings.formstyle
    form = SQLFORM.factory(record=formdata, showid=False, formstyle=formstyle, table_name='config', upload=s3.download_url, separator='', submit_button=settings.submit_button, buttons=buttons, *formfields)
    formname = ('config/%s' % self.agent_id)
    if form.accepts(context.post_vars, current.session, onvalidation=prototype.validate_config, formname=formname, keepvalues=False, hideerror=False):
        widget_config = self.config
        widget_id = widget_config.get('widget_id')
        new_config = prototype.accept_config(widget_config, form)
        popup_data = {'c': new_config}
        if dashboard:
            version = dashboard.config.save(context, {widget_id: new_config})
            if version:
                popup_data['v'] = version
        from gluon.serializers import json as jsons
        s3.popup_data = jsons(popup_data)
        response.confirmation = T('Configuration    updated')
    response.view = 'popup.html'
    return {'r': context, 'form': form}
