mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-12 06:06:05 +10:00
Also License dropdown has been ported to use our GL dropdown instead of Select2. Fixes tests to make it work with current implementation
57 lines
1.1 KiB
CoffeeScript
57 lines
1.1 KiB
CoffeeScript
class @TemplateSelector
|
|
constructor: (opts = {}) ->
|
|
{
|
|
@dropdown,
|
|
@data,
|
|
@pattern,
|
|
@wrapper,
|
|
@editor,
|
|
@fileEndpoint,
|
|
@$input = $('#file_name')
|
|
} = opts
|
|
|
|
@buildDropdown()
|
|
@bindEvents()
|
|
@onFilenameUpdate()
|
|
|
|
buildDropdown: ->
|
|
@dropdown.glDropdown(
|
|
data: @data,
|
|
filterable: true,
|
|
selectable: true,
|
|
search:
|
|
fields: ['name']
|
|
clicked: @onClick
|
|
text: (item) ->
|
|
item.name
|
|
)
|
|
|
|
bindEvents: ->
|
|
@$input.on('keyup blur', (e) =>
|
|
@onFilenameUpdate()
|
|
)
|
|
|
|
onFilenameUpdate: ->
|
|
return unless @$input.length
|
|
|
|
filenameMatches = @pattern.test(@$input.val().trim())
|
|
|
|
if not filenameMatches
|
|
@wrapper.addClass('hidden')
|
|
return
|
|
|
|
@wrapper.removeClass('hidden')
|
|
|
|
onClick: (item, el, e) =>
|
|
e.preventDefault()
|
|
@requestFile(item)
|
|
|
|
requestFile: (item) ->
|
|
# To be implemented on the extending class
|
|
# e.g.
|
|
# Api.gitignoreText item.name, @requestFileSuccess.bind(@)
|
|
|
|
requestFileSuccess: (file) ->
|
|
@editor.setValue(file.content, 1)
|
|
@editor.focus()
|