BigW Consortium Gitlab

_form.html.haml 1.65 KB
Newer Older
1
%h3.page-title
2 3 4
  = @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}"
%hr
.snippet-form-holder
5
  = form_for [@project, @snippet], as: :project_snippet, url: url do |f|
6 7 8 9 10 11
    -if @snippet.errors.any?
      .alert.alert-error
        %ul
          - @snippet.errors.full_messages.each do |msg|
            %li= msg

12
    .control-group
13
      = f.label :title
14 15
      .controls= f.text_field :title, placeholder: "Example Snippet", class: 'input-xlarge', required: true
    .control-group
16
      = f.label "Lifetime"
17 18
      .controls= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'}
    .control-group
19 20
      .file-editor
        = f.label :file_name, "File"
21
        .controls
22 23
          .file-holder.snippet
            .file-title
24
              = f.text_field :file_name, placeholder: "example.rb", class: 'snippet-file-name', required: true
25
            .file-content.code
26 27 28 29
              %pre#editor= @snippet.content
              = f.hidden_field :content, class: 'snippet-file-content'

    .form-actions
30 31 32 33 34
      - if @snippet.new_record?
        = f.submit 'Create snippet', class: "btn-create btn"
      - else
        = f.submit 'Save', class: "btn-save btn"
      = link_to "Cancel", project_snippets_path(@project), class: " btn btn-cancel"
35
      - unless @snippet.new_record?
36
        .pull-right= link_to 'Destroy', project_snippet_path(@project, @snippet), confirm: 'Are you sure?', method: :delete, class: "btn pull-right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}"
37 38 39 40 41 42 43 44


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