Changeset 518 for trunk/web-app/js
- Timestamp:
- Jun 3, 2010, 12:27:08 PM (13 years ago)
- Location:
- trunk/web-app/js
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web-app/js/publication-chooser.js
r496 r518 149 149 * initialize object 150 150 */ 151 PublicationChooser.init = function( ) {151 PublicationChooser.init = function( events ) { 152 152 // find all ontology elements 153 153 $("input[rel*='publication']").each(function() { 154 new PublicationChooser().initAutocomplete( this);154 new PublicationChooser().initAutocomplete( this, events ); 155 155 }); 156 156 }; … … 159 159 minLength : 3, // minimum input length before launching Ajax request 160 160 cache : [], // ontology cache 161 maxResults : 10,// Max number of results retrieved161 maxResults : 8, // Max number of results retrieved 162 162 database : '', // Default database to be used. As for now, also the only possible database 163 163 availableDBs : {}, // Available databases, filled by extensions. Key is databasename and value is reference to method to be called 164 events : {}, // Stores the events to fire 164 165 165 166 /** … … 167 168 * @param element 168 169 */ 169 initAutocomplete: function( element) {170 initAutocomplete: function( element, customEvents ) { 170 171 var that = this 171 172 var inputElement = $(element); 172 173 var selected = false; 173 174 175 // Add spinner element 176 if( !baseUrl ) { 177 var baseUrl = '..'; 178 } 179 var imgEl = document.createElement( 'img' ); 180 imgEl.setAttribute( 'id', inputElement.attr( 'id' ) + '_spinner' ); 181 imgEl.setAttribute( 'src', baseUrl + '/images/spinner.gif' ); 182 imgEl.setAttribute( 'style', 'margin-left: 5px;'); 183 184 // Add the element next to the input box 185 inputElement.after( imgEl ); 186 $( imgEl ).hide(); 187 174 188 // determine what database to use 175 189 var values = inputElement.attr('rel').split("-"); 190 191 // Check which database the user wants 176 192 if( values.length > 1 ) { 177 193 // check for supported databases 178 194 if( this.availableDBs[ values[ 1 ] ] ) { 179 195 this.database = values[1]; 196 this.events = this.availableDBs[ this.database ]; 180 197 } else { 181 alert( 'Database ' + values[1] + ' not supported. Using default: ' + this.database ); 198 this.database = values[1] + " (custom)"; 199 this.events = {}; 182 200 } 201 } else { 202 this.database = "(custom)"; 203 this.events = {}; 204 } 205 206 // Add custom events to this object 207 if( customEvents ) { 208 $.each( customEvents, function( id, func ) { 209 that.events[ id ] = func; 210 }) 211 } 212 213 // If no 'source' function is defined, nothing can be searched for 214 if( !this.events[ 'source' ]) { 215 alert( 'Database ' + this.database + ' not supported. Using none.' ); 183 216 } 184 217 … … 189 222 inputElement.autocomplete({ 190 223 minLength: that.minLength, 191 delay: 400,224 delay: 300, 192 225 193 226 source: function(request, response) { … … 199 232 response(that.cache[ that.database ][ q ]); 200 233 } else { 201 if( that.database != "" && that. availableDBs[ that.database ] && that.availableDBs[ that.database ][ 'source' ] ) {202 that.availableDBs[ that.database ][ 'source' ]( that, q, response );234 if( that.database != "" && that.events[ 'source' ] ) { 235 that.events[ 'source' ]( that, q, response ); 203 236 } 204 237 } … … 206 239 search: function(event, ui ) { 207 240 that.selected = false; 241 $( '#' + inputElement.attr( 'id' ) + '_spinner' ).show(); 242 }, 243 open: function(event, ui ) { 244 $( '#' + inputElement.attr( 'id' ) + '_spinner' ).hide(); 208 245 }, 209 246 select: function(event, ui) { … … 211 248 that.selected = true; 212 249 213 if( that.database != "" && that. availableDBs[ that.database ] && that.availableDBs[ that.database ][ 'select' ] ) {214 that. availableDBs[ that.database ][ 'select' ]( that, inputElement, event, ui );250 if( that.database != "" && that.events[ 'select' ] ) { 251 that.events[ 'select' ]( that, inputElement, event, ui ); 215 252 } 216 253 }, 217 254 close: function(event, ui) { 218 255 if( !that.selected ) { 219 if( that.database != "" && that.availableDBs[ that.database ] && that.availableDBs[ that.database ][ 'close' ] ) { 220 that.availableDBs[ that.database ][ 'close' ]( that, inputElement, event, ui ); 256 if( that.database != "" && that.events[ 'close' ] ) { 257 that.events[ 'close' ]( that, inputElement, event, ui ); 258 } 259 260 if( inputElement.closePublication ) { 261 inputElement.closePublication( that, event, ui ); 221 262 } 222 263 } -
trunk/web-app/js/publication-chooser.pubmed.js
r496 r518 4 4 var terms = searchterm.split( " " ); 5 5 for( var i = 0; i < terms.length; i++ ) { 6 searchFor[ searchFor.length ] = "(" + terms[i].trim() + "[title]" + " OR " + terms[i].trim() + "[author]" + ")";6 searchFor[ searchFor.length ] = "(" + $.trim( terms[i] ) + "[title]" + " OR " + $.trim( terms[i] ) + "[author]" + ")"; 7 7 } 8 8 … … 38 38 }; 39 39 40 selectPubMed = function( chooserObject, inputElement, event, ui ) { 40 // Handler that handles the select of a publication 41 selectPubMedAdd = function( chooserObject, inputElement, event, ui ) { 41 42 42 43 // option selected, set hidden fields … … 52 53 element.removeClass('error'); 53 54 }; 54 closePubMed = function( chooserObject, inputElement, event, ui ) { 55 56 // Handler that handles the closing of the autocomplete 57 closePubMedAdd = function( chooserObject, inputElement, event, ui ) { 55 58 // no he didn't, clear the field(s) 56 59 var element = inputElement; … … 116 119 } 117 120 121 // Only the source method should be used for all pubmed autocompletes 122 // The select and close handlers that are defined here, should only be used 123 // on the add publication page. They can be overridden in the initialization 124 // of the publication chooser class 118 125 PublicationChooser.prototype.availableDBs[ "pubmed" ] = { 119 126 'source': sourcePubMed, 120 'select': selectPubMed ,121 'close': closePubMed 127 'select': selectPubMedAdd, 128 'close': closePubMedAdd 122 129 }; 130 -
trunk/web-app/js/wizard.js
r507 r518 351 351 return '<a target="_blank" href="' + baseUrl + '/file/get/' + filename + '">' + filename + '</a>'; 352 352 } 353 354 function addPublication( element_id ) { 355 /* Find publication ID and add to form */ 356 jQuery.ajax({ 357 type:"GET", 358 url: baseUrl + "/publication/getID?" + $("#" + element_id + "_form").serialize(), 359 success: function(data,textStatus){ 360 var id = parseInt( data ); 361 362 // Put the ID in the array, but only if it does not yet exist 363 var ids = getPublicationIds( element_id ); 364 365 if( $.inArray(id, ids ) == -1 ) { 366 ids[ ids.length ] = id; 367 $( '#' + element_id + '_ids' ).val( ids.join( ',' ) ); 368 369 // Show the title and a remove button 370 showPublication( element_id, id, $("#" + element_id + "_form").find( '[name=publication-title]' ).val(), $("#" + element_id + "_form").find( '[name=publication-authorsList]' ).val(), ids.length - 1 ); 371 372 // Hide the 'none box' 373 $( '#' + element_id + '_none' ).css( 'display', 'none' ); 374 } 375 }, 376 error:function(XMLHttpRequest,textStatus,errorThrown){ alert( "Publication could not be added." ) } 377 }); return false; 378 } 379 380 function removePublication( element_id, id ) { 381 var ids = getPublicationIds( element_id ); 382 if( $.inArray(id, ids ) != -1 ) { 383 // Remove the ID 384 ids.splice($.inArray(id, ids ), 1); 385 $( '#' + element_id + '_ids' ).val( ids.join( ',' ) ); 386 387 // Remove the title from the list 388 var li = $( "#" + element_id + '_item_' + id ); 389 if( li ) { 390 li.remove(); 391 } 392 393 // Show the 'none box' if needed 394 if( ids.length == 0 ) { 395 $( '#' + element_id + '_none' ).css( 'display', 'inline' ); 396 } 397 398 } 399 } 400 401 function getPublicationIds( element_id ) { 402 var ids = $( '#' + element_id + '_ids' ).val(); 403 if( ids == "" ) { 404 return new Array(); 405 } else { 406 ids_array = ids.split( ',' ); 407 for( var i = 0; i < ids_array.length; i++ ) { 408 ids_array[ i ] = parseInt( ids_array[ i ] ); 409 } 410 411 return ids_array; 412 } 413 } 414 415 function showPublication( element_id, id, title, authors, nr ) { 416 var deletebutton = document.createElement( 'img' ); 417 deletebutton.setAttribute( 'class', 'famfamfam delete_button' ); 418 deletebutton.setAttribute( 'alt', 'remove this publication' ); 419 deletebutton.setAttribute( 'src', baseUrl + '/images/icons/famfamfam/delete.png' ); 420 deletebutton.setAttribute( 'onClick', 'removePublication( "' + element_id + '", ' + id + ' ); return false;' ); 421 deletebutton.setAttribute( 'style', 'cursor: pointer;' ); 422 423 var titleDiv = document.createElement( 'div' ); 424 titleDiv.setAttribute( 'class', 'title' ); 425 titleDiv.appendChild( document.createTextNode( title ) ); 426 427 var authorsDiv = document.createElement( 'div' ); 428 authorsDiv.setAttribute( 'class', 'authors' ); 429 authorsDiv.appendChild( document.createTextNode( authors ) ); 430 431 var li = document.createElement( 'li' ); 432 li.setAttribute( 'id', element_id + '_item_' + id ); 433 li.setAttribute( 'class', nr % 2 == 0 ? 'even' : 'odd' ); 434 li.appendChild( deletebutton ); 435 li.appendChild( titleDiv ); 436 li.appendChild( authorsDiv ); 437 438 $( '#' + element_id + '_list' ).append( li ); 439 }
Note: See TracChangeset
for help on using the changeset viewer.