X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=root%2Fjs%2Frelationship.js;h=0f5ae0994fe1d59355ba11bea42fb321272c525c;hb=48156ccde369b0fbd72c5efb322e2f6e04f5444b;hp=0b0b959ac32dd89537b6600c088a3637cd1e2a2d;hpb=fdb375813058a9ce84302986d594f4f08cc9f291;p=scpubgit%2Fstemmaweb.git
diff --git a/root/js/relationship.js b/root/js/relationship.js
index 0b0b959..0f5ae09 100644
--- a/root/js/relationship.js
+++ b/root/js/relationship.js
@@ -5,6 +5,12 @@ var start_element_height = 0;
var reltypes = {};
var readingdata = {};
+jQuery.removeFromArray = function(value, arr) {
+ return jQuery.grep(arr, function(elem, index) {
+ return elem !== value;
+ });
+};
+
function arrayUnique(array) {
var a = array.concat();
for(var i=0; i
' );
+ '' + value + '
' );
});
- $('#multiple_selected_readings').attr('value', readings.join(',') );
+ $('#multiple_selected_readings').attr('value', readings.join(',') );
$('#multipleselect-form').dialog( 'open' );
}
self.svg_rect.remove( $('#marquee') );
@@ -735,6 +947,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 () {
@@ -742,7 +969,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)
@@ -807,23 +1035,37 @@ $(document).ready(function () {
});
+ // Set up the relationship creation dialog. This also functions as the reading
+ // merge dialog where appropriate.
+
if( editable ) {
- $( "#dialog-form" ).dialog({
+ $( '#dialog-form' ).dialog( {
autoOpen: false,
height: 270,
width: 290,
modal: true,
buttons: {
- "Ok": function( evt ) {
- $(evt.target).button("disable");
- $('#status').empty();
- form_values = $('#collapse_node_form').serialize();
+ '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 ) {
+ merge_nodes( $( '#source_node_id' ).val(), $( '#target_node_id' ).val(), data );
+ $(evt.target).button( 'enable' );
+ $( '#dialog-form' ).dialog( 'close' );
+ } );
+ },
+ OK: function( evt ) {
+ $( evt.target ).button( 'disable' );
+ $( '#status' ).empty();
+ form_values = $( '#collapse_node_form' ).serialize();
ncpath = getTextURL( 'relationships' );
- var jqjson = $.post( ncpath, form_values, function(data) {
- $.each( data, function(item, source_target) {
+ var jqjson = $.post( ncpath, form_values, function( data ) {
+ $.each( data, function( item, source_target ) {
var source_found = get_ellipse( source_target[0] );
var target_found = get_ellipse( source_target[1] );
- var relation_found = $.inArray( source_target[2], $('#keymap').data('relations') );
+ var relation_found = $.inArray( source_target[2], $( '#keymap' ).data( 'relations' ) );
if( source_found.size() && target_found.size() && relation_found > -1 ) {
var relation = relation_manager.create( source_target[0], source_target[1], relation_found );
relation.data( 'type', source_target[2] );
@@ -831,13 +1073,13 @@ $(document).ready(function () {
relation.data( 'note', $('#note').val() );
relation_manager.toggle_active( relation.attr('id') );
}
- $(evt.target).button("enable");
+ $(evt.target).button( 'enable' );
});
- $( "#dialog-form" ).dialog( "close" );
+ $( '#dialog-form' ).dialog( 'close' );
}, 'json' );
},
Cancel: function() {
- $( this ).dialog( "close" );
+ $( this ).dialog( 'close' );
}
},
create: function(event, ui) {
@@ -859,7 +1101,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() );
@@ -892,23 +1142,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']");
@@ -920,22 +1170,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() {}
@@ -947,18 +1196,18 @@ $(document).ready(function () {
width: 250,
modal: true,
buttons: {
- Cancel: function() { $( this ).dialog( "close" ); },
- Detach: function ( evt ) {
- $(evt.target).button("disable");
- var form_values = $('#detach_collated_form').serialize();
- ncpath = getTextURL( 'duplicate' );
- var jqjson = $.post( ncpath, form_values, function(data) {
- $.each( data, function(reading, newreading) {
- alert( "Would detach reading " + newreading['id'] + " from " + reading );
- });
- $(evt.target).button("enable");
- });
- }
+ Cancel: function() { $( this ).dialog( "close" ); },
+ Detach: function ( evt ) {
+ var self = $(this);
+ $( evt.target ).button( "disable" );
+ 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");
+ self.dialog( "close" );
+ } );
+ }
},
create: function(event, ui) {
var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' );
@@ -978,23 +1227,23 @@ $(document).ready(function () {
$("#dialog_overlay").hide();
}
}).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
- if( ajaxSettings.url == getTextURL('duplicate')
- && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
- var error;
- if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) {
- error = 'You are not authorized to modify this tradition. (Try logging in again?)';
- } else {
- try {
- var errobj = jQuery.parseJSON( jqXHR.responseText );
- error = errobj.error + 'The relationship cannot be made.
Error: ' + error ); - } - $(event.target).parent().find('.ui-button').button("enable"); - }); + if( ajaxSettings.url == getTextURL('duplicate') + && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) { + var error; + if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) { + error = 'You are not authorized to modify this tradition. (Try logging in again?)'; + } else { + try { + var errobj = jQuery.parseJSON( jqXHR.responseText ); + error = errobj.error + 'The relationship cannot be made.
'; + } catch(e) { + error = jqXHR.responseText; + } + } + $('#multipleselect-form-status').append( 'Error: ' + error ); + } + $(event.target).parent().find('.ui-button').button("enable"); + }); // Helpers for relationship deletion