summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-08-10 06:42:31 -0700
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-08-10 06:42:31 -0700
commit5fd0e7ba119d59a3e9f2ea3eed03ece1e8baeec3 (patch)
tree2df982fb426d38e61589e66eb958138a105a0a19
parent35b45da63e683e29318afac2e41ec8b3ac8419ab (diff)
parent9639780359f16d784f22af2a1dbbcd8322ffd6c3 (diff)
downloadgitlab-ce-5fd0e7ba119d59a3e9f2ea3eed03ece1e8baeec3.tar.gz
Merge pull request #1198 from NARKOZ/preview_notes
ability to preview notes
-rw-r--r--app/assets/javascripts/application.js25
-rw-r--r--app/controllers/notes_controller.rb6
-rw-r--r--app/views/notes/_form.html.haml4
-rw-r--r--config/routes.rb6
4 files changed, 35 insertions, 6 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 56e26a06f18..25732ae5289 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -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() {
@@ -108,6 +127,6 @@ function showDiff(link) {
})(jQuery);
-function ajaxGet(url) {
- $.ajax({type: "GET", url: url, dataType: "script"});
+function ajaxGet(url) {
+ $.ajax({type: "GET", url: url, dataType: "script"});
}
diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb
index e8e4bb544a8..8fac6428a58 100644
--- a/app/controllers/notes_controller.rb
+++ b/app/controllers/notes_controller.rb
@@ -33,7 +33,11 @@ class NotesController < ApplicationController
end
end
- protected
+ def preview
+ render :text => view_context.markdown(params[:note])
+ end
+
+ protected
def notes
@notes = Notes::LoadContext.new(project, current_user, params).execute
diff --git a/app/views/notes/_form.html.haml b/app/views/notes/_form.html.haml
index 43d95564cc0..f5571aede5e 100644
--- a/app/views/notes/_form.html.haml
+++ b/app/views/notes/_form.html.haml
@@ -7,10 +7,12 @@
= f.hidden_field :noteable_id
= f.hidden_field :noteable_type
- = f.text_area :note, :size => 255
+ = 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
diff --git a/config/routes.rb b/config/routes.rb
index 7ece304450d..04e13bc4a86 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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