                 $("#new-assignment").parent().addClass("has-error")
                 return
 
-Template.assignments.assignments = ->
-    # Fake dependency on update_interval to update periodically.
-    Meteor.extra_garbage_of_tomfoolery = Session.get "update_interval"
-
-    # Determine which assignments to display in main pane,
-    # selected based on class_id and tag_filter.
-    class_id = Session.get "class_id"
-
-    sel = class_id: class_id
-    if class_id is ""
-        sel = {}
-
-    return _(Offline.smart.assignments().find(sel).fetch()).chain()
-           .sortBy((obj) -> new Date(obj.timestamp).getTime())
-           .sortBy((obj) -> new Date(obj.due).getTime())
-           .sortBy("done")
-           .groupBy("done")
-           .pairs()
-           .map(([truthiness, list]) -> _.sortBy(list, (obj) ->
-                if truthiness is "true"
-                    Math.abs(DateOMatic.msDifferential(new Date(obj.due)))
-                else
-                    new Date(obj.due).getTime()
-            ))
-           .reduce(((memo, list) -> memo.concat(list)), [])
-           .value()
-
-Template.assignment_item.precise_due_date = -> DateOMatic.stringify(@due, yes, no, yes)
-
-Template.assignment_item.editable_due_date = -> DateOMatic.stringify(@due, no, yes, yes)
-
 div = (a, b) -> (a - a % b) / b
 
-Template.assignment_item.fuzzy_due_date = -> if DateOMatic.isFuture(@due) then "in #{DateOMatic.fuzzyDifferential(@due)}" else "#{DateOMatic.fuzzyDifferential(@due)} ago"
-
-Template.assignment_item.done_class = -> if this.done then "muted" else ""
-
-Template.assignment_item.done_checkbox = -> if this.done then "check-" else ""
-
-Template.assignment_item.editing = -> Session.equals("editing_itemname", this._id)
-
-Template.assignment_item.class_color = ->
-    Offline.smart.classes().findOne(@class_id)?.color
-
-Template.assignment_item.color_class = ->
-    if @done
-        return "list-group-item-success"
-    msLeft = new Date(@due).getTime() - (new Date()).getTime()
-    if msLeft < 0
-        return "list-group-item-danger"
-    if div(msLeft, 1000 * 60 * 60) < 24
-        return "list-group-item-warning"
-    if div(msLeft, 1000 * 60 * 60 * 24) < 2
-        return "list-group-item-info"
-    return ""
+assignmentHelpers =
+    assignments: ->
+        # Fake dependency on update_interval to update periodically.
+        Meteor.extra_garbage_of_tomfoolery = Session.get "update_interval"
+
+        # Determine which assignments to display in main pane,
+        # selected based on class_id and tag_filter.
+        class_id = Session.get "class_id"
+
+        sel = class_id: class_id
+        if class_id is ""
+            sel = {}
+
+        return _(Offline.smart.assignments().find(sel).fetch()).chain()
+               .sortBy((obj) -> new Date(obj.timestamp).getTime())
+               .sortBy((obj) -> new Date(obj.due).getTime())
+               .sortBy("done")
+               .groupBy("done")
+               .pairs()
+               .map(([truthiness, list]) -> _.sortBy(list, (obj) ->
+                    if truthiness is "true"
+                        Math.abs(DateOMatic.msDifferential(new Date(obj.due)))
+                    else
+                        new Date(obj.due).getTime()
+                ))
+               .reduce(((memo, list) -> memo.concat(list)), [])
+               .value()
+
+    precise_due_date: ->
+        DateOMatic.stringify(@due, yes, no, yes)
+
+    editable_due_date: ->
+        DateOMatic.stringify(@due, no, yes, yes)
+
+    fuzzy_due_date: ->
+        if DateOMatic.isFuture(@due) then "in #{DateOMatic.fuzzyDifferential(@due)}" else "#{DateOMatic.fuzzyDifferential(@due)} ago"
+
+    done_class: ->
+        if this.done then "muted" else ""
+
+    done_checkbox: ->
+        if this.done then "check-" else ""
+
+    editing: ->
+        Session.equals("editing_itemname", this._id)
+
+    class_color: ->
+        Offline.smart.classes().findOne(@class_id)?.color
+
+    color_class: ->
+        if @done
+            return "list-group-item-success"
+        msLeft = new Date(@due).getTime() - (new Date()).getTime()
+        if msLeft < 0
+            return "list-group-item-danger"
+        if div(msLeft, 1000 * 60 * 60) < 24
+            return "list-group-item-warning"
+        if div(msLeft, 1000 * 60 * 60 * 24) < 2
+            return "list-group-item-info"
+        return ""
+
+Template.assignments.helpers assignmentHelpers
+Template.assignment_item.helpers assignmentHelpers
 
 Template.assignment_item.events
     "click .check": ->

    input.focus()
    input.select()

Template.contents.showEverything = ->
    return true if Meteor.userId()?
    return true if !online
    return false

# Classes #


                Offline.save()
        evt.target.value = ""

Template.classes.helpers
    active: ->
        if Session.equals("class_id", this._id)
            "active"
        else
            ""

# Class Editing #

Template.edit_class_modal.helpers
    name: -> Offline.smart.classes().findOne(Session.get("editing_class"))?.name
    abbr: -> Offline.smart.classes().findOne(Session.get("editing_class"))?.abbr
    class_color: -> Offline.smart.classes().findOne(Session.get("editing_class"))?.color
do ->
    ecmHelpers = {}
    for dow, n in (DateOMatic.getDowName(n).toLowerCase() for n in [0..6])
        do (dow, n) ->
            ecmHelpers["#{dow}Checked"] = ->
                if Offline.smart.classes().findOne(Session.get("editing_class"))?.schedule?[n]?.enabled then "checked" else ""
            ecmHelpers["#{dow}Time"] = ->
                Offline.smart.classes().findOne(Session.get("editing_class"))?.schedule?[n]?.time
    Template.edit_class_modal.helpers ecmHelpers

Template.edit_class_modal.events
    "click .delete": ->
