Commit ece56329 authored by Riyad Preukschas's avatar Riyad Preukschas

Fix Notes JS

Also fixes #1983
parent 433d2278
...@@ -58,25 +58,6 @@ $ -> ...@@ -58,25 +58,6 @@ $ ->
$(@).next('table').show() $(@).next('table').show()
$(@).remove() $(@).remove()
# Note markdown preview
$(document).on 'click', '#preview-link', (e) ->
$('#preview-note').text 'Loading...'
previewLinkText = if $(@).text() is 'Preview' then 'Edit' else 'Preview'
$(@).text previewLinkText
note = $('#note_note').val()
if note.trim().length is 0
$('#preview-note').text 'Nothing to preview.'
else
$.post $(@).attr('href'), {note: note}, (data) ->
$('#preview-note').html(data)
$('#preview-note, #note_note').toggle()
e.preventDefault()
false
(($) -> (($) ->
_chosen = $.fn.chosen _chosen = $.fn.chosen
$.fn.extend chosen: (options) -> $.fn.extend chosen: (options) ->
......
...@@ -14,8 +14,8 @@ var NoteList = { ...@@ -14,8 +14,8 @@ var NoteList = {
this.notes_path = path + ".js"; this.notes_path = path + ".js";
this.target_id = tid; this.target_id = tid;
this.target_type = tt; this.target_type = tt;
this.reversed = $("#notes-list").hasClass("reversed"); this.reversed = $("#notes-list").is(".reversed");
this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id; this.target_params = "target_type=" + this.target_type + "&target_id=" + this.target_id;
// get initial set of notes // get initial set of notes
this.getContent(); this.getContent();
...@@ -33,6 +33,8 @@ var NoteList = { ...@@ -33,6 +33,8 @@ var NoteList = {
$(".note-form-holder").on("ajax:complete", function(){ $(".note-form-holder").on("ajax:complete", function(){
$(".submit_note").enable(); $(".submit_note").enable();
$('#preview-note').hide();
$('#note_note').show();
}) })
disableButtonIfEmptyField(".note-text", ".submit_note"); disableButtonIfEmptyField(".note-text", ".submit_note");
...@@ -52,6 +54,26 @@ var NoteList = { ...@@ -52,6 +54,26 @@ var NoteList = {
$('.note_advanced_opts').show(); $('.note_advanced_opts').show();
}); });
} }
// Setup note preview
$(document).on('click', '#preview-link', function(e) {
$('#preview-note').text('Loading...');
$(this).text($(this).text() === "Edit" ? "Preview" : "Edit");
var note_text = $('#note_note').val();
if(note_text.trim().length === 0) {
$('#preview-note').text('Nothing to preview.');
} else {
$.post($(this).attr('href'), {note: note_text}).success(function(data) {
$('#preview-note').html(data);
});
}
$('#preview-note, #note_note').toggle();
e.preventDefault();
});
}, },
...@@ -69,7 +91,7 @@ var NoteList = { ...@@ -69,7 +91,7 @@ var NoteList = {
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: this.notes_path, url: this.notes_path,
data: "?" + this.target_params, data: this.target_params,
complete: function(){ $('.notes-status').removeClass("loading")}, complete: function(){ $('.notes-status').removeClass("loading")},
beforeSend: function() { $('.notes-status').addClass("loading") }, beforeSend: function() { $('.notes-status').addClass("loading") },
dataType: "script"}); dataType: "script"});
...@@ -131,7 +153,7 @@ var NoteList = { ...@@ -131,7 +153,7 @@ var NoteList = {
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: this.notes_path, url: this.notes_path,
data: "loading_more=1&" + (this.reversed ? "before_id" : "after_id") + "=" + this.bottom_id + this.target_params, data: this.target_params + "&loading_more=1&" + (this.reversed ? "before_id" : "after_id") + "=" + this.bottom_id,
complete: function(){ $('.notes-status').removeClass("loading")}, complete: function(){ $('.notes-status').removeClass("loading")},
beforeSend: function() { $('.notes-status').addClass("loading") }, beforeSend: function() { $('.notes-status').addClass("loading") },
dataType: "script"}); dataType: "script"});
...@@ -192,7 +214,7 @@ var NoteList = { ...@@ -192,7 +214,7 @@ var NoteList = {
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: this.notes_path, url: this.notes_path,
data: "loading_new=1&after_id=" + (this.reversed ? this.top_id : this.bottom_id) + this.target_params, data: this.target_params + "&loading_new=1&after_id=" + (this.reversed ? this.top_id : this.bottom_id),
dataType: "script"}); dataType: "script"});
}, },
...@@ -264,7 +286,7 @@ var PerLineNotes = { ...@@ -264,7 +286,7 @@ var PerLineNotes = {
$(this).closest("tr").after(form); $(this).closest("tr").after(form);
form.find("#note_line_code").val($(this).data("lineCode")); form.find("#note_line_code").val($(this).data("lineCode"));
form.show(); form.show();
return false; e.preventDefault();
}); });
disableButtonIfEmptyField(".line-note-text", ".submit_inline_note"); disableButtonIfEmptyField(".line-note-text", ".submit_inline_note");
...@@ -285,7 +307,7 @@ var PerLineNotes = { ...@@ -285,7 +307,7 @@ var PerLineNotes = {
// elements must really be removed for this to work reliably // elements must really be removed for this to work reliably
var trLine = trNote.prev(); var trLine = trNote.prev();
var trRpl = trNote.next(); var trRpl = trNote.next();
if (trLine.hasClass("line_holder") && trRpl.hasClass("reply")) { if (trLine.is(".line_holder") && trRpl.is(".reply")) {
trRpl.fadeOut(function() { $(this).remove(); }); trRpl.fadeOut(function() { $(this).remove(); });
} }
}); });
......
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