Moving edit screens to be template based for i18n (almost done with editor.
This commit is contained in:
parent
e81accaa15
commit
38c7ee33c4
8 changed files with 142 additions and 153 deletions
|
|
@ -169,6 +169,7 @@ $self->session->errorHandler->error("LOADING\n".Dumper $jsonHash."\n\n");
|
|||
$hashRef = decode_json($jsonHash) if defined $jsonHash;
|
||||
|
||||
$self->{_data} = WebGUI::Asset::Wobject::Survey::SurveyJSON->new($hashRef);#,$self->session->errorHandler);
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -181,13 +182,20 @@ Saves the survey collateral to the DB
|
|||
|
||||
sub saveSurveyJSON{
|
||||
my $self = shift;
|
||||
# $self->{_data}->{log} = $self->session->errorHandler;
|
||||
|
||||
my $data = $self->{_data}->freeze();
|
||||
$self->{_data}->{log} = $self->session->errorHandler;
|
||||
my $data;
|
||||
$self->session->errorHandler->error("Calling Freeze");
|
||||
$self->session->errorHandler->error("data type = ".ref $self->{_data});
|
||||
eval{
|
||||
$data = $self->{_data}->freeze();
|
||||
};
|
||||
$self->session->errorHandler->error("Freeze error".$@);
|
||||
$self->session->errorHandler->error("data type = ".ref $data);
|
||||
|
||||
|
||||
use Data::Dumper;
|
||||
$self->session->errorHandler->error(Dumper $data);
|
||||
$self->session->errorHandler->error("Log defined:".defined $data->{log});
|
||||
#$self->session->errorHandler->error(Dumper $data);
|
||||
|
||||
eval{
|
||||
$self->session->errorHandler->error(join(',',keys %{$data}));
|
||||
|
|
@ -392,11 +400,94 @@ $self->session->errorHandler->error("The object isa\n".Dumper $object);
|
|||
$self->session->errorHandler->error(1);
|
||||
|
||||
my @data;
|
||||
my %buttons;
|
||||
$self->{_data}->getDragDropList($address,\@data,$self->session->errorHandler);
|
||||
$self->session->errorHandler->error("In Survey".Dumper @data);
|
||||
my $html;
|
||||
my ($scount,$qcount,$acount) = (0,0,0);
|
||||
my $lastType;
|
||||
my %lastId;
|
||||
my @ids;
|
||||
my ($s,$q,$a) = (0,0,0);#bools on if a button has already been created
|
||||
|
||||
my $return = {"address",$address,"data",\@data,"object",$object};
|
||||
$self->session->errorHandler->warn(encode_json($return));
|
||||
foreach (@data){
|
||||
if($_->{type} eq 'section'){
|
||||
if($lastType eq 'answer'){
|
||||
$html .= "<span id='newAnswer'></span><br>";
|
||||
$buttons{answer} = "$lastId{section}-$lastId{question}";
|
||||
$a = 1;
|
||||
}
|
||||
elsif($lastType eq 'question'){
|
||||
$html .= "<span id='newQuestion'></span><br>";
|
||||
$buttons{'question'} = "$lastId{section}-$lastId{question}";
|
||||
$q = 1;
|
||||
}
|
||||
$html .= "<li id='$scount' class='section'>S". ($scount + 1). ": $_->{text}<\/li><br>\n";
|
||||
push(@ids,$scount);
|
||||
$lastId{section} = $scount++;
|
||||
$lastType = 'section';
|
||||
}
|
||||
elsif($_->{type} eq 'question'){
|
||||
if($lastType eq 'answer'){
|
||||
$html .= "<span id='newAnswer'></span><br>";
|
||||
$buttons{answer} = "$lastId{section}-$lastId{question}";
|
||||
$a = 1;
|
||||
}
|
||||
$html .= "<li id='$scount-$qcount' class='question'>Q". ($qcount + 1). ": $_->{text}<\/li><br>\n";
|
||||
push(@ids,$qcount);
|
||||
$lastId{question} = $qcount++;
|
||||
$lastType = 'question';
|
||||
}
|
||||
elsif($_->{type} eq 'answer'){
|
||||
$html .= "<li id='$scount-$qcount-$acount' class='answer'>A". ($acount + 1). ": $_->{text}<\/li><br>\n";
|
||||
push(@ids,$acount);
|
||||
$lastId{answer} = $acount++;
|
||||
$lastType = 'answer';
|
||||
}
|
||||
}
|
||||
if($lastType eq 'answer'){
|
||||
if(!$a){
|
||||
$html .= "<span id='newAnswer'></span><br>";
|
||||
$buttons{'answer'} = "$lastId{section}-$lastId{question}";
|
||||
}
|
||||
if(!$b){
|
||||
$html .= "<span id='newQuestion'></span><br>";
|
||||
$buttons{'question'} = "$lastId{section}-$lastId{question}";
|
||||
}
|
||||
if(!$s){
|
||||
$html .= "<span id='newSection'></span><br>";
|
||||
$buttons{'section'} = "$lastId{section}";
|
||||
}
|
||||
}
|
||||
elsif($lastType eq 'question'){
|
||||
if(!$b){
|
||||
$html .= "<span id='newQuestion'></span><br>";
|
||||
$buttons{'question'} = "$lastId{section}-$lastId{question}";
|
||||
}
|
||||
if(!$s){
|
||||
$html .= "<span id='newSection'></span><br>";
|
||||
$buttons{'section'} = "$lastId{section}";
|
||||
}
|
||||
}
|
||||
elsif($lastType eq 'section'){
|
||||
if(!$b){
|
||||
$html .= "<span id='newQuestion'></span><br>";
|
||||
$buttons{'question'} = "$lastId{section}-$lastId{question}";
|
||||
}
|
||||
if(!$s){
|
||||
$html .= "<span id='newSection'></span><br>";
|
||||
$buttons{'section'} = "$lastId{section}";
|
||||
}
|
||||
}
|
||||
#my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
|
||||
$self->session->errorHandler->error($html);
|
||||
|
||||
#address is the address of the focused object
|
||||
#buttons are the data to create the Add buttons
|
||||
#object is the data to create the edited object
|
||||
#ddhtml is the html to create the draggable html divs
|
||||
#ids is a list of all ids passed in which are draggable (for adding events)
|
||||
my $return = {"address",$address,"buttons",\%buttons,"object",$object,"ddhtml",$html,"ids",\@ids};
|
||||
$self->session->errorHandler->error(encode_json($return));
|
||||
$self->session->errorHandler->error(3);
|
||||
return encode_json($return);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ use Data::Structure::Util qw/unbless/;
|
|||
|
||||
sub new{
|
||||
my $class = shift;
|
||||
my $parent = shift;
|
||||
my $self = shift || {};
|
||||
my $parent = shift;
|
||||
$self->{answers} = $self->{answers} || [];
|
||||
$self->{text};
|
||||
$self->{index};
|
||||
|
|
@ -24,6 +24,7 @@ sub new{
|
|||
$self->{value};
|
||||
$self->{terminal};
|
||||
$self->{terminalUrl};
|
||||
$self->{type} = 'answer';
|
||||
bless($self,$class);
|
||||
return $self;
|
||||
}
|
||||
|
|
@ -50,6 +51,6 @@ sub freeze{
|
|||
#data is the array of hash items for displaying
|
||||
sub getDragDropList{
|
||||
my ($self,$data,$address,$selected) = @_;
|
||||
push(@$data, { "type","answer","text",$self->{"text"}, "recorded", $self->{'recordedAnswer'} });
|
||||
push(@$data, { "type",$self->{type},"text",$self->{"text"}, "recorded", $self->{'recordedAnswer'} });
|
||||
}
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ sub new{
|
|||
$self->{textInButton};
|
||||
$self->{terminal};
|
||||
$self->{terminalUrl};
|
||||
$self->{type} = 'question';
|
||||
bless($self,$class);
|
||||
return $self;
|
||||
}
|
||||
|
|
@ -45,7 +46,7 @@ sub update{
|
|||
}
|
||||
#is a new answer
|
||||
}elsif($$ref{ids}->[2] eq 'NEW'){
|
||||
push(@{$self->{answers}}, WebGUI::Assest::Wobject::Survey::AnswerJSON->new( $self,@{$self->{object}}) );
|
||||
push(@{$self->{answers}}, WebGUI::Assest::Wobject::Survey::AnswerJSON->new( @{$self->{object}}) );
|
||||
#is updating a answer
|
||||
}else{
|
||||
$self->{answers}->[$$ref{ids}->[2]]->update($ref);
|
||||
|
|
@ -90,7 +91,7 @@ sub freeze{
|
|||
#data is the array of hash items for displaying
|
||||
sub getDragDropList{
|
||||
my ($self,$data,$address,$selected) = @_;
|
||||
push(@$data, { "type","question","text",$self->{text} });
|
||||
push(@$data, { "type",$self->{type},"text",$self->{text} });
|
||||
if($selected){
|
||||
for (@{$self->{answers}}){
|
||||
$_->getDragDropList($data, $address);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ sub new{
|
|||
$self->{terminalUrl};
|
||||
$self->{goto};
|
||||
$self->{timeLimit};
|
||||
$self->{type} = 'section';
|
||||
|
||||
bless($self,$class);
|
||||
return $self;
|
||||
|
|
@ -91,7 +92,7 @@ sub deleteQuestion{
|
|||
#data is the array of hash items for displaying
|
||||
sub getDragDropList{
|
||||
my ($self,$data,$address,$selected) = @_;
|
||||
push(@$data,{ "type","section","text",$self->{"title"} });
|
||||
push(@$data,{ "type",$self->{type},"text",$self->{"title"} });
|
||||
if($selected){
|
||||
for(my $i=0; $i<=$#{$self->{questions}}; $i++){
|
||||
$self->{questions}->[$i]->getDragDropList($data, $address, $i == $address->[1]);
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ sub update{
|
|||
if(ref $$ref{ids} eq 'ARRAY' and $$ref{ids}->[0] ne 'NEW'){
|
||||
$self->{sections}->[$$ref{ids}->[0]]->update($ref);
|
||||
}else{
|
||||
push(@{$self->{sections}}, WebGUI::Asset::Wobject::Survey::SectionJSON->new($self,$ref->{object}));
|
||||
push(@{$self->{sections}}, WebGUI::Asset::Wobject::Survey::SectionJSON->new($ref->{object}));
|
||||
}
|
||||
}
|
||||
#determine what to add and add it.
|
||||
|
|
@ -77,16 +77,15 @@ sub createTemp{
|
|||
return WebGUI::Asset::Wobject::Survey::SectionJSON->new($self);
|
||||
}
|
||||
}
|
||||
|
||||
sub freeze{
|
||||
my $self = shift;
|
||||
my ($self) = @_;
|
||||
my %temp = %{$self};
|
||||
$temp{sections} = [];
|
||||
$temp{PPPPPPPOOOOOOOOOOOOOOOOPPPPPPPPPPPP} = 1;
|
||||
delete $temp{log};
|
||||
foreach (@{$self->{sections}}){
|
||||
# push(@{$temp{sections}},$_->freeze());
|
||||
push(@{$temp{sections}},$_->freeze());
|
||||
}
|
||||
$self->{log}->error(Dumper %temp);
|
||||
return \%temp;
|
||||
}
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue