button_helper.rb 1.47 KB
Newer Older
1
module ButtonHelper
2 3 4 5 6 7 8 9 10 11 12
  # Output a "Copy to Clipboard" button
  #
  # data - Data attributes passed to `content_tag`
  #
  # Examples:
  #
  #   # Define the clipboard's text
  #   clipboard_button(clipboard_text: "Foo")
  #   # => "<button class='...' data-clipboard-text='Foo'>...</button>"
  #
  #   # Define the target element
13 14
  #   clipboard_button(clipboard_target: "div#foo")
  #   # => "<button class='...' data-clipboard-target='div#foo'>...</button>"
15 16 17
  #
  # See http://clipboardjs.com/#usage
  def clipboard_button(data = {})
18 19
    content_tag :button,
      icon('clipboard'),
20
      class: 'btn btn-clipboard',
21
      data: data,
22 23 24
      type: :button
  end

25
  def http_clone_button(project)
26
    klass = 'http-selector'
27
    klass << ' has-tooltip' if current_user.try(:require_password?)
28 29 30

    protocol = gitlab_config.protocol.upcase

31
    content_tag :a, protocol,
32
      class: klass,
33
      href: project.http_url_to_repo,
34
      data: {
35
        html: true,
36 37
        placement: 'right',
        container: 'body',
38
        title: "Set a password on your account<br>to pull or push via #{protocol}"
39
      }
40 41 42
  end

  def ssh_clone_button(project)
43
    klass = 'ssh-selector'
44
    klass << ' has-tooltip' if current_user.try(:require_ssh_key?)
45

46
    content_tag :a, 'SSH',
47
      class: klass,
48
      href: project.ssh_url_to_repo,
49
      data: {
50
        html: true,
51 52
        placement: 'right',
        container: 'body',
53
        title: 'Add an SSH key to your profile<br>to pull or push via SSH.'
54
      }
55 56
  end
end