From 87cba1cf750670935ef27259e8878f97683235bf Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 4 Oct 2010 11:33:49 -0400 Subject: [PATCH] Hook up the PathControl and Actor up to the move service request. --- web_frontend/actor.js | 14 ++++++++++++++ web_frontend/file.js | 18 ++++++++++++++++++ web_frontend/path_control.js | 8 ++++++++ 3 files changed, 40 insertions(+) diff --git a/web_frontend/actor.js b/web_frontend/actor.js index 8517031..fb280c5 100644 --- a/web_frontend/actor.js +++ b/web_frontend/actor.js @@ -174,6 +174,18 @@ armadillo.Actor.prototype.performMove_ = function() { var editor = new armadillo.PathControl(this.file_.getFullPath(), true); dialog.addChild(editor, true); + var closeCallback = function(e) { + if (e.key != goog.ui.Dialog.DefaultButtonKeys.CANCEL) { + var newPath = editor.getPath(); + this.file_.move(newPath); + } + dialog.dispose(); + this.dispose(); + }; + // Will be removed when the event source closes. + goog.events.listen(dialog, goog.ui.Dialog.SELECT_EVENT, + closeCallback, false, this); + dialog.setVisible(true); var position = goog.style.getPosition(dialog.getElement()); goog.style.setPosition(dialog.getElement(), position.x, '10%'); @@ -197,6 +209,8 @@ armadillo.Actor.prototype.performDelete_ = function() { var closeCallback = function(e) { if (e.key != goog.ui.Dialog.DefaultButtonKeys.CANCEL) { this.file_.remove(); + confirm.dispose(); + this.dispose(); } }; // Will be removed when the event source closes. diff --git a/web_frontend/file.js b/web_frontend/file.js index 4b8ccb5..54ec108 100644 --- a/web_frontend/file.js +++ b/web_frontend/file.js @@ -119,6 +119,24 @@ armadillo.File.prototype.remove = function() { app.sendRequest('remove', {'path':this.path_ + this.name_}, callback); }; +/** + * Moves a file from one absolute path to another. On success, it will navigate + * to the new path. + * @param {string} dest The destination path. + */ +armadillo.File.prototype.move = function(dest) { + var file = this; + var callback = function(data) { + if (data['error']) { + app.showError(data['message']); + } else { + app.clearError(); + app.list(app.stripLastPathComponent(dest)); + } + }; + app.sendRequest('move', {'source':this.getFullPath(), 'target':dest}, callback); +}; + /** * Click handler for the list element. * @param {Event} e diff --git a/web_frontend/path_control.js b/web_frontend/path_control.js index aa4a625..b743a79 100644 --- a/web_frontend/path_control.js +++ b/web_frontend/path_control.js @@ -73,6 +73,14 @@ armadillo.PathControl.prototype.setPath = function(path) { console.log(this.path_ + ' = ' + this.name_); }; +/** + * Gets the new path. + * @returns {string} + */ +armadillo.PathControl.prototype.getPath = function() { + return app.joinPath(this.path_, this.name_); +}; + /** * Creates a new path control object. */ -- 2.22.5