Search in sources :

Example 36 with NSMutableDictionary

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

the class AjaxModalContainer method appendToResponse.

@Override
public void appendToResponse(WOResponse response, WOContext context) {
    WOComponent component = context.component();
    String linkID = (String) valueForBinding("id", component);
    if (linkID == null) {
        linkID = ERXWOContext.safeIdentifierName(context, false);
    }
    String containerID = (String) valueForBinding("containerID", linkID + "Container", component);
    response.appendContentString("<a");
    String href = (String) valueForBinding("href", component);
    if (href == null) {
        String directActionName = stringValueForBinding("directActionName", component);
        if (directActionName != null) {
            NSDictionary queryDictionary = (NSDictionary) valueForBinding("queryDictionary", component);
            boolean secure = booleanValueForBinding("secure", ERXRequest.isRequestSecure(context.request()), component);
            if (secure) {
                boolean generatingCompleteURLs = context.doesGenerateCompleteURLs();
                if (!generatingCompleteURLs) {
                    context.generateCompleteURLs();
                }
                try {
                    href = context._directActionURL(directActionName, queryDictionary, secure, 0, false);
                    ERXMutableURL u = new ERXMutableURL(href);
                    u.addQueryParameter(String.valueOf(System.currentTimeMillis()), null);
                    href = u.toExternalForm();
                } catch (MalformedURLException e) {
                    throw new NSForwardException(e);
                } finally {
                    if (!generatingCompleteURLs) {
                        context.generateRelativeURLs();
                    }
                }
            } else {
                href = context.directActionURLForActionNamed(directActionName, queryDictionary);
            }
        }
    }
    boolean isAjax = booleanValueForBinding("ajax", false, component);
    if (href == null) {
        if (isAjax) {
            if (valueForBinding("id", component) == null) {
                throw new IllegalArgumentException("If ajax = 'true', you must also bind 'id'.");
            }
            href = AjaxUtils.ajaxComponentActionUrl(context);
        } else if (associations().objectForKey("action") != null) {
            // don't use ajax request handler here
            href = context.componentActionURL();
        }
        if (href == null) {
            href = "#" + containerID;
        }
    }
    appendTagAttributeToResponse(response, "href", href);
    String relAttributeValue = "ibox";
    Object height = valueForBinding("height", component);
    Object width = valueForBinding("width", component);
    Object closeLabel = valueForBinding("closeLabel", component);
    if (height != null) {
        relAttributeValue += "&height=" + URLEncoder.encode(height.toString(), Charset.forName(WOMessage.defaultURLEncoding()));
    }
    if (width != null) {
        relAttributeValue += "&width=" + URLEncoder.encode(width.toString(), Charset.forName(WOMessage.defaultURLEncoding()));
    }
    if (closeLabel != null) {
        relAttributeValue += "&closeLabel=" + URLEncoder.encode(closeLabel.toString(), Charset.forName(WOMessage.defaultURLEncoding()));
    }
    if (booleanValueForBinding("locked", false, component)) {
        relAttributeValue += "&locked=true";
    }
    // don't escape the ampersands
    response._appendTagAttributeAndValue("rel", relAttributeValue, false);
    appendTagAttributeToResponse(response, "title", valueForBinding("title", component));
    appendTagAttributeToResponse(response, "value", valueForBinding("value", component));
    appendTagAttributeToResponse(response, "class", valueForBinding("class", component));
    appendTagAttributeToResponse(response, "style", valueForBinding("style", component));
    appendTagAttributeToResponse(response, "id", linkID);
    response.appendContentString(">");
    if (!href.startsWith("#") && !isAjax && childrenElements() != null && childrenElements().count() > 0) {
        appendChildrenToResponse(response, context);
    } else {
        Object label = valueForBinding("label", "", component);
        response.appendContentString(label.toString());
    }
    response.appendContentString("</a>");
    if (AjaxUtils.isAjaxRequest(context.request())) {
        NSMutableDictionary userInfo = ERXWOContext.contextDictionary();
        if (!userInfo.containsKey("er.ajax.AjaxModalContainer.init")) {
            AjaxUtils.appendScriptHeader(response);
            response.appendContentString("iBox.init()");
            AjaxUtils.appendScriptFooter(response);
            userInfo.setObjectForKey(Boolean.TRUE, "er.ajax.AjaxModalContainer.init");
        }
    }
    if (booleanValueForBinding("open", false, component)) {
        if (AjaxUtils.isAjaxRequest(context.request())) {
            // PROTOTYPE FUNCTIONS
            response.appendContentString("<script>iBox.handleTag.bind($wi('" + linkID + "'))()</script>");
        } else {
            // PROTOTYPE FUNCTIONS
            response.appendContentString("<script>Event.observe(window, 'load', iBox.handleTag.bind($wi('" + linkID + "')))</script>");
        }
    }
    if (href.startsWith("#")) {
        response.appendContentString("<div");
        appendTagAttributeToResponse(response, "id", containerID);
        appendTagAttributeToResponse(response, "style", "display:none;");
        response.appendContentString(">");
        appendChildrenToResponse(response, context);
        response.appendContentString("</div>");
    }
    super.appendToResponse(response, context);
}
Also used : MalformedURLException(java.net.MalformedURLException) WOComponent(com.webobjects.appserver.WOComponent) NSDictionary(com.webobjects.foundation.NSDictionary) ERXMutableURL(er.extensions.foundation.ERXMutableURL) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary) NSForwardException(com.webobjects.foundation.NSForwardException)

Example 37 with NSMutableDictionary

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

the class AjaxToggleLink method _appendAttributesToResponse.

public static void _appendAttributesToResponse(WOResponse response, WOContext context, WOAssociation toggleIDAssociation, WOAssociation effectAssociation, WOAssociation durationAssociation) {
    WOComponent component = context.component();
    String effect = null;
    if (effectAssociation != null) {
        effect = (String) effectAssociation.valueInComponent(component);
    }
    if (effect == null) {
        effect = "blind";
    }
    String toggleID = (String) toggleIDAssociation.valueInComponent(component);
    // PROTOTYPE EFFECTS
    response.appendContentString(" onclick = \"Effect.toggle($wi('");
    response.appendContentString(toggleID);
    response.appendContentString("'), '");
    response.appendContentString(effect);
    response.appendContentString("', ");
    NSMutableDictionary<String, WOAssociation> options = new NSMutableDictionary<>();
    if (durationAssociation != null) {
        options.setObjectForKey(durationAssociation, "duration");
    }
    AjaxOptions.appendToResponse(options, response, context);
    response.appendContentString(")\"");
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) WOComponent(com.webobjects.appserver.WOComponent) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 38 with NSMutableDictionary

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

the class AjaxProgress method registerProgress.

/**
 * Register a progress object in the registry.
 *
 * @param session
 *            the session
 * @param progress
 *            the progress object to register
 */
public static void registerProgress(WOSession session, AjaxProgress progress) {
    NSMutableDictionary progresses = (NSMutableDictionary) session.objectForKey(AjaxProgressBar.AJAX_PROGRESSES_KEY);
    if (progresses == null) {
        progresses = new NSMutableDictionary();
        session.setObjectForKey(progresses, AjaxProgressBar.AJAX_PROGRESSES_KEY);
    }
    progresses.setObjectForKey(progress, progress.id());
}
Also used : NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 39 with NSMutableDictionary

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

the class AjaxResponse method generateResponse.

@Override
public WOResponse generateResponse() {
    if (AjaxUpdateContainer.hasUpdateContainerID(_request)) {
        String originalSenderID = _context.senderID();
        _context._setSenderID("");
        try {
            CharSequence originalContent = _content;
            _content = new StringBuilder();
            NSMutableDictionary userInfo = ERXWOContext.contextDictionary();
            userInfo.setObjectForKey(Boolean.TRUE, AjaxResponse.AJAX_UPDATE_PASS);
            WOActionResults woactionresults = WOApplication.application().invokeAction(_request, _context);
            _content.append(originalContent);
            if (_responseAppenders != null) {
                Enumeration responseAppendersEnum = _responseAppenders.objectEnumerator();
                while (responseAppendersEnum.hasMoreElements()) {
                    AjaxResponseAppender responseAppender = (AjaxResponseAppender) responseAppendersEnum.nextElement();
                    responseAppender.appendToResponse(this, _context);
                }
            }
            if (_contentLength() == 0) {
                setStatus(HTTP_STATUS_INTERNAL_ERROR);
                log.warn("You performed an Ajax update, but no response was generated. A common cause of this is that you spelled your updateContainerID wrong.  You specified a container ID '" + AjaxUpdateContainer.updateContainerID(_request) + "'.");
            }
        } finally {
            _context._setSenderID(originalSenderID);
        }
    }
    return this;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults) Enumeration(java.util.Enumeration) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 40 with NSMutableDictionary

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

the class AjaxFunctionLink method processAssociations.

protected static NSDictionary processAssociations(NSDictionary associations) {
    NSMutableDictionary mutableAssociations = (NSMutableDictionary) associations;
    mutableAssociations.setObjectForKey(new WOConstantValueAssociation("javascript:void(0)"), "href");
    return mutableAssociations;
}
Also used : WOConstantValueAssociation(com.webobjects.appserver._private.WOConstantValueAssociation) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Aggregations

NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)59 Enumeration (java.util.Enumeration)12 WOAssociation (com.webobjects.appserver.WOAssociation)10 WOComponent (com.webobjects.appserver.WOComponent)8 NSDictionary (com.webobjects.foundation.NSDictionary)7 NSMutableArray (com.webobjects.foundation.NSMutableArray)6 WOConstantValueAssociation (com.webobjects.appserver._private.WOConstantValueAssociation)5 NSArray (com.webobjects.foundation.NSArray)5 WODeclaration (com.webobjects.appserver._private.WODeclaration)4 WOHTMLCommentString (com.webobjects.appserver._private.WOHTMLCommentString)4 NoSuchElementException (java.util.NoSuchElementException)4 StringTokenizer (java.util.StringTokenizer)4 NSForwardException (com.webobjects.foundation.NSForwardException)2 ERXMutableURL (er.extensions.foundation.ERXMutableURL)2 MalformedURLException (java.net.MalformedURLException)2 JSONObject (org.json.JSONObject)2 WOActionResults (com.webobjects.appserver.WOActionResults)1 WOContext (com.webobjects.appserver.WOContext)1 WODynamicElementCreationException (com.webobjects.appserver._private.WODynamicElementCreationException)1 NSBundle (com.webobjects.foundation.NSBundle)1