button_helper.rb 1.66 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
  #
  # See http://clipboardjs.com/#usage
Phil Hughes's avatar
Phil Hughes committed
17
  def clipboard_button(data = {})
18 19
    content_tag :button,
      icon('clipboard'),
Phil Hughes's avatar
Phil Hughes committed
20
      class: "btn",
21
      data: data,
22 23 24
      type: :button
  end

Phil Hughes's avatar
Phil Hughes committed
25 26 27 28 29 30 31 32
  def clipboard_button_with_class(data = {}, css_class: 'btn-clipboard')
    content_tag :button,
      icon('clipboard'),
      class: "btn #{css_class}",
      data: data,
      type: :button
  end

33
  def http_clone_button(project)
34
    klass = 'http-selector'
35
    klass << ' has-tooltip' if current_user.try(:require_password?)
36 37 38

    protocol = gitlab_config.protocol.upcase

39
    content_tag :a, protocol,
40
      class: klass,
41
      href: project.http_url_to_repo,
42
      data: {
43
        html: true,
44 45
        placement: 'right',
        container: 'body',
46
        title: "Set a password on your account<br>to pull or push via #{protocol}"
47
      }
48 49 50
  end

  def ssh_clone_button(project)
51
    klass = 'ssh-selector'
52
    klass << ' has-tooltip' if current_user.try(:require_ssh_key?)
53

54
    content_tag :a, 'SSH',
55
      class: klass,
56
      href: project.ssh_url_to_repo,
57
      data: {
58
        html: true,
59 60
        placement: 'right',
        container: 'body',
61
        title: 'Add an SSH key to your profile<br>to pull or push via SSH.'
62
      }
63 64
  end
end