Differential D12032 Diff 28963 webroot/rsrc/js/application/differential/DifferentialInlineCommentEditor.js
Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/differential/DifferentialInlineCommentEditor.js
| Show All 13 Lines | construct : function(uri) { | ||||
| this._uri = uri; | this._uri = uri; | ||||
| }, | }, | ||||
| events : ['done'], | events : ['done'], | ||||
| members : { | members : { | ||||
| _uri : null, | _uri : null, | ||||
| _undoText : null, | _undoText : null, | ||||
| _completed: false, | |||||
| _skipOverInlineCommentRows : function(node) { | _skipOverInlineCommentRows : function(node) { | ||||
| // TODO: Move this semantic information out of class names. | // TODO: Move this semantic information out of class names. | ||||
| while (node && node.className.indexOf('inline') !== -1) { | while (node && node.className.indexOf('inline') !== -1) { | ||||
| node = node.nextSibling; | node = node.nextSibling; | ||||
| } | } | ||||
| return node; | return node; | ||||
| }, | }, | ||||
| _buildRequestData : function() { | _buildRequestData : function() { | ||||
| Show All 38 Lines | members : { | ||||
| }, | }, | ||||
| _removeUndoLink : function() { | _removeUndoLink : function() { | ||||
| var rows = JX.DifferentialInlineCommentEditor._undoRows; | var rows = JX.DifferentialInlineCommentEditor._undoRows; | ||||
| if (rows) { | if (rows) { | ||||
| for (var ii = 0; ii < rows.length; ii++) { | for (var ii = 0; ii < rows.length; ii++) { | ||||
| JX.DOM.remove(rows[ii]); | JX.DOM.remove(rows[ii]); | ||||
| } | } | ||||
| } | } | ||||
| JX.DifferentialInlineCommentEditor._undoRows = []; | |||||
| }, | }, | ||||
| _undo : function() { | _undo : function() { | ||||
| this._removeUndoLink(); | this._removeUndoLink(); | ||||
| if (this._undoText) { | |||||
| this.setText(this._undoText); | this.setText(this._undoText); | ||||
| } else { | |||||
| this.setOperation('undelete'); | |||||
| } | |||||
| this.start(); | this.start(); | ||||
| }, | }, | ||||
| _registerUndoListener : function() { | _registerUndoListener : function() { | ||||
| if (!JX.DifferentialInlineCommentEditor._activeEditor) { | if (!JX.DifferentialInlineCommentEditor._activeEditor) { | ||||
| JX.Stratcom.listen( | JX.Stratcom.listen( | ||||
| 'click', | 'click', | ||||
| 'differential-inline-comment-undo', | 'differential-inline-comment-undo', | ||||
| function(e) { | function(e) { | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | _didContinueWorkflow : function(response) { | ||||
| JX.DOM.alterClass(drawn[0], 'differential-inline-loading', true); | JX.DOM.alterClass(drawn[0], 'differential-inline-loading', true); | ||||
| }); | }); | ||||
| JX.DOM.listen( | JX.DOM.listen( | ||||
| drawn[0], | drawn[0], | ||||
| ['submit', 'didSyntheticSubmit'], | ['submit', 'didSyntheticSubmit'], | ||||
| 'inline-edit-form', | 'inline-edit-form', | ||||
| onsubmit); | onsubmit); | ||||
| }, | }, | ||||
| _didCompleteWorkflow : function(response) { | _didCompleteWorkflow : function(response) { | ||||
| var op = this.getOperation(); | var op = this.getOperation(); | ||||
| if (op == 'delete' || op == 'refdelete') { | |||||
| this._undoText = null; | |||||
| this._drawUndo(); | |||||
| } else { | |||||
| this._removeUndoLink(); | |||||
| } | |||||
| // We don't get any markup back if the user deletes a comment, or saves | // We don't get any markup back if the user deletes a comment, or saves | ||||
| // an empty comment (which effects a delete). | // an empty comment (which effects a delete). | ||||
| if (response.markup) { | if (response.markup) { | ||||
| this._draw(JX.$H(response.markup).getNode()); | this._draw(JX.$H(response.markup).getNode()); | ||||
| } | } | ||||
| // These operations remove the old row (edit adds a new row first). | // These operations remove the old row (edit adds a new row first). | ||||
| var remove_old = (op == 'edit' || op == 'delete'); | var remove_old = (op == 'edit' || op == 'delete' || op == 'refdelete'); | ||||
| if (remove_old) { | if (remove_old) { | ||||
| JX.DOM.remove(this.getRow()); | this._setRowState('hidden'); | ||||
| var other_rows = this.getOtherRows(); | |||||
| for(var i = 0; i < other_rows.length; ++i) { | |||||
| JX.DOM.remove(other_rows[i]); | |||||
| } | } | ||||
| if (op == 'undelete') { | |||||
| this._setRowState('visible'); | |||||
| } | } | ||||
| // Once the user saves something, get rid of the 'undo' option. A | this._completed = true; | ||||
| // particular case where we need this is saving a delete, when we might | |||||
| // otherwise leave around an 'undo' for an earlier edit to the same | |||||
| // comment. | |||||
| this._removeUndoLink(); | |||||
| JX.Stratcom.invoke('differential-inline-comment-update'); | JX.Stratcom.invoke('differential-inline-comment-update'); | ||||
| this.invoke('done'); | this.invoke('done'); | ||||
| }, | }, | ||||
| _didCancelWorkflow : function() { | _didCancelWorkflow : function() { | ||||
| this.invoke('done'); | this.invoke('done'); | ||||
| var op = this.getOperation(); | switch (this.getOperation()) { | ||||
| if (op == 'delete') { | case 'delete': | ||||
| // No undo for delete, we prompt the user explicitly. | case 'refdelete': | ||||
| if (!this._completed) { | |||||
| this._setRowState('visible'); | |||||
| } | |||||
| return; | |||||
| case 'undelete': | |||||
| return; | return; | ||||
| } | } | ||||
| var textarea; | var textarea; | ||||
| try { | try { | ||||
| textarea = JX.DOM.find( | textarea = JX.DOM.find( | ||||
| document.body, // TODO: use getDialogRootNode() when available | document.body, // TODO: use getDialogRootNode() when available | ||||
| 'textarea', | 'textarea', | ||||
| 'differential-inline-comment-edit-textarea'); | 'differential-inline-comment-edit-textarea'); | ||||
| Show All 12 Lines | _didCancelWorkflow : function() { | ||||
| // 'edit' or no text at all), don't offer them an undo. | // 'edit' or no text at all), don't offer them an undo. | ||||
| if (text == this.getOriginalText() || text === '') { | if (text == this.getOriginalText() || text === '') { | ||||
| return; | return; | ||||
| } | } | ||||
| // Save the text so we can 'undo' back to it. | // Save the text so we can 'undo' back to it. | ||||
| this._undoText = text; | this._undoText = text; | ||||
| this._drawUndo(); | |||||
| }, | |||||
| _drawUndo: function() { | |||||
| var templates = this.getTemplates(); | var templates = this.getTemplates(); | ||||
| var template = this.getOnRight() ? templates.r : templates.l; | var template = this.getOnRight() ? templates.r : templates.l; | ||||
| template = JX.$H(template).getNode(); | template = JX.$H(template).getNode(); | ||||
| // NOTE: Operation order matters here; we can't remove anything until | // NOTE: Operation order matters here; we can't remove anything until | ||||
| // after we draw the new rows because _draw uses the old rows to figure | // after we draw the new rows because _draw uses the old rows to figure | ||||
| // out where to place the comment. | // out where to place the comment. | ||||
| // We use 'exact_row' to put the "undo" text directly above the affected | // We use 'exact_row' to put the "undo" text directly above the affected | ||||
| // comment. | // comment. | ||||
| var exact_row = true; | var exact_row = true; | ||||
| var rows = this._draw(template, exact_row); | var rows = this._draw(template, exact_row); | ||||
| this._removeUndoLink(); | this._removeUndoLink(); | ||||
| JX.DifferentialInlineCommentEditor._undoRows = rows; | JX.DifferentialInlineCommentEditor._undoRows = rows; | ||||
| }, | }, | ||||
| start : function() { | start : function() { | ||||
| this._registerUndoListener(); | this._registerUndoListener(); | ||||
| var data = this._buildRequestData(); | var data = this._buildRequestData(); | ||||
| var op = this.getOperation(); | var op = this.getOperation(); | ||||
| if (op == 'delete') { | if (op == 'delete' || op == 'refdelete' || op == 'undelete') { | ||||
| this._setRowState('loading'); | this._setRowState('loading'); | ||||
| var oncomplete = JX.bind(this, this._didCompleteWorkflow); | var oncomplete = JX.bind(this, this._didCompleteWorkflow); | ||||
| var onclose = JX.bind(this, function() { | var oncancel = JX.bind(this, this._didCancelWorkflow); | ||||
| this._setRowState('visible'); | |||||
| this._didCancelWorkflow(); | |||||
| }); | |||||
| new JX.Workflow(this._uri, data) | new JX.Workflow(this._uri, data) | ||||
| .setHandler(oncomplete) | .setHandler(oncomplete) | ||||
| .setCloseHandler(onclose) | .setCloseHandler(oncancel) | ||||
| .start(); | .start(); | ||||
| } else { | } else { | ||||
| var handler = JX.bind(this, this._didContinueWorkflow); | var handler = JX.bind(this, this._didContinueWorkflow); | ||||
| if (op == 'edit') { | if (op == 'edit') { | ||||
| this._setRowState('loading'); | this._setRowState('loading'); | ||||
| } | } | ||||
| new JX.Request(this._uri, handler) | new JX.Request(this._uri, handler) | ||||
| .setData(data) | .setData(data) | ||||
| .send(); | .send(); | ||||
| } | } | ||||
| return this; | return this; | ||||
| }, | |||||
| deleteByID: function(id) { | |||||
| var data = { | |||||
| op: 'refdelete', | |||||
| changesetID: id | |||||
| }; | |||||
| new JX.Workflow(this._uri, data) | |||||
| .setHandler(function() { | |||||
| JX.Stratcom.invoke('differential-inline-comment-update'); | |||||
| }) | |||||
| .start(); | |||||
| } | } | ||||
| }, | }, | ||||
| statics : { | statics : { | ||||
| /** | /** | ||||
| * Global refernece to the 'undo' rows currently rendered in the document. | * Global refernece to the 'undo' rows currently rendered in the document. | ||||
| */ | */ | ||||
| _undoRows : null, | _undoRows : null, | ||||
| /** | /** | ||||
| * Global listener for the 'undo' click associated with the currently | * Global listener for the 'undo' click associated with the currently | ||||
| * displayed 'undo' link. When an editor is start()ed, it becomes the active | * displayed 'undo' link. When an editor is start()ed, it becomes the active | ||||
| * editor. | * editor. | ||||
| */ | */ | ||||
| _activeEditor : null | _activeEditor : null | ||||
| }, | }, | ||||
| properties : { | properties : { | ||||
| operation : null, | operation : null, | ||||
| row : null, | row : null, | ||||
| otherRows: [], | |||||
| table : null, | table : null, | ||||
| onRight : null, | onRight : null, | ||||
| ID : null, | ID : null, | ||||
| lineNumber : null, | lineNumber : null, | ||||
| changesetID : null, | changesetID : null, | ||||
| length : null, | length : null, | ||||
| isNew : null, | isNew : null, | ||||
| text : null, | text : null, | ||||
| templates : null, | templates : null, | ||||
| originalText : null, | originalText : null, | ||||
| renderer: null, | renderer: null, | ||||
| replyToCommentPHID: null | replyToCommentPHID: null | ||||
| } | } | ||||
| }); | }); | ||||