making notifications when bulk uploading csvs make a little more sense
This commit is contained in:
parent
f72b9c31db
commit
9b76faf60f
@ -59,7 +59,7 @@
|
||||
|
||||
<script type='text/mustache' class="importActionsTemplate">
|
||||
<li><a data-action="urlImport" class="menuAction" href="JavaScript:void(0);">JSON API</a></li>
|
||||
<li><a data-action="pasteImport" class="menuAction" href="JavaScript:void(0);">Copy & Paste JSON</a></li>
|
||||
<li><a data-action="pasteImport" class="menuAction" href="JavaScript:void(0);">Paste JSON</a></li>
|
||||
<li><a data-action="uploadImport" class="menuAction" href="JavaScript:void(0);">Upload CSV</a></li>
|
||||
</script>
|
||||
|
||||
@ -290,7 +290,7 @@
|
||||
Paste in an array of JSON objects representing the documents that you would like to insert into the database.
|
||||
</p>
|
||||
<p class="info">
|
||||
<code>[{woo: pizza}, {tasty: muffins}]</code>
|
||||
<code>[{woo: "pizza"}, {tasty: "muffins"}]</code>
|
||||
</p>
|
||||
<div class="menu-container data-table-cell-editor">
|
||||
<textarea class="data-table-cell-copypaste-editor" bind="textarea">{{value}}</textarea>
|
||||
@ -311,7 +311,6 @@
|
||||
<div class="grid-layout layout-tight layout-full">
|
||||
<strong>Please choose a CSV file to upload:</strong><br />
|
||||
<input type="file" id="file" />
|
||||
<input type="button" value="Load file" onclick="costco.uploadCSV()" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
|
||||
@ -13,12 +13,6 @@ onmessage = function(message) {
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState == 4) postMessage(JSON.stringify({done: true}))
|
||||
};
|
||||
req.onprogress = function(e) {
|
||||
if (e.lengthComputable) {
|
||||
var percentComplete = (e.loaded / e.total) * 100;
|
||||
postMessage(JSON.stringify({percent: percentComplete}));
|
||||
}
|
||||
}
|
||||
req.open('POST', message.data.url);
|
||||
req.setRequestHeader('Content-Type', 'application/json');
|
||||
req.send(JSON.stringify({docs: docs}));
|
||||
|
||||
@ -105,13 +105,11 @@ var costco = function() {
|
||||
}
|
||||
|
||||
function uploadCSV() {
|
||||
util.notify('Upload started.');
|
||||
var file = $('#file')[0].files[0];
|
||||
if (file) {
|
||||
var reader = new FileReader();
|
||||
reader.readAsText(file);
|
||||
reader.onload = function(event) {
|
||||
util.notify('File loaded.');
|
||||
var payload = {
|
||||
url: window.location.href + "/api/_bulk_docs", // todo more robust url composition
|
||||
data: event.target.result
|
||||
@ -119,9 +117,9 @@ var costco = function() {
|
||||
var worker = new Worker('script/costco-csv-worker.js');
|
||||
worker.onmessage = function(message) {
|
||||
if(JSON.parse(message.data).done) {
|
||||
util.hide('dialog');
|
||||
util.notify("Data uploaded successfully!");
|
||||
recline.initializeTable(app.offset);
|
||||
util.hide('dialog');
|
||||
} else {
|
||||
util.notify(message.data);
|
||||
}
|
||||
|
||||
@ -186,6 +186,13 @@ app.after = {
|
||||
);
|
||||
})
|
||||
},
|
||||
uploadImport: function() {
|
||||
$('.dialog-content .okButton').click(function(e) {
|
||||
util.hide('dialog');
|
||||
util.notify("Saving documents...", {persist: true, loader: true});
|
||||
costco.uploadCSV();
|
||||
})
|
||||
},
|
||||
jsonTree: function() {
|
||||
util.renderTree(app.apiDocs);
|
||||
$('.dialog-content .okButton').click(function(e) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user