Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/diff/DiffInline.js
/** | /** | ||||
* @provides phabricator-diff-inline | * @provides phabricator-diff-inline | ||||
* @requires javelin-dom | * @requires javelin-dom | ||||
* phabricator-diff-inline-content-state | |||||
* @javelin | * @javelin | ||||
*/ | */ | ||||
JX.install('DiffInline', { | JX.install('DiffInline', { | ||||
construct : function() { | construct : function() { | ||||
this._activeContentState = new JX.DiffInlineContentState(); | |||||
}, | }, | ||||
members: { | members: { | ||||
_id: null, | _id: null, | ||||
_phid: null, | _phid: null, | ||||
_changesetID: null, | _changesetID: null, | ||||
_row: null, | _row: null, | ||||
_number: null, | _number: null, | ||||
Show All 30 Lines | members: { | ||||
_skipFocus: false, | _skipFocus: false, | ||||
_menu: null, | _menu: null, | ||||
_startOffset: null, | _startOffset: null, | ||||
_endOffset: null, | _endOffset: null, | ||||
_isSelected: false, | _isSelected: false, | ||||
_canSuggestEdit: false, | _canSuggestEdit: false, | ||||
_activeContentState: 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 20 Lines • Show All 716 Lines • ▼ Show 20 Lines | _onSuggestEdit: function(e) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Save the "hasSuggestion" part of the content state. | // Save the "hasSuggestion" part of the content state. | ||||
this.triggerDraft(); | this.triggerDraft(); | ||||
}, | }, | ||||
_getActiveContentState: function() { | |||||
return this._activeContentState; | |||||
}, | |||||
setHasSuggestion: function(has_suggestion) { | setHasSuggestion: function(has_suggestion) { | ||||
this._hasSuggestion = has_suggestion; | var state = this._getActiveContentState(); | ||||
state.setHasSuggestion(has_suggestion); | |||||
var button = this._getSuggestionButton(); | var button = this._getSuggestionButton(); | ||||
var pht = this.getChangeset().getChangesetList().getTranslations(); | var pht = this.getChangeset().getChangesetList().getTranslations(); | ||||
if (has_suggestion) { | if (has_suggestion) { | ||||
button | button | ||||
.setIcon('fa-times') | .setIcon('fa-times') | ||||
.setText(pht('Discard Edit')); | .setText(pht('Discard Edit')); | ||||
} else { | } else { | ||||
button | button | ||||
.setIcon('fa-plus') | .setIcon('fa-plus') | ||||
.setText(pht('Suggest Edit')); | .setText(pht('Suggest Edit')); | ||||
} | } | ||||
if (this._editRow) { | if (this._editRow) { | ||||
JX.DOM.alterClass(this._editRow, 'has-suggestion', has_suggestion); | JX.DOM.alterClass(this._editRow, 'has-suggestion', has_suggestion); | ||||
} | } | ||||
}, | }, | ||||
getHasSuggestion: function() { | getHasSuggestion: function() { | ||||
return this._hasSuggestion; | return this._getActiveContentState().getHasSuggestion(); | ||||
}, | }, | ||||
save: function() { | save: function() { | ||||
var handler = JX.bind(this, this._onsubmitresponse); | var handler = JX.bind(this, this._onsubmitresponse); | ||||
this.setLoading(true); | this.setLoading(true); | ||||
var uri = this._getInlineURI(); | var uri = this._getInlineURI(); | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | _readFormState: function(row) { | ||||
// Ignore. | // Ignore. | ||||
} | } | ||||
node = this._getSuggestionNode(row); | node = this._getSuggestionNode(row); | ||||
if (node) { | if (node) { | ||||
state.suggestionText = node.value; | state.suggestionText = node.value; | ||||
} | } | ||||
state.hasSuggestion = this.getHasSuggestion(); | state.hasSuggestion = this._getActiveContentState().getHasSuggestion(); | ||||
return state; | return state; | ||||
}, | }, | ||||
_getSuggestionNode: function(row) { | _getSuggestionNode: function(row) { | ||||
try { | try { | ||||
return JX.DOM.find(row, 'textarea', 'inline-content-suggestion'); | return JX.DOM.find(row, 'textarea', 'inline-content-suggestion'); | ||||
} catch (ex) { | } catch (ex) { | ||||
▲ Show 20 Lines • Show All 250 Lines • Show Last 20 Lines |