}
+sub compress :Chained('text') :PathPart :Args(0) {
+ my( $self, $c ) = @_;
+ my $tradition = delete $c->stash->{'tradition'};
+ my $collation = $tradition->collation;
+ my $m = $c->model('Directory');
+
+ my @rids = $c->request->param('readings[]');
+ my @readings;
+
+ foreach my $rid (@rids) {
+ my $rdg = $collation->reading( $rid );
+
+ push @readings, $rdg;
+ }
+
+ my $len = scalar @readings;
+
+ if( $c->request->method eq 'POST' ) {
+ if( $c->stash->{'permission'} ne 'full' ) {
+ $c->response->status( '403' );
+ $c->stash->{'result'} = {
+ 'error' => 'You do not have permission to modify this tradition.' };
+ $c->detach('View::JSON');
+ return;
+ }
+
+ # Sanity check: first save the original text of each witness.
+ my %origtext;
+ foreach my $wit ( $tradition->witnesses ) {
+ $origtext{$wit->sigil} = $collation->path_text( $wit->sigil );
+ if( $wit->is_layered ) {
+ my $acsig = $wit->sigil . $collation->ac_label;
+ $origtext{$acsig} = $collation->path_text( $acsig );
+ }
+ }
+
+ my $first = 0;
+
+ for (my $i = 0; $i < $len; $i++) {
+ my $rdg = $readings[$i];
+
+ if ($rdg->is_combinable) {
+ $first = $i;
+ last;
+ }
+ }
+
+ for (my $i = $first+1; $i < $len; $i++) {
+ my $rdg = $readings[$first];
+ my $next = $readings[$i];
+
+ last unless $next->is_combinable;
+
+ warn "Joining readings $rdg and $next\n";
+
+ $collation->merge_readings( "$rdg", "$next", 1 );
+ }
+
+ # Finally, make sure we haven't screwed anything up.
+ foreach my $wit ( $tradition->witnesses ) {
+ my $pathtext = $collation->path_text( $wit->sigil );
+ throw( "Text differs for witness " . $wit->sigil )
+ unless $pathtext eq $origtext{$wit->sigil};
+ if( $wit->is_layered ) {
+ my $acsig = $wit->sigil . $collation->ac_label;
+ $pathtext = $collation->path_text( $acsig );
+ throw( "Layered text differs for witness " . $wit->sigil )
+ unless $pathtext eq $origtext{$acsig};
+ }
+ }
+
+ $collation->relations->rebuild_equivalence();
+ $collation->calculate_ranks();
+
+ $m->save($collation);
+
+ $c->stash->{'result'} = {};
+ $c->forward('View::JSON');
+ }
+}
+
=head2 merge
POST relation/$textid/merge { data }
var reltypes = {};
var readingdata = {};
var text_direction = 'LR';
+var current_selected = [];
jQuery.removeFromArray = function(value, arr) {
return jQuery.grep(arr, function(elem, index) {
$( jq( source_node_id ) ).remove();
}
+function compress_nodes(readings) {
+ //add text of other readings to 1st reading
+ for (var i = 1; i < readings.length; i++) {
+ var first = get_ellipse(readings[0]);
+ var cur = get_ellipse(readings[i]);
+
+ var first_title = first.parent().find('text')[0];
+ var cur_title = cur.parent().find('text')[0];
+
+ first_title.textContent += " " + cur_title.textContent;
+ };
+
+ //delete all others
+ for (var i = 1; i < readings.length; i++) {
+ var node = get_ellipse(readings[i]);
+ var rid = readings[i-1] + '->' + readings[i];
+
+ //[].slice.call(s.getElementsByTagName('title')).find(function(elem){return elem.textContent=='r64.2->r66.2'}).parentNode.remove()
+
+ console.log(svg_root, svg_root_element);
+
+ console.log(rid);
+
+ [].slice.call(svg_root.getElementsByTagName('title'))
+ .find(function(elem){
+ return elem.textContent==rid
+ }).parentNode.remove();
+
+ node.parent().remove();
+ }
+}
+
function Marquee() {
var self = this;
}
});
if( $('ellipse[fill="#9999ff"]').size() > 0 ) {
+ current_selected = readings;
+
//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 ) );
- });
- $.each( witnesses, function( index, value ) {
+ });
+ $.each( witnesses, function( index, value ) {
$('#detach_collated_form').append(
'<input type="checkbox" name="witnesses[]" value="' + value
+ '">' + value + '<br>' );
});
$('#multiple_selected_readings').attr('value', readings.join(',') );
+
+ if ($('#action-merge')[0].checked) {
+ $('#detach_collated_form').hide();
+ $('#multipleselect-form-text').hide();
+
+ $('#detach_btn').hide();
+ $('#merge_btn').show();
+ } else {
+ $('#detach_collated_form').show();
+ $('#multipleselect-form-text').show();
+
+ $('#detach_btn').show();
+ $('#merge_btn').hide();
+ }
+
+ $('#action-detach').change(function() {
+ if ($('#action-detach')[0].checked) {
+ $('#detach_collated_form').show();
+
+ $('#detach_btn').show();
+ $('#merge_btn').hide();
+ }
+ });
+
+ $('#action-merge').change(function() {
+ if ($('#action-merge')[0].checked) {
+ $('#detach_collated_form').hide();
+
+ $('#detach_btn').hide();
+ $('#merge_btn').show();
+ }
+ });
+
$('#multipleselect-form').dialog( 'open' );
}
self.svg_rect.remove( $('#marquee') );
modal: true,
buttons: {
Cancel: function() { $( this ).dialog( "close" ); },
- Detach: function ( evt ) {
+ Detach: function ( evt ) {
+ evt.target.id = 'detach_btn';
+
var self = $(this);
- var mybuttons = $(evt.target).closest('button').parent().find('button');
- mybuttons.button( 'disable' );
+ var mybuttons = $(evt.target).closest('button').parent().find('button');
+ mybuttons.button( 'disable' );
var form_values = $('#detach_collated_form').serialize();
ncpath = getTextURL( 'duplicate' );
var jqjson = $.post( ncpath, form_values, function(data) {
mybuttons.button("enable");
self.dialog( "close" );
} );
+ },
+ Merge: function (evt) {
+ evt.target.id = 'merge_btn';
+
+ var self = $(this);
+ var mybuttons = $(evt.target).closest('button').parent().find('button');
+ mybuttons.button('disable');
+
+ var ncpath = getTextURL('compress');
+ var form_values = $('#detach_collated_form').serialize();
+
+ var jqjson = $.post(ncpath, form_values, function(data) {
+ compress_nodes(current_selected);
+ current_selected = [];
+
+ mybuttons.button('enable');
+ self.dialog('close');
+ });
}
},
create: function(event, ui) {
$("#dialog_overlay").height( $("#enlargement_container").height() );
$("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
$("#dialog_overlay").offset( $("#enlargement_container").offset() );
+
+ var mybuttons = $(this).parent().find('button');
+
+ mybuttons[1].id = 'detach_btn';
+ mybuttons[2].id = 'merge_btn';
},
close: function() {
marquee.unselect();