Search in sources :

Example 6 with NSDictionary

use of com.webobjects.foundation.NSDictionary in project wonder-slim by undur.

the class AjaxOptions method appendToResponse.

@Override
public void appendToResponse(WOResponse response, WOContext context) {
    response.appendContentCharacter('{');
    NSMutableDictionary options = _associations;
    WOAssociation optionsBinding = _associations.objectForKey("options");
    if (optionsBinding != null) {
        NSDictionary passedInOptions = (NSDictionary) optionsBinding.valueInComponent(context.component());
        if (passedInOptions != null) {
            options = passedInOptions.mutableClone();
            options.addEntriesFromDictionary(_associations);
        }
    }
    AjaxOptions._appendToResponse(options, response, context);
    if (_children != null) {
        _children.appendToResponse(response, context);
    }
    response.appendContentCharacter('}');
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) NSDictionary(com.webobjects.foundation.NSDictionary) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 7 with NSDictionary

use of com.webobjects.foundation.NSDictionary 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 8 with NSDictionary

use of com.webobjects.foundation.NSDictionary in project wonder-slim by undur.

the class AjaxProgress method progress.

/**
 * Returns the progress object with the given id (or null if one does not exist).
 *
 * @param session
 *            the session
 * @param id
 *            the id of the progress to retrieve
 * @return the matching progess object (or null)
 */
public static AjaxProgress progress(WOSession session, String id) {
    AjaxProgress progress = null;
    NSDictionary progresses = (NSDictionary) session.objectForKey(AjaxProgressBar.AJAX_PROGRESSES_KEY);
    if (progresses != null) {
        progress = (AjaxProgress) progresses.objectForKey(id);
    }
    return progress;
}
Also used : NSDictionary(com.webobjects.foundation.NSDictionary)

Example 9 with NSDictionary

use of com.webobjects.foundation.NSDictionary in project wonder-slim by undur.

the class AjaxRoundEffect method appendToResponse.

@Override
public void appendToResponse(WOResponse response, WOContext context) {
    super.appendToResponse(response, context);
    WOComponent component = context.component();
    String className = (String) _classAssociation.valueInComponent(component);
    String elementName = (String) _elementNameAssociation.valueInComponent(component);
    boolean generateTags = ((Boolean) _generateTagsAssociation.valueInComponent(component)).booleanValue();
    if (generateTags) {
        elementName = "div";
        response.appendContentString("<");
        response.appendContentString(elementName);
        response.appendContentString(" class = \"");
        response.appendContentString(className);
        response.appendContentString("\"");
        if (_idAssociation != null) {
            response.appendContentString(" id = \"");
            String id = (String) _idAssociation.valueInComponent(component);
            response.appendContentString(id);
            response.appendContentString("\"");
        }
        response.appendContentString(">");
    }
    appendChildrenToResponse(response, context);
    if (generateTags) {
        response.appendContentString("\n</");
        response.appendContentString(elementName);
        response.appendContentString(">");
    }
    response.appendContentString("\n");
    AjaxUtils.appendScriptHeader(response);
    response.appendContentString("new Rico.Effect.Round('");
    response.appendContentString(elementName);
    response.appendContentString("', '");
    response.appendContentString(className);
    response.appendContentString("', ");
    NSDictionary options = createAjaxOptions(component);
    AjaxOptions.appendToResponse(options, response, context);
    response.appendContentString(");");
    AjaxUtils.appendScriptFooter(response);
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) NSDictionary(com.webobjects.foundation.NSDictionary)

Example 10 with NSDictionary

use of com.webobjects.foundation.NSDictionary in project wonder-slim by undur.

the class AjaxValue method javascriptValue.

/**
 * @return a String representing this AjaxValue in a form suitable for use in JavaScript
 */
public String javascriptValue() {
    String strValue;
    AjaxOption.Type type = _type;
    if (type == AjaxOption.STRING_OR_ARRAY) {
        if (_value == null) {
            type = AjaxOption.STRING;
        } else if (_value instanceof NSArray) {
            type = AjaxOption.ARRAY;
        } else if (_value instanceof String) {
            strValue = (String) _value;
            if (strValue.startsWith("[")) {
                type = AjaxOption.ARRAY;
            } else {
                type = AjaxOption.STRING;
            }
        }
    }
    if (_value == null || _value == NSKeyValueCoding.NullValue) {
        strValue = null;
    } else if (type == AjaxOption.STRING) {
        strValue = javaScriptEscaped(_value);
    } else if (type == AjaxOption.NUMBER) {
        strValue = _value.toString();
    } else if (type == AjaxOption.ARRAY) {
        if (_value instanceof NSArray) {
            NSArray arrayValue = (NSArray) _value;
            StringBuilder sb = new StringBuilder();
            sb.append('[');
            Enumeration objEnum = arrayValue.objectEnumerator();
            while (objEnum.hasMoreElements()) {
                Object o = objEnum.nextElement();
                sb.append(new AjaxValue(o).javascriptValue());
                if (objEnum.hasMoreElements()) {
                    sb.append(',');
                }
            }
            sb.append(']');
            strValue = sb.toString();
        } else {
            strValue = _value.toString();
        }
    } else if (type == AjaxOption.DICTIONARY) {
        if (_value instanceof NSDictionary) {
            NSDictionary dictValue = (NSDictionary) _value;
            StringBuilder sb = new StringBuilder();
            sb.append('{');
            Enumeration keyEnum = dictValue.keyEnumerator();
            while (keyEnum.hasMoreElements()) {
                Object key = keyEnum.nextElement();
                Object value = dictValue.objectForKey(key);
                sb.append(new AjaxValue(key).javascriptValue());
                sb.append(':');
                sb.append(new AjaxValue(value).javascriptValue());
                if (keyEnum.hasMoreElements()) {
                    sb.append(',');
                }
            }
            sb.append('}');
            strValue = sb.toString();
        } else {
            strValue = _value.toString();
        }
    } else if (type == AjaxOption.STRING_ARRAY) {
        if (_value instanceof NSArray) {
            NSArray arrayValue = (NSArray) _value;
            int count = arrayValue.count();
            if (count == 1) {
                strValue = new AjaxValue(AjaxOption.STRING, arrayValue.objectAtIndex(0)).javascriptValue();
            } else if (count > 0) {
                StringBuilder sb = new StringBuilder();
                sb.append('[');
                Enumeration objEnum = arrayValue.objectEnumerator();
                while (objEnum.hasMoreElements()) {
                    Object o = objEnum.nextElement();
                    sb.append(new AjaxValue(AjaxOption.STRING, o).javascriptValue());
                    if (objEnum.hasMoreElements()) {
                        sb.append(',');
                    }
                }
                sb.append(']');
                strValue = sb.toString();
            } else {
                strValue = "[]";
            }
        } else {
            strValue = _value.toString();
        }
    } else if (type == AjaxOption.SCRIPT) {
        strValue = _value.toString();
    } else if (type == AjaxOption.FUNCTION) {
        strValue = "function() {" + _value.toString() + "}";
    } else if (type == AjaxOption.FUNCTION_1) {
        strValue = "function(v) {" + _value.toString() + "}";
    } else if (type == AjaxOption.FUNCTION_2) {
        strValue = "function(v1, v2) {" + _value.toString() + "}";
    } else {
        strValue = _value.toString();
    }
    return strValue;
}
Also used : Enumeration(java.util.Enumeration) NSArray(com.webobjects.foundation.NSArray) NSDictionary(com.webobjects.foundation.NSDictionary)

Aggregations

NSDictionary (com.webobjects.foundation.NSDictionary)34 WOComponent (com.webobjects.appserver.WOComponent)7 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)7 Enumeration (java.util.Enumeration)7 WOAssociation (com.webobjects.appserver.WOAssociation)4 WOResponse (com.webobjects.appserver.WOResponse)4 NSArray (com.webobjects.foundation.NSArray)3 NSForwardException (com.webobjects.foundation.NSForwardException)3 WOApplication (com.webobjects.appserver.WOApplication)2 WOComponentDefinition (com.webobjects.appserver._private.WOComponentDefinition)2 WOComponentReference (com.webobjects.appserver._private.WOComponentReference)2 WOHTMLCommentString (com.webobjects.appserver._private.WOHTMLCommentString)2 NSBundle (com.webobjects.foundation.NSBundle)2 ERXMutableURL (er.extensions.foundation.ERXMutableURL)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 WOContext (com.webobjects.appserver.WOContext)1 WORequest (com.webobjects.appserver.WORequest)1