Search in sources :

Example 1 with ERXBrowser

use of er.extensions.appserver.ERXBrowser in project wonder-slim by undur.

the class AjaxDefaultSubmitButton method appendToResponse.

@Override
public void appendToResponse(WOResponse response, WOContext context) {
    WOComponent component = context.component();
    String formName = (String) valueForBinding("formName", component);
    String formReference = "this.form";
    if (formName != null) {
        formReference = "document." + formName;
    }
    StringBuilder onClickBuffer = new StringBuilder();
    String onClickBefore = (String) valueForBinding("onClickBefore", component);
    if (onClickBefore != null) {
        onClickBuffer.append("if (");
        onClickBuffer.append(onClickBefore);
        onClickBuffer.append(") {");
    }
    // PROTOTYPE EFFECTS
    String updateContainerID = AjaxUpdateContainer.updateContainerID(this, component);
    String beforeEffect = (String) valueForBinding("beforeEffect", component);
    if (beforeEffect != null) {
        onClickBuffer.append("new ");
        onClickBuffer.append(AjaxUpdateLink.fullEffectName(beforeEffect));
        onClickBuffer.append("('");
        String beforeEffectID = (String) valueForBinding("beforeEffectID", component);
        if (beforeEffectID == null) {
            beforeEffectID = AjaxUpdateContainer.currentUpdateContainerID();
            if (beforeEffectID == null) {
                beforeEffectID = updateContainerID;
            }
        }
        onClickBuffer.append(beforeEffectID);
        onClickBuffer.append("', { ");
        String beforeEffectDuration = (String) valueForBinding("beforeEffectDuration", component);
        if (beforeEffectDuration != null) {
            onClickBuffer.append("duration: ");
            onClickBuffer.append(beforeEffectDuration);
            onClickBuffer.append(", ");
        }
        onClickBuffer.append("queue:'end', afterFinish: function() {");
    }
    if (updateContainerID != null) {
        onClickBuffer.append("ASB.update('" + updateContainerID + "',");
    } else {
        onClickBuffer.append("ASB.request(");
    }
    onClickBuffer.append(formReference);
    onClickBuffer.append(",null,");
    NSMutableDictionary options = createAjaxOptions(component);
    AjaxUpdateLink.addEffect(options, (String) valueForBinding("effect", component), updateContainerID, (String) valueForBinding("effectDuration", component));
    String afterEffectID = (String) valueForBinding("afterEffectID", component);
    if (afterEffectID == null) {
        afterEffectID = AjaxUpdateContainer.currentUpdateContainerID();
        if (afterEffectID == null) {
            afterEffectID = updateContainerID;
        }
    }
    AjaxUpdateLink.addEffect(options, (String) valueForBinding("afterEffect", component), afterEffectID, (String) valueForBinding("afterEffectDuration", component));
    AjaxOptions.appendToBuffer(options, onClickBuffer, context);
    onClickBuffer.append(')');
    String onClick = (String) valueForBinding("onClick", component);
    if (onClick != null) {
        onClickBuffer.append(';');
        onClickBuffer.append(onClick);
    }
    if (beforeEffect != null) {
        onClickBuffer.append("}});");
    }
    if (onClickBefore != null) {
        onClickBuffer.append('}');
    }
    onClickBuffer.append("; return false;");
    response.appendContentString("<input ");
    appendTagAttributeToResponse(response, "tabindex", "");
    appendTagAttributeToResponse(response, "type", "submit");
    String name = nameInContext(context, component);
    appendTagAttributeToResponse(response, "name", name);
    appendTagAttributeToResponse(response, "value", valueForBinding("value", component));
    appendTagAttributeToResponse(response, "accesskey", valueForBinding("accesskey", component));
    // Suppress modal box focus ring if used inside of modal dialog
    if (AjaxModalDialog.isInDialog(context)) {
        StringBuilder sb = new StringBuilder("MB_notFocusable ");
        Object cssClass = valueForBinding("class", component);
        if (cssClass != null) {
            sb.append(cssClass);
        }
        appendTagAttributeToResponse(response, "class", sb.toString());
    } else {
        appendTagAttributeToResponse(response, "class", valueForBinding("class", component));
    }
    appendTagAttributeToResponse(response, "style", "position:absolute;left:-10000px");
    appendTagAttributeToResponse(response, "id", valueForBinding("id", component));
    appendTagAttributeToResponse(response, "onclick", onClickBuffer.toString());
    response.appendContentString(" />");
    // fix for IE < 9 that deactivates the standard submit routine of the form and
    // triggers the onClick handler of this submit element instead if the return key
    // is pressed within a textfield, radiobutton, checkbox or select
    ERXBrowser browser = ERXBrowserFactory.factory().browserMatchingRequest(context.request());
    if (browser.isIE() && browser.majorVersion().compareTo(Integer.valueOf(9)) < 0) {
        if (!hasBinding("formName")) {
            formName = ERXWOForm.formName(context, "");
        }
        AjaxUtils.appendScriptHeader(response);
        response.appendContentString("\nEvent.observe(document." + formName + ", 'keypress', function(e){");
        // return key
        response.appendContentString("if(e.keyCode==13){");
        response.appendContentString("var shouldFire=false;var t=e.target;var tn=t.tagName.toLowerCase();");
        response.appendContentString("if(tn==='select'){shouldFire=true;}");
        response.appendContentString("else if(tn==='input'){var ty=t.type.toLowerCase();");
        response.appendContentString("if(ty==='text' || ty==='radio' || ty==='checkbox'){shouldFire=true;}}");
        response.appendContentString("if(shouldFire){$$('[name=" + name + "]')[0].fireEvent('onClick');e.returnValue=false;}");
        response.appendContentString("}});");
        AjaxUtils.appendScriptFooter(response);
    }
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) ERXBrowser(er.extensions.appserver.ERXBrowser) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Aggregations

WOComponent (com.webobjects.appserver.WOComponent)1 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)1 ERXBrowser (er.extensions.appserver.ERXBrowser)1