You can now copy sections and questions. And if I correctly understand how to bundle asset packages, all the new template changes are included.

This commit is contained in:
Kaleb Murphy 2008-10-20 16:17:25 +00:00
parent 5b8a1df90e
commit 5afae6de85
4 changed files with 50 additions and 3 deletions

View file

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

View file

@ -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){

Binary file not shown.

View file

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