Skip to content

Commit

Permalink
Merge pull request #219 from bartvde/importer_new
Browse files Browse the repository at this point in the history
upgrade to the new importer API (r=@ahocevar)
  • Loading branch information
Bart van den Eijnden committed Nov 19, 2013
2 parents 1925403 + 57885f7 commit 29dbedf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
14 changes: 9 additions & 5 deletions src/script/plugins/AddLayers.js
Expand Up @@ -824,17 +824,21 @@ gxp.plugins.AddLayers = Ext.extend(gxp.plugins.Tool, {
},
listeners: {
uploadcomplete: function(panel, detail) {
var layers = detail["import"].tasks[0].items;
var layers = detail["import"].tasks;
var item, names = {}, resource, layer;
for (var i=0, len=layers.length; i<len; ++i) {
item = layers[i];
if (item.state === "ERROR") {
Ext.Msg.alert(item.originalName, item.errorMessage);
Ext.Msg.alert(item.layer.originalName, item.errorMessage);
return;
}
resource = item.resource;
layer = resource.featureType || resource.coverage;
names[layer.namespace.name + ":" + layer.name] = true;
var ws;
if (item.target.dataStore) {
ws = item.target.dataStore.workspace.name;
} else if (item.target.coverageStore) {
ws = item.target.coverageStore.workspace.name;
}
names[ws + ":" + item.layer.name] = true;
}
this.selectedSource.store.load({
callback: function(records, options, success) {
Expand Down
46 changes: 23 additions & 23 deletions src/script/widgets/LayerUploadPanel.js
Expand Up @@ -172,7 +172,7 @@ gxp.LayerUploadPanel = Ext.extend(Ext.FormPanel, {
this._import = response.getResponseHeader("Location");
this.optionsFieldset.expand();
form.submit({
url: this._import + "/tasks",
url: this._import + "/tasks?expand=all",
waitMsg: this.waitMsgText,
waitMsgTarget: true,
reset: true,
Expand Down Expand Up @@ -382,15 +382,12 @@ gxp.LayerUploadPanel = Ext.extend(Ext.FormPanel, {
if (!task) {
success = false;
msg = "Unknown upload error";
} else if (!task.items || !task.items.length) {
} else if (task.state === 'NO_FORMAT') {
success = false;
msg = "Upload contains no items that can be imported.";
} else if (task.state !== "READY") {
if (!(task.state === "INCOMPLETE" && task.items[0].state === "NO_CRS" && formData.nativeCRS)) {
success = false;
msg = "Source " + task.source.file + " is " + task.state + ": " + task.items[0].state;
break;
}
msg = "Upload contains no suitable files.";
} else if (task.state === 'NO_CRS' && !formData.nativeCRS) {
success = false;
msg = "Coordinate Reference System (CRS) of source file " + task.data.file + " could not be determined. Please specify manually.";
}
}
}
Expand All @@ -400,27 +397,26 @@ gxp.LayerUploadPanel = Ext.extend(Ext.FormPanel, {
// mark the file field as invlid
records = [{data: {id: "file", msg: msg || this.uploadFailedText}}];
} else {
var itemModified = !!(formData.title || formData["abstract"] || formData.nativeCRS),
queue = [];
if (itemModified) {
var itemModified = !!(formData.title || formData["abstract"] || formData.nativeCRS);
// do not do this for coverages see https://github.com/boundlessgeo/suite/issues/184
if (itemModified && tasks[0].target.dataStore) {
this.waitMsg = new Ext.LoadMask((this.ownerCt || this).getEl(), {msg: this.processingUploadText});
this.waitMsg.show();
// for now we only support a single item (items[0])
var resource = task.items[0].resource,
layer = resource.featureType ? "featureType" : "coverage",
item = {id: task.items[0].id, resource: {}};
item.resource[layer] = {
// for now we only support a single task
var payload = {
title: formData.title || undefined,
"abstract": formData["abstract"] || undefined,
srs: formData.nativeCRS || undefined
};
Ext.Ajax.request({
method: "PUT",
url: tasks[0].items[0].href,
jsonData: item,
url: tasks[0].layer.href,
jsonData: payload,
success: this.finishUpload,
failure: function(response) {
this.waitMsg.hide();
if (this.waitMsg) {
this.waitMsg.hide();
}
var errors = [];
try {
var json = Ext.decode(response.responseText);
Expand Down Expand Up @@ -490,10 +486,12 @@ gxp.LayerUploadPanel = Ext.extend(Ext.FormPanel, {
handleUploadSuccess: function(response) {
Ext.Ajax.request({
method: "GET",
url: this._import,
url: this._import + '?expand=all',
failure: this.handleFailure,
success: function(response) {
this.waitMsg.hide();
if (this.waitMsg) {
this.waitMsg.hide();
}
this.getForm().reset();
var details = Ext.decode(response.responseText);
this.fireEvent("uploadcomplete", this, details);
Expand All @@ -506,7 +504,9 @@ gxp.LayerUploadPanel = Ext.extend(Ext.FormPanel, {
/** private: method[handleFailure]
*/
handleFailure: function() {
this.waitMsg.hide();
if (this.waitMsg) {
this.waitMsg.hide();
}
this.getForm().markInvalid([{file: this.uploadFailedText}]);
}

Expand Down

0 comments on commit 29dbedf

Please sign in to comment.