- Timestamp:
- 08/06/13 01:48:17 (12 years ago)
- Location:
- Dev/trunk/src
- Files:
-
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/client/qed-client/css/fonts.less
r447 r477 3 3 font-size: @font_size; 4 4 color: @text; 5 &.light { 6 color: black; // FIXME : hack for readability 7 } 5 8 6 9 a { -
Dev/trunk/src/client/qed-client/css/layout.less
r443 r477 7 7 height: 100%; 8 8 background-color: @base; 9 .light { 10 background-color: white; // FIXME : hack for readability 11 } 9 12 } -
Dev/trunk/src/client/qed-client/model/widgets/TabbedQuestionBrowser.js
r443 r477 78 78 title: (topic || '[No topic]')+" ("+count+")", 79 79 selectedActions: this.selectedActions, 80 itemActions: this.itemActions 80 itemActions: this.itemActions, 81 itemTitle: this._itemTitle 81 82 }).placeAt(categoryMap._widget.containerNode); 82 83 w.startup(); … … 87 88 } 88 89 }, 90 _itemTitle: function(item) { 91 var title = '['+item.code+']'+item.title; 92 if ( this.include === 'all' ) { 93 title += (item.publicationDate?' (published on '+item.publicationDate+')':' (unpublished)'); 94 } 95 return title; 96 }, 89 97 _fillTopicSelector: function(topic,category) { 90 98 var categoryMap = this._dataMap[category]; … … 93 101 topicMap._filled = true; 94 102 this._busy(); 95 store.query(this._query, {reduce:false,include_docs:true,key:[category,topic]}) 96 .forEach(lang.hitch(this,function(value){ 97 var title; 98 if ( this.include === 'all' ) { 99 title = value.title+(value.publicationDate?' (published on '+value.publicationDate+')':' (unpublished)'); 100 } 101 topicMap._widget.addItem(value,title); 103 store.query(this._query, { 104 reduce:false, 105 include_docs:true, 106 key:[category,topic] 107 }).forEach(lang.hitch(this,function(value){ 108 topicMap._widget.addItem(value); 102 109 })).then(lang.hitch(this,function(){ 103 110 this._done(); -
Dev/trunk/src/client/qed-client/pages/response.js
r461 r477 9 9 "dojo/_base/declare", 10 10 "dojo/_base/event", 11 "dojo/_base/json", 11 12 "dojo/_base/lang", 12 13 "dojo/promise/all", 14 "dojo/request", 13 15 "dojo/when", 14 16 "require", 15 17 "dojo/text!./templates/response.html" 16 ], function(Content, Page, async, Response, Survey, SurveyRun, store, declare, event, lang, all, when, require, template) {18 ], function(Content, Page, async, Response, Survey, SurveyRun, store, declare, event, json, lang, all, request, when, require, template) { 17 19 return declare([Page],{ 18 20 contextRequire: require, … … 37 39 this._enableSubmit(); 38 40 } 39 }), function() {41 }), lang.hitch(this,function() { 40 42 this._showInfo("<div>The url seems to be incorrect, no survey found.</div>"); 41 }) ;43 })); 42 44 } else { 43 45 throw new Error("No valid uid or survey passed!"); … … 45 47 }, 46 48 _loadSurveyAndResponse: function(surveyRunId,responseId){ 47 return all([store.get(surveyRunId),store.get(responseId)]) 49 return all([request.get('/api/surveyRuns/'+surveyRunId,{handleAs:'json'}), 50 request.get('/api/responses/'+responseId,{handleAs:'json'})]) 48 51 .then(lang.hitch(this,function(surveyAndResponse){ 49 52 var surveyRun = surveyAndResponse[0]; … … 73 76 var answers = this.surveyWidget.get('value'); 74 77 this.response.answers = answers; 75 return store.put(this.response).then(function(){ 78 return request.put('/api/responses/'+store.getIdentity(this.response),{ 79 handleAs:'json', 80 data:json.toJson(this.response), 81 headers:{"Content-Type": "application/json"} 82 }).then(function(){ 76 83 Content.notify("Your response is saved."); 77 84 }, function(err){ … … 82 89 this.response.publicationDate = store.timestamp(); 83 90 this._getAnswersAndSaveResponse() 84 .then( function(){91 .then(lang.hitch(this,function(){ 85 92 this._showInfo("<div>Thanks for filling in the survey. You cannot edit your answers anymore.</div>"); 86 93 this._disableSubmit(); 87 }) ;94 })); 88 95 if ( e ) { event.stop(e); } 89 96 return false; -
Dev/trunk/src/client/qed-client/response.js
r443 r477 1 1 define([ 2 'dojo/date', 3 'dojo/date/locale', 4 'dojo/hash', 5 'dojo/parser', 6 './store', 7 './app/Content', 8 './app/Page', 9 './app/Path', 10 './lib/async', 11 './model/classes/Response', 12 './model/classes/SurveyRun', 13 './pages/response', 14 'dojo/domReady!', 15 './stddeps' 16 ],function(date,locale,hash,parser,store,Content,Page,Path,async,Response,SurveyRun,ResponsePage) { 2 "./app/Content", 3 "./app/Page", 4 "./app/Path", 5 "./lib/async", 6 "./model/classes/Response", 7 "./model/classes/SurveyRun", 8 "./pages/response", 9 "./store", 10 "dojo/_base/json", 11 "dojo/date", 12 "dojo/date/locale", 13 "dojo/hash", 14 "dojo/parser", 15 "dojo/request", 16 "./stddeps", 17 "dojo/domReady!" 18 ], function(Content, Page, Path, async, Response, SurveyRun, ResponsePage, store, json, date, locale, hash, parser, request) { 17 19 parser.parse(); 18 20 Content.startup(); … … 49 51 } 50 52 51 store.get(surveyRunId)53 request.get('/api/surveyRuns/'+surveyRunId,{handleAs:'json'}) 52 54 .then(function(surveyRun){ 53 55 checkDates(surveyRun); … … 58 60 var response = Response.create(); 59 61 response.surveyRunId = surveyRunId; 60 return store.put(response).then(function(res){ 61 return store.getIdentity(res); 62 return request.post('/api/responses',{ 63 handleAs:'json', 64 data:json.toJson(response), 65 headers:{"Content-Type": "application/json"} 66 }).then(function(res){ 67 return res.id; 62 68 }); 63 69 } else { -
Dev/trunk/src/client/qed-client/widgets/Selector.js
r472 r477 18 18 ], function(LineWithActionsWidget, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, registry, baseArray, declare, event, lang, Source, domClass, domConstruct, fx, query, templateString) { 19 19 20 function get(selector, item) { 21 if ( lang.isFunction(selector) ) { 22 return selector(item); 23 } else { 24 return item[selector || 'title']; 25 } 26 } 27 20 28 return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{ 21 29 templateString: templateString, … … 25 33 selectedActions: null, 26 34 itemActions: null, 35 itemTitle: 'title', 27 36 // main selector action: Object 28 37 // title: … … 111 120 this._selectedItem = item; 112 121 this.onToggle(); 113 this._selectorLine.set("title", item.title);122 this._selectorLine.set("title", get(this.itemTitle,item)); 114 123 baseArray.forEach(this.optionsNode.childNodes, function(node){ 115 124 var line = registry.byNode(node); … … 174 183 return domConstruct.create("div",{ 175 184 'class': 'dragAvatar', 176 innerHTML: item.title185 innerHTML: get(this.itemTitle,item) 177 186 }); 178 187 }, … … 197 206 } 198 207 var w = new LineWithActionsWidget({ 199 title: item.title,208 title: get(this.itemTitle,item), 200 209 actions: actions 201 210 }); -
Dev/trunk/src/client/response.html
r452 r477 6 6 <link rel="stylesheet" type="text/css" href="qed-client/css/qed.css" /> 7 7 </head> 8 <body id="rft" class="dijitReset claro ">8 <body id="rft" class="dijitReset claro light" > 9 9 <script type="text/javascript"> 10 10 var dojoConfig = { -
Dev/trunk/src/server/app.js
r475 r477 48 48 49 49 // cookies and session 50 app.use('/api /login',express.bodyParser());50 app.use('/api',express.bodyParser()); 51 51 app.use(express.cookieParser()); 52 52 app.use(express.session({ secret: "quasi experimental design" })); … … 99 99 }); 100 100 101 // expose everything needed to fill in responses 102 // FIXME : this needs more security, now you can guess ids 103 // and get actual survey and response data! 104 app.get( 105 '/live', 106 function(req,res){ 107 res.redirect('/response.html#!/55704d6a84194c2d7ba9bec93c000e75'); 108 }); 109 app.get( 110 '/api/surveyRuns/:id', 111 function(req,res){ 112 var id = req.params.id; 113 couch.get(id).then(function(result){ 114 if ( result.type === 'SurveyRun') { 115 res.send(200, result); 116 } else { 117 res.send(404, {error: "Cannot find survey run "+id}); 118 } 119 }, function(error){ 120 res.send(404, {error: "Cannot find survey run "+id}); 121 }); 122 }); 123 app.get( 124 '/api/responses/:id', 125 function(req,res){ 126 var id = req.params.id; 127 couch.get(id).then(function(result){ 128 if ( result.type === 'Response') { 129 res.send(200, result); 130 } else { 131 res.send(404, {error: "Cannot find response "+id}); 132 } 133 }, function(error){ 134 res.send(404, {error: "Cannot find response "+id}); 135 }); 136 }); 137 app.post( 138 '/api/responses', 139 function(req,res){ 140 console.log(req.body); 141 couch.post(req.body).then(function(result){ 142 res.send(200, result); 143 }, function(error){ 144 res.send(500, error); 145 }); 146 }); 147 app.put( 148 '/api/responses/:id', 149 function(req,res){ 150 var id = req.params.id; 151 couch.put(id,req.body).then(function(result){ 152 res.send(200, result); 153 }, function(error){ 154 res.send(500, error); 155 }); 156 }); 157 101 158 // data is proxied to couch 102 159 app.use('/api/data', ensureAuthenticated); … … 135 192 function responseToVariables(response) { 136 193 var result = flattenObject(response.answers); 137 result.respondent = response.id;138 194 return result; 139 195 } … … 143 199 (function agg(val,key,res){ 144 200 if ( _.isObject(val) ) { 145 _.forEach(val, function(v,k){ 146 agg(v,(key ? key+'.' : '')+k,res); 147 }); 201 var keys = _.keys(val); 202 // FIXME : dirty hack for questions with only one input 203 if ( keys.length === 1 ) { 204 agg(val[keys[0]],key,res); 205 } else { 206 _.forEach(val, function(v,k){ 207 agg(v,(key ? key+'.' : '')+k,res); 208 }); 209 } 148 210 } else if ( _.isArray(val) ) { 149 _.forEach(val, function(v,i){ 150 agg(v,(key ? key+'.' : '')+i,res); 151 }); 211 // FIXME : dirty hack for questions with only one input 212 if ( val.length === 1 ) { 213 agg(val[0],key,res); 214 } else { 215 _.forEach(val, function(v,i){ 216 agg(v,(key ? key+'.' : '')+i,res); 217 }); 218 } 152 219 } else { 153 220 res[key] = val; -
Dev/trunk/src/server/config/couchdb-design-docs.js
r464 r477 33 33 map: function(doc){ 34 34 emit(doc.type, doc); 35 } 36 }, 37 typeless: { 38 map: function(doc){ 39 if ( !doc.type ) { 40 emit(doc._id, doc); 41 } 35 42 } 36 43 } -
Dev/trunk/src/server/util/couch.coffee
r475 r477 9 9 url = "#{@url}/#{id}" 10 10 couchRequest 'GET', url 11 post: (doc) -> 12 url = "#{@url}" 13 couchRequest 'POST', url, doc 11 14 put: (id, doc) -> 12 15 url = "#{@url}/#{id}"
Note: See TracChangeset
for help on using the changeset viewer.