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