'Show a default cancel button in standalone create/update forms.
Individual controllers can override this by setting
response.s3.cancel = False.
@param r: the S3Request'

def _default_cancel_button(self, r):

    if (r.representation != 'html'):
        return False
    s3 = current.response.s3
    cancel = s3.cancel
    if ((cancel is False) or isinstance(cancel, dict)):
        success = False
    elif ((cancel is True) or current.deployment_settings.get_ui_default_cancel_button()):
        if isinstance(cancel, basestring):
            default_url = cancel
        else:
            method = r.method
            if (method == 'create'):
                if r.component:
                    default_url = r.url(method='', component_id='', vars={})
                else:
                    config = self._config('summary')
                    if (config or current.deployment_settings.get_ui_summary()):
                        default_url = r.url(method='summary', id=0)
                    else:
                        default_url = r.url(method='', id=0)
            elif ((method == 'update') or (not method)):
                if r.component:
                    default_url = r.url(method='', component_id='', vars={})
                else:
                    default_url = r.url(method='read')
        if default_url:
            script = ("$.cancelButtonS3('%s')" % default_url)
        else:
            script = '$.cancelButtonS3()'
        jquery_ready = current.response.s3.jquery_ready
        if (script not in jquery_ready):
            jquery_ready.append(script)
        success = s3.cancel = True
    else:
        success = False
    return success
