implement json copypaste bulk uploader

This commit is contained in:
Max Ogden 2011-07-24 13:44:28 -07:00
parent a6093b1018
commit ce26ed6afb
3 changed files with 36 additions and 1 deletions

View File

@ -284,10 +284,16 @@
<script type='text/mustache' class="pasteImportTemplate">
<div class="dialog-header">
Import raw copy & pasted data
Import raw copy & pasted JSON
</div>
<div class="dialog-body">
<div class="grid-layout layout-tight layout-full">
<p class="info">
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}]</code>
</p>
<div class="menu-container data-table-cell-editor">
<textarea class="data-table-cell-copypaste-editor" bind="textarea">{{value}}</textarea>
</div>

View File

@ -40,6 +40,8 @@ var recline = function() {
function renderRows(response) {
var rows = response.rows;
if (rows.length < 1) return;
var tableRows = [];
rows.map(function(row) {

View File

@ -185,6 +185,33 @@ app.after = {
}
);
})
},
pasteImport: function() {
$('.dialog-content .okButton').click(function(e) {
util.notify("Uploading documents...", {persist: true, loader: true});
try {
var docs = JSON.parse($('.data-table-cell-copypaste-editor').val());
} catch(e) {
util.notify("JSON parse error: " + e);
}
if (docs) {
if(_.isArray(docs)) {
costco.uploadDocs(docs).then(
function(docs) {
util.notify("Data uploaded successfully!");
recline.fetchRows(false, app.offset);
util.hide('dialog');
},
function (err) {
util.hide('dialog');
util.notify("Error uploading: " + err.responseText);
}
);
} else {
util.notify("Error: JSON must be an array of objects");
}
}
})
}
}