'Dispatch Ajax requests
@param dashboard: the calling S3Dashboard instance
@param context: the current S3DashboardContext
@return: tuple (output, error), where:
- "output" is the output of the command execution
- "error" is a tuple (http_status, message), or None'

def __call__(self, dashboard, context):

    command = context.command
    representation = context.representation
    output = None
    error = None
    if command:
        if (command == 'config'):
            if (representation == 'popup'):
                output = self.configure(dashboard, context)
            else:
                error = (415, current.ERROR.BAD_FORMAT)
        elif (command == 'authorize'):
            error = (501, current.ERROR.NOT_IMPLEMENTED)
        else:
            try:
                output = self.do(command, context)
            except NotImplementedError:
                error = (501, current.ERROR.NOT_IMPLEMENTED)
    elif (context.http == 'GET'):
        if (representation in ('html', 'iframe')):
            output = self.widget.widget(self.agent_id, self.config, context=context)
        else:
            error = (415, current.ERROR.BAD_FORMAT)
    else:
        error = (405, current.ERROR.BAD_METHOD)
    return (output, error)
