From 4ce25aa9de05c41f48348c2ef3dc6518c7af9b2b Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 26 Dec 2011 17:49:24 -0500 Subject: [PATCH] Switch to using jQuery XHR --- web_frontend/file.js | 4 ++-- web_frontend/main.js | 24 ++++++++++++------------ web_frontend/path_control.js | 3 +-- web_frontend/tv_renamer.js | 4 +--- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/web_frontend/file.js b/web_frontend/file.js index 94b0f4a..66e758f 100644 --- a/web_frontend/file.js +++ b/web_frontend/file.js @@ -135,7 +135,7 @@ armadillo.File.prototype.draw = function() { */ armadillo.File.prototype.remove = function() { var file = this; - var callback = function(data) { + var callback = function(data, status, xhr) { if (data['error']) { app.showError(data['message']); return; @@ -154,7 +154,7 @@ armadillo.File.prototype.remove = function() { */ armadillo.File.prototype.move = function(dest) { var file = this; - var callback = function(data) { + var callback = function(data, status, xhr) { if (data['error']) { app.showError(data['message']); } else { diff --git a/web_frontend/main.js b/web_frontend/main.js index f46ab73..bb0cab1 100644 --- a/web_frontend/main.js +++ b/web_frontend/main.js @@ -16,9 +16,7 @@ goog.require('goog.array'); goog.require('goog.dom'); goog.require('goog.fx.dom.FadeInAndShow'); goog.require('goog.fx.dom.FadeOutAndHide'); -goog.require('goog.net.XhrIo'); goog.require('goog.string.format'); -goog.require('goog.Uri.QueryData'); armadillo.App = function() { var start_path = '/'; @@ -44,14 +42,18 @@ armadillo.App = function() { /** * Starts a new XHR service request from the backend. * @param {string} action Action to perform. - * @param {Object} extra_data Extra data to add. + * @param {Object} data Extra data to add. * @param {Function} callback XHR callback. + * @return {jqXHR} The jQuery XHR object. */ -armadillo.App.prototype.sendRequest = function(action, extra_data, callback) { - var data = new goog.Uri.QueryData(); - data.set('action', action); - data.extend(extra_data); - goog.net.XhrIo.send('service', callback, 'POST', data); +armadillo.App.prototype.sendRequest = function(action, data, callback) { + data.action = action; + return $.ajax({ + url: 'service', + type: 'POST', + data: data, + success: callback + }); }; /** @@ -59,8 +61,7 @@ armadillo.App.prototype.sendRequest = function(action, extra_data, callback) { * @param {string} path Path to list; relative to jail. */ armadillo.App.prototype.list = function(path) { - var callback = function(e) { - var data = e.target.getResponseJson(); + var callback = function(data, status, xhr) { if (data['error']) { app.showError(data['message']); return; // Error. @@ -196,8 +197,7 @@ armadillo.App.prototype.mkdirHandler_ = function() { var name = prompt('Name the new subdirectory', ''); if (name != null && name != '') { var path = this.joinPath(this.getCurrentPath(), name); - this.sendRequest('mkdir', {'path':path}, function(e) { - var data = e.target.getResponseJson(); + this.sendRequest('mkdir', {'path':path}, function(data, status, xhr) { if (data['error']) { app.showError(data['message']); } else { diff --git a/web_frontend/path_control.js b/web_frontend/path_control.js index a45517c..3c6e8a2 100644 --- a/web_frontend/path_control.js +++ b/web_frontend/path_control.js @@ -152,8 +152,7 @@ armadillo.PathControl.prototype.createComponentNode_ = function(path, name) { * @param {goog.ui.Menu} The menu to attach items to */ armadillo.PathControl.prototype.fetchMenuContents_ = function(path, name, menu) { - var callback = function(e) { - var data = e.target.getResponseJson(); + var callback = function(data, status, xhr) { if (data['error']) { app.showError(data['message']); return; diff --git a/web_frontend/tv_renamer.js b/web_frontend/tv_renamer.js index db794a0..a42de8a 100644 --- a/web_frontend/tv_renamer.js +++ b/web_frontend/tv_renamer.js @@ -10,7 +10,6 @@ goog.provide('armadillo.TVRenamer'); goog.require('goog.Disposable'); -goog.require('goog.net.XhrIo'); /** * Creates a helper to rename a file in a pretty format for TV episodes. @@ -42,8 +41,7 @@ armadillo.TVRenamer.prototype.disposeInternal = function() { */ armadillo.TVRenamer.prototype.run = function() { var file = this.file_; - var callback = function(xhr) { - var data = xhr.currentTarget.getResponseJson(); + var callback = function(data, stauts, xhr) { if (data['error']) { app.showError(data['message']); } else { -- 2.43.5