Welcome to mirror list, hosted at ThFree Co, Russian Federation.

protected_branch_select.js.coffee « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6d45770ace9c6e4692f9965c29f2b20572976dea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class @ProtectedBranchSelect
  constructor: (currentProject) ->
    $('.dropdown-footer').hide();
    @dropdown = $('.js-protected-branch-select').glDropdown(
      data: @getProtectedBranches
      filterable: true
      remote: false
      search:
        fields: ['title']
      selectable: true
      toggleLabel: (selected) -> if (selected and 'id' of selected) then selected.title else 'Protected Branch'
      fieldName: 'protected_branch[name]'
      text: (protected_branch) -> _.escape(protected_branch.title)
      id: (protected_branch) -> _.escape(protected_branch.id)
      onFilter: @toggleCreateNewButton
      clicked: () -> $('.protect-branch-btn').attr('disabled', false)
    )

    $('.create-new-protected-branch').on 'click', (event) =>
      # Refresh the dropdown's data, which ends up calling `getProtectedBranches`
      @dropdown.data('glDropdown').remote.execute()
      @dropdown.data('glDropdown').selectRowAtIndex(event, 0)

  getProtectedBranches: (term, callback) =>
    if @selectedBranch
      callback(gon.open_branches.concat(@selectedBranch))
    else
      callback(gon.open_branches)

  toggleCreateNewButton: (branchName) =>
    @selectedBranch = { title: branchName, id: branchName, text: branchName }

    if branchName is ''
      $('.protected-branch-select-footer-list').addClass('hidden')
      $('.dropdown-footer').hide();
    else
      $('.create-new-protected-branch').text("Create Protected Branch: #{branchName}")
      $('.protected-branch-select-footer-list').removeClass('hidden')
      $('.dropdown-footer').show();