Permalink
Browse files

Record history of changes.

  • Loading branch information...
1 parent 3b794b6 commit 1c963460d6d845bbff3b19f919a55de3f42e6dc7 @dustin dustin committed Aug 30, 2011
Showing with 15 additions and 0 deletions.
  1. +15 −0 updates/set_state.js
View
@@ -1,5 +1,20 @@
function(doc, req) {
+
+ function ISODateString(d){
+ function pad(n){return n<10 ? '0'+n : n;}
+ return d.getUTCFullYear()+'-'
+ + pad(d.getUTCMonth()+1)+'-'
+ + pad(d.getUTCDate())+'T'
+ + pad(d.getUTCHours())+':'
+ + pad(d.getUTCMinutes())+':'
+ + pad(d.getUTCSeconds())+'Z';
+ }
+
var old_state = doc['rm_state'];
doc['rm_state'] = req.form.new_state;
+ var h = doc.rm_history || [];
+ h.push({who: req.userCtx, when: ISODateString(new Date()),
+ from: old_state, to: req.form.new_state});
+ doc.rm_history = h;
return [doc, (old_state === req.form.new_state) ? "nochange" : "change"];
}

0 comments on commit 1c96346

Please sign in to comment.