diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index a92a6d392..152ea5fa2 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -254,6 +254,11 @@ $self->session->errorHandler->error("Submit Edit Object"); $self->session->errorHandler->error("Deleting ".join(',',@address)); return $self->deleteObject(\@address); } + elsif($responses->{copy}){ +$self->session->errorHandler->error("Copying ".join(',',@address)); + return $self->copyObject(\@address); + } + $self->session->errorHandler->error("Updating ".join(',',@address)); #each object checks the ref and then either updates or passes it to the correct child. New objects will have an index of -1. my $message = $self->survey->update(\@address,$responses); @@ -263,6 +268,19 @@ $self->session->errorHandler->error("Updating ".join(',',@address)); return $self->www_loadSurvey({address => \@address}); } +#------------------------------------------------------------------- +sub copyObject{ + my ($self,$address) = @_; + + $self->loadSurveyJSON(); + + $address = $self->survey->copy($address);#each object checks the ref and then either updates or passes it to the correct child. New objects will have an index of -1. + + $self->saveSurveyJSON(); + #The parent address of the deleted object is returned. + + return $self->www_loadSurvey({address => $address}); +} #------------------------------------------------------------------- sub deleteObject{ @@ -274,7 +292,12 @@ sub deleteObject{ $self->saveSurveyJSON(); #The parent address of the deleted object is returned. - pop(@{$address}) unless @$address == 1 and $$address[0] == 0; + if(@$address == 1){ + $$address[0] = 0; + }else{ + pop(@{$address});# unless @$address == 1 and $$address[0] == 0; + } +$self->session->errorHandler->error("returning ".join(',',@$address)); return $self->www_loadSurvey({address => $address, message=>$message}); } diff --git a/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm b/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm index c7d56673c..5d3ee40b9 100644 --- a/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm +++ b/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm @@ -178,6 +178,8 @@ sub update{ $object->{$key} = $ref->{$key} if(defined $$ref{$key}); } } + + #determine what to add and add it. # ref should contain all the information for the new sub insertObject{ @@ -193,6 +195,25 @@ $self->log("Inserting ".join(',',@$address)); $self->log("Finished inserting "); } + +sub copy{ + my ($self,$address) = @_; + if(@$address == 1){ + my %newSection = %{$self->section($address)}; + push(@{$self->sections}, \%newSection); + return [$#{$self->sections}]; +$self->log("copying here $$address[0] :".$#{$self->sections}); + }elsif(@$address == 2){ +$self->log("copying question $$address[0] $$address[1]"); + my %newQuestion = %{$self->question($address)}; + push( @{$self->questions($address)}, \%newQuestion); + $$address[1] = $#{$self->questions($address)}; +$self->log("to $$address[0] $$address[1]"); + return $address; + } +} + + sub remove{ my ($self,$address,$movingOverride) = @_; if(@$address == 1){ diff --git a/survey_templates.wgpkg b/survey_templates.wgpkg index d6a776e96..ee9fbb6ae 100644 Binary files a/survey_templates.wgpkg and b/survey_templates.wgpkg differ diff --git a/www/extras/wobject/Survey/editsurvey/object.js b/www/extras/wobject/Survey/editsurvey/object.js index 7c7090178..cf67d07d1 100644 --- a/www/extras/wobject/Survey/editsurvey/object.js +++ b/www/extras/wobject/Survey/editsurvey/object.js @@ -8,8 +8,11 @@ Survey.ObjectTemplate = new function(){ document.getElementById('edit').innerHTML = html; - var butts = [ { text:"Submit", handler:function(){this.submit();}, isDefault:true }, { text:"Cancel", handler:function(){this.cancel();}}, - {text:"Delete", handler:function(){document.getElementById('delete').value = 1; this.submit();}} + var butts = [ + { text:"Submit", handler:function(){this.submit();}, isDefault:true }, + { text:"Copy", handler:function(){document.getElementById('copy').value = 1; this.submit();}}, + { text:"Cancel", handler:function(){this.cancel();}}, + { text:"Delete", handler:function(){document.getElementById('delete').value = 1; this.submit();}} ]; var form = new YAHOO.widget.Dialog(type,