Last change
on this file since 527 was
525,
checked in by hendrikvanantwerpen, 11 years ago
|
- Allow empty subcodes.
- Use HTTPResult exclusively on server (no more q).
- Set readonly & disabled on ourselves as well in _ComplexValueMixin
- Split server into several modules.
- Check codes on the variable level, not question level.
- We can add modules in design documents now.
|
File size:
1.7 KB
|
Rev | Line | |
---|
[506] | 1 | var env = require('../env') |
---|
| 2 | , upgradeCouch = require('../config/upgrade-couchdb') |
---|
| 3 | , cryptoken = require('../util/crypto-token') |
---|
[525] | 4 | , HTTPResult = require('../util/http-result') |
---|
[506] | 5 | , _ = require('underscore') |
---|
| 6 | ; |
---|
| 7 | |
---|
| 8 | function strip(obj) { |
---|
| 9 | var subcoded = false; |
---|
| 10 | var res = []; |
---|
| 11 | if ( _.isArray(obj) ) { |
---|
| 12 | res = _.map(obj,strip); |
---|
| 13 | } else if ( _.isObject(obj) ) { |
---|
| 14 | if ( obj.type === "Question" ) { |
---|
| 15 | _.each(obj.content, function(value,vindex) { |
---|
| 16 | switch(value.type) { |
---|
| 17 | case "StringInput": |
---|
| 18 | case "TextInput": |
---|
| 19 | case "NumberInput": |
---|
| 20 | if ( !value.subcode ) { |
---|
| 21 | value.subcode = '' + vindex; |
---|
| 22 | subcoded = true; |
---|
| 23 | } |
---|
| 24 | break; |
---|
| 25 | case "ScaleInput": |
---|
| 26 | case "MultipleChoiceInput": |
---|
| 27 | _.each(value.items, function(item,iindex) { |
---|
| 28 | if ( !item.subcode ) { |
---|
| 29 | item.subcode = '' + vindex + iindex; |
---|
| 30 | subcoded = true; |
---|
| 31 | } |
---|
| 32 | }); |
---|
| 33 | break; |
---|
| 34 | } |
---|
| 35 | }); |
---|
| 36 | } |
---|
| 37 | res = _.map(obj,function(val,key) { |
---|
| 38 | if ( val === null || val === "" ) { |
---|
| 39 | delete obj[key]; |
---|
| 40 | return true; |
---|
| 41 | } else { |
---|
| 42 | return strip(val); |
---|
| 43 | } |
---|
| 44 | }); |
---|
| 45 | } |
---|
| 46 | return subcoded || _.contains(res,true); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | upgradeCouch(env.couchServerURL,env.dbName,function(doc){ |
---|
| 50 | if ( strip(doc) ) { |
---|
| 51 | return doc; |
---|
| 52 | } else { |
---|
[525] | 53 | return new HTTPResult(-1); |
---|
[506] | 54 | } |
---|
| 55 | }).then(function(res){ |
---|
| 56 | console.log("done",res); |
---|
| 57 | }, function(err){ |
---|
| 58 | console.error("fail",err); |
---|
| 59 | }); |
---|
Note: See
TracBrowser
for help on using the repository browser.