Last change
on this file since 441 was
420,
checked in by hendrikvanantwerpen, 12 years ago
|
We can store answers for surveys now!
Introduces SurveyRun?, which can be edited. Workflow not quite clear yet. A
running survey can be accessed to leave a response. When the response
has an ID, it is loaded (used for closed surveys and continuations). A
researcher cannot create responses yet. He should also be able to add
comments to responses (that he creates).
Introduced caching of store requests.
Factored out path matching and formatting.
Put object creation in separate classes, to localize model/storage
dependency. Not consistent at the moment.
|
File size:
1.4 KB
|
Line | |
---|
1 | define([ |
---|
2 | 'dojo/_base/declare', |
---|
3 | 'dojo/io-query' |
---|
4 | ],function(declare,ioQuery){ |
---|
5 | |
---|
6 | var _paramMatch = /:(\w[\w\d]*)/g; |
---|
7 | var _paramReplace = "([^\\/!]+)"; |
---|
8 | |
---|
9 | var Path = declare(null,{ |
---|
10 | _paramNames: null, |
---|
11 | _matcher: null, |
---|
12 | constructor: function(pattern) { |
---|
13 | var match = null; |
---|
14 | this._paramNames = []; |
---|
15 | while((match = _paramMatch.exec(pattern)) !== null){ |
---|
16 | this._paramNames.push(match[1]); |
---|
17 | } |
---|
18 | pattern = pattern.replace(_paramMatch, _paramReplace); |
---|
19 | this._matcher = new RegExp('^!'+pattern+'(!(.*))?$'); |
---|
20 | }, |
---|
21 | match: function(path) { |
---|
22 | var params = null; |
---|
23 | var result = null; |
---|
24 | if ((result = this._matcher.exec(path)) !== null) { |
---|
25 | var numParams = this._paramNames.length; |
---|
26 | params = {}; |
---|
27 | for (var j = 0; j < numParams; j++) { |
---|
28 | params[this._paramNames[j]] = result[j+1]; |
---|
29 | } |
---|
30 | if ( result.length > numParams+1 && result[numParams+2] ) { |
---|
31 | params.options = ioQuery.queryToObject(result[numParams+2]); |
---|
32 | } |
---|
33 | } |
---|
34 | return params; |
---|
35 | } |
---|
36 | }); |
---|
37 | |
---|
38 | Path.getDefault = function() { |
---|
39 | return "!/"; |
---|
40 | }; |
---|
41 | |
---|
42 | Path.format = function(path,options) { |
---|
43 | var hash = '!'+path; |
---|
44 | if ( options ) { |
---|
45 | hash += '!'+ioQuery.objectToQuery(options); |
---|
46 | } |
---|
47 | return hash; |
---|
48 | }; |
---|
49 | |
---|
50 | return Path; |
---|
51 | }); |
---|
Note: See
TracBrowser
for help on using the repository browser.