1 | define([ |
---|
2 | 'dojo/_base/declare', |
---|
3 | 'dojo/_base/event', |
---|
4 | 'dojo/_base/lang', |
---|
5 | 'dojo/when', |
---|
6 | '../app/Content', |
---|
7 | '../app/Router', |
---|
8 | '../lib/func', |
---|
9 | '../store', |
---|
10 | '../app/Page', |
---|
11 | '../model/classes/SurveyRun', |
---|
12 | 'dojo/text!./templates/surveyRun.html' |
---|
13 | ],function(declare,event,lang,when,Content,Router,func,store,Page,SurveyRun,template){ |
---|
14 | return declare([Page],{ |
---|
15 | templateString: template, |
---|
16 | surveyRun: null, |
---|
17 | startup: function() { |
---|
18 | if ( this._started ) { return; } |
---|
19 | this.inherited(arguments); |
---|
20 | this.propertiesForm.on("blur",lang.hitch(this,'_onPropChange')); |
---|
21 | if ( this.surveyRunId ) { |
---|
22 | this._loadSurveyRun(); |
---|
23 | } else { |
---|
24 | throw "No valid uid or survey passed!"; |
---|
25 | } |
---|
26 | }, |
---|
27 | _loadSurveyRun: function() { |
---|
28 | when(store.get(this.surveyRunId)) |
---|
29 | .then(lang.hitch(this,function(surveyRun){ |
---|
30 | this.surveyRun = surveyRun; |
---|
31 | this.refresh(); |
---|
32 | })); |
---|
33 | }, |
---|
34 | refresh: function() { |
---|
35 | this.titleNode.innerHTML = SurveyRun.DisplayTitle.get(this.surveyRun); |
---|
36 | this.surveyNode.set('value',SurveyRun.Survey.get(this.surveyRun)); |
---|
37 | this.propertiesForm.set('value',this.surveyRun); |
---|
38 | this._onPropChange(); |
---|
39 | }, |
---|
40 | _onPropChange: function(e) { |
---|
41 | var surveyRun = this.propertiesForm.get('value'); |
---|
42 | if ( surveyRun.mode === "open" ) { |
---|
43 | var url = 'response.html#!/'+store.getIdentity(this.surveyRun); |
---|
44 | this.runURLNode.innerHTML = '<a target="_black" href="'+url+'">'+url+'</a>'; |
---|
45 | } else { |
---|
46 | this.runURLNode.innerHTML = "No general URL. Add individual respondents below."; |
---|
47 | } |
---|
48 | }, |
---|
49 | _onSave: function(evt) { |
---|
50 | lang.mixin(this.surveyRun,this.propertiesForm.get('value')); |
---|
51 | var not = function(p){ return !p; }; |
---|
52 | func.modPropIf(this.surveyRun,"startDate",not.compose(lang.isString),store.formatDate); |
---|
53 | func.modPropIf(this.surveyRun,"endDate",not.compose(lang.isString),store.formatDate); |
---|
54 | store.put(this.surveyRun) |
---|
55 | .then(function() { |
---|
56 | Router.go('/surveys'); |
---|
57 | },function(err){ |
---|
58 | Content.notify(err); |
---|
59 | }); |
---|
60 | event.stop(evt); |
---|
61 | return false; |
---|
62 | }, |
---|
63 | _onDiscard: function(evt) { |
---|
64 | Router.go('/surveys'); |
---|
65 | } |
---|
66 | }); |
---|
67 | }); |
---|
68 | |
---|