Last change
on this file since 493 was
492,
checked in by hendrikvanantwerpen, 11 years ago
|
- Enable/disable buttons on content change.
- One place to do date formatting, because it was going wrong again.
- Serialize questions in survey properly.
- _ComplexValueMixin consumes submit events, but does trigger outer
forms if present.
- Trigger dialog show/hide for login only after previous effect is
finished.
- Check that documents are actually valid, not just that validator
returned a result.
- Validate email and timestamp formats.
- Prepared for live runs.
|
File size:
1.3 KB
|
Rev | Line | |
---|
[479] | 1 | var Q = require('q') |
---|
| 2 | , _ = require('underscore') |
---|
[492] | 3 | , validator = require('../util/validator') |
---|
[479] | 4 | , CouchDB = require('../util/couch').CouchDB |
---|
| 5 | ; |
---|
| 6 | |
---|
| 7 | var schema = require('./couchdb-schema'); |
---|
| 8 | |
---|
[487] | 9 | module.exports = function(couchServerURL,dbName) { |
---|
| 10 | var server = new CouchDB(couchServerURL,dbName); |
---|
[479] | 11 | var designRe = /^_design\//; |
---|
[492] | 12 | |
---|
| 13 | var codes = {}; |
---|
| 14 | function codeUnique(code) { |
---|
| 15 | if ( code in codes ) { |
---|
| 16 | return false; |
---|
| 17 | } else { |
---|
| 18 | codes[code] = true; |
---|
| 19 | return true; |
---|
| 20 | } |
---|
| 21 | } |
---|
| 22 | |
---|
[479] | 23 | return server.get('/_all_docs') |
---|
| 24 | .then(function(allDocs){ |
---|
| 25 | return _.chain(allDocs.rows) |
---|
| 26 | .filter(function(doc){ |
---|
| 27 | return doc.id.match(designRe) === null; |
---|
| 28 | }) |
---|
| 29 | .reduce(function(memo, doc){ |
---|
| 30 | return memo.then(function(result){ |
---|
| 31 | return server.get(doc.id) |
---|
| 32 | .then(function(doc){ |
---|
[492] | 33 | var valid = validator(doc,schema); |
---|
| 34 | if ( doc.type === "Question" && !codeUnique(doc.code) ) { |
---|
| 35 | valid.valid = false; |
---|
| 36 | valid.error = "Question code "+doc.code+" is not unique."; |
---|
| 37 | } |
---|
[479] | 38 | result[doc._id] = valid; |
---|
| 39 | return result; |
---|
| 40 | }); |
---|
| 41 | }); |
---|
| 42 | }, Q.resolve({})) |
---|
| 43 | .value(); |
---|
| 44 | }).all(); |
---|
| 45 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.