use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.
the class AjaxModalDialog method handleRequest.
/**
* Handles the open and close dialog actions.
*
* @see er.ajax.AjaxComponent#handleRequest(com.webobjects.appserver.WORequest, com.webobjects.appserver.WOContext)
*
* @return null or dialog contents
*/
@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
WOActionResults response = null;
String modalBoxAction = NSPathUtilities.pathExtension(context.senderID());
if ("close".equals(modalBoxAction)) {
// This update can't be done in the closeDialog() method as that also gets called from close(WOContext) and
// and Ajax update is not taking place. If the page structure changes, this update will not take place,
// but the correct container ID is on the URL and the update will still happen thanks to the magic in
// AjaxResponse.AjaxResponseDelegate
String closeUpdateContainerID = AjaxUpdateContainer.updateContainerID((String) valueForBinding("closeUpdateContainerID"));
if (closeUpdateContainerID != null) {
AjaxUpdateContainer.setUpdateContainerID(request, closeUpdateContainerID);
}
// This needs to happen AFTER setting up for an update so that AjaxUtils.appendScriptHeaderIfNecessary
// knows if the script header is needed or not. Doing this before and setting up a JS response in
// the onClose callback, resulted in plain text getting injected into the page.
closeDialog();
} else if ("open".equals(modalBoxAction) && !isOpen()) {
openDialog();
// the awake, takeValues, etc. messages can get passed onto it
if (hasBinding("action")) {
_actionResults = (WOComponent) valueForBinding("action");
_actionResults._awakeInContext(context);
} else if (hasBinding("pageName")) {
_actionResults = pageWithName((String) valueForBinding("pageName"));
_actionResults._awakeInContext(context);
}
// wrong and can correct it.
if (_actionResults != null && (_actionResults.template() instanceof WOForm || _actionResults.template() instanceof ERXWOForm)) {
throw new RuntimeException(_actionResults.name() + " is used as contents of AjaxModalDialog, but starts with WOForm tag. " + "Action elements inside the dialog will not function. Add a space at the start or end of " + _actionResults.name() + ".html");
}
}
if (isOpen()) {
response = AjaxUtils.createResponse(request, context);
// Register the id of this component on the page in the request so that when
// it comes time to cache the context, it knows that this area is an Ajax updating area
AjaxUtils.setPageReplacementCacheKey(context, _containerID(context));
if (_actionResults != null) {
pushActionResultsIntoContext(context);
try {
_actionResults.appendToResponse((WOResponse) response, context);
} finally {
popActionResultsFromContext(context);
}
} else {
// This loads the content from the default ERWOTemplate (our component contents that are not
// in the "link" template.
super.appendToResponse((WOResponse) response, context);
}
}
return response;
}
use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.
the class AjaxObserveField method invokeAction.
@Override
public WOActionResults invokeAction(WORequest request, WOContext context) {
WOActionResults result = null;
WOComponent component = context.component();
String nameInContext = nameInContext(context, component, this);
boolean shouldHandleRequest = !context.wasActionInvoked() && context.wasFormSubmitted() && nameInContext.equals(ERXAjaxApplication.ajaxSubmitButtonName(request));
if (shouldHandleRequest) {
String updateContainerID = AjaxUpdateContainer.updateContainerID(this, component);
AjaxUpdateContainer.setUpdateContainerID(request, updateContainerID);
context.setActionInvoked(true);
result = (WOActionResults) valueForBinding("action", component);
if (result == null) {
result = handleRequest(request, context);
}
ERXAjaxApplication.enableShouldNotStorePage();
} else {
result = invokeChildrenAction(request, context);
}
return result;
}
use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.
the class AjaxHyperlink method appendToResponse.
@Override
public void appendToResponse(WOResponse response, WOContext context) {
WOComponent component = context.component();
boolean disabled = booleanValueForBinding("disabled", false, component);
String elementName = (String) valueForBinding("elementName", "a", component);
String functionName = (String) valueForBinding("functionName", null, component);
boolean isATag = "a".equalsIgnoreCase(elementName);
boolean renderTags = ((!disabled || !isATag) && functionName == null);
if (renderTags) {
response.appendContentString("<");
response.appendContentString(elementName);
response.appendContentString(" ");
if (isATag) {
appendTagAttributeToResponse(response, "href", "javascript:void(0)");
}
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", valueForBinding("id", component));
if (!disabled) {
appendTagAttributeToResponse(response, "onclick", onClick(context));
}
response.appendContentString(">");
}
if (functionName != null) {
AjaxUtils.appendScriptHeader(response);
response.appendContentString(functionName + " = function() { " + onClick(context) + " }\n");
AjaxUtils.appendScriptFooter(response);
}
if (!hasBinding("string")) {
appendChildrenToResponse(response, context);
} else {
response.appendContentString((String) valueForBinding("string", component));
}
if (renderTags) {
response.appendContentString("</");
response.appendContentString(elementName);
response.appendContentString(">");
}
super.appendToResponse(response, context);
}
use of com.webobjects.appserver.WOComponent in project wonder-slim by undur.
the class AjaxInPlaceEditor method appendToResponse.
@Override
public void appendToResponse(WOResponse response, WOContext context) {
WOComponent component = context.component();
String id;
if (_idAssociation == null) {
id = ERXWOContext.safeIdentifierName(context, false);
} else {
id = (String) _idAssociation.valueInComponent(component);
}
String elementName = (String) _elementNameAssociation.valueInComponent(component);
String actionUrl = AjaxUtils.ajaxComponentActionUrl(context);
super.appendToResponse(response, context);
response.appendContentString("<");
response.appendContentString(elementName);
response.appendContentString(" id = \"");
response.appendContentString(id);
response.appendContentString("\"");
if (_classAssociation != null) {
String className = (String) _classAssociation.valueInComponent(component);
response.appendContentString(" class = \"");
response.appendContentString(className);
response.appendContentString("\"");
}
response.appendContentString(">");
_appendValueAttributeToResponse(response, context);
response.appendContentString("</");
response.appendContentString(elementName);
response.appendContentString(">");
AjaxUtils.appendScriptHeader(response);
response.appendContentString("new Ajax.InPlaceEditorWithEmptyText('");
response.appendContentString(id);
response.appendContentString("', '");
response.appendContentString(actionUrl);
response.appendContentString("',");
NSDictionary options = createAjaxOptions(component);
AjaxOptions.appendToResponse(options, response, context);
response.appendContentString(");");
AjaxUtils.appendScriptFooter(response);
}
use of com.webobjects.appserver.WOComponent 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);
}
Aggregations