%--
* Licensed Materials - Property of IBM
*
* 5724-U18
*
* (C) COPYRIGHT IBM CORP. 2006, 2016 All Rights Reserved.
*
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with
* IBM Corp.
--%><%--
This JSP is the handler for "treenode" component.
It provides a wrapper/container for this treenode and its children.
It handles the following events
- render
- render within refresh of parent when parent is expanded
- collapse
--%><%@ include file="../common/simpleheader.jsp" %><%
String label = component.getProperty("label");
String cdataTest = (String)app.get("incdata");
if(designmode && component.needsRender())
{ %>
<%@ include file="../common/designerevents.jsp" %>
<% label = control.getLocalizedType();
String automationIdTn = "";
String automationIdChildren = "";
if(automation)
{
automationIdTn="automationid=\""+realId+"_tn\"";
automationIdChildren="automationid=\""+realId+"_children\"";
} %>
style="<%=designerSelected%>">
<%
}//if design mode
if(!designmode)
{
TreeNode treeNode = (TreeNode)control;
Tree treeControl = treeNode.getTree();
ControlInstance parentNode = (ControlInstance)control.getParentInstance();
//Attributes and flags specified for this control from tree
TreeNode selectedNode = treeControl.getSelectedNode();
String lastSelectedNodeId = treeControl.getLastSelectedNodeId();
String restrictActionOn = treeControl.getRestrictActionOn();
//Attributes specified for this control (in xml)
String nodeImage = component.getProperty("image");
String selectImage = component.getProperty("selectimage");
String objectname = component.getProperty("objectname");
String keyValue = treeNode.getKeyValue();
String collapsedImage = component.getProperty("collapsedimage");
String expandedImage = component.getProperty("expandedimage");
String noChildImage = component.getProperty("nochildrenimage");
String waitImage = component.getProperty("waitimage");
String toggleEvent = component.getProperty("toggleevent");
String nodeEvent = component.getProperty("nodeevent");
String nodeImageEvent = component.getProperty("nodeimageevent");
String nodeClass = "n ";
String nodeLabelClass = "";
String nodeImageClass= "";
String nodeLabel = treeNode.getNodeLabel();
String nodeLinkTextDecoration = "style=\"text-decoration:none\"";
boolean enableReturn = component.getProperty("enablereturn").equals("true");
boolean enableSelectNode = component.getProperty("enableselectnode").equals("true");
boolean displayNodeImage = component.getProperty("displaynodeimage").equals("true");
boolean nodeHasChildren = treeNode.hasChildNodes();
boolean handleAction = true;
boolean expanded = treeNode.isExpanded();
boolean collapsed = treeNode.isCollapsed();
boolean isfakenode = treeNode.isFakeMessageNode();
boolean ishidden = treeNode.isDataHidden();
boolean ismarkedfordelete = treeNode.isMarkedForDelete();
String unformattedKeyValue = keyValue.replaceAll("'","");
//Set events
String nodeStateImage = (nodeHasChildren)? collapsedImage : noChildImage;
JSONObject selectNodeEvent = new JSONObject();
selectNodeEvent.put("eventtype", "selectnode");
selectNodeEvent.put("targetid", id);
selectNodeEvent.put("value", unformattedKeyValue); //For clicking only on the node name
String nodeEvents = "onmouseout=\"return noStatus();\" "+
"onmouseover=\"return noStatus();\" "+
"onfocus=\"return noStatus(); this.style.border='1px solid black'\" "+
"onblur=\"return noStatus(); this.style.border='1px transparent'\" ";
//Alts and Messages
String browser = wcs.getUserAgentName();
String selectRecordlbl = wcs.getMessage("tableinfo","cntrlTableAltSelectRow");
String selectNodelbl = wcs.getMessage("jspmessages","selectnode",new String[]{nodeLabel});
String expandalt = wcs.getMessage("jspmessages","expandnode");
String collapsealt = wcs.getMessage("jspmessages","collapsenode");
String controlId = id;
String collapseExpandEvents = "changeImageSrc('"+controlId + "_state_image','"+IMAGE_PATH + waitImage+"'),sendEvent('"+toggleEvent+"','"+id+"','"+unformattedKeyValue+"')";
JSONObject nodeEventJson = new JSONObject();//For clicking on the node image
if(nodeEvent.length()>0)
{
nodeEventJson.put("eventtype", nodeEvent);
nodeEventJson.put("targetid", id);
nodeEventJson.put("value", unformattedKeyValue);
}
//nodeEvent = "sendEvent('"+nodeEvent+"','"+id+"','"+unformattedKeyValue+"')";//For clicking on the node image
JSONObject nodeImageEventJson = new JSONObject();//for custom event
if(nodeImageEvent.length()>0)
{
nodeImageEventJson.put("eventtype", nodeImageEvent);
nodeImageEventJson.put("targetid", id);
nodeImageEventJson.put("value", unformattedKeyValue);
}
toggleEvent = (nodeHasChildren)? toggleEvent: "";//toggle event
if(expanded)
{
nodeStateImage = expandedImage;
}
if(!nodeHasChildren)
nodeStateImage = noChildImage;
//Determine if action needed based on node type
if(!restrictActionOn.equals(""))
{
if(restrictActionOn.equalsIgnoreCase(Tree.CONST_RESTRICT_ACTION_ON_BRANCHNODES))
{
if(!nodeHasChildren)
handleAction = false;
}
else if(restrictActionOn.equalsIgnoreCase(Tree.CONST_RESTRICT_ACTION_ON_LEAFNODES))
{
if(nodeHasChildren)
handleAction = false;
}
}
String tabIndex = "-1";
boolean currentlySelected = (selectedNode!=null && selectedNode.getRenderId().equals(control.getRenderId()));
if(currentlySelected || (selectedNode==null && !parentNode.getType().equals("treenode")) && parentNode.getChildren().get(0) == control){
tabIndex = "0";
}
if(ismarkedfordelete)
{
nodeLinkTextDecoration = "style=\"text-decoration: line-through;\"";
}
if(isfakenode)
{
nodeStateImage = component.getProperty("overflowimage");
nodeLabelClass = "fnl";
nodeClass = "fn";
}
if(ishidden)
{
nodeLabelClass = "nn";
nodeEvent="";
nodeEventJson.clear();
selectNodeEvent.clear();
collapseExpandEvents="";
}
//If needs render and the parent doesnt need render, and parent is NOT tree and parent is expanded
if(component.needsRender())
{
if(!parentNode.needsRender() && (parentNode instanceof TreeNode))
{
String automationIdWrapper = "";
if(automation)
{
automationIdWrapper="automationid=\""+realId+"_wrapper\"";
}
if(treeNode.isFirstChildForParent())
{
holderId = parentNode.getRenderId()+"-trn_children"; %>
<%@ include file="../common/componentholder_start.jsp" %>
<% }
}
JSONObject primaryEvent = new JSONObject();
if(enableSelectNode)
{
primaryEvent = selectNodeEvent;
}
JSONObject secondaryEvent = nodeEventJson;
if(treeControl.getId().contains("associateClassification_tree"))
{
primaryEvent = nodeEventJson;
}
if(enableReturn && handleAction)
{
if(currentlySelected)
{
nodeLabelClass = "sn";
}
else
{
nodeLabelClass = "nn";
}
}
else
{
if(enableSelectNode)
{
if(selectedNode!=null && selectedNode.getId().equals(controlId))
nodeLabelClass = "sn";
else
nodeLabelClass = "nn";
}
else
nodeLabelClass = "nn";
}
nodeLabelClass = nodeLabelClass + " " + cssclass;
String topULId = treeControl.getTopULId();
%> class="<%= nodeClass%>" style="background:transparent;" nodeinfo='{"selected": <%=currentlySelected%>, "expanded":<%=expanded%>, "toggleevent": {"eventtype":"<%=toggleEvent%>","targetid":"<%=id%>","value":"<%=unformattedKeyValue%>"}, "primaryevent" : <%=primaryEvent.serialize()%>, "secondaryevent" : <%=secondaryEvent.serialize()%>}' async="0" ae="togglechildren" fldInfo="{eventpriority:2}">
<% if(nodeHasChildren)
{
// Chrome - in chrome the "display" attribute causes issues when expanding a treenode. Use margin-left instead.
// For later processing below and in Async.js, attach a maxtype="treenode" attribute to this element to identify it a Chrome treenode.
if(browser.equals("CHROME")) {
%>"><%
}
else {
%>"><%
}
if(expanded)
component.renderChildrenControls();
%>
<%
}
%>
<%
if(!parentNode.needsRender() && (parentNode instanceof TreeNode))
{
//Parent was expanded, copy it rendered children from the hidden doc os
if(treeNode.isLastChildForParent())
{
app.put("endcdata","true");//this will force component end to end the component tag
treeNode.setFocus();
%>
<%@ include file="../common/componentholder_end.jsp" %>
>
var treeDiv = getElement("<%=treeControl.getId()%>_treecontainer");
var otn = getElement("<%=parentNode.getRenderId()%>-trn_children");
scrollToMiddle(treeDiv,otn);
var nodeImage = getElement("<%=parentNode.getRenderId()%>-trn_state_image");
if(!undef(nodeImage))
{
nodeImage.src = "<%=IMAGE_PATH+expandedImage%>";
var nodeDiv = nodeImage.parentNode.parentNode;
if(nodeDiv)
{
nodeDiv.setAttribute("aria-expanded", "true");
}
}
reFocusItem();
]]>
<%
app.remove("endcdata");
}//if first
}//if parent
}
else
{
if(collapsed)
{
//remove old children
//change status image
%>
>
var outer = getElement("<%=controlId%>_children");
if(!undef(outer))
{
outer.innerHTML="";
// Chrome - in Chrome the "display" attribute causes issues with tree rendering.
// If maxtype=treenode, then we're in Chrome and we won't do the display=none, but
// use margin-left, which was set above
var elementtype = outer.getAttribute("maxtype");
if(undef(elementtype) || elementtype != "treenode") {
hideShowElement(outer,false);
}
}
var nodeImage = getElement("<%=control.getRenderId()%>-trn_state_image");
if(!undef(nodeImage))
{
nodeImage.src = "<%=IMAGE_PATH+collapsedImage%>";
var nodeDiv = nodeImage.parentNode.parentNode;
if(nodeDiv)
{
nodeDiv.setAttribute("aria-expanded", "false");
}
}
reFocusItem();
]]>
<%
treeNode.setCollapsed(false);
} //if collapsed
if(((enableReturn && handleAction) || enableSelectNode) && selectedNode!=null && selectedNode.getRenderId().equals(control.getRenderId()))
{
//deslect the previous node
if(lastSelectedNodeId!=null)
{
if(!lastSelectedNodeId.equals(treeNode.getId()))//if last node was not this one, the replace its class, otherwise ignore
{
%>
>
var previousNode = getElement("<%=lastSelectedNodeId+"-trn_nodename_link"%>");
if(!undef(previousNode))
{
var item = previousNode;
while(item!=null && item.tagName!="LI")
{
item=item.parentNode;
}
if(item)
{
updateJSONAttribute(item, "nodeinfo", ["selected"], false);
}
replaceClass(previousNode,"sn","nn");
}
]]>
<%
}
} //if enable return
%>
>
var newSelectedName = getElement("<%=controlId%>_nodename_link");
if(!undef(newSelectedName))
{
var item = newSelectedName;
while(item!=null && item.tagName!="LI")
{
item = item.parentNode;
if(item.tagName =='DIV'){
dojo.attr(item, {'tabindex':'0'});
}
}
if(item)
{
updateJSONAttribute(item, "nodeinfo", ["selected"], true);
}
replaceClass(newSelectedName,"nn","sn");
}
]]>
<%
}// if node selected
component.renderChildrenControls();
}//else
}//design mode
else if(!component.needsRender())
{ %>
>
<% if(control.hasPropertyChanged("designerselected"))
{ %>
var el = document.getElementById("<%=id%>");
if(el)
{
el.style.backgroundColor="<%=designerSelectedColor%>";
}
<% } %>
]]>
<%
component.renderChildrenControls();
}%><%@ include file="../common/componentfooter.jsp" %>