diff --git a/resources/celerity/map.php b/resources/celerity/map.php --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -13,7 +13,7 @@ 'core.pkg.js' => 'ab3502fe', 'dark-console.pkg.js' => '187792c2', 'differential.pkg.css' => 'ffb69e3d', - 'differential.pkg.js' => '442567d7', + 'differential.pkg.js' => '7747755e', 'diffusion.pkg.css' => '42c75c37', 'diffusion.pkg.js' => '78c9885d', 'maniphest.pkg.css' => '35995d6d', @@ -385,7 +385,7 @@ 'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => '0116d3e8', 'rsrc/js/application/diff/DiffChangeset.js' => 'd7d3ba75', 'rsrc/js/application/diff/DiffChangesetList.js' => 'cc2c5de5', - 'rsrc/js/application/diff/DiffInline.js' => 'fdebbba6', + 'rsrc/js/application/diff/DiffInline.js' => '34ccdeda', 'rsrc/js/application/diff/DiffInlineContentState.js' => '68e6339d', 'rsrc/js/application/diff/DiffPathView.js' => '8207abf9', 'rsrc/js/application/diff/DiffTreeView.js' => '5d83623b', @@ -788,7 +788,7 @@ 'phabricator-dashboard-css' => '5a205b9d', 'phabricator-diff-changeset' => 'd7d3ba75', 'phabricator-diff-changeset-list' => 'cc2c5de5', - 'phabricator-diff-inline' => 'fdebbba6', + 'phabricator-diff-inline' => '34ccdeda', 'phabricator-diff-inline-content-state' => '68e6339d', 'phabricator-diff-path-view' => '8207abf9', 'phabricator-diff-tree-view' => '5d83623b', @@ -1220,6 +1220,10 @@ 'javelin-stratcom', 'javelin-workflow', ), + '34ccdeda' => array( + 'javelin-dom', + 'phabricator-diff-inline-content-state', + ), '34e2a838' => array( 'aphront-typeahead-control-css', 'phui-tag-view-css', @@ -2231,10 +2235,6 @@ 'fdc13e4e' => array( 'javelin-install', ), - 'fdebbba6' => array( - 'javelin-dom', - 'phabricator-diff-inline-content-state', - ), 'ff688a7a' => array( 'owners-path-editor', 'javelin-behavior', diff --git a/src/infrastructure/diff/PhabricatorInlineCommentController.php b/src/infrastructure/diff/PhabricatorInlineCommentController.php --- a/src/infrastructure/diff/PhabricatorInlineCommentController.php +++ b/src/infrastructure/diff/PhabricatorInlineCommentController.php @@ -186,23 +186,15 @@ if ($op === 'save') { $this->updateCommentContentState($inline); - $inline->setIsEditing(false); + $inline + ->setIsEditing(false) + ->setIsDeleted(0); - if (!$inline->isVoidComment($viewer)) { - $inline->setIsDeleted(0); + $this->saveComment($inline); - $this->saveComment($inline); - - return $this->buildRenderedCommentResponse( - $inline, - $this->getIsOnRight()); - } else { - $inline->setIsDeleted(1); - - $this->saveComment($inline); - - return $this->buildEmptyResponse(); - } + return $this->buildRenderedCommentResponse( + $inline, + $this->getIsOnRight()); } else { // NOTE: At time of writing, the "editing" state of inlines is // preserved by simulating a click on "Edit" when the inline loads. diff --git a/webroot/rsrc/js/application/diff/DiffInline.js b/webroot/rsrc/js/application/diff/DiffInline.js --- a/webroot/rsrc/js/application/diff/DiffInline.js +++ b/webroot/rsrc/js/application/diff/DiffInline.js @@ -45,6 +45,7 @@ _undoRow: null, _undoType: null, _undoState: null, + _preventUndo: false, _draftRequest: null, _skipFocus: false, @@ -161,6 +162,14 @@ return this._endOffset; }, + _setPreventUndo: function(prevent_undo) { + this._preventUndo = prevent_undo; + }, + + _getPreventUndo: function() { + return this._preventUndo; + }, + setIsSelected: function(is_selected) { this._isSelected = is_selected; @@ -617,7 +626,9 @@ this._editRow = null; } - this._drawUndeleteRows(state); + if (!this._getPreventUndo()) { + this._drawUndeleteRows(state); + } this.setLoading(false); this.setDeleted(true); @@ -815,17 +826,53 @@ }, save: function() { + if (this._shouldDeleteOnSave()) { + this._setPreventUndo(true); + this._applyDelete(); + } else { + this._applySave(); + } + }, + + _shouldDeleteOnSave: function() { 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()); - new JX.Request(uri, handler) - .setData(data) - .send(); + this._applyCall(handler, data); + }, + + _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() { @@ -917,7 +964,7 @@ } }, - _onsubmitresponse: function(response) { + _onsaveresponse: function(response) { if (this._editRow) { JX.DOM.remove(this._editRow); this._editRow = null; @@ -927,30 +974,9 @@ this.setInvisible(false); this.setEditing(false); - this._onupdate(response); - }, - - _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); - } - - // 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); - } else { - this.setDeleted(true); - this._row = null; - } + var new_row = this._drawContentRows(JX.$H(response.view).getNode()); + JX.DOM.remove(this._row); + this.bindToRow(new_row); this._didUpdate(); },