X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=root%2Fjs%2Frelationship.js;h=89ca5e8ab847e79815292bbfbacb0f321075df71;hb=b001c73dc563fa9fd781375fc6916e3d93189657;hp=39d8f5032843d9c09d21a6d2425c85b7b51e1960;hpb=769401c346187d797fdb5ff1b860a1c117f8c5be;p=scpubgit%2Fstemmaweb.git diff --git a/root/js/relationship.js b/root/js/relationship.js index 39d8f50..89ca5e8 100644 --- a/root/js/relationship.js +++ b/root/js/relationship.js @@ -837,6 +837,21 @@ function Marquee() { } +function readings_equivalent( source, target ) { + var sourcetext = readingdata[source].text; + var targettext = readingdata[target].text; + if( sourcetext === targettext ) { + return true; + } + // Lowercase and strip punctuation from both and compare again + var stlc = sourcetext.toLowerCase().replace(/[^\w\s]|_/g, ""); + var ttlc = targettext.toLowerCase().replace(/[^\w\s]|_/g, ""); + if( stlc === ttlc ) { + return true; + } + return false; +} + $(document).ready(function () { @@ -844,7 +859,8 @@ $(document).ready(function () { relation_manager = new relation_factory(); $('#update_workspace_button').data('locked', false); - + + // Set up the mouse events on the SVG enlargement $('#enlargement').mousedown(function (event) { $(this) .data('down', true) @@ -909,6 +925,11 @@ $(document).ready(function () { }); + // Set up the relationship creation dialog. This also functions as the reading + // merge dialog where appropriate. + var relation_buttonset = { + }; + if( editable ) { $( "#dialog-form" ).dialog({ autoOpen: false, @@ -916,7 +937,16 @@ $(document).ready(function () { width: 290, modal: true, buttons: { - "Ok": function( evt ) { + "Merge readings": function( evt ) { + $(evt.target).button("disable"); + $('#status').empty(); + form_values = $('#collapse_node_form').serialize(); + ncpath = getTextURL( 'merge' ); + var jqjson = $.post( ncpath, form_values, function(data) { + alert( "Did a node merge" ); + }); + }, + OK: function( evt ) { $(evt.target).button("disable"); $('#status').empty(); form_values = $('#collapse_node_form').serialize(); @@ -961,7 +991,15 @@ $(document).ready(function () { }); }, open: function() { - relation_manager.create_temporary( $('#source_node_id').val(), $('#target_node_id').val() ); + relation_manager.create_temporary( + $('#source_node_id').val(), $('#target_node_id').val() ); + var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ) + if( readings_equivalent( $('#source_node_id').val(), + $('#target_node_id').val() ) ) { + buttonset.find( "button:contains('Merge readings')" ).show(); + } else { + buttonset.find( "button:contains('Merge readings')" ).hide(); + } $(".ui-widget-overlay").css("background", "none"); $("#dialog_overlay").show(); $("#dialog_overlay").height( $("#enlargement_container").height() ); @@ -994,23 +1032,23 @@ $(document).ready(function () { } ); } - var deletion_buttonset = { - cancel: function() { $( this ).dialog( "close" ); }, - global: function () { delete_relation( true ); }, - delete: function() { delete_relation( false ); } - }; - + // Set up the relationship info display and deletion dialog. $( "#delete-form" ).dialog({ autoOpen: false, height: 135, width: 250, modal: false, + buttons: { + OK: function() { $( this ).dialog( "close" ); }, + "Delete all": function () { delete_relation( true ); }, + Delete: function() { delete_relation( false ); } + }, create: function(event, ui) { // TODO What is this logic doing? // This scales the buttons in the dialog and makes it look proper // Not sure how essential it is, does anything break if it's not here? var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' ); - buttonset.find( "button:contains('Cancel')" ).css( 'float', 'right' ); + buttonset.find( "button:contains('OK')" ).css( 'float', 'right' ); // A: This makes sure that the pop up delete relation dialogue for a hovered over // relation auto closes if the user doesn't engage (mouseover) with it. var dialog_aria = $("div[aria-labelledby='ui-dialog-title-delete-form']"); @@ -1022,22 +1060,21 @@ $(document).ready(function () { }) }, open: function() { + // Show the appropriate buttons... + var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ) + // If the user can't edit, show only the OK button if( !editable ) { - $( this ).dialog( "option", "buttons", - [{ text: "OK", click: deletion_buttonset['cancel'] }] ); + buttonset.find( "button:contains('Delete')" ).hide(); + // If the relationship scope is local, show only OK and Delete } else if( $('#delete_relation_scope').text() === 'local' ) { $( this ).dialog( "option", "width", 160 ); - $( this ).dialog( "option", "buttons", - [{ text: "Delete", click: deletion_buttonset['delete'] }, - { text: "Cancel", click: deletion_buttonset['cancel'] }] ); + buttonset.find( "button:contains('Delete')" ).show(); + buttonset.find( "button:contains('Delete all')" ).hide(); + // Otherwise, show all three } else { $( this ).dialog( "option", "width", 200 ); - $( this ).dialog( "option", "buttons", - [{ text: "Delete", click: deletion_buttonset['delete'] }, - { text: "Delete all", click: deletion_buttonset['global'] }, - { text: "Cancel", click: deletion_buttonset['cancel'] }] ); + buttonset.find( "button:contains('Delete')" ).show(); } - mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 ); }, close: function() {} @@ -1055,10 +1092,10 @@ $(document).ready(function () { var form_values = $('#detach_collated_form').serialize(); ncpath = getTextURL( 'duplicate' ); var jqjson = $.post( ncpath, form_values, function(data) { - detach_node( data ); - $(evt.target).button("enable"); - $( this ).dialog( "close" ); - }); + detach_node( data ); + $(evt.target).button("enable"); + $( "#multipleselect-form" ).dialog( "close" ); + }); } }, create: function(event, ui) {