debian-mirror-gitlab/app/assets/javascripts/project.js.coffee

89 lines
2.4 KiB
CoffeeScript
Raw Normal View History

2015-04-26 12:48:37 +05:30
class @Project
2014-09-02 18:07:02 +05:30
constructor: ->
2015-12-23 02:04:40 +05:30
# Git protocol switcher
$('ul.clone-options-dropdown a').click ->
2015-12-23 02:04:40 +05:30
return if $(@).hasClass('active')
# Remove the active class for all buttons (ssh, http, kerberos if shown)
$('.active').not($(@)).removeClass('active');
# Add the active class for the clicked button
$(@).toggleClass('active')
url = $("#project_clone").val()
2015-12-23 02:04:40 +05:30
# Update the input field
$('#project_clone').val(url)
# Update the command line instructions
$('.clone').text(url)
2015-04-26 12:48:37 +05:30
# Ref switcher
2016-06-22 15:30:34 +05:30
@initRefSwitcher()
2015-04-26 12:48:37 +05:30
$('.project-refs-select').on 'change', ->
$(@).parents('form').submit()
$('.hide-no-ssh-message').on 'click', (e) ->
path = '/'
$.cookie('hide_no_ssh_message', 'false', { path: path })
$(@).parents('.no-ssh-key-message').remove()
e.preventDefault()
$('.hide-no-password-message').on 'click', (e) ->
path = '/'
$.cookie('hide_no_password_message', 'false', { path: path })
$(@).parents('.no-password-message').remove()
e.preventDefault()
2015-09-25 12:07:36 +05:30
2016-04-02 18:10:28 +05:30
@projectSelectDropdown()
projectSelectDropdown: ->
new ProjectSelect()
$('.project-item-select').on 'click', (e) =>
@changeProject $(e.currentTarget).val()
$('.js-projects-dropdown-toggle').on 'click', (e) ->
e.preventDefault()
$('.js-projects-dropdown').select2('open')
changeProject: (url) ->
window.location = url
2016-06-22 15:30:34 +05:30
initRefSwitcher: ->
$('.js-project-refs-dropdown').each ->
$dropdown = $(@)
selected = $dropdown.data('selected')
$dropdown.glDropdown(
data: (term, callback) ->
$.ajax(
url: $dropdown.data('refs-url')
data:
ref: $dropdown.data('ref')
).done (refs) ->
callback(refs)
selectable: true
filterable: true
filterByText: true
fieldName: 'ref'
renderRow: (ref) ->
if ref.header?
"<li class='dropdown-header'>#{ref.header}</li>"
else
isActiveClass = if ref is selected then 'is-active' else ''
"<li>
<a href='#' data-ref='#{escape(ref)}' class='#{isActiveClass}'>
#{ref}
</a>
</li>"
id: (obj, $el) ->
$el.data('ref')
toggleLabel: (obj, $el) ->
$el.text().trim()
clicked: (e) ->
$dropdown.closest('form').submit()
)