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 = $ '