Skip to content

Commit

Permalink
Propogate "dirty" events up the hierarchy
Browse files Browse the repository at this point in the history
Handle deletion of Questions from inside a Round
Initial work on an Question editor modal dialog
  • Loading branch information
hlship committed May 8, 2012
1 parent 98735aa commit f0ed77b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
36 changes: 34 additions & 2 deletions assets/js/author.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ QuizEditorView = FormView.extend

$("#top-level-tabs .nav-tabs a:last").tab "show"

@roundsEditor.on "dirty", @triggerDirtyEvent

addRound: (event) ->
event.preventDefault()

Expand Down Expand Up @@ -290,6 +292,7 @@ QuizRoundsEditorView = View.extend
@model.trigger "childChange"

@collection.on "add remove", @renumberRounds, this
@collection.on "add remove change", => @trigger "dirty"

createRoundView: (round) ->
ctor = roundKindToViewClass[round.get("kind")]
Expand All @@ -303,6 +306,8 @@ QuizRoundsEditorView = View.extend

@$el.append header.$el

view.on "dirty", => @trigger "dirty"

return header

addRound: (kind) ->
Expand Down Expand Up @@ -377,11 +382,15 @@ NormalRoundEditView = FormView.extend
@collection = @model.get("questions")

$tbody = @$("tbody")
@collection.each (question) ->
row = new QuestionTableRowView model: question
@collection.each (question) =>
row = new QuestionTableRowView
model: question
collection: @collection
row.render()
$tbody.append row.el

@collection.on "change add remove", => @trigger "dirty"

doAddQuestion: (event) ->
event.stopPropagation()
window.alert "Not yet implemented"
Expand Down Expand Up @@ -410,10 +419,33 @@ QuestionTableRowView = View.extend
render: ->
@$el.html readTemplate "QuestionTableRowView"
$cells = @$("td")
# TODO: Truncate the text & answer values, possibly strip HTML from them
@linkCell $cells.eq(0), "text", "None"
@linkCell $cells.eq(1), "answer", "None"
@linkCell $cells.eq(2), "value", "Not Set"

events:
"click .x-edit": "doEdit"
"click .x-delete": "doDelete"

doEdit: ->
new EditQuestionModalView model: @model

doDelete: ->
@collection.remove(@model)
@remove()

EditQuestionModalView = FormView.extend

className: "modal fade in"

initialize: ->
@$el.html readTemplate "EditQuestionModalView"

$("body").append @$el

@$el.modal().on "hidden", => @remove()

# Now some page-load-time initialization:

jQuery ->
Expand Down
5 changes: 2 additions & 3 deletions assets/js/q-views.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ ConfirmDialog = View.extend

@$(".x-confirm").addClass @options.buttonClass or "btn-primary"

$("body").append(@$el)
$("body").append @$el

# After the modal dialog is hidden, remove it from the DOM
@$el.modal().on "hidden", =>
@remove()
@$el.modal().on "hidden", => @remove()

doConfirm: ->
@trigger "confirm"
Expand Down
15 changes: 7 additions & 8 deletions views/author.jade
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ block append templates
| {{content}}

script#EditQuestionModalView(type="text/template")
.modal.fade.in
.modal-header
a.close(data-dismiss="modal") ×
h3 {{title}}
.modal-body
| Form goes here
.modal-footer
button.btn.btn-primary(data-dismiss="modal") OK
.modal-header
a.close(data-dismiss="modal") ×
h3 Edit Question
.modal-body
| Form goes here
.modal-footer
button.btn.btn-primary(data-dismiss="modal") OK

0 comments on commit f0ed77b

Please sign in to comment.