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
|
|
@ -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 = '<empty>';
|
||||
}
|
||||
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 = "<span id='newSection'></span>";
|
||||
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 = "<span id='newQuestion'></span>";
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ Survey.SectionTemplate = new function(){
|
|||
";
|
||||
html = html + "<p>Title on every page: " + this.makeRadio('everyPageTitle',[{text:'Yes',value:1},{text:'No',value:0}],params.everyPageTitle);
|
||||
html = html + "<p>Text on every page: " + this.makeRadio('everyPageText',[{text:'Yes',value:1},{text:'No',value:0}],params.everyPageText);
|
||||
html = html + "<p>Terminal section: " + this.makeRadio('terminal',[{text:'Yes',value:1},{text:'No',value:0}],params.terminal);
|
||||
html = html + "<vr><p>Terminal section: " + this.makeRadio('terminal',[{text:'Yes',value:1},{text:'No',value:0}],params.terminal);
|
||||
html = html + "<p> Terminal section URL: <input type=text name=terminalURL value='"+params.terminalURL+"'>";
|
||||
document.getElementById('edit').innerHTML = html;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue