debian-mirror-gitlab/app/assets/javascripts/issuable_form.js.coffee

113 lines
2.8 KiB
CoffeeScript
Raw Normal View History

2015-04-26 12:48:37 +05:30
class @IssuableForm
2016-06-02 11:05:42 +05:30
issueMoveConfirmMsg: 'Are you sure you want to move this issue to another project?'
wipRegex: /^\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i
2015-04-26 12:48:37 +05:30
constructor: (@form) ->
2015-09-11 14:41:01 +05:30
GitLab.GfmAutoComplete.setup()
new UsersSelect()
new ZenMode()
2015-04-26 12:48:37 +05:30
@titleField = @form.find("input[name*='[title]']")
@descriptionField = @form.find("textarea[name*='[description]']")
2016-06-02 11:05:42 +05:30
@issueMoveField = @form.find("#move_to_project_id")
2015-04-26 12:48:37 +05:30
return unless @titleField.length && @descriptionField.length
@initAutosave()
2016-06-02 11:05:42 +05:30
@form.on "submit", @handleSubmit
2015-04-26 12:48:37 +05:30
@form.on "click", ".btn-cancel", @resetAutosave
2016-06-02 11:05:42 +05:30
@initWip()
@initMoveDropdown()
$issuableDueDate = $('#issuable-due-date')
if $issuableDueDate.length
$('.datepicker').datepicker(
dateFormat: 'yy-mm-dd',
onSelect: (dateText, inst) ->
$issuableDueDate.val dateText
).datepicker 'setDate', $.datepicker.parseDate('yy-mm-dd', $issuableDueDate.val())
2016-06-02 11:05:42 +05:30
2015-04-26 12:48:37 +05:30
initAutosave: ->
new Autosave @titleField, [
document.location.pathname,
document.location.search,
"title"
]
new Autosave @descriptionField, [
document.location.pathname,
document.location.search,
"description"
]
2016-06-02 11:05:42 +05:30
handleSubmit: =>
if (parseInt(@issueMoveField?.val()) ? 0) > 0
return false unless confirm(@issueMoveConfirmMsg)
@resetAutosave()
2015-04-26 12:48:37 +05:30
resetAutosave: =>
@titleField.data("autosave").reset()
@descriptionField.data("autosave").reset()
2016-06-02 11:05:42 +05:30
initWip: ->
@$wipExplanation = @form.find(".js-wip-explanation")
@$noWipExplanation = @form.find(".js-no-wip-explanation")
return unless @$wipExplanation.length and @$noWipExplanation.length
@form.on "click", ".js-toggle-wip", @toggleWip
@titleField.on "keyup blur", @renderWipExplanation
@renderWipExplanation()
workInProgress: ->
@wipRegex.test @titleField.val()
renderWipExplanation: =>
if @workInProgress()
@$wipExplanation.show()
@$noWipExplanation.hide()
else
@$wipExplanation.hide()
@$noWipExplanation.show()
toggleWip: (event) =>
event.preventDefault()
if @workInProgress()
@removeWip()
else
@addWip()
@renderWipExplanation()
removeWip: ->
@titleField.val @titleField.val().replace(@wipRegex, "")
addWip: ->
@titleField.val "WIP: #{@titleField.val()}"
initMoveDropdown: ->
$moveDropdown = $('.js-move-dropdown')
if $moveDropdown.length
$('.js-move-dropdown').select2
ajax:
url: $moveDropdown.data('projects-url')
results: (data) ->
return {
results: data
}
data: (query) ->
{
search: query
}
formatResult: (project) ->
project.name_with_namespace
formatSelection: (project) ->
project.name_with_namespace