Editor is done except for prettifying it, but you can now build a survey with the new data layer
This commit is contained in:
parent
9c5082f450
commit
2de1d83d65
4 changed files with 73 additions and 62 deletions
|
|
@ -110,10 +110,17 @@ sub definition {
|
||||||
questionEditTemplateId => {
|
questionEditTemplateId => {
|
||||||
tab => 'display',
|
tab => 'display',
|
||||||
fieldType => 'template',
|
fieldType => 'template',
|
||||||
label => "Section Edit Tempalte",
|
label => "Question Edit Tempalte",
|
||||||
defaultValue => 'wAc4azJViVTpo-2NYOXWvg',
|
defaultValue => 'wAc4azJViVTpo-2NYOXWvg',
|
||||||
namespace => 'Survey/Edit',
|
namespace => 'Survey/Edit',
|
||||||
},
|
},
|
||||||
|
answerEditTemplateId => {
|
||||||
|
tab => 'display',
|
||||||
|
fieldType => 'template',
|
||||||
|
label => "Answer Edit Tempalte",
|
||||||
|
defaultValue => 'AjhlNO3wZvN5k4i4qioWcg',
|
||||||
|
namespace => 'Survey/Edit',
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
push(@{$definition}, {
|
push(@{$definition}, {
|
||||||
|
|
@ -183,10 +190,12 @@ sub loadSurveyJSON{
|
||||||
my $jsonHash = $self->session->db->quickScalar("select surveyJSON from Survey where assetId = ?",[$self->getId]);
|
my $jsonHash = $self->session->db->quickScalar("select surveyJSON from Survey where assetId = ?",[$self->getId]);
|
||||||
|
|
||||||
$self->session->errorHandler->error("LOADING JSON");
|
$self->session->errorHandler->error("LOADING JSON");
|
||||||
|
eval{
|
||||||
$self->{jsonHelper} = WebGUI::Asset::Wobject::Survey::SurveyJSON->new($jsonHash,$self->session->errorHandler);
|
$self->{jsonHelper} = WebGUI::Asset::Wobject::Survey::SurveyJSON->new($jsonHash,$self->session->errorHandler);
|
||||||
|
};
|
||||||
|
$self->session->errorHandler->error("Loaded JSON".$@);
|
||||||
|
|
||||||
$self->session->errorHandler->error("Loaded JSON\n\n".Dumper $self->helper->freeze);
|
#$self->session->errorHandler->error("Loaded JSON\n\n".Dumper $self->helper->freeze);
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -206,7 +215,7 @@ sub saveSurveyJSON{
|
||||||
|
|
||||||
my $data = $self->helper->freeze();
|
my $data = $self->helper->freeze();
|
||||||
|
|
||||||
$self->session->errorHandler->error("Saving THIS DATA\n\n".$data);
|
$self->session->errorHandler->error("Saving THIS DATA");#\n\n".$data);
|
||||||
|
|
||||||
$self->session->db->write("update Survey set surveyJSON = ? where assetId = ?",[$data,$self->getId]);
|
$self->session->db->write("update Survey set surveyJSON = ? where assetId = ?",[$data,$self->getId]);
|
||||||
}
|
}
|
||||||
|
|
@ -315,7 +324,14 @@ $self->session->errorHandler->error("In Drag Drop ".Dumper $p);
|
||||||
$bid[0] = -1 if(! defined $bid[0]);
|
$bid[0] = -1 if(! defined $bid[0]);
|
||||||
$self->helper->insertObject($target, [$bid[0]]);
|
$self->helper->insertObject($target, [$bid[0]]);
|
||||||
}elsif(@tid == 2){#questions can be moved to any section, but a pushed to the end of a new section.
|
}elsif(@tid == 2){#questions can be moved to any section, but a pushed to the end of a new section.
|
||||||
if(@bid == 1){#moved to a new section or head of current section
|
if($bid[0] !~ /\d/){
|
||||||
|
$bid[0] = $tid[0];
|
||||||
|
$bid[1] = $tid[1];
|
||||||
|
}elsif(@bid == 1){#moved to a new section or head of current section
|
||||||
|
if($bid[0] !~ /\d/){
|
||||||
|
$bid[0] = $tid[0];
|
||||||
|
$bid[1] = $tid[1];
|
||||||
|
}
|
||||||
if($bid[0] == $tid[0]){
|
if($bid[0] == $tid[0]){
|
||||||
#moved to top of current section
|
#moved to top of current section
|
||||||
$bid[1] = -1;
|
$bid[1] = -1;
|
||||||
|
|
@ -363,18 +379,25 @@ $self->session->errorHandler->error("Entering loadSurvey");
|
||||||
#$self->session->errorHandler->error("Getting edit vars:".join(',',@$address));
|
#$self->session->errorHandler->error("Getting edit vars:".join(',',@$address));
|
||||||
my $var = defined $options->{var} ? $options->{var} : $self->helper->getEditVars($address);
|
my $var = defined $options->{var} ? $options->{var} : $self->helper->getEditVars($address);
|
||||||
|
|
||||||
$self->session->errorHandler->error("Got edit vars");
|
$self->session->errorHandler->error("Got edit vars".Dumper $self->helper->freeze);
|
||||||
$self->session->errorHandler->error("Loaded beginning params ".join(',',@$address));
|
$self->session->errorHandler->error("Loaded beginning params ".join(',',@$address));
|
||||||
my $editHtml;
|
my $editHtml;
|
||||||
#$self->session->errorHandler->error("The edit vars:".Dumper $var);
|
$self->session->errorHandler->error("The edit vars:".Dumper $var);
|
||||||
if($var->{type} eq 'section'){
|
if($var->{type} eq 'section'){
|
||||||
$editHtml = $self->processTemplate($var,$self->get("sectionEditTemplateId"));
|
$editHtml = $self->processTemplate($var,$self->get("sectionEditTemplateId"));
|
||||||
}elsif($var->{type} eq 'question'){
|
}elsif($var->{type} eq 'question'){
|
||||||
$editHtml = $self->processTemplate($var,$self->get("questionEditTemplateId"));
|
$editHtml = $self->processTemplate($var,$self->get("questionEditTemplateId"));
|
||||||
|
}elsif($var->{type} eq 'answer'){
|
||||||
|
$editHtml = $self->processTemplate($var,$self->get("answerEditTemplateId"));
|
||||||
}
|
}
|
||||||
#$self->session->errorHandler->error("The HTML :$editHtml");
|
$self->session->errorHandler->error("The HTML :$editHtml");
|
||||||
|
|
||||||
my %buttons;
|
my %buttons;
|
||||||
|
$buttons{question} = $$address[0];
|
||||||
|
if(@$address == 2 or @$address == 3){
|
||||||
|
$buttons{answer} = "$$address[0]-$$address[1]";
|
||||||
|
}
|
||||||
|
|
||||||
my $data = $self->helper->getDragDropList($address);
|
my $data = $self->helper->getDragDropList($address);
|
||||||
#$self->session->errorHandler->error("The DD data :".Dumper $data);
|
#$self->session->errorHandler->error("The DD data :".Dumper $data);
|
||||||
my $html;
|
my $html;
|
||||||
|
|
@ -388,26 +411,17 @@ $self->session->errorHandler->error("Loaded beginning params ".join(',',@$addres
|
||||||
if($_->{type} eq 'section'){
|
if($_->{type} eq 'section'){
|
||||||
$lastId{section} = ++$scount;
|
$lastId{section} = ++$scount;
|
||||||
if($lastType eq 'answer'){
|
if($lastType eq 'answer'){
|
||||||
$html .= "<span id='newAnswer'></span><br>";
|
|
||||||
$buttons{answer} = "$lastId{section}-$lastId{question}";
|
|
||||||
$a = 1;
|
$a = 1;
|
||||||
}
|
}
|
||||||
elsif($lastType eq 'question'){
|
elsif($lastType eq 'question'){
|
||||||
$html .= "<span id='newQuestion'></span><br>";
|
|
||||||
$buttons{'question'} = "$lastId{section}-$lastId{question}";
|
|
||||||
$q = 1;
|
$q = 1;
|
||||||
}
|
}
|
||||||
$html .= "<li id='$scount' class='section'>S". ($scount + 1). ": $_->{text}<\/li><br>\n";
|
$html .= "<li id='$scount' class='section'>S". ($scount + 1). ": $_->{text}<\/li><br>\n";
|
||||||
push(@ids,$scount);
|
push(@ids,$scount);
|
||||||
$lastType = 'section';
|
|
||||||
$qcount = -1;
|
|
||||||
$acount = -1;
|
|
||||||
}
|
}
|
||||||
elsif($_->{type} eq 'question'){
|
elsif($_->{type} eq 'question'){
|
||||||
$lastId{question} = ++$qcount;
|
$lastId{question} = ++$qcount;
|
||||||
if($lastType eq 'answer'){
|
if($lastType eq 'answer'){
|
||||||
$html .= "<span id='newAnswer'></span><br>";
|
|
||||||
$buttons{answer} = "$lastId{section}-$lastId{question}";
|
|
||||||
$a = 1;
|
$a = 1;
|
||||||
}
|
}
|
||||||
$html .= "<li id='$scount-$qcount' class='question'>Q". ($qcount + 1). ": $_->{text}<\/li><br>\n";
|
$html .= "<li id='$scount-$qcount' class='question'>Q". ($qcount + 1). ": $_->{text}<\/li><br>\n";
|
||||||
|
|
@ -422,40 +436,6 @@ $self->session->errorHandler->error("Loaded beginning params ".join(',',@$addres
|
||||||
$lastType = 'answer';
|
$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}";
|
|
||||||
}
|
|
||||||
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}";
|
|
||||||
}
|
|
||||||
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}";
|
|
||||||
}
|
|
||||||
if(!$s){
|
|
||||||
$html .= "<span id='newSection'></span><br>";
|
|
||||||
$buttons{'section'} = "$lastId{section}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#$self->session->errorHandler->error($html);
|
#$self->session->errorHandler->error($html);
|
||||||
|
|
||||||
#address is the address of the focused object
|
#address is the address of the focused object
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ sub new{
|
||||||
my $temp = decode_json($json) if defined $json;
|
my $temp = decode_json($json) if defined $json;
|
||||||
$self->{sections} = defined $temp->{sections} ? $temp->{sections} : [];
|
$self->{sections} = defined $temp->{sections} ? $temp->{sections} : [];
|
||||||
$self->{survey} = defined $temp->{survey} ? $temp->{survey} : {};
|
$self->{survey} = defined $temp->{survey} ? $temp->{survey} : {};
|
||||||
$self->{gotoMap} = defined $temp->{gotoMap} ? $temp->{gotoMap} : {};
|
|
||||||
bless($self,$class);
|
bless($self,$class);
|
||||||
if(@{$self->sections} == 0){
|
if(@{$self->sections} == 0){
|
||||||
$self->newObject([]);
|
$self->newObject([]);
|
||||||
|
|
@ -25,7 +24,6 @@ sub freeze{
|
||||||
my %temp;
|
my %temp;
|
||||||
$temp{sections} = $self->{sections};
|
$temp{sections} = $self->{sections};
|
||||||
$temp{survey} = $self->{survey};
|
$temp{survey} = $self->{survey};
|
||||||
$temp{gotoMap} = $self->{gotoMap};
|
|
||||||
return encode_json(\%temp);
|
return encode_json(\%temp);
|
||||||
}
|
}
|
||||||
sub newObject{
|
sub newObject{
|
||||||
|
|
@ -40,7 +38,7 @@ sub newObject{
|
||||||
return $address;
|
return $address;
|
||||||
}elsif(@$address == 2){
|
}elsif(@$address == 2){
|
||||||
push(@{$self->answers($address)}, $self->newAnswer($address));
|
push(@{$self->answers($address)}, $self->newAnswer($address));
|
||||||
$$address[2] = $#{$self->answers($$address)};
|
$$address[2] = $#{$self->answers($address)};
|
||||||
return $address;
|
return $address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +136,13 @@ sub getQuestionEditVars{
|
||||||
return \%var;
|
return \%var;
|
||||||
}
|
}
|
||||||
sub getAnswerEditVars{
|
sub getAnswerEditVars{
|
||||||
|
my $self = shift;
|
||||||
|
my $address = shift;
|
||||||
|
my $object = $self->answer($address);
|
||||||
|
my %var = %{$object};
|
||||||
|
$var{id} = $address->[0]."-".$address->[1]."-".$address->[2];
|
||||||
|
$var{displayed_id} = $address->[2]+1;
|
||||||
|
return \%var;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub update{
|
sub update{
|
||||||
|
|
@ -157,6 +162,12 @@ $self->log("$object didn't exist");
|
||||||
push(@{$self->questions($address)},$object);
|
push(@{$self->questions($address)},$object);
|
||||||
}
|
}
|
||||||
}elsif(@$address == 3){
|
}elsif(@$address == 3){
|
||||||
|
$object = $self->answer($address);
|
||||||
|
if(! defined $object){
|
||||||
|
$self->log("$object didn't exist");
|
||||||
|
$object = $self->newAnswer();
|
||||||
|
push(@{$self->answers($address)},$object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for my $key(keys %$object){
|
for my $key(keys %$object){
|
||||||
$object->{$key} = $ref->{$key} if(defined $$ref{$key});
|
$object->{$key} = $ref->{$key} if(defined $$ref{$key});
|
||||||
|
|
@ -234,6 +245,23 @@ sub newQuestion{
|
||||||
return \%members;
|
return \%members;
|
||||||
}
|
}
|
||||||
sub newAnswer{
|
sub newAnswer{
|
||||||
|
my %members = (
|
||||||
|
'text', '',
|
||||||
|
'verbatim',0,
|
||||||
|
'textCols',10,
|
||||||
|
'textRows',5,
|
||||||
|
'goto','',
|
||||||
|
'recordedAnswer','',
|
||||||
|
'isCorrect',1,
|
||||||
|
'min',1,
|
||||||
|
'max',10,
|
||||||
|
'step',1,
|
||||||
|
'value',1,
|
||||||
|
'terminal',0,
|
||||||
|
'terminalUrl','',
|
||||||
|
'type','answer'
|
||||||
|
);
|
||||||
|
return \%members;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,16 +56,19 @@ console.log('adding handler for '+ d.ids[x]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//add the add object buttons
|
//add the add object buttons
|
||||||
if(d.buttons['section']){
|
// if(d.buttons['section']){
|
||||||
var button = new YAHOO.widget.Button({ label:"Add Section", id:"addsection", container:"newSection" });
|
document.getElementById('addSection').innerHTML = '';
|
||||||
|
document.getElementById('addQuestion').innerHTML = '';
|
||||||
|
document.getElementById('addAnswer').innerHTML = '';
|
||||||
|
var button = new YAHOO.widget.Button({ label:"Add Section", id:"addsection", container:"addSection" });
|
||||||
button.on("click", this.addSection);
|
button.on("click", this.addSection);
|
||||||
}
|
// }
|
||||||
if(d.buttons['question']){
|
// if(d.buttons['question']){
|
||||||
var button = new YAHOO.widget.Button({ label:"Add Question", id:"addquestion", container:"newQuestion" });
|
var button = new YAHOO.widget.Button({ label:"Add Question", id:"addquestion", container:"addQuestion" });
|
||||||
button.on("click", this.addQuestion,d.buttons['question']);
|
button.on("click", this.addQuestion,d.buttons['question']);
|
||||||
}
|
// }
|
||||||
if(d.buttons['answer']){
|
if(d.buttons['answer']){
|
||||||
var button = new YAHOO.widget.Button({ label:"Add Answer", id:"addanswer", container:"newAnswer" });
|
var button = new YAHOO.widget.Button({ label:"Add Answer", id:"addanswer", container:"addAnswer" });
|
||||||
button.on("click", this.addAnswer,d.buttons['answer']);
|
button.on("click", this.addAnswer,d.buttons['answer']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ div.entry {
|
||||||
|
|
||||||
ul.draglist {
|
ul.draglist {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 300px;
|
width: 340px;
|
||||||
background: #f7f7f7;
|
background: #f7f7f7;
|
||||||
border: 1px solid gray;
|
border: 1px solid gray;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue