flyui.namespace("flyui.apps.expressionbygenebatch");flyui.apps.expressionbygenebatch.Application=function(){var A=this;var C=null;var B=null;var D=null;var E=null;this.initBatchGeneFinder=function(){var H="flyui.apps.expressionbygenebatch.Application.initBatchGeneFinder";try{flyui.debug("instantiate a service for the batchgenefinder widget",H);var F=new flyui.flybase.Service("../../../data/flybase");flyui.debug("instantiate a renderer for the batchgenefinder widget",H);var J=$("#batchGeneFinderWidget");var I=new flyui.genefinder.BatchWidget.DefaultRenderer();I.setCanvas(J);flyui.debug("instantiate a genefinder widget",H);C=new flyui.genefinder.BatchWidget(F,I)}catch(G){flyui.apps.expressionbygenebatch.handleError(G)}};this.initBatchBdgp=function(){var H="flyui.apps.expressionbygenebatch.Application.initBatchBdgp";try{flyui.debug("instantiate a service for the bdgp batch widget",H);var F=new flyui.bdgp.Service();F.setEndpoint("../../../data/bdgp");flyui.debug("instantiate a renderer for the bdgp batch widget",H);var J=$("#batchBdgpImageWidget");var I=new flyui.bdgp.BatchWidget.DefaultRenderer();I.setCanvas(J);flyui.debug("instantiate a bdgp widget",H);B=new flyui.bdgp.BatchWidget(F,I)}catch(G){flyui.apps.expressionbygenebatch.handleError(G)}};this.initBatchFlyted=function(){var H="flyui.apps.expressionbygenebatch.Application.initBatchFlyted";try{flyui.debug("instantiate a service for the flyted batch widget",H);var F=new flyui.flyted.Service();F.setEndpoint("../../../data/flyted");flyui.debug("instantiate a renderer for the flyted batch widget",H);var J=$("#batchFlytedImageWidget");var I=new flyui.flyted.BatchWidget.DefaultRenderer();I.setCanvas(J);flyui.debug("instantiate a flyted widget",H);E=new flyui.flyted.BatchWidget(F,I)}catch(G){flyui.apps.expressionbygenebatch.handleError(G)}};this.initBatchFlyatlas=function(){var H="flyui.apps.flyatlasbygenebatch.Application.initBatchFlyatlas";try{flyui.debug("instantiate a service for the batchgenefinder widget",H);var F=new flyui.flyatlas.Service();F.setEndpoint("../../../data/flyatlas");flyui.debug("instantiate a renderer for the batchgenefinder widget",H);var J=$("#batchFlyatlasWidget");var I=new flyui.flyatlas.BatchWidget.DefaultRenderer();I.setCanvas(J);flyui.debug("instantiate a flyatlas widget",H);D=new flyui.flyatlas.BatchWidget(F,I)}catch(G){flyui.apps.flyatlasbygenebatch.handleError(G)}};this.init=function(){var G="flyui.apps.expressionbygenebatch.Application.init";try{var H=new YAHOO.widget.LogReader("logger");this.initBatchGeneFinder();this.initBatchBdgp();this.initBatchFlyatlas();this.initBatchFlyted();flyui.debug("hook form submission to widget call",G);YAHOO.util.Event.addListener("queryForm","submit",this.onFormSubmitted);flyui.debug("add listener for genes found event",G);C.subscribe("GENESFOUND",this.onGenesFound,null);flyui.debug("application loaded, showing main pane",G);$("#loadingPane").hide();$("#applicationPane").show();this.initState()}catch(F){flyui.apps.expressionbygenebatch.handleError(F)}};this.onFormSubmitted=function(H){var G="flyui.apps.expressionbygenebatch.Application.onFormSubmitted";try{flyui.debug("form submitted",G);$("#errorMessage").hide().html("this should never be visible");var I=document.getElementById("queryInput").value;A.setQueryState(I);A.doQuery(I)}catch(F){flyui.apps.expressionbygenebatch.handleError(F)}};this.doQuery=function(J){var I="flyui.apps.expressionbygenebatch.Application.doQuery";try{flyui.debug("raw query: "+J,I);flyui.debug("strip out newlines, commas, quotes, ...",I);J=J.replace(/[,'"\n\s]/g," ");var K=J.split(" ");var F=[];for(var H=0;H<K.length;H++){var L=K[H];if(L.length>0){F[F.length]=L}}flyui.debug("cleaned names: "+F,I);C.findGenesByAnyNameBatch(F);$("#batchBdgpImageWidget").hide();$("#batchFlyatlasWidget").hide();$("#batchFlytedImageWidget").hide();D.clear();B.clear();E.clear()}catch(G){flyui.apps.expressionbygenebatch.handleError(G)}};this.setQueryState=function(I){try{var G=new String(window.location.href);var H=G.indexOf("#");if(H>0){G=G.substring(0,H)}window.location.href=G+"#query="+escape(I)}catch(F){flyui.apps.expressionbygenebatch.handleError(F)}};this.initState=function(){try{var H=new String(window.location.href);var J=H.indexOf("#query=");if(J>0){var F=H.length;var I=unescape(H.substring(J+7,F));flyui.info("found query: "+I);document.getElementById("queryInput").value=I;A.doQuery(I)}}catch(G){flyui.apps.expressionbygenebatch.handleError(G)}};this.onGenesFound=function(M,K){try{flyui.debug("application: genes found");var J=K[0];var H=K[1];flyui.debug("query names: "+J);var F=[];var G=[];var N=[];for(var I=0;I<J.length;I++){if(H[J[I]].length==1){F[F.length]=J[I];G[G.length]=H[J[I]][0].flybaseID;N[N.length]=H[J[I]][0]}}flyui.debug("found query names: "+F);flyui.debug("found genes: "+N);if(F.length>0){B.findImagesByGeneBatch(F,N);$("#batchBdgpImageWidget").show();D.getAssaysByGeneBatch(F,G);$("#batchFlyatlasWidget").show();E.findImagesByGeneBatch(F,N);$("#batchFlytedImageWidget").show()}}catch(L){flyui.apps.expressionbygenebatch.handleError(L)}};this.init()};flyui.apps.expressionbygenebatch.handleError=function(A){flyui.err(A.name+" :: "+A.message);$("#errorMessage").html("an error has occurred, please see the log for more details").show()};YAHOO.util.Event.onDOMReady(function(){new flyui.apps.expressionbygenebatch.Application()})