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