/* $This file is distributed under the terms of the license in /doc/license.txt$ */ var classHierarchyUtils = { onLoad: function(urlBase,displayOption) { this.imagePath = urlBase + "/images/"; this.displayOption = displayOption; this.initObjects(); this.expandAll.hide(); if ( this.displayOption == "all" ) { this.buildAllClassesHtml(); } else if ( this.displayOption == "group" ) { this.buildClassGroupHtml(); } else { this.buildClassHierarchyHtml(); this.wireExpandLink(); } if ( this.displayOption == "asserted" || this.displayOption == "inferred" || this.displayOption == "group") { this.expandAll.show(); } this.bindEventListeners(); }, initObjects: function() { this.expandAll = $('span#expandAll').find('a'); this.classCounter = 1; this.expandCounter = 1; this.classHtml = ""; this.clickableSpans = [] ; this.form = $('form#classHierarchyForm'); this.select = $('select#displayOption'); this.addClass = $('input#addClass'); this.addGroup = $('input#addGroup'); }, bindEventListeners: function() { this.select.change(function() { if ( classHierarchyUtils.select.val() == "all") { classHierarchyUtils.form.attr("action", "listVClassWebapps"); } else if ( classHierarchyUtils.select.val() == "group") { classHierarchyUtils.form.attr("action", "listGroups"); } classHierarchyUtils.form.submit(); }); this.addClass.click(function() { classHierarchyUtils.form.attr("action", "vclass_retry"); classHierarchyUtils.form.submit(); }); this.addGroup.click(function() { classHierarchyUtils.form.attr("action", "editForm?controller=Classgroup"); classHierarchyUtils.form.submit(); }); if ( this.displayOption == "group" ) { this.expandAll.click(function() { if ( classHierarchyUtils.expandAll.text() == "hide subclasses" ) { $('td.subclassCell').parent('tr').hide(); $('table.innerDefinition').hide(); classHierarchyUtils.expandAll.text("show subclasses"); } else { $('td.subclassCell').parent('tr').show(); $('table.innerDefinition').show(); classHierarchyUtils.expandAll.text("hide subclasses"); } }); } }, buildClassHierarchyHtml: function() { $.each(json, function() { $newClassSection = jQuery("
", { id: "classContainer" + classHierarchyUtils.classCounter }); var descendants = ""; var headerSpan = ""; var closingTable = ""; if ( this.children.length ) { descendants = classHierarchyUtils.getTheChildren(this); closingTable = ""; headerSpan = " "; } classHierarchyUtils.classHtml += "
" + this.name + headerSpan + "
" + "" ; if ( this.data.shortDef.length > 0 ) { classHierarchyUtils.classHtml += ""; } if ( this.data.classGroup.length > 0 ) { classHierarchyUtils.classHtml += ""; } classHierarchyUtils.classHtml += ""; if ( descendants.length > 1 ) { descendants = descendants.substring(0, descendants.length - 10); } classHierarchyUtils.classHtml += descendants; classHierarchyUtils.classHtml += closingTable; // alert(classHierarchyUtils.classHtml); $newClassSection.html(classHierarchyUtils.classHtml); $newClassSection.appendTo($('section#container')); classHierarchyUtils.makeHeaderSpansClickable(classHierarchyUtils.classCounter); classHierarchyUtils.makeSubclassSpansClickable(); classHierarchyUtils.clickableSpans = [] ; classHierarchyUtils.classHtml = ""; classHierarchyUtils.classCounter += 1; }); }, getTheChildren: function(node) { var childDetails = ""; var subclassString = " "; var ctr = 0 $.each(node.children, function() { if ( ctr == 0 ) { childDetails += ""; ctr = ctr + 1; } else { childDetails += "" ; } if ( this.children.length == 1 ) { subclassString += " (1 subclass)"; } else if ( this.children.length > 1 ) { subclassString += " (" + this.children.length + " subclasses)"; } childDetails += ""; return childDetails; }, makeHeaderSpansClickable: function(ctr) { var $clickableHeader = $('section#classContainer' + ctr).find('span.headerSpanPlus'); $clickableHeader.click(function() { if ( $clickableHeader.attr('view') == "less" ) { $clickableHeader.addClass("headerSpanMinus"); $('table#classHierarchy' + ctr).find('span.subclassExpandPlus').addClass("subclassExpandMinus"); $('table#classHierarchy' + ctr).find('table.subclassTable').show(); $clickableHeader.attr('view', 'more' ); } else { $clickableHeader.removeClass("headerSpanMinus"); $('table#classHierarchy' + ctr).find('span.subclassExpandPlus').removeClass("subclassExpandMinus"); $('table#classHierarchy' + ctr).find('table.subclassTable').hide(); $clickableHeader.attr('view', 'less' ); } }); },// $('myOjbect').css('background-image', 'url(' + imageUrl + ')'); makeSubclassSpansClickable: function() { $.each(classHierarchyUtils.clickableSpans, function() { var currentSpan = this; var $clickableSpan = $('section#container').find('span#' + currentSpan); var $subclassTable = $('section#container').find('table#subclassTable' + currentSpan.replace("subclassExpand","")); $clickableSpan.click(function() { if ( $subclassTable.is(':visible') ) { $subclassTable.hide(); $subclassTable.find('table.subclassTable').hide(); $subclassTable.find('span').removeClass("subclassExpandMinus"); $clickableSpan.removeClass("subclassExpandMinus"); } else { $subclassTable.show(); $clickableSpan.addClass("subclassExpandMinus"); } }); }); }, wireExpandLink: function() { this.expandAll.click(function() { if ( classHierarchyUtils.expandAll.text() == "expand all" ) { classHierarchyUtils.expandAll.text("collapse all"); $('span.headerSpanPlus').addClass("headerSpanMinus"); $('table.classHierarchy').find('span.subclassExpandPlus').addClass("subclassExpandMinus"); $('table.classHierarchy').find('table.subclassTable').show(); $('section#container').find('span.headerSpanPlus').attr('view','more'); } else { classHierarchyUtils.expandAll.text("expand all"); $('span.headerSpanPlus').removeClass("headerSpanMinus"); $('table.classHierarchy').find('span.subclassExpandPlus').removeClass("subclassExpandMinus"); $('table.classHierarchy').find('table.subclassTable').hide(); $('section#container').find('span.headerSpanPlus').attr('view','less'); } }); }, buildAllClassesHtml: function() { $.each(json, function() { $newClassSection = jQuery("
", { id: "classContainer" + classHierarchyUtils.classCounter }); classHierarchyUtils.classHtml += "
" + this.name + "
" + "
" + this.data.shortDef + "
Class Group:" + this.data.classGroup + "
Ontology:" + this.data.ontology + "
Subclasses:
 " + this.name + subclassString + "
"; subclassString = " "; classHierarchyUtils.clickableSpans.push('subclassExpand' + classHierarchyUtils.expandCounter); classHierarchyUtils.expandCounter += 1; if ( this.data.shortDef.length > 0 ) { childDetails += ""; } if ( this.data.classGroup.length > 0 ) { childDetails += ""; } childDetails += ""; if ( this.children ) { var grandChildren = classHierarchyUtils.getTheChildren(this); childDetails += grandChildren; } }); childDetails += "
" + this.data.shortDef + "
Class Group:" + this.data.classGroup + "
Ontology:" + this.data.ontology + "
" ; if ( this.data.shortDef.length > 0 ) { classHierarchyUtils.classHtml += ""; } if ( this.data.classGroup.length > 0 ) { classHierarchyUtils.classHtml += ""; } classHierarchyUtils.classHtml += ""; classHierarchyUtils.classHtml += "
" + this.data.shortDef + "
Class Group:" + this.data.classGroup + "
Ontology:" + this.data.ontology + "
"; $newClassSection.html(classHierarchyUtils.classHtml); $newClassSection.appendTo($('section#container')); classHierarchyUtils.classHtml = ""; classHierarchyUtils.classCounter += 1; }); }, buildClassGroupHtml: function() { $.each(json, function() { $newClassSection = jQuery("
", { id: "classContainer" + classHierarchyUtils.classCounter }); var descendants = ""; if ( this.children.length ) { var ctr = 0; $.each(this.children, function() { if ( ctr == 0 ) { descendants += "Classes:"; ctr = ctr + 1; } else { descendants += "" ; } descendants += "" + this.name + ""; descendants += "
" + this.data.shortDef + "
"; }); descendants += ""; } classHierarchyUtils.classHtml += "
" + this.name + "
" + "" ; if ( this.data.displayRank.length > 0 ) { classHierarchyUtils.classHtml += "" } classHierarchyUtils.classHtml += descendants; classHierarchyUtils.classHtml += "
Display Rank:" + this.data.displayRank + "
"; $newClassSection.html(classHierarchyUtils.classHtml); $newClassSection.appendTo($('section#container')); classHierarchyUtils.classHtml = ""; classHierarchyUtils.classCounter += 1; }); } }