From 38c7ee33c4c93faf9899c9d696c90809b2531d63 Mon Sep 17 00:00:00 2001 From: Kaleb Murphy Date: Thu, 25 Sep 2008 02:09:22 +0000 Subject: [PATCH] Moving edit screens to be template based for i18n (almost done with editor. --- lib/WebGUI/Asset/Wobject/Survey.pm | 105 ++++++++++- lib/WebGUI/Asset/Wobject/Survey/AnswerJSON.pm | 5 +- .../Asset/Wobject/Survey/QuestionJSON.pm | 5 +- .../Asset/Wobject/Survey/SectionJSON.pm | 3 +- lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm | 9 +- www/extras/wobject/Survey/editsurvey.js | 165 ++++-------------- www/extras/wobject/Survey/editsurvey/comm.js | 1 - .../wobject/Survey/editsurvey/section.js | 2 +- 8 files changed, 142 insertions(+), 153 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index b982d0d45..14d6f4f92 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -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 .= "
"; + $buttons{answer} = "$lastId{section}-$lastId{question}"; + $a = 1; + } + elsif($lastType eq 'question'){ + $html .= "
"; + $buttons{'question'} = "$lastId{section}-$lastId{question}"; + $q = 1; + } + $html .= "
  • S". ($scount + 1). ": $_->{text}<\/li>
    \n"; + push(@ids,$scount); + $lastId{section} = $scount++; + $lastType = 'section'; + } + elsif($_->{type} eq 'question'){ + if($lastType eq 'answer'){ + $html .= "
    "; + $buttons{answer} = "$lastId{section}-$lastId{question}"; + $a = 1; + } + $html .= "
  • Q". ($qcount + 1). ": $_->{text}<\/li>
    \n"; + push(@ids,$qcount); + $lastId{question} = $qcount++; + $lastType = 'question'; + } + elsif($_->{type} eq 'answer'){ + $html .= "
  • A". ($acount + 1). ": $_->{text}<\/li>
    \n"; + push(@ids,$acount); + $lastId{answer} = $acount++; + $lastType = 'answer'; + } + } + if($lastType eq 'answer'){ + if(!$a){ + $html .= "
    "; + $buttons{'answer'} = "$lastId{section}-$lastId{question}"; + } + if(!$b){ + $html .= "
    "; + $buttons{'question'} = "$lastId{section}-$lastId{question}"; + } + if(!$s){ + $html .= "
    "; + $buttons{'section'} = "$lastId{section}"; + } + } + elsif($lastType eq 'question'){ + if(!$b){ + $html .= "
    "; + $buttons{'question'} = "$lastId{section}-$lastId{question}"; + } + if(!$s){ + $html .= "
    "; + $buttons{'section'} = "$lastId{section}"; + } + } + elsif($lastType eq 'section'){ + if(!$b){ + $html .= "
    "; + $buttons{'question'} = "$lastId{section}-$lastId{question}"; + } + if(!$s){ + $html .= "
    "; + $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); } diff --git a/lib/WebGUI/Asset/Wobject/Survey/AnswerJSON.pm b/lib/WebGUI/Asset/Wobject/Survey/AnswerJSON.pm index 5f870388d..5f00b4b0f 100644 --- a/lib/WebGUI/Asset/Wobject/Survey/AnswerJSON.pm +++ b/lib/WebGUI/Asset/Wobject/Survey/AnswerJSON.pm @@ -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; diff --git a/lib/WebGUI/Asset/Wobject/Survey/QuestionJSON.pm b/lib/WebGUI/Asset/Wobject/Survey/QuestionJSON.pm index 9e73e170c..c3e8ddb8a 100644 --- a/lib/WebGUI/Asset/Wobject/Survey/QuestionJSON.pm +++ b/lib/WebGUI/Asset/Wobject/Survey/QuestionJSON.pm @@ -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); diff --git a/lib/WebGUI/Asset/Wobject/Survey/SectionJSON.pm b/lib/WebGUI/Asset/Wobject/Survey/SectionJSON.pm index ab9125553..8fa4d4a4a 100644 --- a/lib/WebGUI/Asset/Wobject/Survey/SectionJSON.pm +++ b/lib/WebGUI/Asset/Wobject/Survey/SectionJSON.pm @@ -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]); diff --git a/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm b/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm index 06baa382c..37091d45e 100644 --- a/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm +++ b/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm @@ -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; diff --git a/www/extras/wobject/Survey/editsurvey.js b/www/extras/wobject/Survey/editsurvey.js index 788ef12e5..f306176a2 100644 --- a/www/extras/wobject/Survey/editsurvey.js +++ b/www/extras/wobject/Survey/editsurvey.js @@ -45,108 +45,32 @@ Survey.Data = new function(){ this.loadData = function(d){ - focus = d.focus;//What is the current highlighted item. - var lastType = '';//What was the last type created. - var lastId = {'section': '', 'question': '', 'answer': ''};//what is the last id of each type placed, so we know a child's parent. - var buttons = {'question':0,'answer':0,'section':0}; //array of bools on if buttons put down - document.getElementById('sections').innerHTML=''; - var scount = 1; - var qcount = 1; - var acount = 1; - for(var x in d.data){ - //Now check to see if this is where an add button goes. - //Add addAnswer when we go from answer to question or section or end - //Add addQuestion when we go from question to section or end - - if(lastType == 'answer' && d.data[x].type == 'question'){ - this.addAnswerButton(lastId['section'],lastId['question']); - buttons['answer'] = 1; - acount = 1; - } - else if(lastType == 'answer' && d.data[x].type == 'section'){ - this.addAnswerButton(lastId['section'],lastId['question']); - buttons['answer'] = 1; - this.addQuestionButton(lastId['section']); - buttons['question'] = 1; - acount = 1; - qcount = 1; - } - else if(lastType == 'question' && d.data[x].type == 'section'){ - if(!buttons['answer']){ - this.addAnswerButton(lastId['section'],lastId['question']); - buttons['answer']=1; - } - this.addQuestionButton(lastId['section']); - buttons['question'] = 1; - acount = 1; - qcount = 1; - } - else if(d.data[x].type == 'section' && lastType == 'section' && lastId['section'] == focus){ - this.addQuestionButton(lastId['section']); - buttons['question'] = 1; - acount = 1; - qcount = 1; - } - else if(d.data[x].type != 'answer' && lastType == 'question' && lastId['section'] + '||||'+ lastId['question'] == focus){ - this.addAnswerButton(lastId['section'],lastId['question']); - buttons['answer']=1; - acount = 1; - qcount = 1; - } - - var node = document.createElement('li'); - if(focus != undefined && focus.indexOf(d.data[x].id) > -1){ - node.className = "s"+d.data[x].type; - }else{ - node.className = d.data[x].type; - } - if(d.data[x].text == undefined){//== 'null'){ - d.data[x].text = ''; - } - var id = ''; - var delim = "||||"; - var pre; - if(d.data[x].type == 'section'){ - pre = 'S'+ scount++ +':'; - id = d.data[x].id; - } - else if(d.data[x].type == 'question'){ - pre = 'Q'+ qcount++ +':'; - id = lastId['section'] + delim + d.data[x].id; - } - else if(d.data[x].type == 'answer'){ - if(d.data[x].recordedAnswers != null){ - } - pre = 'A'+ acount++ +':'; - id = lastId['section'] + delim + lastId['question'] + delim + d.data[x].id; - } - node.innerHTML = pre + ' ' + d.data[x].text; - node.id = id; - new Survey.DDList(node.id,"sections"); - document.getElementById('sections').appendChild(node); - YAHOO.util.Event.addListener(id, "click", this.clicked); - - lastType = d.data[x].type; - lastId[d.data[x].type] = d.data[x].id; - } - if(lastType == 'answer' && ! buttons['answer']){ - this.addAnswerButton(lastId['section'],lastId['question']); - this.addQuestionButton(lastId['section']); - } - if(lastType == 'question' && ! buttons['question']){ - this.addAnswerButton(lastId['section'],lastId['question']); - } - if(lastType == 'question' || lastType == 'section' && ! buttons['question']){ - this.addQuestionButton(lastId['section']); - } - - this.addSectionButton(); + focus = d.address;//What is the current highlighted item. + document.getElementById('sections').innerHTML=d.ddhtml; - this.loadObjectEdit(d.edit); + //add event handlers for if a tag is clicked + for(var x in d.ids){ + YAHOO.util.Event.addListener(d.ids[x], "click", this.clicked); + } + + //add the add object buttons + if(d.buttons['section']){ + var button = new YAHOO.widget.Button({ label:"Add Section", id:"addsection", container:"newSection" }); + button.on("click", this.addSection); + } + if(d.buttons['question']){ + var button = new YAHOO.widget.Button({ label:"Add Question", id:"addquestion", container:"newQuestion" }); + button.on("click", this.addQuestion,d.buttons['question']); + } + if(d.buttons['answer']){ + var button = new YAHOO.widget.Button({ label:"Add Answer", id:"addanswer", container:"newAnswer" }); + button.on("click", this.addQuestion,d.buttons['answer']); + } + + this.loadObjectEdit(d.object); lastDataSet = d; } - this.addSection = function(){ Survey.Comm.newSection(); } @@ -160,46 +84,19 @@ Survey.Data = new function(){ Survey.Comm.newAnswer(ids[0],ids[1]); } - - this.addSectionButton = function(){ - var node = document.createElement('li'); - node.innerHTML = ""; - document.getElementById('sections').appendChild(node); - var button = new YAHOO.widget.Button({ label:"Add Section", id:"addsection", container:"newSection" }); - button.on("click", this.addSection); - } - - - this.addQuestionButton = function(sid){ - var node = document.createElement('li'); - node.className = 'newQuestion'; - node.innerHTML = ""; - document.getElementById('sections').appendChild(node); - var button = new YAHOO.widget.Button({ label:"Add Question", id:'addquestion', container:"newQuestion"});//, onclick:{fn:this.addQuestion} }); - button.on("click", this.addQuestion,sid); - } - - - this.addAnswerButton = function(sid,qid){ - var node = document.createElement('li'); - node.id = 'newAnswer'; - node.className = 'newAnswer'; - document.getElementById('sections').appendChild(node); - var button = new YAHOO.widget.Button({ label:"Add Answer", id:'addanswer', container:"newAnswer" }); - button.on("click", this.addAnswer,[sid,qid]); - } - - this.loadObjectEdit = function(edit){ if(edit){ - if(edit.type == "loadSection"){ - Survey.SectionTemplate.loadSection(edit.params); + if(edit.type == "section"){ +console.log('made it here section'); + Survey.SectionTemplate.loadSection(edit); } - else if(edit.type == "loadQuestion"){ - Survey.QuestionTemplate.loadQuestion(edit.params); + else if(edit.type == "question"){ +console.log('made it here question'); + Survey.QuestionTemplate.loadQuestion(edit); } - else if(edit.type == "loadAnswer"){ - Survey.AnswerTemplate.loadAnswer(edit.params); + else if(edit.type == "answer"){ +console.log('made it here answer'); + Survey.AnswerTemplate.loadAnswer(edit); } } } diff --git a/www/extras/wobject/Survey/editsurvey/comm.js b/www/extras/wobject/Survey/editsurvey/comm.js index 02d9849ff..5fd5c677b 100644 --- a/www/extras/wobject/Survey/editsurvey/comm.js +++ b/www/extras/wobject/Survey/editsurvey/comm.js @@ -16,7 +16,6 @@ Survey.Comm = new function(){ this.callback = { success:function(o){ callMade = 0; -console.log(o.responseText); Survey.Data.loadData(YAHOO.lang.JSON.parse(o.responseText)); }, failure: function(o){ diff --git a/www/extras/wobject/Survey/editsurvey/section.js b/www/extras/wobject/Survey/editsurvey/section.js index 837758b02..4736976cb 100644 --- a/www/extras/wobject/Survey/editsurvey/section.js +++ b/www/extras/wobject/Survey/editsurvey/section.js @@ -58,7 +58,7 @@ Survey.SectionTemplate = new function(){ "; html = html + "

    Title on every page: " + this.makeRadio('everyPageTitle',[{text:'Yes',value:1},{text:'No',value:0}],params.everyPageTitle); html = html + "

    Text on every page: " + this.makeRadio('everyPageText',[{text:'Yes',value:1},{text:'No',value:0}],params.everyPageText); - html = html + "

    Terminal section: " + this.makeRadio('terminal',[{text:'Yes',value:1},{text:'No',value:0}],params.terminal); + html = html + "

    Terminal section: " + this.makeRadio('terminal',[{text:'Yes',value:1},{text:'No',value:0}],params.terminal); html = html + "

    Terminal section URL: "; document.getElementById('edit').innerHTML = html;