var QuizEditorState = Class.create({
currentUser : null,
currentQuiz : null,
canvasDiv : null,
nextCallback : null,
textArea : null,
button : null,
initialize : function(_user, _quiz, _canvas, _nextCallback) {
this.currentUser = _user;
this.currentQuiz = _quiz;
this.canvasDiv = _canvas;
this.nextCallback = _nextCallback;
// Setup the text area
this.textArea = new Element('textarea', {
'id' : 'quiz_editor',
'class' : 'quizEditor textarea',
'name' : 'quiz'
});
if (this.currentQuiz != null && this.currentQuiz.content.length > 0) {
this.textArea.value = this.currentQuiz.content;
} else {
this.textArea.value = 'Type your quiz here...';
}
// Setup the button
this.button = new Element('input', {
'type' : 'button',
'class' : 'quizButton button',
'value' : ' Done '
});
this.button.observe('click', function(evt) {
Debug.log('click ' + Event.element(evt));
this.currentQuiz.content = this.cleanQuiz($('quiz_editor').value);
this.clear();
this.nextCallback(this.currentQuiz);
}.bind(this));
// Insert into the page
this.canvasDiv.insert(this.textArea);
this.canvasDiv.insert(this.button);
// Ready
this.canvasDiv.addClassName('quizEditor');
this.canvasDiv.show();
this.textArea.focus();
},
cleanQuiz : function(quizTxt) {
var parsed = new Array();
for (var i = 0; i < quizTxt.length; ++i)
{
if (quizTxt.charAt(i) == "\n")
parsed.push('
');
else
parsed.push(quizTxt.charAt(i));
}
quizTxt = parsed.join('');
return quizTxt.stripScripts();
},
clear : function() {
this.canvasDiv.hide();
this.canvasDiv.update('');
this.canvasDiv.removeClassName('quizEditor');
}
});
var DialogState = Class.create({
currentUser : null,
canvasDiv : null,
yesCallback : null,
noCallback : null,
titleH1 : null,
yesButton : null,
noButton : null,
initialize : function(_user, _canvas, _titleTxt, _yesTxt, _yesCallback, _noTxt, _noCallback) {
this.currentUser = _user;
this.canvasDiv = _canvas;
this.yesCallback = _yesCallback;
this.noCallback = _noCallback;
// Setup the elements
this.titleH1 = new Element('h1', {
'class' : 'dialog center'
});
this.titleH1.update(_titleTxt);
this.yesButton = new Element('input', {
'type' : 'button',
'class' : 'yesButton button',
'value' : _yesTxt
});
this.noButton = new Element('input', {
'type' : 'button',
'class' : 'noButton button',
'value' : _noTxt
});
this.yesButton.observe('click', function(evt) {
Debug.log('click ' + Event.element(evt));
this.clear();
this.yesCallback();
}.bind(this)
);
this.noButton.observe('click', function(evt) {
Debug.log('click ' + Event.element(evt));
this.clear();
this.noCallback();
}.bind(this)
);
// Insert into the page
this.canvasDiv.insert(this.titleH1);
this.canvasDiv.insert(this.yesButton);
this.canvasDiv.insert(this.noButton);
// Ready
this.canvasDiv.show();
this.canvasDiv.addClassName('askProfile');
this.yesButton.focus();
},
clear : function() {
this.canvasDiv.hide();
this.canvasDiv.update('');
this.canvasDiv.removeClassName('askProfile');
}
});
/*
Select friends
*/
var FriendSelectorState = Class.create({
appUrl : null,
friends : null,
selections : null,
currentQuiz : null,
canvas : null,
callbackFunc : null,
measure : null,
html : [],
initialize : function(_appUrl, _canvasDiv, _friends, _currentQuiz, _callbackFunc, _measure)
{
this.canvasDiv = _canvasDiv;
this.friends = _friends;
this.callbackFunc = _callbackFunc;
this.selections = new Array();
this.currentQuiz = _currentQuiz;
this.appUrl = _appUrl;
this.measure = _measure;
if (this.friends.size() > 0) {
this.renderFriends();
this.renderActionBar();
this.canvasDiv.innerHTML = this.html.join('');
this.observeActions();
this.canvasDiv.show();
} else {
this.callbackFunc();
}
},
renderFriends : function()
{
this.html.push('
Click continue when you\'re done.
'); this.html.push('