Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/diff/DiffInline.js
Show All 39 Lines | members: { | ||||
_isNew: false, | _isNew: false, | ||||
_isSynthetic: false, | _isSynthetic: false, | ||||
_isHidden: false, | _isHidden: false, | ||||
_editRow: null, | _editRow: null, | ||||
_undoRow: null, | _undoRow: null, | ||||
_undoType: null, | _undoType: null, | ||||
_undoState: null, | _undoState: null, | ||||
_preventUndo: false, | |||||
_draftRequest: null, | _draftRequest: null, | ||||
_skipFocus: false, | _skipFocus: false, | ||||
_menu: null, | _menu: null, | ||||
_startOffset: null, | _startOffset: null, | ||||
_endOffset: null, | _endOffset: null, | ||||
_isSelected: false, | _isSelected: false, | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | members: { | ||||
getStartOffset: function() { | getStartOffset: function() { | ||||
return this._startOffset; | return this._startOffset; | ||||
}, | }, | ||||
getEndOffset: function() { | getEndOffset: function() { | ||||
return this._endOffset; | return this._endOffset; | ||||
}, | }, | ||||
_setPreventUndo: function(prevent_undo) { | |||||
this._preventUndo = prevent_undo; | |||||
}, | |||||
_getPreventUndo: function() { | |||||
return this._preventUndo; | |||||
}, | |||||
setIsSelected: function(is_selected) { | setIsSelected: function(is_selected) { | ||||
this._isSelected = is_selected; | this._isSelected = is_selected; | ||||
if (this._row) { | if (this._row) { | ||||
JX.DOM.alterClass( | JX.DOM.alterClass( | ||||
this._row, | this._row, | ||||
'inline-comment-selected', | 'inline-comment-selected', | ||||
this._isSelected); | this._isSelected); | ||||
▲ Show 20 Lines • Show All 440 Lines • ▼ Show 20 Lines | _ondeleteresponse: function() { | ||||
// read and preserve the text so "Undo" restores it. | // read and preserve the text so "Undo" restores it. | ||||
var state = null; | var state = null; | ||||
if (this._editRow) { | if (this._editRow) { | ||||
state = this._getActiveContentState().getWireFormat(); | state = this._getActiveContentState().getWireFormat(); | ||||
JX.DOM.remove(this._editRow); | JX.DOM.remove(this._editRow); | ||||
this._editRow = null; | this._editRow = null; | ||||
} | } | ||||
if (!this._getPreventUndo()) { | |||||
this._drawUndeleteRows(state); | this._drawUndeleteRows(state); | ||||
} | |||||
this.setLoading(false); | this.setLoading(false); | ||||
this.setDeleted(true); | this.setDeleted(true); | ||||
this._didUpdate(); | this._didUpdate(); | ||||
}, | }, | ||||
_drawUndeleteRows: function(content_state) { | _drawUndeleteRows: function(content_state) { | ||||
▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | setHasSuggestion: function(has_suggestion) { | ||||
} | } | ||||
}, | }, | ||||
getHasSuggestion: function() { | getHasSuggestion: function() { | ||||
return this._getActiveContentState().getHasSuggestion(); | return this._getActiveContentState().getHasSuggestion(); | ||||
}, | }, | ||||
save: function() { | save: function() { | ||||
if (this._shouldDeleteOnSave()) { | |||||
this._setPreventUndo(true); | |||||
this._applyDelete(); | |||||
} else { | |||||
this._applySave(); | |||||
} | |||||
}, | |||||
_shouldDeleteOnSave: function() { | |||||
var state = this._getActiveContentState(); | var state = this._getActiveContentState(); | ||||
var handler = JX.bind(this, this._onsubmitresponse); | |||||
this.setLoading(true); | // TODO: This is greatly simplified because we don't track all the | ||||
// state we need yet. | |||||
var uri = this._getInlineURI(); | return !state.getText().length; | ||||
}, | |||||
_applySave: function() { | |||||
var handler = JX.bind(this, this._onsaveresponse); | |||||
var state = this._getActiveContentState(); | |||||
var data = this._newRequestData('save', state.getWireFormat()); | var data = this._newRequestData('save', state.getWireFormat()); | ||||
new JX.Request(uri, handler) | this._applyCall(handler, data); | ||||
.setData(data) | }, | ||||
.send(); | |||||
_applyDelete: function() { | |||||
var handler = JX.bind(this, this._ondeleteresponse); | |||||
var data = this._newRequestData('delete'); | |||||
this._applyCall(handler, data); | |||||
}, | |||||
_applyCall: function(handler, data) { | |||||
var uri = this._getInlineURI(); | |||||
var callback = JX.bind(this, function() { | |||||
this.setLoading(false); | |||||
handler.apply(null, arguments); | |||||
}); | |||||
this.setLoading(true); | |||||
new JX.Workflow(uri, data) | |||||
.setHandler(callback) | |||||
.start(); | |||||
}, | }, | ||||
undo: function() { | undo: function() { | ||||
JX.DOM.remove(this._undoRow); | JX.DOM.remove(this._undoRow); | ||||
this._undoRow = null; | this._undoRow = null; | ||||
if (this._undoType === 'undelete') { | if (this._undoType === 'undelete') { | ||||
var uri = this._getInlineURI(); | var uri = this._getInlineURI(); | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | members: { | ||||
_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) { | ||||
return null; | return null; | ||||
} | } | ||||
}, | }, | ||||
_onsubmitresponse: function(response) { | _onsaveresponse: function(response) { | ||||
if (this._editRow) { | if (this._editRow) { | ||||
JX.DOM.remove(this._editRow); | JX.DOM.remove(this._editRow); | ||||
this._editRow = null; | this._editRow = null; | ||||
} | } | ||||
this.setLoading(false); | this.setLoading(false); | ||||
this.setInvisible(false); | this.setInvisible(false); | ||||
this.setEditing(false); | this.setEditing(false); | ||||
this._onupdate(response); | var new_row = this._drawContentRows(JX.$H(response.view).getNode()); | ||||
}, | |||||
_onupdate: function(response) { | |||||
var new_row; | |||||
if (response.view) { | |||||
new_row = this._drawContentRows(JX.$H(response.view).getNode()); | |||||
} | |||||
// TODO: Save the old row so the action it's undo-able if it was a | |||||
// delete. | |||||
var remove_old = true; | |||||
if (remove_old) { | |||||
JX.DOM.remove(this._row); | JX.DOM.remove(this._row); | ||||
} | |||||
// If you delete the content on a comment and save it, it acts like a | |||||
// delete: the server does not return a new row. | |||||
if (new_row) { | |||||
this.bindToRow(new_row); | this.bindToRow(new_row); | ||||
} else { | |||||
this.setDeleted(true); | |||||
this._row = null; | |||||
} | |||||
this._didUpdate(); | this._didUpdate(); | ||||
}, | }, | ||||
_didUpdate: function(local_only) { | _didUpdate: function(local_only) { | ||||
// After making changes to inline comments, refresh the transaction | // After making changes to inline comments, refresh the transaction | ||||
// preview at the bottom of the page. | // preview at the bottom of the page. | ||||
if (!local_only) { | if (!local_only) { | ||||
▲ Show 20 Lines • Show All 204 Lines • Show Last 20 Lines |