making notifications when bulk uploading csvs make a little more sense

This commit is contained in:
Max Ogden
2011-08-01 22:04:19 -04:00
parent f72b9c31db
commit 9b76faf60f
4 changed files with 10 additions and 12 deletions

View File

@@ -59,7 +59,7 @@
<script type='text/mustache' class="importActionsTemplate"> <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="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> <li><a data-action="uploadImport" class="menuAction" href="JavaScript:void(0);">Upload CSV</a></li>
</script> </script>
@@ -290,7 +290,7 @@
Paste in an array of JSON objects representing the documents that you would like to insert into the database. Paste in an array of JSON objects representing the documents that you would like to insert into the database.
</p> </p>
<p class="info"> <p class="info">
<code>[{woo: pizza}, {tasty: muffins}]</code> <code>[{woo: "pizza"}, {tasty: "muffins"}]</code>
</p> </p>
<div class="menu-container data-table-cell-editor"> <div class="menu-container data-table-cell-editor">
<textarea class="data-table-cell-copypaste-editor" bind="textarea">{{value}}</textarea> <textarea class="data-table-cell-copypaste-editor" bind="textarea">{{value}}</textarea>
@@ -311,7 +311,6 @@
<div class="grid-layout layout-tight layout-full"> <div class="grid-layout layout-tight layout-full">
<strong>Please choose a CSV file to upload:</strong><br /> <strong>Please choose a CSV file to upload:</strong><br />
<input type="file" id="file" /> <input type="file" id="file" />
<input type="button" value="Load file" onclick="costco.uploadCSV()" />
</div> </div>
</div> </div>
<div class="dialog-footer"> <div class="dialog-footer">

View File

@@ -13,12 +13,6 @@ onmessage = function(message) {
req.onreadystatechange = function() { req.onreadystatechange = function() {
if (req.readyState == 4) postMessage(JSON.stringify({done: true})) 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.open('POST', message.data.url);
req.setRequestHeader('Content-Type', 'application/json'); req.setRequestHeader('Content-Type', 'application/json');
req.send(JSON.stringify({docs: docs})); req.send(JSON.stringify({docs: docs}));

View File

@@ -105,13 +105,11 @@ var costco = function() {
} }
function uploadCSV() { function uploadCSV() {
util.notify('Upload started.');
var file = $('#file')[0].files[0]; var file = $('#file')[0].files[0];
if (file) { if (file) {
var reader = new FileReader(); var reader = new FileReader();
reader.readAsText(file); reader.readAsText(file);
reader.onload = function(event) { reader.onload = function(event) {
util.notify('File loaded.');
var payload = { var payload = {
url: window.location.href + "/api/_bulk_docs", // todo more robust url composition url: window.location.href + "/api/_bulk_docs", // todo more robust url composition
data: event.target.result data: event.target.result
@@ -119,9 +117,9 @@ var costco = function() {
var worker = new Worker('script/costco-csv-worker.js'); var worker = new Worker('script/costco-csv-worker.js');
worker.onmessage = function(message) { worker.onmessage = function(message) {
if(JSON.parse(message.data).done) { if(JSON.parse(message.data).done) {
util.hide('dialog');
util.notify("Data uploaded successfully!"); util.notify("Data uploaded successfully!");
recline.initializeTable(app.offset); recline.initializeTable(app.offset);
util.hide('dialog');
} else { } else {
util.notify(message.data); util.notify(message.data);
} }

View File

@@ -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() { jsonTree: function() {
util.renderTree(app.apiDocs); util.renderTree(app.apiDocs);
$('.dialog-content .okButton').click(function(e) { $('.dialog-content .okButton').click(function(e) {