many small bugfixes to display and server logic
[scpubgit/stemmatology.git] / stemmaweb / root / js / componentload.js
CommitLineData
3524c08f 1function loadTradition( textid, textname, editable ) {
2 selectedTextID = textid;
3 // First insert the placeholder image and register an error handler
8c64c9bc 4 $('#textinfo_load_status').empty();
37777737 5 $('#stemma_graph').empty();
3524c08f 6 $('#textinfo_waitbox').show();
0bded693 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") );
3524c08f 13 }
0bded693 14 });
15
16 // Hide the functionality that is irrelevant
17 if( editable ) {
789cbe47 18 $('#open_stemma_add').show();
19 $('#open_stemma_edit').show();
20 $('#open_textinfo_edit').show();
0bded693 21 } else {
789cbe47 22 $('#open_stemma_add').hide();
23 $('#open_stemma_edit').hide();
24 $('#open_textinfo_edit').hide();
0bded693 25 }
26
56455620 27 // Then get and load the actual content.
3524c08f 28 // TODO: scale #stemma_graph both horizontally and vertically
e2f647b9 29 // TODO: load svgs from SVG.Jquery (to make scaling react in Safari)
3524c08f 30 $.getJSON( basepath + "/textinfo/" + textid, function (textdata) {
31 // Add the scalar data
0bded693 32 selectedTextInfo = textdata;
33 load_textinfo();
34 // Add the stemma(ta) and set up the stexaminer button
3524c08f 35 stemmata = textdata.stemmata;
36 if( stemmata.length ) {
37 selectedStemmaID = 0;
38 load_stemma( selectedStemmaID, basepath );
39 }
40 // Set up the relationship mapper button
41 $('#run_relater').attr( 'action', basepath + "/relation/" + textid );
42 });
43}
44
0bded693 45function load_textinfo() {
46 $('#textinfo_waitbox').hide();
47 $('#textinfo_load_status').empty();
48 $('#textinfo_container').show();
49 $('.texttitle').empty().append( selectedTextInfo.name );
50 // Witnesses
51 $('#witness_num').empty().append( selectedTextInfo.witnesses.size );
52 $('#witness_list').empty().append( selectedTextInfo.witnesses.join( ', ' ) );
53 // Who the owner is
54 $('#owner_id').empty().append('no one');
55 if( selectedTextInfo.owner ) {
56 $('#owner_id').empty().append( selectedTextInfo.owner );
57 }
58 // Whether or not it is public
59 $('#not_public').empty();
60 if( selectedTextInfo['public'] == false ) {
61 $('#not_public').append('NOT ');
62 }
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 );
67 }
68}
69
70function load_stemma( idx ) {
3524c08f 71 if( idx > -1 ) {
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 );
78 }
a88e75b1 79}
0bded693 80
81function display_error( jqXHR, el ) {
789cbe47 82 var errmsg;
83 if( jqXHR.responseText == "" ) {
84 errmsg = "perhaps the server went down?"
0bded693 85 } else {
789cbe47 86 var errobj;
87 try {
88 errobj = jQuery.parseJSON( jqXHR.responseText );
89 errmsg = errobj.error;
90 } catch ( parse_err ) {
91 errmsg = "something went wrong on the server."
92 }
0bded693 93 }
789cbe47 94 var msghtml = $('<span>').attr('class', 'error').text( "An error occurred: " + errmsg );
0bded693 95 $(el).empty().append( msghtml ).show();
96}