calendar.js.coffee 1.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
class @calendar
  options =
    month: "short"
    day: "numeric"
    year: "numeric"

  constructor: (timestamps,starting_year,starting_month,activities_path) ->
    cal = new CalHeatMap()
    cal.init
      itemName: ["commit"]
      data: timestamps
      start: new Date(starting_year, starting_month)
      domainLabelFormat: "%b"
      id: "cal-heatmap"
      domain: "month"
      subDomain: "day"
      range: 12
      tooltip: true
      domainDynamicDimension: false
      colLimit: 4
      label:
        position: "top"
      domainMargin: 1
      legend: [
        0
        1
        4
        7
      ]
      legendCellPadding: 3
      onClick: (date, count) ->
        $.ajax
          url: activities_path
          data:
            date: date

          dataType: "json"
          success: (data) ->
            $("#loading_commits").fadeIn()
            calendar.calendarOnClick data, date, count
            setTimeout (->
              $("#calendar_onclick_placeholder").fadeIn 500
              return
            ), 400
            setTimeout (->
              $("#loading_commits").hide()
              return
            ), 400
            return  
        return
    return

  @calendarOnClick: (data, date, nb)->
    $("#calendar_onclick_placeholder").hide()
    $("#calendar_onclick_placeholder").html ->
      "<span class='calendar_onclick_second'><b>" +
      ((if nb is null then "no" else nb)) + 
      "</b><span class='calendar_commit_date'> commit" + 
      ((if (nb isnt 1) then "s" else "")) + " " + 
      date.toLocaleDateString("en-US", options) + 
      "</span><hr class='calendar_onclick_hr'></span>"
    $.each data, (key, data) ->
      $.each data, (index, data) ->
        $("#calendar_onclick_placeholder").append ->
          "Pushed <b>" + ((if data is null then "no" else data)) + " commit" +
          ((if (data isnt 1) then "s" else "")) + 
          "</b> to <a href='/" + index + "'>" + 
          index + "</a><hr class='calendar_onclick_hr'>"
        return
      return
    return