From 1e8cb7df250334c4ccc478701f6a970146637185 Mon Sep 17 00:00:00 2001 From: Miles Steele Date: Fri, 12 Jul 2013 13:52:07 -0400 Subject: [PATCH] clean & comment coffeescript, add util.coffee --- .../src/instructor_dashboard/analytics.coffee | 41 +-- .../instructor_dashboard/course_info.coffee | 31 +- .../instructor_dashboard/data_download.coffee | 47 +-- .../instructor_dashboard.coffee | 84 ++--- .../instructor_dashboard/membership.coffee | 297 ++++++++++-------- .../instructor_dashboard/student_admin.coffee | 48 +-- .../src/instructor_dashboard/util.coffee | 27 ++ .../instructor_dashboard_2.html | 2 +- 8 files changed, 339 insertions(+), 238 deletions(-) create mode 100644 lms/static/coffee/src/instructor_dashboard/util.coffee diff --git a/lms/static/coffee/src/instructor_dashboard/analytics.coffee b/lms/static/coffee/src/instructor_dashboard/analytics.coffee index e586a2400a..b4deb93f8a 100644 --- a/lms/static/coffee/src/instructor_dashboard/analytics.coffee +++ b/lms/static/coffee/src/instructor_dashboard/analytics.coffee @@ -1,17 +1,15 @@ -log = -> console.log.apply console, arguments -plantTimeout = (ms, cb) -> setTimeout cb, ms - -std_ajax_err = (handler) -> (jqXHR, textStatus, errorThrown) -> - console.warn """ajax error - textStatus: #{textStatus} - errorThrown: #{errorThrown}""" - handler.apply this, arguments +# Analytics Section +# imports from other modules. +# wrap in (-> ... apply) to defer evaluation +# such that the value can be defined later than this assignment (file load order). +plantTimeout = -> window.InstructorDashboard.util.plantTimeout.apply this, arguments +std_ajax_err = -> window.InstructorDashboard.util.std_ajax_err.apply this, arguments +# Analytics Section class Analytics constructor: (@$section) -> - log "setting up instructor dashboard section - analytics" - + # gather elements @$display = @$section.find '.distribution-display' @$display_text = @$display.find '.distribution-display-text' @$display_graph = @$display.find '.distribution-display-graph' @@ -21,20 +19,23 @@ class Analytics @populate_selector => @$distribution_select.change => @on_selector_change() - reset_display: -> @$display_text.empty() @$display_graph.empty() @$display_table.empty() @$request_response_error.empty() - + # fetch and list available distributions + # `cb` is a callback to be run after populate_selector: (cb) -> @get_profile_distributions [], + # on error, print to console and dom. error: std_ajax_err => @$request_response_error.text "Error getting available distributions." success: (data) => + # replace loading text in drop-down with "-- Select Distribution --" @$distribution_select.find('option').eq(0).text "-- Select Distribution --" + # add all fetched available features to drop-down for feature in data.available_features opt = $ '