Create a gist now

Instantly share code, notes, and snippets.

class SpracticeClient.AppController extends Batman.Controller
question_list: null
step: 0
current: null
answer_text: null
step_message: null
options: [
new Option(body: "N/A", value: 0, image:'assets/options/na.png', skip: true)
new Option(body: "Sad", value: 1, image:'assets/options/1.png')
new Option(body: "Unhappy", value: 2, image:'assets/options/2.png')
new Option(body: "Indifferent", value: 3, image:'assets/options/3.png')
new Option(body: "Happy", value: 4, image:'assets/options/4.png')
new Option(body: "Ecstacy", value: 5, image:'assets/options/5.png')
]
index: ->
Question.load (error, questions) =>
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 (error) -> throw error if error
@set 'question_list', questions
rec = @question_list[@step]
if rec
@set 'current', rec
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
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
else
@set 'step_message', 'Thanks!, Survey Finished!'
update: (node, event) ->
_id = parseInt node.getAttribute('id')
@set 'current.selected_answer', _id
@current.save (error) -> throw error if error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment