Created
October 26, 2011 16:47
-
-
Save goyox86/1316954 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SpracticeClient.AppController extends Batman.Controller | |
question_list: null | |
step: 0 | |
current: null | |
options: null | |
answer_text: null | |
step_message: null | |
index: -> | |
Question.load (error, questions) => | |
throw error if error | |
callback = (error) -> throw error if error | |
if questions.length < 1 | |
q_list = [ | |
new Question(body: 'Was it easy to reach us?') | |
new Question(body: 'Was the person answering the phone friendly and helpful?') | |
new Question(body: 'Was it easy to make an appointment?') | |
new Question(body: 'Was the office easy to find? Was ample parking available?') | |
new Question(body: 'Was the staff friendly and did they greet you promptly?') | |
new Question(body: 'Was the waiting room clean and comfortable?') | |
new Question(body: 'Were you seen close to your appointment time?') | |
new Question(body: 'Did the doctor greet you promptly?') | |
new Question(body: 'Was the doctor approachable and have a good bedside manner?') | |
] | |
for q in q_list | |
q.save(callback) | |
new Option(body: "N/A", value: 0, image:'assets/options/na.png', question_id: q.id, skip: true).save(callback) | |
new Option(body: "Sad", value: 1, image:'assets/options/1.png', question_id: q.id).save(callback) | |
new Option(body: "Unhappy", value: 2, image:'assets/options/2.png', question_id: q.id).save(callback) | |
new Option(body: "Indifferent", value: 3, image:'assets/options/3.png', question_id: q.id).save(callback) | |
new Option(body: "Happy", value: 4, image:'assets/options/4.png', question_id: q.id).save(callback) | |
new Option(body: "Ecstacy", value: 5, image:'assets/options/5.png', question_id: q.id).save(callback) | |
else | |
for q in questions | |
new Option(body: "N/A", value: 0, image:'assets/options/na.png', question_id: q.id, skip: true).save(callback) | |
new Option(body: "Sad", value: 1, image:'assets/options/1.png', question_id: q.id).save(callback) | |
new Option(body: "Unhappy", value: 2, image:'assets/options/2.png', question_id: q.id).save(callback) | |
new Option(body: "Indifferent", value: 3, image:'assets/options/3.png', question_id: q.id).save(callback) | |
new Option(body: "Happy", value: 4, image:'assets/options/4.png', question_id: q.id).save(callback) | |
new Option(body: "Ecstacy", value: 5, image:'assets/options/5.png', question_id: q.id).save(callback) | |
@set 'question_list', questions | |
rec = @question_list[@step] | |
if rec | |
@set 'current', rec | |
@set 'options', Option.find_by_question_id( rec.get('id') ) | |
if @step_message is null | |
@set 'step_message', "Step #{@step+1} of #{@question_list.length}" | |
prev: -> | |
if @step-1 >= 0 | |
@step-- | |
@set 'step_message', "Step #{@step+1} of #{@question_list.length}" | |
rec = @question_list[@step] | |
@set 'current', rec | |
@set 'options', Option.find_by_question_id( rec.get('id') ) | |
next: -> | |
if @current.get('selected_answer') == 0 | |
return if confirm('Are you sure you want to skip this question?') is false | |
else | |
@next | |
if @step+1 < @question_list.length | |
@step++ | |
@set 'step_message', "Step #{@step+1} of #{@question_list.length}" | |
rec = @question_list[@step] | |
@set 'current', rec | |
@set 'options', Option.find_by_question_id( rec.get('id') ) | |
else | |
@set 'step_message', 'Thanks!, Survey Finished!' | |
update: (node, event) -> | |
_id = parseInt node.getAttribute('id') | |
@set 'current.selected_answer', _id | |
@current.save() | |
@options.map (e) -> | |
if e.get('value') == _id | |
e.set('selected', true) | |
else | |
e.set('selected', false) | |
e.save() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment