Merge lp:~blr/launchpad/inline-comment-delint into lp:launchpad

Proposed by Kit Randel
Status: Merged
Approved by: Kit Randel
Approved revision: no longer in the source branch.
Merged at revision: 17311
Proposed branch: lp:~blr/launchpad/inline-comment-delint
Merge into: lp:launchpad
Diff against target: 233 lines (+38/-34)
1 file modified
lib/lp/code/javascript/branchmergeproposal.inlinecomments.js (+38/-34)
To merge this branch: bzr merge lp:~blr/launchpad/inline-comment-delint
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+243322@code.launchpad.net

Description of the change

A delinting pass over the inline comment code I've been looking at recently.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/javascript/branchmergeproposal.inlinecomments.js'
2--- lib/lp/code/javascript/branchmergeproposal.inlinecomments.js 2014-11-27 22:27:28 +0000
3+++ lib/lp/code/javascript/branchmergeproposal.inlinecomments.js 2014-12-01 19:25:34 +0000
4@@ -43,7 +43,7 @@
5 namespace.flush_drafts_to_server = function() {
6 var config = {
7 on: {
8- success: function () {
9+ success: function() {
10 Y.fire('inlinecomment.UPDATED');
11 }
12 },
13@@ -89,10 +89,10 @@
14 });
15 widget.editor.on('keydown', function(e) {
16 var enterKeyCode = 13;
17- if (e.domEvent.ctrlKey === true &&
18+ if (e.domEvent.ctrlKey === true &&
19 e.domEvent.button === enterKeyCode) {
20 this.save();
21- }
22+ }
23 });
24 widget.editor.on('cancel', function(e) {
25 handling_request = false;
26@@ -111,7 +111,6 @@
27 .append('<div class="editorShortcutTip">' +
28 '[Esc] Cancel, [Ctrl+Enter] Save' +
29 '</div>');
30-
31 };
32 var delete_handler = function(e) {
33 var line_number = namespace.find_line_number(e.currentTarget);
34@@ -143,11 +142,14 @@
35
36 namespace.create_row = function(comment) {
37 // Find or create the container for this line's comments.
38- var comments_tr = Y.one('#comments-diff-line-' + comment.line_number);
39+ var comments_tr = Y.one('#comments-diff-line-' +
40+ comment.line_number),
41+ comment_date;
42+
43 if (comments_tr === null) {
44- var comments_tr = Y.Node.create(
45- '<tr class="inline-comments">'
46- + '<td colspan="2"><div></div></td></tr>')
47+ comments_tr = Y.Node.create(
48+ '<tr class="inline-comments">' +
49+ '<td colspan="2"><div></div></td></tr>')
50 .set('id', 'comments-diff-line-' + comment.line_number);
51 Y.one('#diff-line-' + comment.line_number)
52 .insert(comments_tr, 'after');
53@@ -181,7 +183,7 @@
54 // Wrap resources coming from LP.cache, as they come from
55 // the LP API (updates during the page life-span). This way
56 // the handling code can be unified.
57- if (LP.links['me'] !== undefined) {
58+ if (LP.links.me !== undefined) {
59 newrow.append('<div class="boardCommentFooter"></div>');
60 newrow.one('.boardCommentFooter')
61 .append('<a class="js-action draft-edit">Reply</a>');
62@@ -198,10 +200,10 @@
63 // XXX cprov 20140226: the date should be formatted according to
64 // the user locale/timezone similar to fmt:displaydate.
65 // We should leverage Y.Intl features.
66- if (typeof comment.date === "string") {
67- var comment_date = Y.lp.app.date.parse_date(comment.date);
68+ if (typeof comment.date === 'string') {
69+ comment_date = Y.lp.app.date.parse_date(comment.date);
70 } else {
71- var comment_date = comment.date;
72+ comment_date = comment.date;
73 }
74 var date = Y.lp.app.date.approximatedate(comment_date);
75 headerspan.one('span').set('text', date);
76@@ -228,11 +230,11 @@
77 namespace.populate_comments = function() {
78 var config_published = {
79 on: {
80- success: function (comments) {
81+ success: function(comments) {
82 // Display published inline comments.
83 // [{'line_number': <lineno>, 'person': <IPerson>,
84 // 'text': <comment>, 'date': <timestamp>}, ...]
85- comments.forEach( function (comment) {
86+ comments.forEach(function(comment) {
87 namespace.create_row(comment);
88 });
89 Y.fire('inlinecomment.UPDATED');
90@@ -249,14 +251,14 @@
91 namespace.populate_drafts = function() {
92 var config_draft = {
93 on: {
94- success: function (drafts) {
95+ success: function(drafts) {
96 namespace.inlinecomments = {};
97 if (drafts === null) {
98 return;
99 }
100 // Display draft inline comments:
101 // {'<line_number>':''<comment>', ...})
102- Object.keys(drafts).forEach( function (line_number) {
103+ Object.keys(drafts).forEach(function(line_number) {
104 var comment = {
105 'line_number': line_number,
106 'text': drafts[line_number]
107@@ -284,7 +286,7 @@
108 // loaded for anonymous requests.
109 // In fact, if loading draft is attempted is will fail due to
110 // the LP permission checks.
111- if (LP.links['me'] !== undefined) {
112+ if (LP.links.me !== undefined) {
113 // Add the double-click handler for each row in the diff. This needs
114 // to be done first since populating existing published and draft
115 // comments may add more rows.
116@@ -295,7 +297,7 @@
117 };
118
119
120-var PublishDrafts = function () {
121+var PublishDrafts = function() {
122 PublishDrafts.superclass.constructor.apply(this, arguments);
123 };
124
125@@ -320,29 +322,31 @@
126 * @method syncUI
127 */
128 syncUI: function() {
129+ var n_drafts = Y.all('.draft').size(),
130+ rc_scroller = Y.one('.review-comment-scroller'),
131+ scroller_text = '';
132+
133 this.get('contentBox').empty();
134- var n_drafts = Y.all('.draft').size();
135- var rc_scroller = Y.one('.review-comment-scroller');
136 if (rc_scroller !== null) {
137 if (n_drafts > 0) {
138- var scroller_text = 'Return to save comment'
139- if (n_drafts > 1) scroller_text += 's';
140+ scroller_text = 'Return to save comment';
141+ if (n_drafts > 1) { scroller_text += 's'; }
142 rc_scroller.set('text', scroller_text);
143 } else {
144 rc_scroller.set('text', 'Return to add comment');
145 }
146 }
147- if (n_drafts == 0) {
148+ if (n_drafts === 0) {
149 Y.fire('CodeReviewComment.SET_DISABLED', true);
150 return;
151 }
152 var text = ' Include ' + n_drafts + ' diff comment';
153- if (n_drafts > 1) text += 's';
154+ if (n_drafts > 1) { text += 's'; }
155 var checkbox = Y.Node.create(
156 '<input id="field.publish_inline_comments"' +
157 'name="field.publish_inline_comments"' +
158 'type="checkbox" class="checkboxType"' +
159- 'checked=""></input>')
160+ 'checked=""></input>');
161 var label = Y.Node.create(
162 '<label for="field.publish_inline_comments" />')
163 .set('text', text);
164@@ -367,7 +371,7 @@
165 namespace.PublishDrafts = PublishDrafts;
166
167
168-var InlineCommentToggle = function () {
169+var InlineCommentToggle = function() {
170 InlineCommentToggle.superclass.constructor.apply(this, arguments);
171 };
172
173@@ -408,7 +412,7 @@
174 if (display) {
175 css_display = 'table-row';
176 }
177- Y.all('.inline-comments').each( function() {
178+ Y.all('.inline-comments').each(function() {
179 this.setStyle('display', css_display);
180 this.next().setStyle('display', css_display);
181 });
182@@ -469,12 +473,12 @@
183 * @method initializer
184 * @protected
185 */
186- initializer: function(cfg){
187+ initializer: function(cfg) {
188 // If we have not been provided with a Launchpad Client, then
189 // create one now:
190- if (null === this.get("lp_client")){
191+ if (null === this.get('lp_client')) {
192 // Create our own instance of the LP client.
193- this.set("lp_client", new Y.lp.client.Launchpad());
194+ this.set('lp_client', new Y.lp.client.Launchpad());
195 }
196 },
197
198@@ -534,7 +538,7 @@
199 _connectScrollers: function() {
200 var self = this;
201 var rc = Y.lp.code.branchmergeproposal.reviewcomment;
202- Y.all('td[data-previewdiff-id]').each( function(td) {
203+ Y.all('td[data-previewdiff-id]').each(function(td) {
204 // Comments from superseded MPs should be ignored.
205 if (td.getData('from-superseded') === 'True') {
206 return;
207@@ -561,7 +565,7 @@
208 return;
209 }
210 rc_scroller = Y.Node.create('<a href="">Return to add comment</a>')
211- .addClass('review-comment-scroller')
212+ .addClass('review-comment-scroller');
213 this.get('srcNode').append(rc_scroller);
214 rc.link_scroller(rc_scroller, '#add-comment-form', function() {
215 if (Y.all('.draft').size() > 0) {
216@@ -583,7 +587,7 @@
217 var container = this.get('srcNode').one('.diff-content');
218 var config = {
219 on: {
220- success: function (diff_html) {
221+ success: function(diff_html) {
222 container.set('innerHTML', diff_html);
223 self.set_status_updated();
224 },
225@@ -642,7 +646,7 @@
226
227 var pub_drafts_anchor = Y.one('[id="field.review_type"]');
228 if (pub_drafts_anchor !== null) {
229- var pub_drafts_container = Y.one('.publish_drafts_container')
230+ var pub_drafts_container = Y.one('.publish_drafts_container');
231 if (pub_drafts_container === null) {
232 pub_drafts_container = Y.Node.create(
233 '<div class="publish_drafts_container">');