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.

This commit is contained in:
Kaleb Murphy 2009-02-13 18:28:52 +00:00
parent 34340e56fb
commit a350398f41
2 changed files with 11 additions and 6 deletions

View file

@ -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 );
}

View file

@ -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;