summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/line_comments/components/comment_button.js.coffee
blob: 13ef6afef09765ee3dabb38413f53326aa8bc64d (plain)
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
@CommentButton =
  model: (args) ->
    @note = m.prop(args.noteId or undefined)
    @resolved = m.prop(args.resolved or false)
    return
  controller: (args) ->
    @model = new CommentButton.model(args)

    @resolvedText = m.prop =>
      if @model.resolved() then 'Mark as un-resolved' else 'Mark as resolved'

    @resolveLine = =>
      @model.resolved(!@model.resolved())
      LinesObserver.trigger(@model.resolved(), @model.note())

    return
  view: (ctrl) ->
    buttonText = ctrl.resolvedText()()
    isActive = if ctrl.model.resolved() then 'is-active' else ''

    # Return the view elements
    m('button',
      'aria-label': buttonText
      title: buttonText
      type: 'button'
      class: "line-resolve-btn #{isActive}"
      onclick: ctrl.resolveLine
      config: (el) ->
        $(el)
          .tooltip('hide')
          .tooltip()
          .tooltip('fixTitle')
    , [
      m('i',
        class: 'fa fa-check'
      )
      m('span',
        class: 'sr-only'
      , buttonText)
    ])