Commit ece563296bcac93ce5918a050a70a95ceba0d7f9

Authored by Riyad Preukschas
1 parent 433d2278

Fix Notes JS

Also fixes #1983
app/assets/javascripts/main.js.coffee
... ... @@ -58,25 +58,6 @@ $ ->
58 58 $(@).next('table').show()
59 59 $(@).remove()
60 60  
61   - # Note markdown preview
62   - $(document).on 'click', '#preview-link', (e) ->
63   - $('#preview-note').text 'Loading...'
64   -
65   - previewLinkText = if $(@).text() is 'Preview' then 'Edit' else 'Preview'
66   - $(@).text previewLinkText
67   -
68   - note = $('#note_note').val()
69   -
70   - if note.trim().length is 0
71   - $('#preview-note').text 'Nothing to preview.'
72   - else
73   - $.post $(@).attr('href'), {note: note}, (data) ->
74   - $('#preview-note').html(data)
75   -
76   - $('#preview-note, #note_note').toggle()
77   - e.preventDefault()
78   - false
79   -
80 61 (($) ->
81 62 _chosen = $.fn.chosen
82 63 $.fn.extend chosen: (options) ->
... ...
app/assets/javascripts/notes.js
... ... @@ -14,8 +14,8 @@ var NoteList = {
14 14 this.notes_path = path + ".js";
15 15 this.target_id = tid;
16 16 this.target_type = tt;
17   - this.reversed = $("#notes-list").hasClass("reversed");
18   - this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id;
  17 + this.reversed = $("#notes-list").is(".reversed");
  18 + this.target_params = "target_type=" + this.target_type + "&target_id=" + this.target_id;
19 19  
20 20 // get initial set of notes
21 21 this.getContent();
... ... @@ -33,6 +33,8 @@ var NoteList = {
33 33  
34 34 $(".note-form-holder").on("ajax:complete", function(){
35 35 $(".submit_note").enable();
  36 + $('#preview-note').hide();
  37 + $('#note_note').show();
36 38 })
37 39  
38 40 disableButtonIfEmptyField(".note-text", ".submit_note");
... ... @@ -52,6 +54,26 @@ var NoteList = {
52 54 $('.note_advanced_opts').show();
53 55 });
54 56 }
  57 +
  58 + // Setup note preview
  59 + $(document).on('click', '#preview-link', function(e) {
  60 + $('#preview-note').text('Loading...');
  61 +
  62 + $(this).text($(this).text() === "Edit" ? "Preview" : "Edit");
  63 +
  64 + var note_text = $('#note_note').val();
  65 +
  66 + if(note_text.trim().length === 0) {
  67 + $('#preview-note').text('Nothing to preview.');
  68 + } else {
  69 + $.post($(this).attr('href'), {note: note_text}).success(function(data) {
  70 + $('#preview-note').html(data);
  71 + });
  72 + }
  73 +
  74 + $('#preview-note, #note_note').toggle();
  75 + e.preventDefault();
  76 + });
55 77 },
56 78  
57 79  
... ... @@ -69,7 +91,7 @@ var NoteList = {
69 91 $.ajax({
70 92 type: "GET",
71 93 url: this.notes_path,
72   - data: "?" + this.target_params,
  94 + data: this.target_params,
73 95 complete: function(){ $('.notes-status').removeClass("loading")},
74 96 beforeSend: function() { $('.notes-status').addClass("loading") },
75 97 dataType: "script"});
... ... @@ -131,7 +153,7 @@ var NoteList = {
131 153 $.ajax({
132 154 type: "GET",
133 155 url: this.notes_path,
134   - data: "loading_more=1&" + (this.reversed ? "before_id" : "after_id") + "=" + this.bottom_id + this.target_params,
  156 + data: this.target_params + "&loading_more=1&" + (this.reversed ? "before_id" : "after_id") + "=" + this.bottom_id,
135 157 complete: function(){ $('.notes-status').removeClass("loading")},
136 158 beforeSend: function() { $('.notes-status').addClass("loading") },
137 159 dataType: "script"});
... ... @@ -192,7 +214,7 @@ var NoteList = {
192 214 $.ajax({
193 215 type: "GET",
194 216 url: this.notes_path,
195   - data: "loading_new=1&after_id=" + (this.reversed ? this.top_id : this.bottom_id) + this.target_params,
  217 + data: this.target_params + "&loading_new=1&after_id=" + (this.reversed ? this.top_id : this.bottom_id),
196 218 dataType: "script"});
197 219 },
198 220  
... ... @@ -264,7 +286,7 @@ var PerLineNotes = {
264 286 $(this).closest("tr").after(form);
265 287 form.find("#note_line_code").val($(this).data("lineCode"));
266 288 form.show();
267   - return false;
  289 + e.preventDefault();
268 290 });
269 291  
270 292 disableButtonIfEmptyField(".line-note-text", ".submit_inline_note");
... ... @@ -285,7 +307,7 @@ var PerLineNotes = {
285 307 // elements must really be removed for this to work reliably
286 308 var trLine = trNote.prev();
287 309 var trRpl = trNote.next();
288   - if (trLine.hasClass("line_holder") && trRpl.hasClass("reply")) {
  310 + if (trLine.is(".line_holder") && trRpl.is(".reply")) {
289 311 trRpl.fadeOut(function() { $(this).remove(); });
290 312 }
291 313 });
... ...