|
| 1 | +I18n.scoped 'AssignmentMuter', (I18n) -> |
| 2 | + class @AssignmentMuter |
| 3 | + constructor: (@$link, @assignment, @url) -> |
| 4 | + @$link = $(@$link) |
| 5 | + @updateLink() |
| 6 | + @$link.click (event) => |
| 7 | + event.preventDefault() |
| 8 | + if @assignment.muted then @confirmUnmute() else @showDialog() |
| 9 | + |
| 10 | + updateLink: => |
| 11 | + @$link.text(if @assignment.muted then I18n.t('unmute_assignment', 'Unmute Assignment') else I18n.t('mute_assignment', 'Mute Assignment')) |
| 12 | + |
| 13 | + showDialog: => |
| 14 | + @$dialog = $(Template('mute_dialog')).dialog |
| 15 | + buttons: [{ |
| 16 | + text: I18n.t('mute_assignment', 'Mute Assignment') |
| 17 | + 'data-text-while-loading': I18n.t('muting_assignment', 'Muting Assignment...') |
| 18 | + click: => |
| 19 | + @$dialog.disableWhileLoading $.ajaxJSON(@url, 'put', { status : true }, @afterUpdate) |
| 20 | + }] |
| 21 | + close: => @$dialog.remove() |
| 22 | + resizable: false |
| 23 | + width: 400 |
| 24 | + |
| 25 | + afterUpdate: (serverResponse) => |
| 26 | + @assignment.muted = serverResponse.assignment.muted |
| 27 | + @updateLink() |
| 28 | + @$dialog.dialog('close') |
| 29 | + $.publish('assignment_muting_toggled', [@assignment]) |
| 30 | + |
| 31 | + confirmUnmute: => |
| 32 | + @$dialog = $('<div />') |
| 33 | + .text(I18n.t('unmute_dialog', "This assignment is currently muted. That means students can't see their grades and feedback. Would you like to unmute now?")) |
| 34 | + .dialog |
| 35 | + buttons: [{ |
| 36 | + text: I18n.t('unmute_button', 'Unmute Assignment') |
| 37 | + 'data-text-while-loading': I18n.t('unmuting_assignment', 'Unmuting Assignment...') |
| 38 | + click: => |
| 39 | + @$dialog.disableWhileLoading $.ajaxJSON(@url, 'put', { status : false }, @afterUpdate) |
| 40 | + }] |
| 41 | + close: => @$dialog.remove() |
| 42 | + resizable: false |
| 43 | + title: I18n.t("unmute_assignment", "Unmute Assignment") |
| 44 | + width: 400 |
0 commit comments