[410] | 1 | define([],function(){ |
---|
| 2 | return { |
---|
| 3 | "_users/rft_admin": { |
---|
| 4 | __configAction: "ignore", |
---|
| 5 | _id: "org.couchdb.user:rft_admin", |
---|
| 6 | name: "rft_admin", |
---|
| 7 | password: "Welkom01", |
---|
| 8 | roles: [ "rft_admin" ], |
---|
| 9 | type: "user" |
---|
[362] | 10 | }, |
---|
[410] | 11 | "rft/_security": { |
---|
| 12 | __configAction: "ignore", |
---|
| 13 | admins: { |
---|
| 14 | names: [], |
---|
| 15 | roles: ["rft_admin"] |
---|
[362] | 16 | }, |
---|
[410] | 17 | readers: { |
---|
| 18 | names: [], |
---|
| 19 | roles: ["rft_user"] |
---|
| 20 | } |
---|
| 21 | }, |
---|
| 22 | "rft/_design/default": { |
---|
| 23 | __configAction: "replace", |
---|
| 24 | _id: "_design/default", |
---|
| 25 | language: "javascript", |
---|
| 26 | validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) { |
---|
| 27 | if ( oldDoc && oldDoc.publicationDate ) { throw({forbidden:'Published documents cannot be modified.'}); } |
---|
| 28 | if ( !newDoc._deleted && !newDoc.type ) { throw({forbidden:'Documents must have a type field.'}); } |
---|
[362] | 29 | }, |
---|
[410] | 30 | views: { |
---|
| 31 | by_type: { |
---|
| 32 | map: function(doc){ |
---|
| 33 | emit(doc.type, doc); |
---|
| 34 | } |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | }, |
---|
| 38 | "rft/_design/questions": { |
---|
| 39 | __configAction: "replace", |
---|
| 40 | _id: "_design/questions", |
---|
| 41 | language: "javascript", |
---|
| 42 | validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) { |
---|
| 43 | if( newDoc._deleted || newDoc.type!=='Question' ){ return; } |
---|
| 44 | if( !newDoc.code ){ throw({forbidden:'Question must have a code field.'});} |
---|
[375] | 45 | }, |
---|
[410] | 46 | views: { |
---|
| 47 | all: { |
---|
| 48 | map: function(doc){ |
---|
| 49 | if ( doc.type !== 'Question' ) { return; } |
---|
| 50 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
| 51 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
| 52 | emit([doc.categories[i],doc.topic||null],1); |
---|
| 53 | } |
---|
| 54 | } else { |
---|
| 55 | emit([null,null],1); |
---|
| 56 | } |
---|
| 57 | }, |
---|
| 58 | reduce: function(keys,values){ return sum(values); } |
---|
| 59 | }, |
---|
| 60 | published: { |
---|
| 61 | map: function(doc){ |
---|
| 62 | if ( doc.type!=='Question' || !doc.publicationDate ) { return; } |
---|
| 63 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
| 64 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
| 65 | emit([doc.categories[i],doc.topic||null],1); |
---|
| 66 | } |
---|
| 67 | } else { |
---|
| 68 | emit([null,null],1); |
---|
| 69 | } |
---|
| 70 | }, |
---|
| 71 | reduce: function(keys,values){ return sum(values); } |
---|
| 72 | }, |
---|
| 73 | all_topics: { |
---|
| 74 | map: function(doc){ |
---|
| 75 | if( doc.type !== 'Question' ){ return; } |
---|
| 76 | emit(doc.topic); |
---|
| 77 | } |
---|
| 78 | }, |
---|
| 79 | published_topics: { |
---|
| 80 | map: function(doc){ |
---|
| 81 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
| 82 | emit(doc.topic); |
---|
| 83 | } |
---|
| 84 | } |
---|
[362] | 85 | } |
---|
[410] | 86 | }, |
---|
| 87 | "rft/_design/surveys": { |
---|
| 88 | __configAction: "replace", |
---|
| 89 | _id: "_design/surveys", |
---|
| 90 | language: "javascript", |
---|
| 91 | views: { |
---|
| 92 | drafts: { |
---|
| 93 | map: function(doc){ |
---|
| 94 | if ( doc.type !== 'Survey' || doc.publicationDate ) { return; } |
---|
| 95 | emit(doc._id,doc); |
---|
| 96 | } |
---|
| 97 | }, |
---|
| 98 | published: { |
---|
| 99 | map: function(doc){ |
---|
| 100 | if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; } |
---|
| 101 | emit(doc._id,doc); |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | } |
---|
[362] | 105 | } |
---|
[410] | 106 | }; |
---|
| 107 | }); |
---|