Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/diff/DiffInline.js
Show All 36 Lines | members: { | ||||
_isSynthetic: false, | _isSynthetic: false, | ||||
_isHidden: false, | _isHidden: false, | ||||
_editRow: null, | _editRow: null, | ||||
_undoRow: null, | _undoRow: null, | ||||
_undoType: null, | _undoType: null, | ||||
_undoText: null, | _undoText: null, | ||||
_draftRequest: null, | |||||
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; | ||||
// TODO: Get smarter about this once we do more editing, this is pretty | // TODO: Get smarter about this once we do more editing, this is pretty | ||||
Show All 31 Lines | bindToRow: function(row) { | ||||
this._changesetID = data.changesetID; | this._changesetID = data.changesetID; | ||||
this._isNew = false; | this._isNew = false; | ||||
this._snippet = data.snippet; | this._snippet = data.snippet; | ||||
this._isEditing = data.isEditing; | this._isEditing = data.isEditing; | ||||
if (this._isEditing) { | if (this._isEditing) { | ||||
this.edit(); | // NOTE: The "original" shipped down in the DOM may reflect a draft | ||||
// which we're currently editing. This flow is a little clumsy, but | |||||
// reasonable until some future change moves away from "send down | |||||
// the inline, then immediately click edit". | |||||
this.edit(this._originalText); | |||||
} else { | } else { | ||||
this.setInvisible(false); | this.setInvisible(false); | ||||
} | } | ||||
this._startDrafts(); | |||||
return this; | return this; | ||||
}, | }, | ||||
isDraft: function() { | isDraft: function() { | ||||
return this._isDraft; | return this._isDraft; | ||||
}, | }, | ||||
isDone: function() { | isDone: function() { | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | bindToRange: function(data) { | ||||
while (target_row && JX.Stratcom.hasSigil(target_row, 'inline-row')) { | while (target_row && JX.Stratcom.hasSigil(target_row, 'inline-row')) { | ||||
target_row = target_row.nextSibling; | target_row = target_row.nextSibling; | ||||
} | } | ||||
var row = this._newRow(); | var row = this._newRow(); | ||||
parent_row.parentNode.insertBefore(row, target_row); | parent_row.parentNode.insertBefore(row, target_row); | ||||
this.setInvisible(true); | this.setInvisible(true); | ||||
this._startDrafts(); | |||||
return this; | return this; | ||||
}, | }, | ||||
bindToReply: function(inline) { | bindToReply: function(inline) { | ||||
this._displaySide = inline._displaySide; | this._displaySide = inline._displaySide; | ||||
this._number = inline._number; | this._number = inline._number; | ||||
this._length = inline._length; | this._length = inline._length; | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | bindToReply: function(inline) { | ||||
target_row = target_row.nextSibling; | target_row = target_row.nextSibling; | ||||
} | } | ||||
var row = this._newRow(); | var row = this._newRow(); | ||||
parent_row.parentNode.insertBefore(row, target_row); | parent_row.parentNode.insertBefore(row, target_row); | ||||
this.setInvisible(true); | this.setInvisible(true); | ||||
this._startDrafts(); | |||||
return this; | return this; | ||||
}, | }, | ||||
setChangeset: function(changeset) { | setChangeset: function(changeset) { | ||||
this._changeset = changeset; | this._changeset = changeset; | ||||
return this; | return this; | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 566 Lines • ▼ Show 20 Lines | _redraw: function() { | ||||
JX.DOM.alterClass(row, 'differential-inline-loading', is_loading); | JX.DOM.alterClass(row, 'differential-inline-loading', is_loading); | ||||
JX.DOM.alterClass(row, 'inline-hidden', is_collapsed); | JX.DOM.alterClass(row, 'inline-hidden', is_collapsed); | ||||
}, | }, | ||||
_getInlineURI: function() { | _getInlineURI: function() { | ||||
var changeset = this.getChangeset(); | var changeset = this.getChangeset(); | ||||
var list = changeset.getChangesetList(); | var list = changeset.getChangesetList(); | ||||
return list.getInlineURI(); | return list.getInlineURI(); | ||||
}, | |||||
_startDrafts: function() { | |||||
if (this._draftRequest) { | |||||
return; | |||||
} | |||||
var onresponse = JX.bind(this, this._onDraftResponse); | |||||
var draft = JX.bind(this, this._getDraftState); | |||||
var uri = this._getInlineURI(); | |||||
var request = new JX.PhabricatorShapedRequest(uri, onresponse, draft); | |||||
// The main transaction code uses a 500ms delay on desktop and a | |||||
// 10s delay on mobile. Perhaps this should be standardized. | |||||
request.setRateLimit(2000); | |||||
this._draftRequest = request; | |||||
request.start(); | |||||
}, | |||||
_onDraftResponse: function() { | |||||
// For now, do nothing. | |||||
}, | |||||
_getDraftState: function() { | |||||
if (this.isDeleted()) { | |||||
return null; | |||||
} | } | ||||
if (!this.isEditing()) { | |||||
return null; | |||||
} | |||||
var text = this._readText(this._editRow); | |||||
if (text === null) { | |||||
return null; | |||||
} | |||||
return { | |||||
op: 'draft', | |||||
id: this.getID(), | |||||
text: text | |||||
}; | |||||
}, | |||||
triggerDraft: function() { | |||||
if (this._draftRequest) { | |||||
this._draftRequest.trigger(); | |||||
} | |||||
} | |||||
} | } | ||||
}); | }); |