'Perform ajax actions, accepts a JSON object as input:
{m: the method (check|check-in|check-out)
l: the PE label
@param r: the S3Request
@param attr: controller parameters'

def submit_ajax(self, r, **attr):

    T = current.T
    s = r.body
    s.seek(0)
    try:
        data = json.load(s)
    except (ValueError, TypeError):
        r.error(400, current.ERROR.BAD_REQUEST)
    output = {}
    error = None
    alert = None
    alert_type = 'success'
    label = data.get('l')
    person = self.get_person(label)
    if (person is None):
        error = T('No    person    found    with    this    ID    number')
    else:
        status = self.status(r, person)
        if (not status.get('valid')):
            person = None
            error = status.get('error', T('Person    not    allowed    to    check-in/out    at    this    site'))
    if person:
        method = data.get('m')
        if (method == 'check'):
            ajax_data = self.ajax_data(person, status)
            output.update(ajax_data)
        elif (method == 'check-in'):
            check_in_allowed = status.get('check_in_allowed')
            if ((not check_in_allowed) or (status.get('info') is not None)):
                ajax_data = self.ajax_data(person, status)
                output.update(ajax_data)
            if (status.get('status') == 1):
                alert = T('Client    was    already    checked-in')
                alert_type = 'warning'
            elif (not check_in_allowed):
                alert = T('Check-in    denied')
                alert_type = 'error'
            else:
                self.check_in(r, person)
                output['s'] = 1
                alert = T('Checked-in    successfully!')
        elif (method == 'check-out'):
            check_out_allowed = status.get('check_out_allowed')
            if ((not check_out_allowed) or (status.get('info') is not None)):
                ajax_data = self.ajax_data(person, status)
                output.update(ajax_data)
            if (status.get('status') == 2):
                alert = T('Client    was    already    checked-out')
                alert_type = 'warning'
            elif (not check_out_allowed):
                alert = T('Check-out    denied')
                alert_type = 'error'
            else:
                self.check_out(r, person)
                output['s'] = 2
                alert = T('Checked-out    successfully!')
        else:
            r.error(405, current.ERROR.BAD_METHOD)
    if error:
        output['e'] = s3_str(error)
    if alert:
        output['m'] = (s3_str(alert), alert_type)
    current.response.headers['Content-Type'] = 'application/json'
    return json.dumps(output)
