From a350398f412e2bd1ff3b2fab4acc5ec16fac1484 Mon Sep 17 00:00:00 2001 From: Kaleb Murphy Date: Fri, 13 Feb 2009 18:28:52 +0000 Subject: [PATCH] Logic is corrected, but the JS should probably be rewritten to be more like the WG PageLayout drag and drop so that it isn't so finicky. --- lib/WebGUI/Asset/Wobject/Survey.pm | 14 ++++++++++---- lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm | 3 +-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index 5fc41586d..a8b4ac4e8 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -673,6 +673,10 @@ sub www_dragDrop { #sections can only be inserted after another section so chop off the question and answer portion of $#bid = 0; $bid[0] = -1 if ( !defined $bid[0] ); + + #If target is being moved down, then before has just moved up do to the target being deleted + $bid[0]-- if($tid[0] < $bid[0]); + $self->surveyJSON->insertObject( $target, [ $bid[0] ] ); } elsif ( @tid == 2 ) { #questions can be moved to any section, but a pushed to the end of a new section. @@ -686,28 +690,30 @@ sub www_dragDrop { $bid[1] = $tid[1]; } if ( $bid[0] == $tid[0] ) { - #moved to top of current section $bid[1] = -1; } else { - #else move to the end of the selected section $bid[1] = $#{ $self->surveyJSON->questions( [ $bid[0] ] ) }; } } ## end elsif ( @bid == 1 ) + else{ #Moved within the same section + $bid[1]-- if($tid[1] < $bid[1]); + } $self->surveyJSON->insertObject( $target, [ $bid[0], $bid[1] ] ); } ## end elsif ( @tid == 2 ) elsif ( @tid == 3 ) { #answers can only be rearranged in the same question - if ( @bid == 2 and $bid[1] == $tid[1] ) { + if ( @bid == 2 and $bid[1] == $tid[1] ) {#moved to the top of the question $bid[2] = -1; $self->surveyJSON->insertObject( $target, [ $bid[0], $bid[1], $bid[2] ] ); } elsif ( @bid == 3 ) { + #If target is being moved down, then before has just moved up do to the target being deleted + $bid[2]-- if($tid[2] < $bid[2]); $self->surveyJSON->insertObject( $target, [ $bid[0], $bid[1], $bid[2] ] ); } else { - #else put it back where it was $self->surveyJSON->insertObject( $target, \@tid ); } diff --git a/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm b/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm index 92aff4a41..3db23b48a 100644 --- a/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm +++ b/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm @@ -655,12 +655,11 @@ sub insertObject { # Figure out what to do by counting the number of elements in the $address array ref my $count = @{$address}; - return if !$count; # Use splice to rearrange the relevant array of objects.. if ( $count == 1 ) { - splice @{ $self->sections($address) }, sIndex($address) + 1, 0, $object; + splice @{ $self->sections($address) }, sIndex($address) +1, 0, $object; } elsif ( $count == 2 ) { splice @{ $self->questions($address) }, qIndex($address) + 1, 0, $object;