2015-02-25 06:22:05 -05:00
|
|
|
class @IssuableForm
|
2016-03-20 06:01:08 -04:00
|
|
|
issueMoveConfirmMsg: 'Are you sure you want to move this issue to another project?'
|
2016-03-18 18:27:35 -04:00
|
|
|
wipRegex: /^\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i
|
2016-03-15 10:01:26 -04:00
|
|
|
|
2015-02-25 06:22:05 -05:00
|
|
|
constructor: (@form) ->
|
2015-06-25 10:17:06 -04:00
|
|
|
GitLab.GfmAutoComplete.setup()
|
|
|
|
new UsersSelect()
|
|
|
|
new ZenMode()
|
|
|
|
|
2015-02-25 06:22:05 -05:00
|
|
|
@titleField = @form.find("input[name*='[title]']")
|
|
|
|
@descriptionField = @form.find("textarea[name*='[description]']")
|
2016-03-15 10:01:26 -04:00
|
|
|
@issueMoveField = @form.find("#move_to_project_id")
|
2015-02-25 06:22:05 -05:00
|
|
|
|
|
|
|
return unless @titleField.length && @descriptionField.length
|
|
|
|
|
|
|
|
@initAutosave()
|
|
|
|
|
2016-03-15 10:01:26 -04:00
|
|
|
@form.on "submit", @handleSubmit
|
2015-02-25 06:22:05 -05:00
|
|
|
@form.on "click", ".btn-cancel", @resetAutosave
|
|
|
|
|
2016-02-26 22:34:32 -05:00
|
|
|
@initWip()
|
|
|
|
|
2015-02-25 06:22:05 -05:00
|
|
|
initAutosave: ->
|
|
|
|
new Autosave @titleField, [
|
|
|
|
document.location.pathname,
|
|
|
|
document.location.search,
|
|
|
|
"title"
|
|
|
|
]
|
|
|
|
|
|
|
|
new Autosave @descriptionField, [
|
|
|
|
document.location.pathname,
|
|
|
|
document.location.search,
|
|
|
|
"description"
|
|
|
|
]
|
|
|
|
|
2016-03-16 05:24:44 -04:00
|
|
|
handleSubmit: =>
|
2016-03-15 10:01:26 -04:00
|
|
|
if (parseInt(@issueMoveField?.val()) ? 0) > 0
|
2016-03-20 06:01:08 -04:00
|
|
|
return false unless confirm(@issueMoveConfirmMsg)
|
2016-03-16 05:24:44 -04:00
|
|
|
|
|
|
|
@resetAutosave()
|
2016-03-15 10:01:26 -04:00
|
|
|
|
2015-02-25 06:22:05 -05:00
|
|
|
resetAutosave: =>
|
|
|
|
@titleField.data("autosave").reset()
|
|
|
|
@descriptionField.data("autosave").reset()
|
2016-02-26 22:34:32 -05:00
|
|
|
|
|
|
|
initWip: ->
|
2016-03-18 18:27:35 -04:00
|
|
|
@$wipExplanation = @form.find(".js-wip-explanation")
|
|
|
|
@$noWipExplanation = @form.find(".js-no-wip-explanation")
|
|
|
|
return unless @$wipExplanation.length and @$noWipExplanation.length
|
2016-02-26 22:34:32 -05:00
|
|
|
|
2016-03-18 18:27:35 -04:00
|
|
|
@form.on "click", ".js-toggle-wip", @toggleWip
|
2016-02-26 22:34:32 -05:00
|
|
|
|
2016-03-18 18:27:35 -04:00
|
|
|
@titleField.on "keyup blur", @renderWipExplanation
|
2016-02-26 22:34:32 -05:00
|
|
|
|
|
|
|
@renderWipExplanation()
|
|
|
|
|
|
|
|
workInProgress: ->
|
2016-03-18 18:27:35 -04:00
|
|
|
@wipRegex.test @titleField.val()
|
2016-02-26 22:34:32 -05:00
|
|
|
|
|
|
|
renderWipExplanation: =>
|
|
|
|
if @workInProgress()
|
2016-03-18 18:27:35 -04:00
|
|
|
@$wipExplanation.show()
|
|
|
|
@$noWipExplanation.hide()
|
2016-02-26 22:34:32 -05:00
|
|
|
else
|
2016-03-18 18:27:35 -04:00
|
|
|
@$wipExplanation.hide()
|
|
|
|
@$noWipExplanation.show()
|
2016-02-26 22:34:32 -05:00
|
|
|
|
2016-03-18 18:27:35 -04:00
|
|
|
toggleWip: (event) =>
|
2016-02-26 22:34:32 -05:00
|
|
|
event.preventDefault()
|
|
|
|
|
2016-03-18 18:27:35 -04:00
|
|
|
if @workInProgress()
|
|
|
|
@removeWip()
|
|
|
|
else
|
|
|
|
@addWip()
|
2016-02-26 22:34:32 -05:00
|
|
|
|
|
|
|
@renderWipExplanation()
|
|
|
|
|
2016-03-18 18:27:35 -04:00
|
|
|
removeWip: ->
|
|
|
|
@titleField.val @titleField.val().replace(@wipRegex, "")
|
2016-02-26 22:34:32 -05:00
|
|
|
|
2016-03-18 18:27:35 -04:00
|
|
|
addWip: ->
|
2016-02-26 22:34:32 -05:00
|
|
|
@titleField.val "WIP: #{@titleField.val()}"
|