mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-23 03:26:07 +10:00
Implements TemplateDropdown class to create custom template dropdowns ## What does this MR do? Refactorize template dropdowns. This MR creates a base TemplateSelector class so it can be reused for multiple types of templates. ## Does this MR meet the acceptance criteria? - [ ] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - [ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md) - [ ] API support added - [ ] Tests - [ ] Added for this feature/bug - [x] All builds are passing - [ ] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) See merge request !4697
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()
|