Skip to content

Commit

Permalink
Fix exports when filename is not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Feb 10, 2016
1 parent 26eb516 commit e78cb44
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/js/components/experiments/answers/AnswerList.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,15 @@ class AnswerList extends DataComponent {
this._export().then((items) => {
let formatter = new JsonFormatter(2);
let content = formatter.format(items);
let filename = this._promptForFilename("json");

if (!filename) {
return;
}

saveAs(new Blob([content], {
type: "application/json; charset=utf-8"
}), this._promptForFilename("json"));
}), filename);
});
}

Expand All @@ -229,16 +234,25 @@ class AnswerList extends DataComponent {
});

let content = formatter.format(data);
let filename = this._promptForFilename("csv");

if (!filename) {
return;
}

saveAs(new Blob([content], {
type: "text/csv; charset=utf-8"
}), this._promptForFilename("csv"));
}), filename);
});
}

_promptForFilename(extension) {
let filename = prompt("Filename");

if (!filename) {
return null;
}

if (filename.length - extension.length > 0 && filename.substr(filename.length - extension.length, extension.length) !== extension) {
return filename + "." + extension;
}
Expand All @@ -264,7 +278,7 @@ class AnswerList extends DataComponent {
} else {
resolve(all);
}
});
}).catch((e) => reject(e));
});
};

Expand Down

0 comments on commit e78cb44

Please sign in to comment.