1 function loadTradition( textid, textname, editable ) {
2 selectedTextID = textid;
3 // First insert the placeholder image and register an error handler
4 $('#textinfo_load_status').empty();
5 $('#stemma_graph').empty();
6 $('#textinfo_waitbox').show();
7 $('#textinfo_container').hide().ajaxError(
8 function(event, jqXHR, ajaxSettings, thrownError) {
9 if( ajaxSettings.url.indexOf( 'textinfo' ) > -1 && ajaxSettings.type == 'GET' ) {
10 $('#textinfo_waitbox').hide();
11 $('#textinfo_container').show();
12 display_error( jqXHR, $("#textinfo_load_status") );
16 // Hide the functionality that is irrelevant
18 $('#add_new_stemma').show();
19 $('#edit_current_stemma').show();
20 $('#edit_textinfo').show();
22 $('#add_new_stemma').hide();
23 $('#edit_current_stemma').hide();
24 $('#edit_textinfo').hide();
27 // Then get and load the actual content.
28 // TODO: scale #stemma_graph both horizontally and vertically
29 // TODO: load svgs from SVG.Jquery (to make scaling react in Safari)
30 $.getJSON( basepath + "/textinfo/" + textid, function (textdata) {
31 // Add the scalar data
32 selectedTextInfo = textdata;
34 // Add the stemma(ta) and set up the stexaminer button
35 stemmata = textdata.stemmata;
36 if( stemmata.length ) {
38 load_stemma( selectedStemmaID, basepath );
40 // Set up the relationship mapper button
41 $('#run_relater').attr( 'action', basepath + "/relation/" + textid );
45 function load_textinfo() {
46 $('#textinfo_waitbox').hide();
47 $('#textinfo_load_status').empty();
48 $('#textinfo_container').show();
49 $('.texttitle').empty().append( selectedTextInfo.name );
51 $('#witness_num').empty().append( selectedTextInfo.witnesses.size );
52 $('#witness_list').empty().append( selectedTextInfo.witnesses.join( ', ' ) );
54 $('#owner_id').empty().append('no one');
55 if( selectedTextInfo.owner ) {
56 $('#owner_id').empty().append( selectedTextInfo.owner );
58 // Whether or not it is public
59 $('#not_public').empty();
60 if( selectedTextInfo['public'] == false ) {
61 $('#not_public').append('NOT ');
63 // What language setting it has, if any
64 $('#marked_language').empty().append('no language set');
65 if( selectedTextInfo.language && selectedTextInfo.language != 'Default' ) {
66 $('#marked_language').empty().append( selectedTextInfo.language );
70 function load_stemma( idx ) {
72 selectedStemmaID = idx;
73 $('#stemma_graph').empty();
74 $('#stemma_graph').append( stemmata[idx] );
75 // Stexaminer submit action
76 var stexpath = basepath + "/stexaminer/" + selectedTextID + "/" + idx;
77 $('#run_stexaminer').attr( 'action', stexpath );
81 function display_error( jqXHR, el ) {
82 var errobj = jQuery.parseJSON( jqXHR.responseText );
85 msg = "An error occurred: " + errobj.error;
87 msg = "An error occurred; perhaps the server went down?"
89 var msghtml = $('<span>').attr('class', 'error').text( msg );
90 $(el).empty().append( msghtml ).show();