2013-05-27 19:45:33 +00:00
|
|
|
define([
|
|
|
|
"jquery",
|
2013-06-22 23:48:57 +00:00
|
|
|
"classes/Provider",
|
2013-06-16 10:47:35 +00:00
|
|
|
"classes/AsyncTask"
|
2013-08-04 00:53:46 +00:00
|
|
|
], function($, Provider, AsyncTask) {
|
2013-05-10 23:49:50 +00:00
|
|
|
|
2013-06-22 23:48:57 +00:00
|
|
|
var downloadProvider = new Provider("download");
|
|
|
|
downloadProvider.sharingAttributes = [
|
|
|
|
"url"
|
|
|
|
];
|
2013-05-29 19:55:23 +00:00
|
|
|
|
|
|
|
downloadProvider.importPublic = function(importParameters, callback) {
|
|
|
|
var title = undefined;
|
|
|
|
var content = undefined;
|
2013-06-16 10:47:35 +00:00
|
|
|
var task = new AsyncTask();
|
2013-05-29 19:55:23 +00:00
|
|
|
task.onRun(function() {
|
|
|
|
var url = importParameters.url;
|
|
|
|
var slashUrl = url.lastIndexOf("/");
|
|
|
|
if(slashUrl === -1) {
|
|
|
|
task.error(new Error("Invalid URL parameter."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
title = url.substring(slashUrl + 1);
|
|
|
|
$.ajax({
|
|
|
|
url: DOWNLOAD_PROXY_URL + "download?url=" + url,
|
|
|
|
type: "GET",
|
|
|
|
dataType: "text",
|
|
|
|
timeout: AJAX_TIMEOUT
|
|
|
|
}).done(function(result, textStatus, jqXHR) {
|
|
|
|
content = result;
|
|
|
|
task.chain();
|
|
|
|
}).fail(function(jqXHR) {
|
|
|
|
task.error(new Error("Unable to access URL " + url));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
task.onSuccess(function() {
|
|
|
|
callback(undefined, title, content);
|
|
|
|
});
|
|
|
|
task.onError(function(error) {
|
|
|
|
callback(error);
|
|
|
|
});
|
2013-06-16 10:47:35 +00:00
|
|
|
task.enqueue();
|
2013-05-29 19:55:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return downloadProvider;
|
2013-05-10 23:49:50 +00:00
|
|
|
});
|