[443] | 1 | define([ |
---|
[477] | 2 | "./app/Content", |
---|
| 3 | "./app/Page", |
---|
| 4 | "./app/Path", |
---|
| 5 | "./lib/async", |
---|
[487] | 6 | "./model/classes/responses", |
---|
| 7 | "./model/classes/surveyRuns", |
---|
[477] | 8 | "./pages/response", |
---|
| 9 | "dojo/_base/json", |
---|
| 10 | "dojo/date", |
---|
| 11 | "dojo/date/locale", |
---|
| 12 | "dojo/hash", |
---|
| 13 | "dojo/parser", |
---|
| 14 | "dojo/request", |
---|
| 15 | "./stddeps", |
---|
| 16 | "dojo/domReady!" |
---|
[487] | 17 | ], function(Content, Page, Path, async, responses, surveyRuns, ResponsePage, json, date, locale, hash, parser, request) { |
---|
[443] | 18 | parser.parse(); |
---|
| 19 | Content.startup(); |
---|
| 20 | |
---|
| 21 | function error(msg) { |
---|
| 22 | Content.set(new Page({ |
---|
| 23 | templateString: "<div>"+msg+"</div>" |
---|
| 24 | })); |
---|
| 25 | } |
---|
| 26 | |
---|
[487] | 27 | var path = new Path('/:type/:id'); |
---|
[443] | 28 | var params = path.match(hash()); |
---|
| 29 | params.options = params.options || {}; |
---|
[487] | 30 | |
---|
| 31 | if ( params && params.type === 'surveyRuns' ) { |
---|
| 32 | var response = responses.create(); |
---|
| 33 | response.surveyRunId = params.id; |
---|
| 34 | responses.postWithSecret(response,params.options.secret) |
---|
| 35 | .then(setContent,function(err){ error(err.error); }); |
---|
| 36 | } else if ( params && params.type === 'responses' ) { |
---|
| 37 | responses.getWithSecret(params.id,params.options.secret) |
---|
| 38 | .then(setContent,function(err){ error(err.error); }); |
---|
| 39 | } else { |
---|
[443] | 40 | error("Something is wrong with the URL, don't know what survey to show you. Sorry."); |
---|
| 41 | } |
---|
| 42 | |
---|
[487] | 43 | function setContent(response) { |
---|
| 44 | hash(Path.format("/responses/"+responses.getId(response), |
---|
| 45 | {secret:response.secret})); |
---|
[443] | 46 | Content.set(new ResponsePage({ |
---|
[487] | 47 | response: response |
---|
[443] | 48 | })); |
---|
[487] | 49 | } |
---|
| 50 | |
---|
[443] | 51 | }); |
---|