var res = [{"id":342,"name":"allsites","description":"","title":"allsites","isLazy":true},{"id":341,"name":"Kempten","description":"","title":"Kempten","isLazy":true},{"id":347,"name":"OTT_Austria_Triesting-TSGroup","description":"","title":"OTT_Austria_Triesting-TSGroup","isLazy":true},{"id":349,"name":"OTT France","description":"","title":"OTT France","isLazy":true},{"id":355,"name":"OTT Netherlands Demo","description":"","title":"OTT Netherlands Demo","isLazy":true},{"id":346,"name":"OTT_UK","description":"","title":"OTT_UK","isLazy":true}] var unselectable=0; $(function(){ var localSelect = false; $("#selectionCriteriaTree").dynatree('destroy'); var error = ''; /*HC - 268*/ var unselectableNode = ""; if(parseInt(unselectableNode) > 0){ $("#noteDiv").css("display","block"); } if(res==null && error.length > 0){ var div = document.createElement('div'); div.innerHTML = error; $("#selectionCriteriaTree").text(div.innerHTML); $("#selectionCriteriaTree").css("color", "red"); }else if(res.length > 0){ $("#selectionCriteriaTree").dynatree({ title: "Site", selectMode: 3, checkbox: true, onPostInit: function(isReloading, isError) {}, fx: {height: "toggle", duration: 200 }, autoFocus: true, children: [{"id":342,"name":"allsites","description":"","title":"allsites","isLazy":true},{"id":341,"name":"Kempten","description":"","title":"Kempten","isLazy":true},{"id":347,"name":"OTT_Austria_Triesting-TSGroup","description":"","title":"OTT_Austria_Triesting-TSGroup","isLazy":true},{"id":349,"name":"OTT France","description":"","title":"OTT France","isLazy":true},{"id":355,"name":"OTT Netherlands Demo","description":"","title":"OTT Netherlands Demo","isLazy":true},{"id":346,"name":"OTT_UK","description":"","title":"OTT_UK","isLazy":true}] , onRender: function(node) { if(node.data.unselectable==true){ $(node.span).addClass("customForDynatree"); } }, onLazyRead:function(node){ onLoadChild(node); }, onClick:function(node,nodeSpan){ var searchTxt = document.getElementById("searchData").value; if(searchTxt.trim().length == 0) { onLoadChild(node); } if(node.data.unselectable==true){ $(node.span).addClass("customForDynatree"); } }, onExpand: function(flag,node){ if(node.data.unselectable==true){ $(node.span).addClass("customForDynatree"); } var child = node.childList; if(child != null){ for (i = 0; i < child.length; i++) { var x = child[i]; if(x.data.unselectable==true){ $(x.span).addClass("customForDynatree"); } } } }, onSelect: function(select, node) { var messageSensor = ""; var sensorNames = ""; var message = ""; var siteName = ""; var tempMessage = ""; var selNodes = node.tree.getSelectedNodes(); var selKeys = $.map(selNodes, function(node){ var path = node.getKeyPath(); //if(document.getElementById('StationSensor').checked){ var stationSensorIndex = document.getElementById("sortByStationSensor").selectedIndex; if(stationSensorIndex == 0){ if((path.split("/").length - 1) == 3){ messageSensor += node.data.sensorid + ","; sensorNames += node.data.title + ","; if(tempMessage != node.getParent().data.siteid){ tempMessage = node.getParent().data.siteid; message += node.getParent().data.siteid + ","; siteName += node.getParent().data.title + ","; } } }else{ if((path.split("/").length - 1) == 2){ messageSensor += node.data.siteid + ","; sensorNames += node.data.title + ","; if(tempMessage != node.data.sensorid){ tempMessage = node.data.sensorid; message += node.data.sensorid + ","; } } } }); localSelect = select; node.expand(); document.getElementById('SiteIDForCustomReport').value = message.toString().substring(0,message.length -1); document.getElementById('SensorIDForCustomReport').value = messageSensor.toString().substring(0,messageSensor.length -1); document.getElementById('SensorNamesForCustomReport').value = sensorNames.toString().substring(0,sensorNames.length -1); } }); }else { var error_message = "Record Not Found"; var div = document.createElement('div'); div.innerHTML = error_message; $("#selectionCriteriaTree").text(div.innerHTML); } function onLoadChild(node){ var regionId = node.data.id; var path = node.getKeyPath(); var url = ""; var stationSensorIndex = document.getElementById("sortByStationSensor").selectedIndex; if(stationSensorIndex != 0){ if((path.split("/").length - 1) == 2){ url = "/Friedberg/customreportcontroller?action=getSiteFromSensor&sensorIdForRegion="+encodeURIComponent(node.data.sensorname)+"&now="+ (new Date()); call(node, url); }else{ url = "/Friedberg/customreportcontroller?action=getSiteFromSensor&sensorIdForRegion="+encodeURIComponent(node.data.title)+"&now="+ (new Date()); call(node, url); } } } function call(node, url){ $.ajax({ async: true, type: "GET", url: url, contentType: "application/x-www-form-urlencoded; charset=UTF-8", beforeSend: function( xhr ) { xhr.overrideMimeType( 'text/plain; charset=UTF-8' ); }, success: function(response){ var parsedObj = jQuery.parseJSON(response); if(parsedObj.Request.status=='Error'){ $("#drError").text(parsedObj.Request.message); }else{ var parsed = parsedObj.Data; if(parsed == ""){ node.setLazyNodeStatus(DTNodeStatus_Ok); } if(node.childList != null){ node.removeChildren(); } node.addChild(parsed); var child = node.childList; if(child != null && node.bSelected){ for (i = 0; i < child.length; i++) { var x = child[i].select(localSelect); } //localSelect = false; } var child = node.childList; if(node.data.unselectable==true){ $(node.span).addClass("customForDynatree"); } } }, error: function(){ } }); } });