Commit 5fd0e7ba authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #1198 from NARKOZ/preview_notes

ability to preview notes
parents 35b45da6 96397803
......@@ -26,7 +26,6 @@ $(document).ready(function(){
$(this).select();
});
$('body').on('ajax:complete, ajax:beforeSend, submit', 'form', function(e){
var buttons = $('[type="submit"]', this);
switch( e.type ){
......@@ -70,6 +69,26 @@ $(document).ready(function(){
$(".supp_diff_link").bind("click", function() {
showDiff(this);
});
/**
* Note markdown preview
*
*/
$('#preview-link').on('click', function(e) {
$('#preview-note').text('Loading...');
var previewLinkText = ($(this).text() == 'Preview' ? 'Edit' : 'Preview');
$(this).text(previewLinkText);
var note = $('#note_note').val();
if (note.trim().length === 0) { note = 'Nothing to preview'; }
$.post($(this).attr('href'), {note: note}, function(data) {
$('#preview-note').html(data);
});
$('#preview-note, #note_note').toggle();
e.preventDefault();
});
});
function focusSearch() {
......
......@@ -33,6 +33,10 @@ class NotesController < ApplicationController
end
end
def preview
render :text => view_context.markdown(params[:note])
end
protected
def notes
......
......@@ -8,9 +8,11 @@
= f.hidden_field :noteable_id
= f.hidden_field :noteable_type
= f.text_area :note, :size => 255
#preview-note.well.hide
%p.hint
= link_to "Gitlab Markdown", help_markdown_path, :target => '_blank'
is enabled.
= link_to 'Preview', preview_project_notes_path(@project), :id => 'preview-link'
.row.note_advanced_opts.hide
.span2
......
......@@ -203,7 +203,11 @@ Gitlab::Application.routes.draw do
get :search
end
end
resources :notes, :only => [:index, :create, :destroy]
resources :notes, :only => [:index, :create, :destroy] do
collection do
post :preview
end
end
end
root :to => "dashboard#index"
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment