--- /dev/null
+function edges_of( ellipse ) {
+ var edges = new Array();
+ var node_id = ellipse.parent().attr('id');
+ var edge_in_pattern = new RegExp( node_id + '$' );
+ $.each( $('#svgenlargement .edge'), function(index) {
+ title = $(this).children('title').text();
+ if( title.search( node_id ) > -1 ) {
+ var edge = new Edge( $(this) );
+ edge.node_id = node_id;
+ if( edge_in_pattern.test(title) ) {
+ edge.is_incoming = true;
+ }
+ edges.push( edge );
+ }
+ } );
+ return edges;
+}
+
+function Edge( g_elem ) {
+
+ var self = this;
+
+ this.g_elem = g_elem;
+ this.witnesses = g_elem.children('text').text().split( /,\s*/ );
+ this.is_incoming = false;
+
+ this.detach_witnesses = function( witnesses_to_detach ) {
+ var detached = [];
+ var left = '';
+ var clone = null;
+ $.each( witnesses_to_detach, function( index, witness_to_detach ) {
+ witness_index = self.witnesses.indexOf( witness_to_detach );
+ if( witness_index > -1 ) {
+ self.witnesses.splice( witness_index, 1 );
+ detached.push( witness_to_detach );
+ }
+ } );
+ if( detached != '' ) {
+ clone = self.clone_for( detached );
+ }
+ var remaining = self.create_label( self.witnesses );
+ if( remaining == '' ) {
+ self.g_elem.remove();
+ } else {
+ self.g_elem.children('text').text( remaining );
+ }
+ return clone;
+ }
+
+ this.get_label = function() {
+ return self.g_elem.children('text').text();
+ }
+
+ this.create_label = function( witnesses ) {
+ var label = '';
+ $.each( witnesses, function( index, witness ) {
+ label = label + witness + ', ';
+ } );
+ label = label.replace( /, $/, '' );
+ return label;
+ }
+
+ this.clone_for = function( witnesses ) {
+ var label = self.create_label( witnesses );
+ var clone = g_elem.clone();
+ clone.children('text').text( label );
+ clone = new Edge( clone );
+ clone.is_incoming = self.is_incoming;
+ return clone;
+ }
+
+ this.attach = function( node_id_maybe ) {
+ //update title
+ return null;
+ }
+
+}
} );
} );
- // Todo: .each is getting us in trouble most likely
- // assuming one element in object readings for now
+ // Todo: .each is getting us in trouble most likely for
+ // duplicating edges in a strand that both are incoming and outgoing
+ // like b and c in -i-> a -ii-> b -iii-> c -iv->
detached_edges = [];
+
+ // here we detach witnesses from the existing edges accoring to what's being relayed by readings
$.each( readings, function( node_id, reading ) {
var edges = edges_of( get_ellipse( reading.orig_rdg ) );
incoming_remaining = [];
} );
}
} );
+
+ // After detachng we still need to check if for *all* readings
+ // an edge was detached. It may be that a witness was not
+ // explicitly named on an edge but was part of a 'majority' edge
+ // in which case we need to duplicate and name that edge after those
+ // remaining witnesses.
if( outgoing_remaining.length > 0 ) {
- console.log( 'jo' );
$.each( edges, function( index, edge ) {
- console.log( edge.get_label() );
if( edge.get_label() == 'majority' && !edge.is_incoming ) {
detached_edges.push( edge.clone_for( outgoing_remaining ) );
}
} );
}
if( incoming_remaining.length > 0 ) {
- console.log( 'je' );
$.each( edges, function( index, edge ) {
if( edge.get_label() == 'majority' && edge.is_incoming ) {
detached_edges.push( edge.clone_for( outgoing_remaining ) );
}
} );
}
- console.log( detached_edges );
} );
+ console.log( detached_edges );
//if not all witnesses of reading are detached in and out clone
// clone remaining from 'majority in'
//clone node with node_id
// in all clones replace reading.orig_rdg with node_id
// move cloned node up 20px
-
}
var cx_max = p.matrixTransform(tf).x;
var cy_max = p.matrixTransform(tf).y;
//select any node with its center inside the marquee
- var readings = [];
//also merge witness sets from nodes
var witnesses = [];
$('#svgenlargement ellipse').each( function( index ) {
if( cy > cy_min && cy < cy_max) {
// we actually heve no real 'selected' state for nodes, except coloring
$(this).attr( 'fill', '#9999ff' );
- // Take note of the selected reading(s) and applicable witness(es)
- // so we can populate the multipleselect-form
- readings.push( $(this).parent().attr('id') );
var this_witnesses = $(this).data( 'node_obj' ).get_witnesses();
witnesses = arrayUnique( witnesses.concat( this_witnesses ) );
}
}
});
if( $('ellipse[fill="#9999ff"]').size() > 0 ) {
- //add intersection of witnesses sets to the multi select form and open it
- $('#detach_collated_form').empty();
- $.each( readings, function( index, value ) {
- $('#detach_collated_form').append( $('<input>').attr(
- "type", "hidden").attr("name", "readings[]").attr(
- "value", value ) );
- });
+ //add interesectio of witnesses sets to the multi select form and open it
$.each( witnesses, function( index, value ) {
- $('#detach_collated_form').append(
- '<input type="checkbox" name="witnesses[]" value="' + value
- + '">' + value + '<br>' );
+ $('#multipleselect-form').append( '<input type="checkbox" name="witnesses" value="' + value + '">' + value + '<br>' );
});
- $('#multiple_selected_readings').attr('value', readings.join(',') );
$('#multipleselect-form').dialog( 'open' );
}
self.svg_rect.remove( $('#marquee') );
close: function() {}
});
+ var multipleselect_buttonset = {
+ cancel: function() { $( this ).dialog( "close" ); },
+ button1: function () { },
+ button2: function() { }
+ };
+
$( "#multipleselect-form" ).dialog({
autoOpen: false,
height: 150,
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");
- });
- }
- },
create: function(event, ui) {
var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' );
buttonset.find( "button:contains('Cancel')" ).css( 'float', 'right' );
},
open: function() {
$( this ).dialog( "option", "width", 200 );
+ $( this ).dialog( "option", "buttons",
+ [{ text: "Button_1", click: multipleselect_buttonset['button1'] },
+ { text: "Button_2", click: multipleselect_buttonset['button2'] },
+ { text: "Cancel", click: multipleselect_buttonset['cancel'] }] );
$(".ui-widget-overlay").css("background", "none");
- $('#multipleselect-form-status').empty();
$("#dialog_overlay").show();
$("#dialog_overlay").height( $("#enlargement_container").height() );
$("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
marquee.unselect();
$("#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 + '</br>The relationship cannot be made.</p>';
- } catch(e) {
- error = jqXHR.responseText;
- }
- }
- $('#multipleselect-form-status').append( '<p class="error">Error: ' + error );
- }
- $(event.target).parent().find('.ui-button').button("enable");
- });
-
+ });
// Helpers for relationship deletion