Sha256: fe89b0be688285a982288951e579c9153dd84870d98a2da8f0d3f50b66e4818f

Contents?: true

Size: 740 Bytes

Versions: 8

Compression:

Stored size: 740 Bytes

Contents

$ ->
  $("[data-study-id-picker]").studyIDPicker()

$.fn.studyIDPicker = ->
  $(this).each ->
    new StudyIDPicker $(this), JSON.parse($(this).attr("data-study-id-picker"))

class StudyIDPicker
  constructor: (@$el, @studyIDMap) ->
    @$studies = @$el.find("select").eq(0)
    @$sites = @$el.find("select").eq(1)
    @$ids = @$el.find("select").eq(2)

    @$studies.change => @change()
    @$sites.change => @change()

  change: ->
    key = "" + @$studies.val() + @$sites.val()
    ids = @idsForKey(key)
    @$ids.html @optionsFromIds(ids)

  idsForKey: (key) ->
    @studyIDMap[key] || []

  optionsFromIds: (ids) ->
    options = ids.map (id) -> "<option value='#{id}'>#{id}</option>"
    "<option>----</option>" + options.join("\n")

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
study_engine-0.3.1 app/assets/javascripts/study_engine/study_id_picker.js.coffee
study_engine-0.3.0 app/assets/javascripts/study_engine/study_id_picker.js.coffee
study_engine-0.2.2 app/assets/javascripts/study_engine/study_id_picker.js.coffee
study_engine-0.2.1 app/assets/javascripts/study_engine/study_id_picker.js.coffee
study_engine-0.2.0 app/assets/javascripts/study_engine/study_id_picker.js.coffee
study_engine-0.1.1 app/assets/javascripts/study_engine/study_id_picker.js.coffee
study_engine-0.1.0 app/assets/javascripts/study_engine/study_id_picker.js.coffee
study_engine-0.0.2 app/assets/javascripts/study_engine/study_id_picker.js.coffee