﻿//----------------------------------------------------------
// Copyright (C) ESRI. All rights reserved.
//----------------------------------------------------------
var esriTaskResultsCancelledJobs = {};function esriTaskResultsCancelJob(jobID, nodeID, treeViewPlusID)
{
esriTaskResultsCancelledJobs[jobID]="cancelled";var node=document.getElementById(nodeID);if (node!==null)
{
node.parentNode.removeChild(node);var tvp = $find(treeViewPlusID);if (tvp){
tvp.updateClearAllControlVisibility();}
window.setTimeout("$find('" + treeViewPlusID + "')._clearNode('" + nodeID + "');",0);}
}
Type.registerNamespace('ESRI.ADF.UI');ESRI.ADF.UI.TaskResults = function(element) { 
this._hoverColor = "";this._map = null;ESRI.ADF.UI.TaskResults.initializeBase(this, [element]);};ESRI.ADF.UI.TaskResults.prototype = {
initialize : function() {
ESRI.ADF.UI.TaskResults.callBaseMethod(this, 'initialize');}, 
dispose : function() {
ESRI.ADF.UI.TaskResults.callBaseMethod(this, 'dispose');},
get_map : function() {
return this._map;},
set_map : function(value) {
this._map = value;},
get_hoverColor : function() {
return this._hoverColor;},
set_hoverColor : function(value) {
this._hoverColor = value;},
processCallbackResult : function(action, params) {
if (action == "insertTaskResultNode") {
this._insert(params[0], params[1], params[2], params[3]);return true;}
else if (action == "removeTaskResultNode") {
this._remove(params[0]);return true;}
else if (action == "replaceTaskResultNode") {
this._replace(params[0], params[1], params[2], params[3]);return true;}
else if (action == "refresh") {
this._refresh();return true;}
return ESRI.ADF.UI.TaskResults.callBaseMethod(this, 'processCallbackResult', [action, params]);},
_insert : function(nodeContent, index, taskJobId, nodeID) { 
if (taskJobId && esriTaskResultsCancelledJobs[taskJobId]) {
window.setTimeout("$find('" + this.get_id() + "')._clearNode('" + nodeID + "');",0);this._cancelled = true;}
else {
var taskContainer = document.getElementById(this.get_contentDivId());nodeContent = ESRI.ADF.System.templateBinder(null, nodeContent);var oldNode = $get(nodeID);if (oldNode) {
oldNode.innerHTML = nodeContent;}
else { 
var temp = document.createElement('div');temp.innerHTML = nodeContent;if (index !== null && index >= taskContainer.childNodes.length){
taskContainer.appendChild(temp.firstChild);}
else {
var sibling = taskContainer.childNodes[index];taskContainer.insertBefore(temp.firstChild, sibling);}
}
this.updateClearAllControlVisibility();var handler = this.get_events().getHandler('taskResultNodeInserted');if(handler){
handler(this,Sys.EventArgs.Empty);}
}
},
_remove : function(nodeId) {
var taskContainer = document.getElementById(this.get_contentDivId());var length = taskContainer.childNodes.length;for (var i = 0;i < length;++i) {
if (taskContainer.childNodes[i].id == nodeId) {
taskContainer.removeChild(taskContainer.childNodes[i]);this.updateClearAllControlVisibility();var handler = this.get_events().getHandler('taskResultNodeRemoved');if(handler) {
handler(this,Sys.EventArgs.Empty);}
return;}
}
},
_replace : function(nodeContent, taskJobId, nodeID, newNodeID) { 
if (taskJobId && esriTaskResultsCancelledJobs[taskJobId]) {
window.setTimeout("$find('" + this.get_id() + "').clearNode('" + nodeID + "');",0);this._cancelled = true;}
else { 
var oldNode = $get(nodeID);if (oldNode) {
oldNode.innerHTML = nodeContent;oldNode.ID = newNodeID;}
}
},
_refresh : function() {
var taskContainer = document.getElementById(this.get_contentDivId());for(var i=0;i<taskContainer.childNodes.length;++i){
var node = taskContainer.childNodes[i];node.innerHTML = ESRI.ADF.System.templateBinder(null, node.innerHTML);}
},
_rerunTask : function(taskJobId) {
window.setTimeout("$find('" + this.get_id() + "')._rerunTask2('" + taskJobId + "');",0);}, 
_rerunTask2 : function(taskJobId) {
var argument='taskJobId=' + taskJobId+ '&EventArg=rerunTask';var context = null;eval(this._callbackFunctionString);},
_getNode : function(graphicId) {
var taskContainer = document.getElementById(this.get_contentDivId());if (taskContainer) {
var nodes = taskContainer.getElementsByTagName('DIV');for (var i = 0;i < nodes.length;++i) {
if (nodes[i].getAttribute("graphicId") == graphicId){
return nodes[i];}
}
return null;}
}, 
add_taskResultNodeInserted : function(handler) {
this.get_events().addHandler('taskResultNodeInserted', handler);},
remove_taskResultNodeInserted : function(handler) {
this.get_events().removeHandler('taskResultNodeInserted', handler);},
add_taskResultNodeRemoved : function(handler) {
this.get_events().addHandler('taskResultNodeRemoved', handler);},
remove_taskResultNodeRemoved : function(handler) {
this.get_events().removeHandler('taskResultNodeRemoved', handler);},
add_mouseOverNode : function(handler) {
this.get_events().addHandler('mouseOverNode', handler);},
remove_mouseOverNode : function(handler) {
this.get_events().removeHandler('mouseOverNode', handler);},
add_mouseOutNode : function(handler) {
this.get_events().addHandler('mouseOutNode', handler);},
remove_mouseOutNode : function(handler) {
this.get_events().removeHandler('mouseOutNode', handler);},
_mouseOverNode : function(element)
{ 
var handler = this.get_events().getHandler('mouseOverNode');if(handler) {
var graphicId = element.getAttribute('graphicId');handler(this, {"element":element, "graphicId":graphicId});}
},
_mouseOutNode : function(element)
{
var handler = this.get_events().getHandler('mouseOutNode');if(handler) {
var graphicId = element.getAttribute('graphicId');handler(this, {"element":element, "graphicId":graphicId});}
}
};ESRI.ADF.UI.TaskResults.registerClass('ESRI.ADF.UI.TaskResults', ESRI.ADF.UI.TreeViewPlus);ESRI.ADF.HighlightTaskResults = function() {
ESRI.ADF.HighlightTaskResults.initializeBase(this);this._taskResults = null;this._hoverColor = "";this._maptipNode = null;this._expandOnMaptipShown = false;}
ESRI.ADF.HighlightTaskResults.prototype = {
initialize : function() {
ESRI.ADF.HighlightTaskResults.callBaseMethod(this, 'initialize');if (this._taskResults != null) 
{
this._onMouseOverNodeHandler = Function.createDelegate(this, this._onMouseOverNode);this._taskResults.add_mouseOverNode(this._onMouseOverNodeHandler);this._onMouseOutNodeHandler = Function.createDelegate(this, this._onMouseOutNode);this._taskResults.add_mouseOutNode(this._onMouseOutNodeHandler);var map = this._taskResults.get_map();if (map) {
this._onMaptipShown = Function.createDelegate(this, this._onMaptipShown);map.__add_mapTipEvent(this._onMaptipShown);} 
}
},
get_hoverColor : function()
{
return this._hoverColor;},
set_hoverColor : function(value)
{
if (this._hoverColor != value) {
this._hoverColor = value;this.raisePropertyChanged('hoverColor');}
},
get_expandOnMaptipShown : function()
{
return this._expandOnMaptipShown;},
set_expandOnMaptipShown : function(value)
{
if (this._expandOnMaptipShown != value) {
this._expandOnMaptipShown = value;this.raisePropertyChanged('expandOnMaptipShown');}
},
get_taskResults : function()
{
return this._taskResults;},
set_taskResults : function(value)
{
this._taskResults = value;},
dispose : function() {
if (this._taskResults != null) {
this._taskResults.remove_mouseOverNode(this._onMouseOverNode);this._taskResults.remove_mouseOutNode(this._onMouseOverNode);}
if (this._onMaptipShown) {
var map = this._taskResults.get_map();if (map) {
map.__remove_mapTipEvent(this._onMaptipShown);}
}
ESRI.ADF.HighlightTaskResults.callBaseMethod(this, 'dispose');},
_onMouseOverNode : function(sender, args)
{
args.element.style.backgroundColor = this._hoverColor;this._highlightFeature(args.graphicId, true);},
_onMouseOutNode : function(sender, args)
{
args.element.style.backgroundColor = "";this._highlightFeature(args.graphicId, false);},
_onMaptipShown : function(sender, args)
{
if (args.action == "show") {
var maptip = args.maptip;if (maptip && maptip.get_isExpanded())
this._highlightElementNode(args.element);}
else if (args.action == "expand")
this._highlightElementNode(args.element);else if (args.action == "hide" && this._maptipNode) {
this._maptipNode.style.backgroundColor = "";this._maptipNode = null;}
},
_highlightElementNode : function(element) {
if (this._maptipNode) {
this._maptipNode.style.backgroundColor = "";this._maptipNode = null;}
if (element) {
var map = this._taskResults.get_map();var node = this._taskResults._getNode(element.get_id());if (node) {
node.style.backgroundColor = this._hoverColor;this._maptipNode= node;if (this._expandOnMaptipShown && !this._taskResults.isNodeExpanded(node.id))
this._taskResults._toggleNodeState(node.id);}
}
},
_highlightFeature : function(graphicId, highlight)
{
var graphic = $find(graphicId);if (graphic)
graphic.set_highlight(highlight);}
}
ESRI.ADF.HighlightTaskResults.registerClass('ESRI.ADF.HighlightTaskResults', Sys.Component);if (typeof(Sys) !== 'undefined') { Sys.Application.notifyScriptLoaded();}

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();