webgui/www/extras/wobject/Survey/editsurvey.js
Patrick Donelan b7520da07d Merge commit 'tags/WebGUI_7.6.8-beta' into survey-rfe
* commit 'tags/WebGUI_7.6.8-beta': (96 commits)
  Release 7.6.8-beta
  preparing for 7.6.8 release
  convert to new storage format
  fixing photo comment test
  fixed: Syndicated Content corrupts wide characters
  Add the WikiPage to the list of contributions shown in the Account Contributions tab.
  added #!/usr/bin/env perl to all utility scripts
  Forward port i18n fix for Gallery Album RSS list.
  Fix some Survey i18n typos in the time limit hoverhelp.
  Large batch of Help and i18n.  Also, make sure that the
  Fix a typo in the i18n help for the ITransact Pay Driver.
  Correct dataform captcha variable name in the help.
  Forward porting expanded patch for handling deleted things.
  Have Thingy check for existance of table and column to prevent
  Fix linking to other things and autocreating the form field for it.
  Update test to match fixed code.
  Remove the warnings pragma
  Only resize photos if they are larger than the Gallery resolutions.
  Fix a syntax error made in the i18n of the search button.
  I18n'ed a submit button in the manage transactions screen.
  ...

Conflicts:

	lib/WebGUI/Asset/Wobject/Survey.pm
	lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm
	www/extras/wobject/Survey/editsurvey.js
	www/extras/wobject/Survey/editsurvey/object.js
2009-01-14 06:00:06 +00:00

143 lines
4.5 KiB
JavaScript

/*global Survey, YAHOO */
if (typeof Survey === "undefined") {
var Survey = {};
}
Survey.Data = (function(){
var lastDataSet = {};
var focus;
var lastId = -1;
return {
dragDrop: function(did){
YAHOO.log('In drag drop');
var type = did.className.match("section") ? 'section'
: did.className.match("question") ? 'question'
: 'answer';
var first = {
id: did.id, // pre-drag index of item
type: type
};
var before = YAHOO.util.Dom.getPreviousSiblingBy( document.getElementById(did.id), function(node){
return node.id; // true iff node has a non-empty id
});
var data = {
id: '',
type: ''
};
if (before) {
type = before.className.match("section") ? 'section'
: before.className.match("question") ? 'question'
: 'answer';
data = {
id: before.id,
type: type
};
}
YAHOO.log(first.id + ' ' + data.id);
Survey.Comm.dragDrop(first, data);
},
clicked: function(){
Survey.Comm.loadSurvey(this.id);
},
loadData: function(d){
focus = d.address;//What is the current highlighted item.
var showEdit = 1;
if (lastId.toString() === d.address.toString()) {
showEdit = 0;
lastId = -1;
}
else {
lastId = d.address;
}
document.getElementById('sections').innerHTML = d.ddhtml;
//add event handlers for if a tag is clicked
for (var x in d.ids) {
if (YAHOO.lang.hasOwnProperty(d.ids, x)) {
YAHOO.log('adding handler for ' + d.ids[x]);
YAHOO.util.Event.addListener(d.ids[x], "click", this.clicked);
var _s = new Survey.DDList(d.ids[x], "sections");
}
}
//add the add object buttons
// if(d.buttons['section']){
document.getElementById('addSection').innerHTML = '';
document.getElementById('addQuestion').innerHTML = '';
document.getElementById('addAnswer').innerHTML = '';
var sButton = new YAHOO.widget.Button({
label: "Add Section",
id: "addsection",
container: "addSection"
});
sButton.on("click", this.addSection);
// }
// if(d.buttons['question']){
var qButton = new YAHOO.widget.Button({
label: "Add Question",
id: "addquestion",
container: "addQuestion"
});
qButton.on("click", this.addQuestion, d.buttons.question);
// }
if (d.buttons.answer) {
var aButton = new YAHOO.widget.Button({
label: "Add Answer",
id: "addanswer",
container: "addAnswer"
});
aButton.on("click", this.addAnswer, d.buttons.answer);
}
if (showEdit == 1) {
this.loadObjectEdit(d.edithtml, d.type);
// build the goto auto-complete widget
if (d.gotoTargets && document.getElementById('goto')) {
var ds = new YAHOO.util.LocalDataSource(d.gotoTargets);
var ac = new YAHOO.widget.AutoComplete('goto', 'goto-yui-ac-container', ds);
}
}
else {
document.getElementById('edit').innerHTML = "";
}
lastDataSet = d;
},
addSection: function(){
Survey.Comm.newSection();
},
addQuestion: function(e, id){
Survey.Comm.newQuestion(id);
},
addAnswer: function(e, id){
Survey.Comm.newAnswer(id);
},
loadObjectEdit: function(edit, type){
if (edit) {
Survey.ObjectTemplate.loadObject(edit, type);
}
},
loadLast: function(){
this.loadData(lastDataSet);
}
};
})();
// Initialize survey
YAHOO.util.Event.onDOMReady(function(){
var ddTarget = new YAHOO.util.DDTarget("sections", "sections");
Survey.Comm.loadSurvey();
});