Commit e63d7b6029142d100adca03e11ba0e33d9c2981c

Authored by Riyad Preukschas
1 parent e1ca155c

Rename note.js to notes.js

app/assets/javascripts/note.js
... ... @@ -1,238 +0,0 @@
1   -var NoteList = {
2   -
3   - notes_path: null,
4   - target_params: null,
5   - target_id: 0,
6   - target_type: null,
7   - bottom_id: 0,
8   - loading_more_disabled: false,
9   -
10   - init:
11   - function(tid, tt, path) {
12   - this.notes_path = path + ".js";
13   - this.target_id = tid;
14   - this.target_type = tt;
15   - this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id;
16   -
17   - // get initial set of notes
18   - this.getContent();
19   -
20   - $("#notes-list, #new-notes-list").on("ajax:success", ".delete-note", function() {
21   - $(this).closest('li').fadeOut();
22   - });
23   -
24   - $(".note-form-holder").on("ajax:before", function(){
25   - $(".submit_note").disable()
26   - })
27   -
28   - $(".note-form-holder").on("ajax:complete", function(){
29   - $(".submit_note").enable()
30   - })
31   -
32   - disableButtonIfEmptyField(".note-text", ".submit_note");
33   -
34   - $(".note-text").on("focus", function(){
35   - $(this).css("height", "80px");
36   - $('.note_advanced_opts').show();
37   - });
38   -
39   - $("#note_attachment").change(function(e){
40   - var val = $('.input-file').val();
41   - var filename = val.replace(/^.*[\\\/]/, '');
42   - $(".file_name").text(filename);
43   - });
44   - },
45   -
46   -
47   - /**
48   - * Handle loading the initial set of notes.
49   - * And set up loading more notes when scrolling to the bottom of the page.
50   - */
51   -
52   -
53   - /**
54   - * Gets an inital set of notes.
55   - */
56   - getContent:
57   - function() {
58   - $.ajax({
59   - type: "GET",
60   - url: this.notes_path,
61   - data: "?" + this.target_params,
62   - complete: function(){ $('.notes-status').removeClass("loading")},
63   - beforeSend: function() { $('.notes-status').addClass("loading") },
64   - dataType: "script"});
65   - },
66   -
67   - /**
68   - * Called in response to getContent().
69   - * Replaces the content of #notes-list with the given html.
70   - */
71   - setContent:
72   - function(last_id, html) {
73   - this.bottom_id = last_id;
74   - $("#notes-list").html(html);
75   -
76   - // Init infinite scrolling
77   - this.initLoadMore();
78   - },
79   -
80   -
81   - /**
82   - * Handle loading more notes when scrolling to the bottom of the page.
83   - * The id of the last note in the list is in this.bottom_id.
84   - *
85   - * Set up refreshing only new notes after all notes have been loaded.
86   - */
87   -
88   -
89   - /**
90   - * Initializes loading more notes when scrolling to the bottom of the page.
91   - */
92   - initLoadMore:
93   - function() {
94   - $(document).endlessScroll({
95   - bottomPixels: 400,
96   - fireDelay: 1000,
97   - fireOnce:true,
98   - ceaseFire: function() {
99   - return NoteList.loading_more_disabled;
100   - },
101   - callback: function(i) {
102   - NoteList.getMore();
103   - }
104   - });
105   - },
106   -
107   - /**
108   - * Gets an additional set of notes.
109   - */
110   - getMore:
111   - function() {
112   - // only load more notes if there are no "new" notes
113   - $('.loading').show();
114   - $.ajax({
115   - type: "GET",
116   - url: this.notes_path,
117   - data: "loading_more=1&after_id=" + this.bottom_id + this.target_params,
118   - complete: function(){ $('.notes-status').removeClass("loading")},
119   - beforeSend: function() { $('.notes-status').addClass("loading") },
120   - dataType: "script"});
121   - },
122   -
123   - /**
124   - * Called in response to getMore().
125   - * Append notes to #notes-list.
126   - */
127   - appendMoreNotes:
128   - function(id, html) {
129   - if(id != this.bottom_id) {
130   - this.bottom_id = id;
131   - $("#notes-list").append(html);
132   - }
133   - },
134   -
135   - /**
136   - * Called in response to getMore().
137   - * Disables loading more notes when scrolling to the bottom of the page.
138   - * Initalizes refreshing new notes.
139   - */
140   - finishedLoadingMore:
141   - function() {
142   - this.loading_more_disabled = true;
143   -
144   - // from now on only get new notes
145   - this.initRefreshNew();
146   - },
147   -
148   -
149   - /**
150   - * Handle refreshing and adding of new notes.
151   - *
152   - * New notes are all notes that are created after the site has been loaded.
153   - * The "old" notes are in #notes-list the "new" ones will be in #new-notes-list.
154   - * The id of the last "old" note is in this.bottom_id.
155   - */
156   -
157   -
158   - /**
159   - * Initializes getting new notes every n seconds.
160   - */
161   - initRefreshNew:
162   - function() {
163   - setInterval("NoteList.getNew()", 10000);
164   - },
165   -
166   - /**
167   - * Gets the new set of notes (i.e. all notes after ).
168   - */
169   - getNew:
170   - function() {
171   - $.ajax({
172   - type: "GET",
173   - url: this.notes_path,
174   - data: "loading_new=1&after_id=" + this.bottom_id + this.target_params,
175   - dataType: "script"});
176   - },
177   -
178   - /**
179   - * Called in response to getNew().
180   - * Replaces the content of #new-notes-list with the given html.
181   - */
182   - replaceNewNotes:
183   - function(html) {
184   - $("#new-notes-list").html(html);
185   - },
186   -
187   - /**
188   - * Adds a single note to #new-notes-list.
189   - */
190   - appendNewNote:
191   - function(id, html) {
192   - if(id != this.bottom_id) {
193   - $("#new-notes-list").append(html);
194   - }
195   - }
196   -};
197   -
198   -var PerLineNotes = {
199   - init:
200   - function() {
201   - /**
202   - * Called when clicking on the "add note" or "reply" button for a diff line.
203   - *
204   - * Shows the note form below the line.
205   - * Sets some hidden fields in the form.
206   - */
207   - $(".diff_file_content").on("click", ".line_note_link, .line_note_reply_link", function(e) {
208   - var form = $(".per_line_form");
209   - $(this).closest("tr").after(form);
210   - form.find("#note_line_code").val($(this).data("lineCode"));
211   - form.show();
212   - return false;
213   - });
214   -
215   - disableButtonIfEmptyField(".line-note-text", ".submit_inline_note");
216   -
217   - /**
218   - * Called in response to successfully deleting a note on a diff line.
219   - *
220   - * Removes the actual note from view.
221   - * Removes the reply button if the last note for that line has been removed.
222   - */
223   - $(".diff_file_content").on("ajax:success", ".delete-note", function() {
224   - var trNote = $(this).closest("tr");
225   - trNote.fadeOut(function() {
226   - $(this).remove();
227   - });
228   -
229   - // check if this is the last note for this line
230   - // elements must really be removed for this to work reliably
231   - var trLine = trNote.prev();
232   - var trRpl = trNote.next();
233   - if (trLine.hasClass("line_holder") && trRpl.hasClass("reply")) {
234   - trRpl.fadeOut(function() { $(this).remove(); });
235   - }
236   - });
237   - }
238   -}
app/assets/javascripts/notes.js 0 → 100644
... ... @@ -0,0 +1,238 @@
  1 +var NoteList = {
  2 +
  3 + notes_path: null,
  4 + target_params: null,
  5 + target_id: 0,
  6 + target_type: null,
  7 + bottom_id: 0,
  8 + loading_more_disabled: false,
  9 +
  10 + init:
  11 + function(tid, tt, path) {
  12 + this.notes_path = path + ".js";
  13 + this.target_id = tid;
  14 + this.target_type = tt;
  15 + this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id;
  16 +
  17 + // get initial set of notes
  18 + this.getContent();
  19 +
  20 + $("#notes-list, #new-notes-list").on("ajax:success", ".delete-note", function() {
  21 + $(this).closest('li').fadeOut();
  22 + });
  23 +
  24 + $(".note-form-holder").on("ajax:before", function(){
  25 + $(".submit_note").disable()
  26 + })
  27 +
  28 + $(".note-form-holder").on("ajax:complete", function(){
  29 + $(".submit_note").enable()
  30 + })
  31 +
  32 + disableButtonIfEmptyField(".note-text", ".submit_note");
  33 +
  34 + $(".note-text").on("focus", function(){
  35 + $(this).css("height", "80px");
  36 + $('.note_advanced_opts').show();
  37 + });
  38 +
  39 + $("#note_attachment").change(function(e){
  40 + var val = $('.input-file').val();
  41 + var filename = val.replace(/^.*[\\\/]/, '');
  42 + $(".file_name").text(filename);
  43 + });
  44 + },
  45 +
  46 +
  47 + /**
  48 + * Handle loading the initial set of notes.
  49 + * And set up loading more notes when scrolling to the bottom of the page.
  50 + */
  51 +
  52 +
  53 + /**
  54 + * Gets an inital set of notes.
  55 + */
  56 + getContent:
  57 + function() {
  58 + $.ajax({
  59 + type: "GET",
  60 + url: this.notes_path,
  61 + data: "?" + this.target_params,
  62 + complete: function(){ $('.notes-status').removeClass("loading")},
  63 + beforeSend: function() { $('.notes-status').addClass("loading") },
  64 + dataType: "script"});
  65 + },
  66 +
  67 + /**
  68 + * Called in response to getContent().
  69 + * Replaces the content of #notes-list with the given html.
  70 + */
  71 + setContent:
  72 + function(last_id, html) {
  73 + this.bottom_id = last_id;
  74 + $("#notes-list").html(html);
  75 +
  76 + // Init infinite scrolling
  77 + this.initLoadMore();
  78 + },
  79 +
  80 +
  81 + /**
  82 + * Handle loading more notes when scrolling to the bottom of the page.
  83 + * The id of the last note in the list is in this.bottom_id.
  84 + *
  85 + * Set up refreshing only new notes after all notes have been loaded.
  86 + */
  87 +
  88 +
  89 + /**
  90 + * Initializes loading more notes when scrolling to the bottom of the page.
  91 + */
  92 + initLoadMore:
  93 + function() {
  94 + $(document).endlessScroll({
  95 + bottomPixels: 400,
  96 + fireDelay: 1000,
  97 + fireOnce:true,
  98 + ceaseFire: function() {
  99 + return NoteList.loading_more_disabled;
  100 + },
  101 + callback: function(i) {
  102 + NoteList.getMore();
  103 + }
  104 + });
  105 + },
  106 +
  107 + /**
  108 + * Gets an additional set of notes.
  109 + */
  110 + getMore:
  111 + function() {
  112 + // only load more notes if there are no "new" notes
  113 + $('.loading').show();
  114 + $.ajax({
  115 + type: "GET",
  116 + url: this.notes_path,
  117 + data: "loading_more=1&after_id=" + this.bottom_id + this.target_params,
  118 + complete: function(){ $('.notes-status').removeClass("loading")},
  119 + beforeSend: function() { $('.notes-status').addClass("loading") },
  120 + dataType: "script"});
  121 + },
  122 +
  123 + /**
  124 + * Called in response to getMore().
  125 + * Append notes to #notes-list.
  126 + */
  127 + appendMoreNotes:
  128 + function(id, html) {
  129 + if(id != this.bottom_id) {
  130 + this.bottom_id = id;
  131 + $("#notes-list").append(html);
  132 + }
  133 + },
  134 +
  135 + /**
  136 + * Called in response to getMore().
  137 + * Disables loading more notes when scrolling to the bottom of the page.
  138 + * Initalizes refreshing new notes.
  139 + */
  140 + finishedLoadingMore:
  141 + function() {
  142 + this.loading_more_disabled = true;
  143 +
  144 + // from now on only get new notes
  145 + this.initRefreshNew();
  146 + },
  147 +
  148 +
  149 + /**
  150 + * Handle refreshing and adding of new notes.
  151 + *
  152 + * New notes are all notes that are created after the site has been loaded.
  153 + * The "old" notes are in #notes-list the "new" ones will be in #new-notes-list.
  154 + * The id of the last "old" note is in this.bottom_id.
  155 + */
  156 +
  157 +
  158 + /**
  159 + * Initializes getting new notes every n seconds.
  160 + */
  161 + initRefreshNew:
  162 + function() {
  163 + setInterval("NoteList.getNew()", 10000);
  164 + },
  165 +
  166 + /**
  167 + * Gets the new set of notes (i.e. all notes after ).
  168 + */
  169 + getNew:
  170 + function() {
  171 + $.ajax({
  172 + type: "GET",
  173 + url: this.notes_path,
  174 + data: "loading_new=1&after_id=" + this.bottom_id + this.target_params,
  175 + dataType: "script"});
  176 + },
  177 +
  178 + /**
  179 + * Called in response to getNew().
  180 + * Replaces the content of #new-notes-list with the given html.
  181 + */
  182 + replaceNewNotes:
  183 + function(html) {
  184 + $("#new-notes-list").html(html);
  185 + },
  186 +
  187 + /**
  188 + * Adds a single note to #new-notes-list.
  189 + */
  190 + appendNewNote:
  191 + function(id, html) {
  192 + if(id != this.bottom_id) {
  193 + $("#new-notes-list").append(html);
  194 + }
  195 + }
  196 +};
  197 +
  198 +var PerLineNotes = {
  199 + init:
  200 + function() {
  201 + /**
  202 + * Called when clicking on the "add note" or "reply" button for a diff line.
  203 + *
  204 + * Shows the note form below the line.
  205 + * Sets some hidden fields in the form.
  206 + */
  207 + $(".diff_file_content").on("click", ".line_note_link, .line_note_reply_link", function(e) {
  208 + var form = $(".per_line_form");
  209 + $(this).closest("tr").after(form);
  210 + form.find("#note_line_code").val($(this).data("lineCode"));
  211 + form.show();
  212 + return false;
  213 + });
  214 +
  215 + disableButtonIfEmptyField(".line-note-text", ".submit_inline_note");
  216 +
  217 + /**
  218 + * Called in response to successfully deleting a note on a diff line.
  219 + *
  220 + * Removes the actual note from view.
  221 + * Removes the reply button if the last note for that line has been removed.
  222 + */
  223 + $(".diff_file_content").on("ajax:success", ".delete-note", function() {
  224 + var trNote = $(this).closest("tr");
  225 + trNote.fadeOut(function() {
  226 + $(this).remove();
  227 + });
  228 +
  229 + // check if this is the last note for this line
  230 + // elements must really be removed for this to work reliably
  231 + var trLine = trNote.prev();
  232 + var trRpl = trNote.next();
  233 + if (trLine.hasClass("line_holder") && trRpl.hasClass("reply")) {
  234 + trRpl.fadeOut(function() { $(this).remove(); });
  235 + }
  236 + });
  237 + }
  238 +}
... ...