_form.html.haml 1.58 KB
Newer Older
1
.snippet-form-holder
2 3
  = form_for @snippet, url: url, html: { class: "form-horizontal snippet-form" } do |f|
    - if @snippet.errors.any?
4
      .alert.alert-danger
5 6 7 8
        %ul
          - @snippet.errors.full_messages.each do |msg|
            %li= msg

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
9
    .form-group
10
      = f.label :title, class: 'control-label'
11
      .col-sm-10= f.text_field :title, placeholder: "Example Snippet", class: 'form-control', required: true
12

13 14
    = render "shared/snippets/visibility_level", f: f, visibility_level: gitlab_config.default_projects_features.visibility_level, can_change_visibility_level: true
    
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
15
    .form-group
16
      .file-editor
17
        = f.label :file_name, "File", class: 'control-label'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
18
        .col-sm-10
19 20
          .file-holder.snippet
            .file-title
21
              = f.text_field :file_name, placeholder: "example.rb", class: 'form-control snippet-file-name', required: true
22
            .file-content.code
23 24 25 26
              %pre#editor= @snippet.content
              = f.hidden_field :content, class: 'snippet-file-content'

    .form-actions
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
27 28 29 30
      - if @snippet.new_record?
        = f.submit 'Create snippet', class: "btn-create btn"
      - else
        = f.submit 'Save', class: "btn-save btn"
31

32
      - if @snippet.respond_to?(:project)
Vinnie Okada's avatar
Vinnie Okada committed
33
        = link_to "Cancel", namespace_project_snippets_path(@project.namespace, @project), class: "btn btn-cancel"
34 35
      - else
        = link_to "Cancel", snippets_path(@project), class: "btn btn-cancel"
36 37 38 39 40 41

:javascript
  var editor = ace.edit("editor");
  $(".snippet-form-holder form").submit(function(){
    $(".snippet-file-content").val(editor.getValue());
  });