X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=stemmaweb%2Froot%2Fjs%2Frelationship.js;h=807b5d4dc44b82ef5dab13bf2139b5799c50e0ee;hb=4aa3aa3db8d45952a7ede6ffac2a06ec2d18c6e3;hp=a73147434acb9ec9ce8c25aad3e4f4f34aa87cfb;hpb=4aed7cc51a1239fd06e7e85481f0545749dfe75b;p=scpubgit%2Fstemmatology.git diff --git a/stemmaweb/root/js/relationship.js b/stemmaweb/root/js/relationship.js index a731474..807b5d4 100644 --- a/stemmaweb/root/js/relationship.js +++ b/stemmaweb/root/js/relationship.js @@ -52,8 +52,8 @@ function node_dblclick_listener( evt ) { // Set the easy properties first $('#reading-form').dialog( 'option', 'title', 'Reading information for "' + reading_info['text'] + '"' ); $('#reading_id').val( reading_id ); - $('#reading_is_nonsense').attr( 'checked', reading_info['is_nonsense'] ); - $('#reading_grammar_invalid').attr( 'checked', reading_info['grammar_invalid'] ); + toggle_checkbox( $('#reading_is_nonsense'), reading_info['is_nonsense'] ); + toggle_checkbox( $('#reading_grammar_invalid'), reading_info['grammar_invalid'] ); // Use .text as a backup for .normal_form var normal_form = reading_info['normal_form']; if( !normal_form ) { @@ -71,17 +71,26 @@ function node_dblclick_listener( evt ) { $('#reading-form').dialog("open"); } +function toggle_checkbox( box, value ) { + if( value == null ) { + value = false; + } + box.attr('checked', value ); +} + function morphology_form ( lexlist ) { $('#morphology').empty(); $.each( lexlist, function( idx, lex ) { var morphoptions = []; - $.each( lex['wordform_matchlist'], function( tdx, tag ) { - var tagstr = stringify_wordform( tag ); - morphoptions.push( tagstr ); - }); + if( 'wordform_matchlist' in lex ) { + $.each( lex['wordform_matchlist'], function( tdx, tag ) { + var tagstr = stringify_wordform( tag ); + morphoptions.push( tagstr ); + }); + } var formtag = 'morphology_' + idx; var formstr = ''; - if( lex['form'] ) { + if( 'form' in lex ) { formstr = stringify_wordform( lex['form'] ); } var form_morph_elements = morph_elements( @@ -93,8 +102,11 @@ function morphology_form ( lexlist ) { } function stringify_wordform ( tag ) { - var elements = tag.split(' // '); - return elements[1] + ' // ' + elements[2]; + if( tag ) { + var elements = tag.split(' // '); + return elements[1] + ' // ' + elements[2]; + } + return '' } function morph_elements ( formtag, formtxt, currform, morphoptions ) { @@ -125,7 +137,7 @@ function color_inactive ( el ) { // otherwise color it green. $(el).attr( {stroke:'green', fill:'#b3f36d'} ); $.each( reading_info['lexemes'], function ( idx, lex ) { - if( !lex['is_disambiguated'] ) { + if( !lex['is_disambiguated'] || lex['is_disambiguated'] == 0 ) { $(el).attr( {stroke:'orange', fill:'#fee233'} ); } }); @@ -133,6 +145,7 @@ function color_inactive ( el ) { function relemmatize () { // Send the reading for a new lemmatization and reopen the form. + $('#relemmatize_pending').show(); var reading_id = $('#reading_id').val() ncpath = getReadingURL( reading_id ); form_values = { @@ -148,6 +161,7 @@ function relemmatize () { } else { alert("Could not relemmatize as requested: " + data['error']); } + $('#relemmatize_pending').hide(); }); } @@ -633,11 +647,11 @@ $(document).ready(function () { width: 290, modal: true, buttons: { - "Ok": function() { + "Ok": function( evt ) { + $(evt.target).button("disable"); $('#status').empty(); form_values = $('#collapse_node_form').serialize(); ncpath = getTextURL( 'relationships' ); - $(':button :contains("Ok")').attr("disabled", true); var jqjson = $.post( ncpath, form_values, function(data) { $.each( data, function(item, source_target) { var source_found = get_ellipse( source_target[0] ); @@ -649,7 +663,8 @@ $(document).ready(function () { relation.data( 'note', $('#note').val() ); relation_manager.toggle_active( relation.attr('id') ); } - }); + $(evt.target).button("enable"); + }); $( "#dialog-form" ).dialog( "close" ); }, 'json' ); }, @@ -687,9 +702,11 @@ $(document).ready(function () { $("#dialog_overlay").hide(); } }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) { - if( ( ajaxSettings.type == 'POST' ) && jqXHR.status == 403 ) { + if( ajaxSettings.url == getTextURL('relationships') + && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) { var errobj = jQuery.parseJSON( jqXHR.responseText ); $('#status').append( '

Error: ' + errobj.error + '
The relationship cannot be made.

' ); + $(event.target).parent().find('.ui-button').button("enable"); } } ); @@ -741,7 +758,10 @@ $(document).ready(function () { Cancel: function() { $( this ).dialog( "close" ); }, - Update: function() { + Update: function( evt ) { + // Disable the button + $(evt.target).button("disable"); + $('#reading_status').empty(); var reading_id = $('#reading_id').val() form_values = { 'id' : reading_id, @@ -757,7 +777,7 @@ $(document).ready(function () { // Make the JSON call ncpath = getReadingURL( reading_id ); var reading_element = readingdata[reading_id]; - $(':button :contains("Update")').attr("disabled", true); + // $(':button :contains("Update")').attr("disabled", true); var jqjson = $.post( ncpath, form_values, function(data) { $.each( data, function(key, value) { reading_element[key] = value; @@ -765,6 +785,7 @@ $(document).ready(function () { if( $('#update_workspace_button').data('locked') == false ) { color_inactive( get_ellipse( reading_id ) ); } + $(evt.target).button("enable"); $( "#reading-form" ).dialog( "close" ); }); // Re-color the node if necessary @@ -776,6 +797,7 @@ $(document).ready(function () { open: function() { $(".ui-widget-overlay").css("background", "none"); $("#dialog_overlay").show(); + $('#reading_status').empty(); $("#dialog_overlay").height( $("#enlargement_container").height() ); $("#dialog_overlay").width( $("#enlargement_container").innerWidth() ); $("#dialog_overlay").offset( $("#enlargement_container").offset() ); @@ -783,6 +805,13 @@ $(document).ready(function () { close: function() { $("#dialog_overlay").hide(); } + }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) { + if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1 + && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) { + var errobj = jQuery.parseJSON( jqXHR.responseText ); + $('#reading_status').append( '

Error: ' + errobj.error + '

' ); + $(event.target).parent().find('.ui-button').button("enable"); + } });