Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/diff/DiffInline.js
| Show All 37 Lines | members: { | ||||
| _isHidden: false, | _isHidden: false, | ||||
| _editRow: null, | _editRow: null, | ||||
| _undoRow: null, | _undoRow: null, | ||||
| _undoType: null, | _undoType: null, | ||||
| _undoText: null, | _undoText: null, | ||||
| _draftRequest: null, | _draftRequest: null, | ||||
| _skipFocus: false, | |||||
| bindToRow: function(row) { | bindToRow: function(row) { | ||||
| this._row = row; | this._row = row; | ||||
| var row_data = JX.Stratcom.getData(row); | var row_data = JX.Stratcom.getData(row); | ||||
| row_data.inline = this; | row_data.inline = this; | ||||
| this._isCollapsed = row_data.hidden || false; | this._isCollapsed = row_data.hidden || false; | ||||
| Show All 36 Lines | bindToRow: function(row) { | ||||
| this._isEditing = data.isEditing; | this._isEditing = data.isEditing; | ||||
| if (this._isEditing) { | if (this._isEditing) { | ||||
| // NOTE: The "original" shipped down in the DOM may reflect a draft | // NOTE: The "original" shipped down in the DOM may reflect a draft | ||||
| // which we're currently editing. This flow is a little clumsy, but | // which we're currently editing. This flow is a little clumsy, but | ||||
| // reasonable until some future change moves away from "send down | // reasonable until some future change moves away from "send down | ||||
| // the inline, then immediately click edit". | // the inline, then immediately click edit". | ||||
| this.edit(this._originalText); | this.edit(this._originalText, true); | ||||
| } else { | } else { | ||||
| this.setInvisible(false); | this.setInvisible(false); | ||||
| } | } | ||||
| this._startDrafts(); | this._startDrafts(); | ||||
| return this; | return this; | ||||
| }, | }, | ||||
| ▲ Show 20 Lines • Show All 277 Lines • ▼ Show 20 Lines | create: function(text) { | ||||
| .send(); | .send(); | ||||
| }, | }, | ||||
| reply: function(text) { | reply: function(text) { | ||||
| var changeset = this.getChangeset(); | var changeset = this.getChangeset(); | ||||
| return changeset.newInlineReply(this, text); | return changeset.newInlineReply(this, text); | ||||
| }, | }, | ||||
| edit: function(text) { | edit: function(text, skip_focus) { | ||||
| this._skipFocus = !!skip_focus; | |||||
| // If you edit an inline ("A"), modify the text ("AB"), cancel, and then | // If you edit an inline ("A"), modify the text ("AB"), cancel, and then | ||||
| // edit it again: discard the undo state ("AB"). Otherwise we end up | // edit it again: discard the undo state ("AB"). Otherwise we end up | ||||
| // with an open editor and an active "Undo" link, which is weird. | // with an open editor and an active "Undo" link, which is weird. | ||||
| if (this._undoRow) { | if (this._undoRow) { | ||||
| JX.DOM.remove(this._undoRow); | JX.DOM.remove(this._undoRow); | ||||
| this._undoRow = null; | this._undoRow = null; | ||||
| ▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | _drawRows: function(rows, cursor, type, text) { | ||||
| anchor.parentNode.insertBefore(row, cursor); | anchor.parentNode.insertBefore(row, cursor); | ||||
| cursor = row; | cursor = row; | ||||
| if (!result_row) { | if (!result_row) { | ||||
| result_row = row; | result_row = row; | ||||
| } | } | ||||
| if (!this._skipFocus) { | |||||
| // If the row has a textarea, focus it. This allows the user to start | // If the row has a textarea, focus it. This allows the user to start | ||||
| // typing a comment immediately after a "new", "edit", or "reply" | // typing a comment immediately after a "new", "edit", or "reply" | ||||
| // action. | // action. | ||||
| // (When simulating an "edit" on page load, we don't do this.) | |||||
| var textareas = JX.DOM.scry( | var textareas = JX.DOM.scry( | ||||
| row, | row, | ||||
| 'textarea', | 'textarea', | ||||
| 'differential-inline-comment-edit-textarea'); | 'differential-inline-comment-edit-textarea'); | ||||
| if (textareas.length) { | if (textareas.length) { | ||||
| var area = textareas[0]; | var area = textareas[0]; | ||||
| area.focus(); | area.focus(); | ||||
| var length = area.value.length; | var length = area.value.length; | ||||
| JX.TextAreaUtils.setSelectionRange(area, length, length); | JX.TextAreaUtils.setSelectionRange(area, length, length); | ||||
| } | } | ||||
| } | |||||
| row = next_row; | row = next_row; | ||||
| } | } | ||||
| JX.Stratcom.invoke('resize'); | JX.Stratcom.invoke('resize'); | ||||
| return result_row; | return result_row; | ||||
| }, | }, | ||||
| ▲ Show 20 Lines • Show All 232 Lines • Show Last 20 Lines | |||||