Commit a5861b8f authored by Cyril's avatar Cyril

fix gfm autocomplete for usernames

parent d3b8952f
# Creates the variables for setting up GFM auto-completion # Creates the variables for setting up GFM auto-completion
window.GitLab ?= {} window.GitLab ?= {}
GitLab.GfmAutoComplete ?= {} GitLab.GfmAutoComplete =
# Emoji
# Emoji Emoji:
data = [] data: []
template = "<li data-value='${insert}'>${name} <img alt='${name}' height='20' src='${image}' width='20' /></li>" template: '<li data-value="${insert}">${name} <img alt="${name}" height="20" src="${image}" width="20" /></li>'
GitLab.GfmAutoComplete.Emoji = {data, template}
# Team Members
data = []
url = '';
params = {private_token: '', page: 1}
GitLab.GfmAutoComplete.Members = {data, url, params}
# Add GFM auto-completion to all input fields, that accept GFM input. # Team Members
GitLab.GfmAutoComplete.setup = -> Members:
data: []
url: ''
params:
private_token: ''
page: 1
template: '<li data-value="${username}">${username} <small>${name}</small></li>'
# Add GFM auto-completion to all input fields, that accept GFM input.
setup: ->
input = $('.js-gfm-input') input = $('.js-gfm-input')
# Emoji # Emoji
input.atWho ':', input.atWho ':',
data: GitLab.GfmAutoComplete.Emoji.data, data: @Emoji.data
tpl: GitLab.GfmAutoComplete.Emoji.template tpl: @Emoji.template
# Team Members # Team Members
input.atWho '@', (query, callback) -> input.atWho '@',
(getMoreMembers = -> tpl: @Members.template
$.getJSON(GitLab.GfmAutoComplete.Members.url, GitLab.GfmAutoComplete.Members.params) callback: (query, callback) =>
.success (members) -> (getMoreMembers = =>
$.getJSON(@Members.url, @Members.params).done (members) =>
# pick the data we need # pick the data we need
newMembersData = $.map(members, (m) -> m.name ) newMembersData = $.map(members, (m) ->
username: m.username
name: m.name
)
# add the new page of data to the rest # add the new page of data to the rest
$.merge(GitLab.GfmAutoComplete.Members.data, newMembersData) $.merge(@Members.data, newMembersData)
# show the pop-up with a copy of the current data # show the pop-up with a copy of the current data
callback(GitLab.GfmAutoComplete.Members.data[..]) callback(@Members.data[..])
# are we past the last page? # are we past the last page?
if newMembersData.length is 0 if newMembersData.length is 0
# set static data and stop callbacks # set static data and stop callbacks
input.atWho '@', input.atWho '@',
data: GitLab.GfmAutoComplete.Members.data data: @Members.data
callback: null callback: null
else else
# get next page # get next page
getMoreMembers() getMoreMembers()
# so the next request gets the next page # so the next callback requests the next page
GitLab.GfmAutoComplete.Members.params.page += 1 @Members.params.page += 1
).call() ).call()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment