1- < script type ="text/javascript " src ="<%=contextPath%>/jbrowseApp/src/dojo/dojo.js " data-dojo-config ="async: 1, baseUrl: '<%=contextPath%>/jbrowseApp/src' "> </ script >
2- < script type ="text/javascript " src ="<%=contextPath%>/jbrowseApp/src/JBrowse/init.js "> </ script >
3-
41< script type ="text/javascript ">
5-
6- require ( [
7- 'JBrowse/Browser' ,
8- 'dijit/form/ComboBox' ,
9- 'dijit/form/Button' ,
10- 'dojo/keys' ,
11- 'JBrowse/View/InfoDialog' ,
12- "dojo/html"
13- ] ,
14- function (
15- Browser ,
16- dijitComboBox ,
17- dijitButton ,
18- keys ,
19- InfoDialog ,
20- html
21- ) {
22- var webpart = < %= webpartContext % > ;
23-
24- var databaseId = webpart.databaseId;
25- if (!databaseId){
26- html . set ( webpart . wrapperDivId , 'The target database has not been set for this webpart. Use the customize link to do this.' ) ;
27- return ;
28- }
29-
30- var base = LABKEY.contextPath + "/jbrowseApp/";
31- var browserRoot = LABKEY.contextPath + "/jbrowseApp/";
32- var dataRoot = LABKEY.contextPath + "/_webdav" + LABKEY.Security.currentContainer.path + "/@Files/.jbrowse/" + "databases/" + databaseId;
33-
34- var browser = new Browser({
35- baseUrl : base ,
36- names : {
37- type : 'Hash' ,
38- url : dataRoot + '/names/'
39- } ,
40- browserRoot : browserRoot ,
41- dataRoot : dataRoot ,
42- unitTestMode : true
43- } );
44- browser.renderedFatalErrors = true;
45- browser.fatalError = function(error){
46- html . set ( webpart . wrapperDivId , 'There was an error loading the JBrowse database with ID: ' + databaseId ) ;
47- }
48-
49- browser.afterMilestone( 'loadNames', function() {
50- this . nameStore = browser . nameStore ;
51-
52- var searchbox = dojo . create ( 'div' , {
53- style : 'display:inline-block;'
54- } , webpart . wrapperDivId ) ;
55-
56- this . inputBox = dojo . create ( 'input' , { placeHolder : "type in your name" , baseClass : 'myClass' } , searchbox ) ;
57-
58- this . locationBox = new dijitComboBox ( {
59- style : { width : '200px' } ,
60- maxLength : 400 ,
61- searchAttr : "name" ,
62- placeHolder : "Enter gene name" ,
63- title : 'Enter gene or feature name' ,
64- 'class' : 'lk-input'
65- } , this . inputBox ) ;
66-
67- browser . afterMilestone ( 'loadNames' , dojo . hitch ( this , function ( ) {
68- if ( this . nameStore ) {
69- this . locationBox . set ( 'store' , browser . nameStore ) ;
70- }
71- } ) ) ;
72- this . locationBox . focusNode . spellcheck = false ;
73-
74- dojo . query ( 'div.dijitArrowButton' , this . locationBox . domNode ) . orphan ( ) ;
75-
76- dojo . connect ( this . locationBox . focusNode , "keydown" , this , function ( event ) {
77- if ( event . keyCode == keys . ESCAPE ) {
78- this . locationBox . set ( 'value' , '' ) ;
79- }
80- else if ( event . keyCode == keys . ENTER ) {
81- this . locationBox . closeDropDown ( false ) ;
82- this . navigateTo ( this . locationBox . get ( 'value' ) ) ;
83- this . goButton . set ( 'disabled' , true ) ;
84- dojo . stopEvent ( event ) ;
85- } else {
86- this . goButton . set ( 'disabled' , false ) ;
87- }
88- } ) ;
89- dojo . connect ( searchbox , 'onselectstart' , function ( evt ) { evt . stopPropagation ( ) ; return true ; } ) ;
90-
91- this . searchNames = function ( /**String*/ loc ) {
92- return browser . nameStore . query ( { name : loc } ) . then (
93- function ( nameMatches ) {
94- // if we have no matches, pop up a dialog saying so, and
95- // do nothing more
96- if ( ! nameMatches . length ) {
97- return false ;
98- }
99-
100- var goingTo ;
101-
102- //first check for exact case match
103- for ( var i = 0 ; i < nameMatches . length ; i ++ ) {
104- if ( nameMatches [ i ] . name == loc )
105- goingTo = nameMatches [ i ] ;
106- }
107- //if no exact case match, try a case-insentitive match
108- if ( ! goingTo ) {
109- for ( i = 0 ; i < nameMatches . length ; i ++ ) {
110- if ( nameMatches [ i ] . name . toLowerCase ( ) == loc . toLowerCase ( ) )
111- goingTo = nameMatches [ i ] ;
112- }
113- }
114- //else just pick a match
115- if ( ! goingTo ) goingTo = nameMatches [ 0 ] ;
116-
117- return goingTo ;
118- } ,
119- function ( e ) {
120- console . error ( e ) ;
121- new InfoDialog ( { title : 'Error' , content : 'Error reading from name store.' } ) . show ( ) ;
122- return false ;
123- } ) ;
124- } ;
125-
126- this . navigateTo = function ( loc , callee ) {
127- if ( ! loc ) {
128- return ;
129- }
130-
131- this . searchNames ( loc ) . then ( function ( loc , callee ) {
132- if ( ! loc ) {
133- new InfoDialog ( { title : 'Error' , content : 'Coordinates not found for this location.' } ) . show ( ) ;
134- }
135- else if ( loc . multipleLocations ) {
136- new InfoDialog ( { title : 'Error' , content : 'This location matched multiple positions in the genome.' } ) . show ( ) ;
137- LDK . Utils . logToServer ( 'Jbrowse multiple locations found: ' + JSON . stringify ( loc . location ) ) ;
138- }
139- else {
140- var url = LABKEY . ActionURL . buildURL ( 'jbrowse' , 'browser' , null , { database : databaseId , loc : loc . location . ref + ':' + loc . location . start + '..' + loc . location . end } )
141- //console.log(url)
142- window . location = url ;
143- }
144- } ) ;
145- } ;
146-
147- // make the 'Go' button
148- this . goButton = new dijitButton ( {
149- label : 'Go' ,
150- baseClass : "noBorder" ,
151- onClick : dojo . hitch ( this , function ( event ) {
152- this . navigateTo ( this . locationBox . get ( 'value' ) ) ;
153- this . goButton . set ( 'disabled' , true ) ;
154- dojo . stopEvent ( event ) ;
155- } ) ,
156- className : 'labkey-button'
157- } , dojo . create ( 'button' , { } , searchbox ) ) ;
158- } );
159-
160- browser.loadNames();
161- } ) ;
162-
163-
2+ + function ( ) {
3+ const sessionId = < %= webpartContext % > .databaseId;
4+ LABKEY.App.loadApp('jbrowseSearchWebpart', < %= webpartContext % > .wrapperDivId, sessionId);
5+ } ( ) ;
1646</ script >
0 commit comments