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
72
73
|
class @IssuableForm
wipRegex: /^\[?WIP(\]|:| )\s*/i
constructor: (@form) ->
GitLab.GfmAutoComplete.setup()
new UsersSelect()
new ZenMode()
@titleField = @form.find("input[name*='[title]']")
@descriptionField = @form.find("textarea[name*='[description]']")
return unless @titleField.length && @descriptionField.length
@initAutosave()
@form.on "submit", @resetAutosave
@form.on "click", ".btn-cancel", @resetAutosave
@initWip()
initAutosave: ->
new Autosave @titleField, [
document.location.pathname,
document.location.search,
"title"
]
new Autosave @descriptionField, [
document.location.pathname,
document.location.search,
"description"
]
resetAutosave: =>
@titleField.data("autosave").reset()
@descriptionField.data("autosave").reset()
initWip: ->
return unless @form.find(".js-wip-explanation").length
@form.on "click", ".js-remove-wip", @removeWip
@form.on "click", ".js-add-wip", @addWip
@titleField.on "change", @renderWipExplanation
@renderWipExplanation()
workInProgress: ->
@titleField.val().match(@wipRegex)
renderWipExplanation: =>
if @workInProgress()
@form.find(".js-wip-explanation").show()
@form.find(".js-no-wip-explanation").hide()
else
@form.find(".js-wip-explanation").hide()
@form.find(".js-no-wip-explanation").show()
removeWip: (event) =>
event.preventDefault()
return unless @workInProgress()
@titleField.val @titleField.val().replace(@wipRegex, "")
@renderWipExplanation()
addWip: (event) =>
event.preventDefault()
return if @workInProgress()
@titleField.val "WIP: #{@titleField.val()}"
@renderWipExplanation()
|