Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/diff/DiffInline.js
Show First 20 Lines • Show All 823 Lines • ▼ Show 20 Lines | members: { | ||||
getHasSuggestion: function() { | getHasSuggestion: function() { | ||||
return this._getActiveContentState().getHasSuggestion(); | return this._getActiveContentState().getHasSuggestion(); | ||||
}, | }, | ||||
save: function() { | save: function() { | ||||
if (this._shouldDeleteOnSave()) { | if (this._shouldDeleteOnSave()) { | ||||
this._setPreventUndo(true); | this._setPreventUndo(true); | ||||
this._applyDelete(); | this._applyDelete(); | ||||
} else { | return; | ||||
this._applySave(); | |||||
} | } | ||||
this._applySave(); | |||||
}, | }, | ||||
_shouldDeleteOnSave: function() { | _shouldDeleteOnSave: function() { | ||||
var state = this._getActiveContentState(); | var state = this._getActiveContentState(); | ||||
// TODO: This is greatly simplified because we don't track all the | // TODO: This is greatly simplified because we don't track all the | ||||
// state we need yet. | // state we need yet. | ||||
return !state.getText().length; | return !state.getText().length; | ||||
}, | }, | ||||
_shouldDeleteOnCancel: function() { | |||||
var state = this._getActiveContentState(); | |||||
// TODO: This is greatly simplified, too. | |||||
return !state.getText().length; | |||||
}, | |||||
_shouldUndoOnCancel: function() { | |||||
var state = this._getActiveContentState().getWireFormat(); | |||||
// TODO: This is also simplified. | |||||
var is_empty = this._isVoidContentState(state); | |||||
var is_same = this._isSameContentState(state, this._originalState); | |||||
if (!is_empty && !is_same) { | |||||
return true; | |||||
} | |||||
return false; | |||||
}, | |||||
_applySave: function() { | _applySave: function() { | ||||
var handler = JX.bind(this, this._onsaveresponse); | var handler = JX.bind(this, this._onsaveresponse); | ||||
var state = this._getActiveContentState(); | var state = this._getActiveContentState(); | ||||
var data = this._newRequestData('save', state.getWireFormat()); | var data = this._newRequestData('save', state.getWireFormat()); | ||||
this._applyCall(handler, data); | this._applyCall(handler, data); | ||||
}, | }, | ||||
_applyDelete: function() { | _applyDelete: function() { | ||||
var handler = JX.bind(this, this._ondeleteresponse); | var handler = JX.bind(this, this._ondeleteresponse); | ||||
var data = this._newRequestData('delete'); | var data = this._newRequestData('delete'); | ||||
this._applyCall(handler, data); | this._applyCall(handler, data); | ||||
}, | }, | ||||
_applyCancel: function(state) { | |||||
var handler = JX.bind(this, this._onCancelResponse); | |||||
var data = this._newRequestData('cancel', state); | |||||
this._applyCall(handler, data); | |||||
}, | |||||
_applyCall: function(handler, data) { | _applyCall: function(handler, data) { | ||||
var uri = this._getInlineURI(); | var uri = this._getInlineURI(); | ||||
var callback = JX.bind(this, function() { | var callback = JX.bind(this, function() { | ||||
this.setLoading(false); | this.setLoading(false); | ||||
handler.apply(null, arguments); | handler.apply(null, arguments); | ||||
}); | }); | ||||
Show All 27 Lines | members: { | ||||
}, | }, | ||||
_onundelete: function() { | _onundelete: function() { | ||||
this.setLoading(false); | this.setLoading(false); | ||||
this._didUpdate(); | this._didUpdate(); | ||||
}, | }, | ||||
cancel: function() { | cancel: function() { | ||||
var state = this._getActiveContentState().getWireFormat(); | |||||
JX.DOM.remove(this._editRow); | JX.DOM.remove(this._editRow); | ||||
this._editRow = null; | this._editRow = null; | ||||
var is_empty = this._isVoidContentState(state); | if (this._shouldDeleteOnCancel()) { | ||||
var is_same = this._isSameContentState(state, this._originalState); | this._setPreventUndo(true); | ||||
if (!is_empty && !is_same) { | this._applyDelete(); | ||||
this._drawUneditRows(state); | return; | ||||
} | } | ||||
// If this was an empty box and we typed some text and then hit cancel, | if (this._shouldUndoOnCancel()) { | ||||
// don't show the empty concrete inline. | var state = this._getActiveContentState().getWireFormat(); | ||||
if (this._isVoidContentState(this._originalState)) { | this._drawUneditRows(state); | ||||
this.setInvisible(true); | |||||
} else { | |||||
this.setInvisible(false); | |||||
} | } | ||||
// If you "undo" to restore text ("AB") and then "Cancel", we put you | // If you "undo" to restore text ("AB") and then "Cancel", we put you | ||||
// back in the original text state ("A"). We also send the original | // back in the original text state ("A"). We also send the original | ||||
// text ("A") to the server as the current persistent state. | // text ("A") to the server as the current persistent state. | ||||
var uri = this._getInlineURI(); | this.setEditing(false); | ||||
var data = this._newRequestData('cancel', this._originalState); | this.setInvisible(false); | ||||
var handler = JX.bind(this, this._onCancelResponse); | |||||
this.setLoading(true); | |||||
new JX.Request(uri, handler) | this._applyCancel(this._originalState); | ||||
.setData(data) | |||||
.send(); | |||||
this._didUpdate(true); | this._didUpdate(true); | ||||
}, | }, | ||||
_onCancelResponse: function(response) { | _onCancelResponse: function(response) { | ||||
this.setEditing(false); | // Nothing to do. | ||||
this.setLoading(false); | |||||
// If the comment was empty when we started editing it (there's no | |||||
// original text) and empty when we finished editing it (there's no | |||||
// undo row), just delete the comment. | |||||
if (this._isVoidContentState(this._originalState) && !this.isUndo()) { | |||||
this.setDeleted(true); | |||||
JX.DOM.remove(this._row); | |||||
this._row = null; | |||||
this._didUpdate(); | |||||
} | |||||
}, | }, | ||||
_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; | ||||
} | } | ||||
}, | }, | ||||
_onsaveresponse: 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.setInvisible(false); | |||||
this.setEditing(false); | this.setEditing(false); | ||||
this.setInvisible(false); | |||||
var new_row = this._drawContentRows(JX.$H(response.view).getNode()); | var new_row = this._drawContentRows(JX.$H(response.view).getNode()); | ||||
JX.DOM.remove(this._row); | JX.DOM.remove(this._row); | ||||
this.bindToRow(new_row); | this.bindToRow(new_row); | ||||
this._didUpdate(); | this._didUpdate(); | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 208 Lines • Show Last 20 Lines |