Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 1 | // Copyright (C) 2016 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | (function() { |
| 15 | 'use strict'; |
| 16 | |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 17 | var STORAGE_DEBOUNCE_INTERVAL = 400; |
| 18 | |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 19 | Polymer({ |
| 20 | is: 'gr-diff-comment', |
| 21 | |
| 22 | /** |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 23 | * Fired when the Reply action is triggered. |
| 24 | * |
| 25 | * @event reply |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * Fired when the Done action is triggered. |
| 30 | * |
| 31 | * @event done |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * Fired when this comment is discarded. |
| 36 | * |
Andrew Bonventre | 6a9312f | 2016-03-25 11:29:36 -0400 | [diff] [blame] | 37 | * @event comment-discard |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 38 | */ |
| 39 | |
Andrew Bonventre | 2816526 | 2016-05-19 17:24:45 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Fired when this comment is saved. |
| 42 | * |
| 43 | * @event comment-save |
| 44 | */ |
| 45 | |
Viktar Donich | 7ad2892 | 2016-05-23 15:24:05 -0700 | [diff] [blame] | 46 | /** |
| 47 | * Fired when this comment is updated. |
| 48 | * |
| 49 | * @event comment-update |
| 50 | */ |
| 51 | |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 52 | /** |
| 53 | * @event comment-mouse-over |
| 54 | */ |
| 55 | |
| 56 | /** |
| 57 | * @event comment-mouse-out |
| 58 | */ |
| 59 | |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 60 | properties: { |
| 61 | changeNum: String, |
| 62 | comment: { |
| 63 | type: Object, |
| 64 | notify: true, |
Viktar Donich | 7ad2892 | 2016-05-23 15:24:05 -0700 | [diff] [blame] | 65 | observer: '_commentChanged', |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 66 | }, |
| 67 | disabled: { |
| 68 | type: Boolean, |
| 69 | value: false, |
| 70 | reflectToAttribute: true, |
| 71 | }, |
| 72 | draft: { |
| 73 | type: Boolean, |
| 74 | value: false, |
| 75 | observer: '_draftChanged', |
| 76 | }, |
| 77 | editing: { |
| 78 | type: Boolean, |
| 79 | value: false, |
| 80 | observer: '_editingChanged', |
| 81 | }, |
| 82 | patchNum: String, |
| 83 | showActions: Boolean, |
Becky Siegel | eb4ea18 | 2016-10-10 17:31:56 -0700 | [diff] [blame] | 84 | collapsed: { |
Becky Siegel | 6bf4e4f | 2016-10-06 10:18:32 -0700 | [diff] [blame] | 85 | type: Boolean, |
| 86 | value: true, |
| 87 | observer: '_toggleCollapseClass', |
| 88 | }, |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 89 | projectConfig: Object, |
| 90 | |
| 91 | _xhrPromise: Object, // Used for testing. |
Wyatt Allen | 035c74f | 2016-05-23 13:53:10 -0700 | [diff] [blame] | 92 | _messageText: { |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 93 | type: String, |
Andrew Bonventre | a12d3cd | 2016-05-23 19:03:11 -0400 | [diff] [blame] | 94 | value: '', |
Wyatt Allen | 035c74f | 2016-05-23 13:53:10 -0700 | [diff] [blame] | 95 | observer: '_messageTextChanged', |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 96 | }, |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 97 | }, |
| 98 | |
Andrew Bonventre | a12d3cd | 2016-05-23 19:03:11 -0400 | [diff] [blame] | 99 | observers: [ |
| 100 | '_commentMessageChanged(comment.message)', |
| 101 | '_loadLocalDraft(changeNum, patchNum, comment)', |
| 102 | ], |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 103 | |
Becky Siegel | 6bf4e4f | 2016-10-06 10:18:32 -0700 | [diff] [blame] | 104 | attached: function() { |
| 105 | if (this.editing) { |
Becky Siegel | eb4ea18 | 2016-10-10 17:31:56 -0700 | [diff] [blame] | 106 | this.collapsed = false; |
Becky Siegel | 6bf4e4f | 2016-10-06 10:18:32 -0700 | [diff] [blame] | 107 | } |
| 108 | }, |
| 109 | |
Viktar Donich | 7ad2892 | 2016-05-23 15:24:05 -0700 | [diff] [blame] | 110 | detached: function() { |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 111 | this.cancelDebouncer('fire-update'); |
Viktar Donich | 7ad2892 | 2016-05-23 15:24:05 -0700 | [diff] [blame] | 112 | }, |
| 113 | |
Becky Siegel | 6bf4e4f | 2016-10-06 10:18:32 -0700 | [diff] [blame] | 114 | _computeShowHideText: function(collapsed) { |
| 115 | return collapsed ? '◀' : '▼'; |
| 116 | }, |
| 117 | |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 118 | save: function() { |
Wyatt Allen | 035c74f | 2016-05-23 13:53:10 -0700 | [diff] [blame] | 119 | this.comment.message = this._messageText; |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 120 | this.disabled = true; |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 121 | |
Wyatt Allen | 035c74f | 2016-05-23 13:53:10 -0700 | [diff] [blame] | 122 | this.$.storage.eraseDraftComment({ |
| 123 | changeNum: this.changeNum, |
| 124 | patchNum: this.patchNum, |
| 125 | path: this.comment.path, |
| 126 | line: this.comment.line, |
| 127 | }); |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 128 | |
Andrew Bonventre | 180693c | 2016-05-03 15:14:57 -0400 | [diff] [blame] | 129 | this._xhrPromise = this._saveDraft(this.comment).then(function(response) { |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 130 | this.disabled = false; |
Andrew Bonventre | 8f23107 | 2016-05-02 15:59:59 -0400 | [diff] [blame] | 131 | if (!response.ok) { return response; } |
| 132 | |
Andrew Bonventre | 180693c | 2016-05-03 15:14:57 -0400 | [diff] [blame] | 133 | return this.$.restAPI.getResponseObject(response).then(function(obj) { |
| 134 | var comment = obj; |
| 135 | comment.__draft = true; |
| 136 | // Maintain the ephemeral draft ID for identification by other |
| 137 | // elements. |
| 138 | if (this.comment.__draftID) { |
| 139 | comment.__draftID = this.comment.__draftID; |
| 140 | } |
| 141 | this.comment = comment; |
| 142 | this.editing = false; |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 143 | this._fireSave(); |
Andrew Bonventre | 180693c | 2016-05-03 15:14:57 -0400 | [diff] [blame] | 144 | return obj; |
| 145 | }.bind(this)); |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 146 | }.bind(this)).catch(function(err) { |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 147 | this.disabled = false; |
Andrew Bonventre | 8f23107 | 2016-05-02 15:59:59 -0400 | [diff] [blame] | 148 | throw err; |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 149 | }.bind(this)); |
| 150 | }, |
| 151 | |
Viktar Donich | 7ad2892 | 2016-05-23 15:24:05 -0700 | [diff] [blame] | 152 | _commentChanged: function(comment) { |
| 153 | this.editing = !!comment.__editing; |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 154 | if (this.editing) { // It's a new draft/reply, notify. |
| 155 | this._fireUpdate(); |
| 156 | } |
| 157 | }, |
| 158 | |
| 159 | _getEventPayload: function(opt_mixin) { |
| 160 | var payload = { |
| 161 | comment: this.comment, |
| 162 | patchNum: this.patchNum, |
| 163 | }; |
| 164 | for (var k in opt_mixin) { |
| 165 | payload[k] = opt_mixin[k]; |
| 166 | } |
| 167 | return payload; |
| 168 | }, |
| 169 | |
| 170 | _fireSave: function() { |
| 171 | this.fire('comment-save', this._getEventPayload()); |
Viktar Donich | 7ad2892 | 2016-05-23 15:24:05 -0700 | [diff] [blame] | 172 | }, |
| 173 | |
| 174 | _fireUpdate: function() { |
| 175 | this.debounce('fire-update', function() { |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 176 | this.fire('comment-update', this._getEventPayload()); |
Wyatt Allen | d0dd392 | 2016-07-14 12:31:09 -0700 | [diff] [blame] | 177 | }); |
Viktar Donich | 7ad2892 | 2016-05-23 15:24:05 -0700 | [diff] [blame] | 178 | }, |
| 179 | |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 180 | _draftChanged: function(draft) { |
| 181 | this.$.container.classList.toggle('draft', draft); |
| 182 | }, |
| 183 | |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 184 | _editingChanged: function(editing, previousValue) { |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 185 | this.$.container.classList.toggle('editing', editing); |
| 186 | if (editing) { |
| 187 | var textarea = this.$.editTextarea.textarea; |
| 188 | // Put the cursor at the end always. |
| 189 | textarea.selectionStart = textarea.value.length; |
| 190 | textarea.selectionEnd = textarea.selectionStart; |
| 191 | this.async(function() { |
| 192 | textarea.focus(); |
| 193 | }.bind(this)); |
| 194 | } |
| 195 | if (this.comment && this.comment.id) { |
| 196 | this.$$('.cancel').hidden = !editing; |
| 197 | } |
Viktar Donich | 7ad2892 | 2016-05-23 15:24:05 -0700 | [diff] [blame] | 198 | if (this.comment) { |
| 199 | this.comment.__editing = this.editing; |
| 200 | } |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 201 | if (editing != !!previousValue) { |
| 202 | // To prevent event firing on comment creation. |
| 203 | this._fireUpdate(); |
| 204 | } |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 205 | }, |
| 206 | |
| 207 | _computeLinkToComment: function(comment) { |
| 208 | return '#' + comment.line; |
| 209 | }, |
| 210 | |
| 211 | _computeSaveDisabled: function(draft) { |
| 212 | return draft == null || draft.trim() == ''; |
| 213 | }, |
| 214 | |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 215 | _handleTextareaKeydown: function(e) { |
Kasper Nilsson | b852326 | 2016-08-23 12:07:04 -0700 | [diff] [blame] | 216 | switch (e.keyCode) { |
| 217 | case 27: // 'esc' |
| 218 | this._handleCancel(e); |
| 219 | break; |
| 220 | case 83: // 's' |
| 221 | if (e.ctrlKey) { |
| 222 | this._handleSave(e); |
| 223 | } |
| 224 | break; |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 225 | } |
| 226 | }, |
| 227 | |
Becky Siegel | 6bf4e4f | 2016-10-06 10:18:32 -0700 | [diff] [blame] | 228 | _handleToggleCollapsed: function() { |
Becky Siegel | eb4ea18 | 2016-10-10 17:31:56 -0700 | [diff] [blame] | 229 | this.collapsed = !this.collapsed; |
Becky Siegel | 6bf4e4f | 2016-10-06 10:18:32 -0700 | [diff] [blame] | 230 | }, |
| 231 | |
Becky Siegel | eb4ea18 | 2016-10-10 17:31:56 -0700 | [diff] [blame] | 232 | _toggleCollapseClass: function(collapsed) { |
| 233 | if (collapsed) { |
Becky Siegel | 6bf4e4f | 2016-10-06 10:18:32 -0700 | [diff] [blame] | 234 | this.$.container.classList.add('collapsed'); |
| 235 | } else { |
| 236 | this.$.container.classList.remove('collapsed'); |
| 237 | } |
| 238 | }, |
| 239 | |
Andrew Bonventre | a12d3cd | 2016-05-23 19:03:11 -0400 | [diff] [blame] | 240 | _commentMessageChanged: function(message) { |
| 241 | this._messageText = message || ''; |
| 242 | }, |
| 243 | |
Wyatt Allen | 035c74f | 2016-05-23 13:53:10 -0700 | [diff] [blame] | 244 | _messageTextChanged: function(newValue, oldValue) { |
Andrew Bonventre | a12d3cd | 2016-05-23 19:03:11 -0400 | [diff] [blame] | 245 | if (!this.comment || (this.comment && this.comment.id)) { return; } |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 246 | |
| 247 | this.debounce('store', function() { |
Wyatt Allen | 035c74f | 2016-05-23 13:53:10 -0700 | [diff] [blame] | 248 | var message = this._messageText; |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 249 | |
Wyatt Allen | 035c74f | 2016-05-23 13:53:10 -0700 | [diff] [blame] | 250 | var commentLocation = { |
| 251 | changeNum: this.changeNum, |
| 252 | patchNum: this.patchNum, |
| 253 | path: this.comment.path, |
| 254 | line: this.comment.line, |
| 255 | }; |
| 256 | |
| 257 | if ((!this._messageText || !this._messageText.length) && oldValue) { |
| 258 | // If the draft has been modified to be empty, then erase the storage |
| 259 | // entry. |
| 260 | this.$.storage.eraseDraftComment(commentLocation); |
| 261 | } else { |
| 262 | this.$.storage.setDraftComment(commentLocation, message); |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 263 | } |
Viktar Donich | 7ad2892 | 2016-05-23 15:24:05 -0700 | [diff] [blame] | 264 | this._fireUpdate(); |
Wyatt Allen | 035c74f | 2016-05-23 13:53:10 -0700 | [diff] [blame] | 265 | }, STORAGE_DEBOUNCE_INTERVAL); |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 266 | }, |
| 267 | |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 268 | _handleLinkTap: function(e) { |
| 269 | e.preventDefault(); |
| 270 | var hash = this._computeLinkToComment(this.comment); |
| 271 | // Don't add the hash to the window history if it's already there. |
| 272 | // Otherwise you mess up expected back button behavior. |
| 273 | if (window.location.hash == hash) { return; } |
| 274 | // Change the URL but don’t trigger a nav event. Otherwise it will |
| 275 | // reload the page. |
| 276 | page.show(window.location.pathname + hash, null, false); |
| 277 | }, |
| 278 | |
| 279 | _handleReply: function(e) { |
| 280 | this._preventDefaultAndBlur(e); |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 281 | this.fire('reply', this._getEventPayload(), {bubbles: false}); |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 282 | }, |
| 283 | |
| 284 | _handleQuote: function(e) { |
| 285 | this._preventDefaultAndBlur(e); |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 286 | this.fire( |
| 287 | 'reply', this._getEventPayload({quote: true}), {bubbles: false}); |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 288 | }, |
| 289 | |
| 290 | _handleDone: function(e) { |
| 291 | this._preventDefaultAndBlur(e); |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 292 | this.fire('done', this._getEventPayload(), {bubbles: false}); |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 293 | }, |
| 294 | |
| 295 | _handleEdit: function(e) { |
| 296 | this._preventDefaultAndBlur(e); |
Wyatt Allen | 035c74f | 2016-05-23 13:53:10 -0700 | [diff] [blame] | 297 | this._messageText = this.comment.message; |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 298 | this.editing = true; |
| 299 | }, |
| 300 | |
| 301 | _handleSave: function(e) { |
| 302 | this._preventDefaultAndBlur(e); |
| 303 | this.save(); |
| 304 | }, |
| 305 | |
| 306 | _handleCancel: function(e) { |
| 307 | this._preventDefaultAndBlur(e); |
| 308 | if (this.comment.message == null || this.comment.message.length == 0) { |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 309 | this._fireDiscard(); |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 310 | return; |
| 311 | } |
Wyatt Allen | 035c74f | 2016-05-23 13:53:10 -0700 | [diff] [blame] | 312 | this._messageText = this.comment.message; |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 313 | this.editing = false; |
| 314 | }, |
| 315 | |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 316 | _fireDiscard: function() { |
Viktar Donich | bed0585 | 2016-08-05 15:05:50 -0700 | [diff] [blame] | 317 | this.cancelDebouncer('fire-update'); |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 318 | this.fire('comment-discard', this._getEventPayload()); |
| 319 | }, |
| 320 | |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 321 | _handleDiscard: function(e) { |
| 322 | this._preventDefaultAndBlur(e); |
| 323 | if (!this.comment.__draft) { |
| 324 | throw Error('Cannot discard a non-draft comment.'); |
| 325 | } |
Andrew Bonventre | a12d3cd | 2016-05-23 19:03:11 -0400 | [diff] [blame] | 326 | this.editing = false; |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 327 | this.disabled = true; |
Andrew Bonventre | 180693c | 2016-05-03 15:14:57 -0400 | [diff] [blame] | 328 | if (!this.comment.id) { |
Andrew Bonventre | a12d3cd | 2016-05-23 19:03:11 -0400 | [diff] [blame] | 329 | this.disabled = false; |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 330 | this._fireDiscard(); |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 331 | return; |
| 332 | } |
Andrew Bonventre | 180693c | 2016-05-03 15:14:57 -0400 | [diff] [blame] | 333 | |
Viktar Donich | 7ad2892 | 2016-05-23 15:24:05 -0700 | [diff] [blame] | 334 | this._xhrPromise = this._deleteDraft(this.comment).then( |
| 335 | function(response) { |
| 336 | this.disabled = false; |
| 337 | if (!response.ok) { return response; } |
Andrew Bonventre | 8f23107 | 2016-05-02 15:59:59 -0400 | [diff] [blame] | 338 | |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 339 | this._fireDiscard(); |
Viktar Donich | 7ad2892 | 2016-05-23 15:24:05 -0700 | [diff] [blame] | 340 | }.bind(this)).catch(function(err) { |
| 341 | this.disabled = false; |
| 342 | throw err; |
| 343 | }.bind(this)); |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 344 | }, |
| 345 | |
| 346 | _preventDefaultAndBlur: function(e) { |
| 347 | e.preventDefault(); |
| 348 | Polymer.dom(e).rootTarget.blur(); |
| 349 | }, |
| 350 | |
Andrew Bonventre | 180693c | 2016-05-03 15:14:57 -0400 | [diff] [blame] | 351 | _saveDraft: function(draft) { |
| 352 | return this.$.restAPI.saveDiffDraft(this.changeNum, this.patchNum, draft); |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 353 | }, |
| 354 | |
Andrew Bonventre | 180693c | 2016-05-03 15:14:57 -0400 | [diff] [blame] | 355 | _deleteDraft: function(draft) { |
| 356 | return this.$.restAPI.deleteDiffDraft(this.changeNum, this.patchNum, |
| 357 | draft); |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 358 | }, |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 359 | |
Andrew Bonventre | a12d3cd | 2016-05-23 19:03:11 -0400 | [diff] [blame] | 360 | _loadLocalDraft: function(changeNum, patchNum, comment) { |
| 361 | // Only apply local drafts to comments that haven't been saved |
| 362 | // remotely, and haven't been given a default message already. |
| 363 | if (!comment || comment.id || comment.message) { |
| 364 | return; |
| 365 | } |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 366 | |
Andrew Bonventre | a12d3cd | 2016-05-23 19:03:11 -0400 | [diff] [blame] | 367 | var draft = this.$.storage.getDraftComment({ |
| 368 | changeNum: changeNum, |
| 369 | patchNum: patchNum, |
| 370 | path: comment.path, |
| 371 | line: comment.line, |
| 372 | }); |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 373 | |
Andrew Bonventre | a12d3cd | 2016-05-23 19:03:11 -0400 | [diff] [blame] | 374 | if (draft) { |
| 375 | this.set('comment.message', draft.message); |
| 376 | } |
Wyatt Allen | 7a4aa8c | 2016-05-18 12:37:53 -0700 | [diff] [blame] | 377 | }, |
Viktar Donich | b2198e8 | 2016-06-09 16:08:04 -0700 | [diff] [blame] | 378 | |
| 379 | _handleMouseEnter: function(e) { |
| 380 | this.fire('comment-mouse-over', this._getEventPayload()); |
| 381 | }, |
| 382 | |
| 383 | _handleMouseLeave: function(e) { |
| 384 | this.fire('comment-mouse-out', this._getEventPayload()); |
| 385 | }, |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 386 | }); |
| 387 | })(); |