2941538d2af00e002904f00a08221458d3519b8e
[scpubgit/stemmaweb.git] / root / js / componentload.js
1 function loadTradition( textid, textname, editable ) {
2         selectedTextID = textid;
3     // First insert the placeholder image and register an error handler
4     var basepath = window.location.pathname
5     if( basepath.lastIndexOf('/') == basepath.length - 1 ) { 
6         basepath = basepath.slice( 0, basepath.length - 1) 
7     };
8     $('#textinfo_waitbox').show();
9     $('#textinfo_container').ajaxError( 
10         function ( e, jqxhr, settings, exception ) {
11                         if ( settings.url.indexOf( 'textinfo' ) > -1 ) {
12                         $('#textinfo_waitbox').hide();
13                                 var msg = "An error occurred: ";
14                                 var msghtml = $('<span>').attr('class', 'error').text(
15                                         msg + jqxhr.status + " " + jqxhr.statusText);
16                                 $("#textinfo_container").append( msghtml ).show();
17                         } 
18         }
19     );
20     // Then get and load the actual content.
21     // TODO: scale #stemma_graph both horizontally and vertically
22     // TODO: load svgs from SVG.Jquery (to make scaling react in Safari)
23     $.getJSON( basepath + "/textinfo/" + textid, function (textdata) {
24         // Add the scalar data
25         $('#textinfo_waitbox').hide();
26                 $('#textinfo_container').show();
27         $('.texttitle').append( textdata.traditionname );
28         $('#witness_num').append( textdata.witnesses.size );
29         $('#witness_list').append( textdata.witnesses.join( ', ' ) );
30         $('#reading_num').append( textdata.readings );
31         $('#relationship_num').append( textdata.relationships );
32         // Add the stemma(ta) and set up the stexaminer button
33         stemmata = textdata.stemmata;
34         if( stemmata.length ) {
35                 selectedStemmaID = 0;
36                 load_stemma( selectedStemmaID, basepath );
37         }
38         // Set up the relationship mapper button
39                 $('#run_relater').attr( 'action', basepath + "/relation/" + textid );
40         });
41 }
42
43 function load_stemma( idx, basepath ) {
44         if( idx > -1 ) {
45                 selectedStemmaID = idx;
46                 $('#stemma_graph').empty();
47                 $('#stemma_graph').append( stemmata[idx] );
48                 // Stexaminer submit action
49                 var stexpath = basepath + "/stexaminer/" + selectedTextID + "/" + idx;
50                 $('#run_stexaminer').attr( 'action', stexpath );
51         }
52 }