From: Tara L Andrews Date: Tue, 11 Jun 2013 08:28:31 +0000 (+0200) Subject: make global deletion optional. Fixes #4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=088a14af970747f494c39cdb47dfad73e757a843;p=scpubgit%2Fstemmaweb.git make global deletion optional. Fixes #4 --- diff --git a/lib/stemmaweb/Controller/Relation.pm b/lib/stemmaweb/Controller/Relation.pm index 71f80ac..e59cd7e 100644 --- a/lib/stemmaweb/Controller/Relation.pm +++ b/lib/stemmaweb/Controller/Relation.pm @@ -236,9 +236,10 @@ sub relationships :Chained('text') :PathPart :Args(0) { } elsif( $c->request->method eq 'DELETE' ) { my $node = $c->request->param('source_id'); my $target = $c->request->param('target_id'); - + my $scopewide = $c->request->param('scopewide') + && $c->request->param('scopewide') eq 'true'; try { - my @vectors = $collation->del_relationship( $node, $target ); + my @vectors = $collation->del_relationship( $node, $target, $scopewide ); $m->save( $tradition ); $c->stash->{'result'} = \@vectors; } catch( Text::Tradition::Error $e ) { diff --git a/root/js/relationship.js b/root/js/relationship.js index 6e4295b..1286ea9 100644 --- a/root/js/relationship.js +++ b/root/js/relationship.js @@ -521,11 +521,11 @@ function relation_factory() { } } this.showinfo = function(relation) { - var htmlstr = 'type: ' + relation.data( 'type' ) + '
scope: ' + relation.data( 'scope' ); + $('#delete_relation_type').text( relation.data('type') ); + $('#delete_relation_scope').text( relation.data('scope') ); if( relation.data( 'note' ) ) { - htmlstr = htmlstr + '
note: ' + relation.data( 'note' ); + $('#delete_relation_note').text('note: ' + relation.data( 'note' ) ); } - $('#delete-form-text').html( htmlstr ); var points = relation.children('path').attr('d').slice(1).replace('C',' ').split(' '); var xs = parseFloat( points[0].split(',')[0] ); var xe = parseFloat( points[1].split(',')[0] ); @@ -732,33 +732,17 @@ $(document).ready(function () { } ); } + var deletion_buttonset = { + cancel: function() { $( this ).dialog( "close" ); }, + global: function () { delete_relation( true ); }, + delete: function() { delete_relation( false ); } + }; $( "#delete-form" ).dialog({ autoOpen: false, height: 135, - width: 160, + width: 250, modal: false, - buttons: { - Cancel: function() { - $( this ).dialog( "close" ); - }, - Delete: function() { - form_values = $('#delete_relation_form').serialize(); - ncpath = getTextURL( 'relationships' ); - var jqjson = $.ajax({ url: ncpath, data: form_values, success: function(data) { - $.each( data, function(item, source_target) { - relation_manager.remove( get_relation_id( source_target[0], source_target[1] ) ); - }); - $( "#delete-form" ).dialog( "close" ); - }, dataType: 'json', type: 'DELETE' }); - } - }, create: function(event, ui) { - // Swap out the buttons if we are in readonly mode - if( !editable ) { - $( this ).dialog( "option", "buttons", - [{ text: "OK", click: function() { $( this ).dialog( "close" ); }}] ); - } - // TODO What is this logic doing? var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' ); buttonset.find( "button:contains('Cancel')" ).css( 'float', 'right' ); @@ -771,12 +755,53 @@ $(document).ready(function () { }) }, open: function() { + if( !editable ) { + $( this ).dialog( "option", "buttons", + [{ text: "OK", click: deletion_buttonset['cancel'] }] ); + } 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'] }] ); + } 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'] }] ); + } + mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 ); }, - close: function() { - } + close: function() {} }); + // Helpers for relationship deletion + + function delete_relation( scopewide ) { + form_values = $('#delete_relation_form').serialize(); + if( scopewide ) { + form_values += "&scopewide=true"; + } + ncpath = getTextURL( 'relationships' ); + var jqjson = $.ajax({ url: ncpath, data: form_values, success: function(data) { + $.each( data, function(item, source_target) { + relation_manager.remove( get_relation_id( source_target[0], source_target[1] ) ); + }); + $( "#delete-form" ).dialog( "close" ); + }, dataType: 'json', type: 'DELETE' }); + } + + function toggle_relation_active( node_id ) { + $('#svgenlargement .relation').find( "title:contains('" + node_id + "')" ).each( function(index) { + matchid = new RegExp( "^" + node_id ); + if( $(this).text().match( matchid ) != null ) { + var relation_id = $(this).parent().attr('id'); + relation_manager.toggle_active( relation_id ); + }; + }); + } + // function for reading form dialog should go here; // just hide the element for now if we don't have morphology if( can_morphologize ) { @@ -936,17 +961,6 @@ $(document).ready(function () { scrollbars:1 }); - - function toggle_relation_active( node_id ) { - $('#svgenlargement .relation').find( "title:contains('" + node_id + "')" ).each( function(index) { - matchid = new RegExp( "^" + node_id ); - if( $(this).text().match( matchid ) != null ) { - var relation_id = $(this).parent().attr('id'); - relation_manager.toggle_active( relation_id ); - }; - }); - } - expandFillPageClients(); $(window).resize(function() { expandFillPageClients(); diff --git a/root/src/relate.tt b/root/src/relate.tt index a3fe4af..fe053ff 100644 --- a/root/src/relate.tt +++ b/root/src/relate.tt @@ -84,7 +84,9 @@ $(document).ready(function () { -
+
Type:
+ Scope:
+