debian-mirror-gitlab/app/assets/javascripts/shortcuts_issuable.coffee

72 lines
1.9 KiB
CoffeeScript
Raw Normal View History

2015-09-11 14:41:01 +05:30
#= require mousetrap
#= require shortcuts_navigation
class @ShortcutsIssuable extends ShortcutsNavigation
constructor: (isMergeRequest) ->
super()
2016-06-02 11:05:42 +05:30
Mousetrap.bind('a', @openSidebarDropdown.bind(@, 'assignee'))
Mousetrap.bind('m', @openSidebarDropdown.bind(@, 'milestone'))
2015-09-11 14:41:01 +05:30
Mousetrap.bind('r', =>
@replyWithSelectedText()
return false
)
2016-04-02 18:10:28 +05:30
Mousetrap.bind('j', =>
@prevIssue()
return false
)
Mousetrap.bind('k', =>
@nextIssue()
return false
)
2016-06-02 11:05:42 +05:30
Mousetrap.bind('e', =>
@editIssue()
return false
)
Mousetrap.bind('l', @openSidebarDropdown.bind(@, 'labels'))
2015-09-11 14:41:01 +05:30
if isMergeRequest
@enabledHelp.push('.hidden-shortcut.merge_requests')
else
@enabledHelp.push('.hidden-shortcut.issues')
2016-04-02 18:10:28 +05:30
prevIssue: ->
$prevBtn = $('.prev-btn')
if not $prevBtn.hasClass('disabled')
Turbolinks.visit($prevBtn.attr('href'))
nextIssue: ->
$nextBtn = $('.next-btn')
if not $nextBtn.hasClass('disabled')
Turbolinks.visit($nextBtn.attr('href'))
2015-09-11 14:41:01 +05:30
replyWithSelectedText: ->
if window.getSelection
selected = window.getSelection().toString()
replyField = $('.js-main-target-form #note_note')
return if selected.trim() == ""
# Put a '>' character before each non-empty line in the selection
quote = _.map selected.split("\n"), (val) ->
"> #{val}\n" if val.trim() != ''
# If replyField already has some content, add a newline before our quote
separator = replyField.val().trim() != "" and "\n" or ''
replyField.val (_, current) ->
current + separator + quote.join('') + "\n"
# Trigger autosave for the added text
replyField.trigger('input')
# Focus the input field
replyField.focus()
2016-06-02 11:05:42 +05:30
editIssue: ->
$editBtn = $('.issuable-edit')
Turbolinks.visit($editBtn.attr('href'))
openSidebarDropdown: (name) ->
sidebar.openDropdown(name)
return false