Search in sources :

Example 16 with WOComponent

use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.

the class AjaxUpdateLink method onClick.

public String onClick(WOContext context, boolean generateFunctionWrapper) {
    WOComponent component = context.component();
    NSMutableDictionary options = createAjaxOptions(component);
    StringBuilder onClickBuffer = new StringBuilder();
    String onClick = (String) valueForBinding("onClick", component);
    String onClickBefore = (String) valueForBinding("onClickBefore", component);
    String updateContainerID = AjaxUpdateContainer.updateContainerID(this, component);
    String functionName = (String) valueForBinding("functionName", component);
    String function = (String) valueForBinding("function", component);
    String replaceID = (String) valueForBinding("replaceID", component);
    // PROTOTYPE EFFECTS
    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;
        }
    }
    // PROTOTYPE EFFECTS
    AjaxUpdateLink.addEffect(options, (String) valueForBinding("afterEffect", component), afterEffectID, (String) valueForBinding("afterEffectDuration", component));
    // PROTOTYPE EFFECTS
    String beforeEffect = (String) valueForBinding("beforeEffect", component);
    WOAssociation directActionNameAssociation = (WOAssociation) associations().valueForKey("directActionName");
    if (beforeEffect == null && updateContainerID != null && directActionNameAssociation == null && replaceID == null && function == null && onClick == null && onClickBefore == null) {
        NSDictionary nonDefaultOptions = AjaxUpdateContainer.removeDefaultOptions(options);
        onClickBuffer.append("AUL.");
        if (generateFunctionWrapper) {
            onClickBuffer.append("updateFunc");
        } else {
            onClickBuffer.append("update");
        }
        onClickBuffer.append("('");
        onClickBuffer.append(updateContainerID);
        onClickBuffer.append("', ");
        AjaxOptions.appendToBuffer(nonDefaultOptions, onClickBuffer, context);
        onClickBuffer.append(", '");
        onClickBuffer.append(context.contextID());
        onClickBuffer.append('.');
        onClickBuffer.append(context.elementID());
        onClickBuffer.append('\'');
        // if (generateFunctionWrapper) {
        // onClickBuffer.append(", additionalParams");
        // }
        onClickBuffer.append(')');
        onClickBuffer.append(';');
    } else {
        if (generateFunctionWrapper) {
            onClickBuffer.append("function(additionalParams) {");
        }
        if (onClickBefore != null) {
            onClickBuffer.append("if (");
            onClickBuffer.append(onClickBefore);
            onClickBuffer.append(") {");
        }
        // PROTOTYPE EFFECTS
        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() {");
        }
        String actionUrl = null;
        if (directActionNameAssociation != null) {
            actionUrl = context._directActionURL((String) directActionNameAssociation.valueInComponent(component), ERXComponentUtilities.queryParametersInComponent(associations(), component), ERXRequest.isRequestSecure(context.request()), 0, false).replaceAll("&", "&");
        } else {
            actionUrl = AjaxUtils.ajaxComponentActionUrl(context);
        }
        if (replaceID != null) {
            try {
                ERXMutableURL tempActionUrl = new ERXMutableURL(actionUrl);
                tempActionUrl.addQueryParameter(ERXAjaxApplication.KEY_REPLACED, "true");
                actionUrl = tempActionUrl.toExternalForm();
            } catch (MalformedURLException e) {
                throw NSForwardException._runtimeExceptionForThrowable(e);
            }
        }
        actionUrl = "'" + actionUrl + "'";
        if (functionName != null) {
            actionUrl = actionUrl + ".addQueryParameters(additionalParams)";
        }
        if (function != null) {
            onClickBuffer.append("return " + function + "(" + actionUrl + ")");
        } else {
            // PROTOTYPE FUNCTIONS
            if (replaceID == null) {
                if (updateContainerID == null) {
                    onClickBuffer.append("new Ajax.Request(" + actionUrl + ", ");
                    AjaxOptions.appendToBuffer(options, onClickBuffer, context);
                    onClickBuffer.append(')');
                } else {
                    onClickBuffer.append("new Ajax.Updater('" + updateContainerID + "', " + actionUrl + ", ");
                    AjaxOptions.appendToBuffer(options, onClickBuffer, context);
                    onClickBuffer.append(')');
                }
            } else {
                onClickBuffer.append("new Ajax.Updater('" + replaceID + "', " + actionUrl + ", ");
                AjaxOptions.appendToBuffer(options, onClickBuffer, context);
                onClickBuffer.append(')');
            }
        }
        if (onClick != null) {
            onClickBuffer.append(';');
            onClickBuffer.append(onClick);
        }
        if (beforeEffect != null) {
            onClickBuffer.append("}});");
        }
        if (onClickBefore != null) {
            onClickBuffer.append('}');
        }
        if (generateFunctionWrapper) {
            onClickBuffer.append('}');
        }
    }
    return onClickBuffer.toString();
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) MalformedURLException(java.net.MalformedURLException) WOComponent(com.webobjects.appserver.WOComponent) NSDictionary(com.webobjects.foundation.NSDictionary) ERXMutableURL(er.extensions.foundation.ERXMutableURL) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 17 with WOComponent

use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.

the class AjaxUpdateTrigger method appendToResponse.

@Override
public void appendToResponse(WOResponse response, WOContext context) {
    super.appendToResponse(response, context);
    final WOComponent component = context.component();
    final List<String> containersToUpdate = new ArrayList<>();
    final String updateContainerID = (String) _updateContainerID.valueInComponent(component);
    if (updateContainerID != null) {
        containersToUpdate.add(updateContainerID);
    }
    final List<String> updateContainerIDs = (List<String>) _updateContainerIDs.valueInComponent(component);
    if (updateContainerIDs != null) {
        containersToUpdate.addAll(updateContainerIDs);
    }
    if (!containersToUpdate.isEmpty()) {
        AjaxUtils.appendScriptHeader(response);
        Iterator<String> updateContainerIDEnum = containersToUpdate.iterator();
        while (updateContainerIDEnum.hasNext()) {
            String nextUpdateContainerID = updateContainerIDEnum.next();
            // PROTOTYPE FUNCTIONS
            Object evalScripts = ERXComponentUtilities.valueForBinding("evalScripts", "true", _associations, component);
            response.appendContentString("if ($wi('" + nextUpdateContainerID + "')) { ");
            response.appendContentString("new Ajax.Updater('" + nextUpdateContainerID + "', $wi('" + nextUpdateContainerID + "').getAttribute('data-updateUrl'), {" + " evalScripts: " + evalScripts + ", insertion: Element.update, method: 'get' });\n");
            response.appendContentString(" }");
        }
        AjaxUtils.appendScriptFooter(response);
        if (_resetAfterUpdate != null && _resetAfterUpdate.booleanValueInComponent(component)) {
            containersToUpdate.clear();
        }
    }
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 18 with WOComponent

use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.

the class AjaxSubmitButton method appendToResponse.

@Override
public void appendToResponse(WOResponse response, WOContext context) {
    WOComponent component = context.component();
    String functionName = (String) valueForBinding("functionName", null, component);
    String formName = (String) valueForBinding("formName", component);
    boolean showUI = (functionName == null || booleanValueForBinding("showUI", false, component));
    boolean showButton = showUI && booleanValueForBinding("button", true, component);
    boolean useButtonTagBinding = booleanValueForBinding("useButtonTag", false, component);
    String formReference;
    if ((!showButton || functionName != null) && formName == null) {
        formName = ERXWOForm.formName(context, null);
        if (formName == null) {
            throw new WODynamicElementCreationException("If button = false or functionName is not null, the containing form must have an explicit name.");
        }
    }
    if (formName == null) {
        formReference = "this.form";
    } else {
        formReference = "document." + formName;
    }
    StringBuilder onClickBuffer = new StringBuilder();
    String onClickBefore = (String) valueForBinding("onClickBefore", component);
    if (onClickBefore != null) {
        onClickBuffer.append("if (");
        onClickBuffer.append(onClickBefore);
        onClickBuffer.append(") {");
    }
    String updateContainerID = AjaxUpdateContainer.updateContainerID(this, component);
    // PROTOTYPE EFFECTS
    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() {");
    }
    String replaceID = (String) valueForBinding("replaceID", component);
    String id = (updateContainerID == null) ? replaceID : updateContainerID;
    if (id != null) {
        onClickBuffer.append("ASB.update('" + id + "',");
    } else {
        onClickBuffer.append("ASB.request(");
    }
    onClickBuffer.append(formReference);
    if (valueForBinding("functionName", component) != null) {
        onClickBuffer.append(",additionalParams");
    } else {
        onClickBuffer.append(",null");
    }
    onClickBuffer.append(',');
    NSMutableDictionary options = createAjaxOptions(component);
    if (replaceID != null) {
        options.setObjectForKey("true", ERXAjaxApplication.KEY_REPLACED);
    }
    AjaxUpdateLink.addEffect(options, (String) valueForBinding("effect", component), id, (String) valueForBinding("effectDuration", component));
    String afterEffectID = (String) valueForBinding("afterEffectID", component);
    if (afterEffectID == null) {
        afterEffectID = AjaxUpdateContainer.currentUpdateContainerID();
        if (afterEffectID == null) {
            afterEffectID = id;
        }
    }
    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('}');
    }
    if (functionName != null) {
        AjaxUtils.appendScriptHeader(response);
        response.appendContentString(functionName + " = function(additionalParams) { " + onClickBuffer + " }\n");
        AjaxUtils.appendScriptFooter(response);
    }
    if (showUI) {
        boolean disabled = disabledInComponent(component);
        String elementName = (String) valueForBinding("elementName", "a", component);
        boolean useButtonTag = useButtonTagBinding || ERXProperties.booleanForKeyWithDefault("er.extensions.foundation.ERXPatcher.DynamicElementsPatches.SubmitButton.useButtonTag", false);
        if (showButton) {
            elementName = useButtonTag ? "button" : "input";
            response.appendContentString("<" + elementName + " ");
            appendTagAttributeToResponse(response, "type", "button");
            String name = nameInContext(context, component);
            appendTagAttributeToResponse(response, "name", name);
            appendTagAttributeToResponse(response, "value", valueForBinding("value", component));
            appendTagAttributeToResponse(response, "accesskey", valueForBinding("accesskey", component));
            if (disabled) {
                appendTagAttributeToResponse(response, "disabled", "disabled");
            }
        } else {
            boolean isATag = "a".equalsIgnoreCase(elementName);
            if (isATag) {
                response.appendContentString("<a href = \"javascript:void(0)\" ");
            } else {
                response.appendContentString("<" + elementName + " ");
            }
        }
        appendTagAttributeToResponse(response, "class", valueForBinding("class", component));
        appendTagAttributeToResponse(response, "style", valueForBinding("style", component));
        appendTagAttributeToResponse(response, "id", valueForBinding("id", component));
        appendTagAttributeToResponse(response, "tabindex", valueForBinding("tabindex", component));
        appendTagAttributeToResponse(response, "title", valueForBinding("title", component));
        if (functionName == null) {
            appendTagAttributeToResponse(response, "onclick", onClickBuffer.toString());
        } else {
            appendTagAttributeToResponse(response, "onclick", functionName + "()");
        }
        if (showButton && !useButtonTag) {
            response.appendContentString(" />");
        } else {
            response.appendContentString(">");
            if (hasChildrenElements()) {
                appendChildrenToResponse(response, context);
            } else {
                response.appendContentString((String) valueForBinding("value", component));
            }
            response.appendContentString("</" + elementName + ">");
        }
    }
    super.appendToResponse(response, context);
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) WODynamicElementCreationException(com.webobjects.appserver._private.WODynamicElementCreationException) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 19 with WOComponent

use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.

the class AjaxSubmitButton method handleRequest.

@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    WOComponent component = context.component();
    WOActionResults result = (WOActionResults) valueForBinding("action", component);
    if (ERXAjaxApplication.isAjaxReplacement(request)) {
        AjaxUtils.setPageReplacementCacheKey(context, (String) valueForBinding("replaceID", component));
    } else if (result == null || booleanValueForBinding("ignoreActionResponse", false, component)) {
        WOResponse response = AjaxUtils.createResponse(request, context);
        String onClickServer = (String) valueForBinding("onClickServer", component);
        if (onClickServer != null) {
            AjaxUtils.appendScriptHeaderIfNecessary(request, response);
            response.appendContentString(onClickServer);
            AjaxUtils.appendScriptFooterIfNecessary(request, response);
        }
        result = response;
    } else {
        String updateContainerID = AjaxUpdateContainer.updateContainerID(this, component);
        if (updateContainerID != null) {
            AjaxUtils.setPageReplacementCacheKey(context, updateContainerID);
        }
    }
    return result;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults) WOComponent(com.webobjects.appserver.WOComponent) WOResponse(com.webobjects.appserver.WOResponse)

Example 20 with WOComponent

use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.

the class AjaxTabbedPanel method appendToResponse.

/**
 * Creates the tabs and pane control.
 */
@Override
public void appendToResponse(WOResponse response, WOContext context) {
    WOComponent component = context.component();
    String idString = (String) id.valueInComponent(component);
    if (idString == null) {
        throw new RuntimeException("id binding evaluated to null");
    }
    // UL for tabs
    response.appendContentString("<ul class=\"ajaxTabbedPanel\"");
    appendTagAttributeToResponse(response, "id", idString);
    // Optional JavaScriplets
    if (onLoad != null) {
        appendTagAttributeToResponse(response, "onLoad", onLoad.valueInComponent(component));
    }
    if (onSelect != null) {
        appendTagAttributeToResponse(response, "onSelect", onSelect.valueInComponent(component));
    }
    response.appendContentString(">\n");
    String paneControlID = idString + "_panecontrol";
    for (int i = 0; i < tabs.count(); i++) {
        String index = Integer.toString(i);
        String tabID = idString + "_tab_" + index;
        AjaxTabbedPanelTab tab = (AjaxTabbedPanelTab) tabs.objectAtIndex(i);
        if (tab.isVisble(component)) {
            boolean isSelectedTab = tab.isSelected(context.component());
            String panelTabID = tab.tabIdInComponent(component);
            String panelID = panelTabID + "_panel";
            response.appendContentString("  <li class=\"ajaxTabbedPanelTab-");
            response.appendContentString(isSelectedTab ? "selected" : "unselected");
            response.appendContentString("\" ");
            appendTagAttributeToResponse(response, "id", tabID);
            response.appendContentString(">\n");
            response.appendContentString("<a ");
            // add the accesskey
            if (tab.accesskey() != null) {
                String accessKeyStr = tab.accesskey().valueInComponent(component).toString();
                appendTagAttributeToResponse(response, "accesskey", accessKeyStr);
            }
            appendTagAttributeToResponse(response, "id", panelTabID);
            response.appendContentString(" href=\"javascript:void(0)\" onclick=\"");
            // Load the tab contents
            response.appendContentString("AjaxTabbedPanel.loadPanel('");
            response.appendContentString(idString);
            response.appendContentString("', '");
            response.appendContentString(panelID);
            response.appendContentString("', '");
            response.appendContentString((busyDiv != null) ? (String) busyDiv.valueInComponent(component) : "");
            response.appendContentString("', ");
            response.appendContentString(tab.refreshesOnSelect(context.component()).toString());
            response.appendContentString("); ");
            // Select the tab contents
            response.appendContentString("AjaxTabbedPanel.selectPanel('");
            response.appendContentString(paneControlID);
            response.appendContentString("', '");
            response.appendContentString(panelID);
            response.appendContentString("'); ");
            // Select the tab control
            response.appendContentString("AjaxTabbedPanel.selectTab('");
            response.appendContentString(idString);
            response.appendContentString("', '");
            response.appendContentString(tabID);
            response.appendContentString("', '");
            response.appendContentString(panelID);
            response.appendContentString("', '");
            response.appendContentString((busyDiv != null) ? (String) busyDiv.valueInComponent(component) : "");
            response.appendContentString("'); ");
            response.appendContentString("\">");
            response.appendContentString((String) tab.name().valueInComponent(component));
            response.appendContentString("</a>\n");
            response.appendContentString("</li>\n");
        }
    }
    response.appendContentString("</ul>\n");
    // UL for panes
    response.appendContentString("<ul class=\"ajaxTabbedPanelPanes\" ");
    appendTagAttributeToResponse(response, "id", paneControlID);
    response.appendContentString(">\n");
    // The tabs render themselves as panes
    if (content != null) {
        content.appendToResponse(response, context);
    }
    response.appendContentString("</ul>\n");
    super.appendToResponse(response, context);
    response.appendContentString("<script>AjaxTabbedPanel.onLoad('");
    response.appendContentString(idString);
    response.appendContentString("');</script>\n");
}
Also used : WOComponent(com.webobjects.appserver.WOComponent)

Aggregations

WOComponent (com.webobjects.appserver.WOComponent)68 WOActionResults (com.webobjects.appserver.WOActionResults)11 WOResponse (com.webobjects.appserver.WOResponse)10 WOContext (com.webobjects.appserver.WOContext)8 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)8 NSDictionary (com.webobjects.foundation.NSDictionary)7 Format (java.text.Format)5 WOApplication (com.webobjects.appserver.WOApplication)4 WOAssociation (com.webobjects.appserver.WOAssociation)4 NSMutableArray (com.webobjects.foundation.NSMutableArray)4 ERXWOContext (er.extensions.appserver.ERXWOContext)4 ParseException (java.text.ParseException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 WOElement (com.webobjects.appserver.WOElement)3 WORequest (com.webobjects.appserver.WORequest)3 WODynamicElementCreationException (com.webobjects.appserver._private.WODynamicElementCreationException)3 NSArray (com.webobjects.foundation.NSArray)3 WOSession (com.webobjects.appserver.WOSession)2 ERXMutableURL (er.extensions.foundation.ERXMutableURL)2