diff --git a/attachments/pages/index.html b/attachments/pages/index.html
index 59c0dae5..fa5bb089 100644
--- a/attachments/pages/index.html
+++ b/attachments/pages/index.html
@@ -191,7 +191,7 @@
@@ -219,20 +219,14 @@
|
- row
+ before
|
- value
- |
-
- value
+ after
|
{{#rows}}
- |
- {{count}}
- |
{{before}}
|
diff --git a/attachments/script/costco.js b/attachments/script/costco.js
index 8370f5be..5383f0bd 100644
--- a/attachments/script/costco.js
+++ b/attachments/script/costco.js
@@ -5,7 +5,7 @@ var costco = function() {
var toUpdate = [];
function handleEditorChange(e) {
- console.log(e.target.value);
+ mapDocs(e.target.value);
}
function computeChanges() {
@@ -37,47 +37,51 @@ var costco = function() {
}
function mapDocs(funcString) {
+ var errors = $('.expression-preview-parsing-status');
try {
eval("var editFunc = " + funcString);
+ errors.text('No syntax error.');
} catch(e) {
- $("#status").html("error evaluating function: "
- + e + "");
+ errors.text(e+"");
return;
}
toUpdate = [];
var deleted = 0
, edited = 0
- , failed = 0;
-
- getDocs(function(data) {
- var rows = data.rows;
- rows.forEach(function(row) {
- var doc = row.doc;
- try {
- var updated = editFunc(_.clone(doc));
- } catch(e) {
- failed++; // ignore if it throws on this doc
- return;
- }
- if(updated === null) {
- doc._deleted = true;
- toUpdate.push(doc);
- deleted++;
- }
- else if(updated && !_.isEqual(updated, doc)) {
- toUpdate.push(updated);
- edited++;
- }
- });
- // todo: make template for this
- $("#status").html("About to edit " + edited
- + " docs and delete " + deleted + " docs from "
- + getDb().name + "");
- if(failed)
- $("#status").append(". Edit function threw on " + failed + " docs");
- $("#update-container").show();
+ , failed = 0
+ , count = 0
+ , preview = [];
+
+ _.each(app.cache, function(doc) {
+ try {
+ var updated = editFunc(_.clone(doc));
+ } catch(e) {
+ failed++; // ignore if it throws on this doc
+ return;
+ }
+ if(updated === null) {
+ doc._deleted = true;
+ toUpdate.push(doc);
+ deleted++;
+ }
+ else if(updated && !_.isEqual(updated, doc)) {
+ toUpdate.push(updated);
+ edited++;
+ }
+ preview.push({before: doc[app.currentColumn], after: updated[app.currentColumn]});
+ count++;
});
+
+ util.render('editPreview', 'editPreview', {rows: preview});
+ //
+ // // todo: make template for this
+ // $("#status").html("About to edit " + edited
+ // + " docs and delete " + deleted + " docs from "
+ // + getDb().name + "");
+ // if(failed)
+ // $("#status").append(". Edit function threw on " + failed + " docs");
+ // $("#update-container").show();
}
function updateDocs(callback) {
@@ -93,22 +97,10 @@ var costco = function() {
});
}
- function getDocs(callback) {
- getDb().allDocs({
- include_docs : true,
- success : callback,
- error: function(req, status, err) {
- $("#status").html("error retrieving docs: "
- + err + "");
- }
- });
- }
-
return {
handleEditorChange: handleEditorChange,
computeChanges: computeChanges,
mapDocs: mapDocs,
- updateDocs: updateDocs,
- getDocs: getDocs
+ updateDocs: updateDocs
};
}();
\ No newline at end of file
diff --git a/attachments/script/removalist.js b/attachments/script/removalist.js
index 67410c9d..dfef2c11 100644
--- a/attachments/script/removalist.js
+++ b/attachments/script/removalist.js
@@ -114,6 +114,7 @@ var removalist = function() {
couch.request(req).then(function(response) {
var offset = response.offset + 1;
$('.viewpanel-pagingcount').text(offset + " - " + ((offset - 1) + getPageSize()));
+ app.cache = response.rows.map(function(row) { return row.value; } );
removalist.renderRows(response);
});
diff --git a/attachments/script/site.js b/attachments/script/site.js
index e40a0337..8e58173e 100644
--- a/attachments/script/site.js
+++ b/attachments/script/site.js
@@ -43,11 +43,12 @@ app.after = {
bulkEdit: function() {
var editor = $('.expression-preview-code');
editor.val("function(doc) {\n doc['"+ app.currentColumn+"'] = doc['"+ app.currentColumn+"'];\n return doc;\n}");
- editor.focus().get(0).setSelectionRange(18, 18);
+ editor.focus().get(0).setSelectionRange(18, 18);
editor.keydown(function(e) {
// if you don't setTimeout it won't grab the latest character if you call e.target.value
window.setTimeout(function(){costco.handleEditorChange(e)}, 1, true);
});
+ editor.keydown();
}
}