source: Dev/branches/rest-dojo-ui/client/rft/pages/surveys.js @ 412

Last change on this file since 412 was 410, checked in by hendrikvanantwerpen, 13 years ago

Next steps to actually make taking surveys possible.

Split Controller in Router and Content. Updated the view.html to work
with the new app/Content mechanism. Include view page in build profile.

Rearranged Couch design documents per type. Changed config tool so the
docs.js can be more readable, functions don't have to be on one line
anymore but are serialized later. Because the .htaccess proxy is limited
to the rft database for security reasons, the config tool has to be run
on Node.js, to be able to access the Couch port (which is limited by
cross domain security in the browser).

Added elastic search to .htaccess proxy as well. Seperated CouchStore?
from rft/store, which contains application specific data.

Removed some old API files that were hanging around still.

Introduced preview mode for viewSurvey page. Changed survey page to
only show published questions to be included. The surveys page has
three categories: drafts, published and runs. Creating survey runs is
not yet implemented.

File size: 6.0 KB
Line 
1define([
2    'dojo/_base/array',
3    'dojo/_base/declare',
4    'dojo/_base/lang',
5    'dojo/when',
6    '../store',
7    '../app/Content',
8    '../app/Page',
9    '../app/Router',
10    '../ui/LineWithActionsWidget',
11    'dojo/text!./surveys.html'
12],function(array,declare,lang,when,store,Content,Page,Router,LineWithActionsWidget,template){
13    return declare([Page],{
14        templateString: template,
15        startup: function() {
16            if ( this._started ) { return; }
17            this.inherited(arguments);
18            this.refresh();
19        },
20        _onNewSurvey: function(){
21            when( store.add({type:'Survey'}) )
22            .then(function(survey) {
23                Router.go('/survey/'+store.getIdentity(survey));
24            });
25        },
26        _onPublishSurvey:function(survey){
27            var self = this;
28            survey.publicationDate = store.timestamp();
29            store.put(survey).then(function(){
30                self.refreshDrafts();
31                self.refreshPublished();
32            },function(err){
33                Content.notify(err.reason,'error');
34            });
35        },
36        _onDeleteSurvey:function(survey){
37            var self = this;
38            store.remove(store.getIdentity(survey),store.getRevision(survey))
39            .then(function(){
40                self.refreshDrafts();
41            },function(err){
42                Content.notify(err.reason,'error');
43            });
44        },
45        _onEditSurvey:function(survey){
46            Router.go('/survey/'+store.getIdentity(survey));
47        },
48        _onPreviewSurvey:function(survey){
49            Router.go('/viewSurvey/'+store.getIdentity(survey),{preview:true});
50        },
51        _onRunSurvey:function(survey){
52
53        },
54        refresh: function() {
55            this.refreshDrafts();
56            this.refreshPublished();
57            this.refreshRuns();
58        },
59        refreshDrafts: function() {
60            this.draftsContainer.set('content','');
61            when(store.query("_design/surveys/_view/drafts")
62                    ,lang.hitch(this,function(surveys){
63                this.draftsTab.set('title','Drafts ('+surveys.length+')');
64                array.forEach(surveys,function(survey){
65                    var w = new LineWithActionsWidget({
66                        title: survey.title || '(unnamed)',
67                        actions: [{
68                            callback: lang.hitch(this,'_onPublishSurvey',survey),
69                            properties: {
70                                label: 'Publish',
71                                tooltip: 'Publish survey',
72                                icon: 'Publish'
73                            }
74                        },{
75                            callback: lang.hitch(this,'_onPreviewSurvey',survey),
76                            properties: {
77                                label: 'Preview',
78                                tooltip: 'Preview survey',
79                                icon: 'Preview'
80                            }
81                        },{
82                            callback: lang.hitch(this,'_onDeleteSurvey',survey),
83                            properties: {
84                                label: 'Delete',
85                                tooltip: 'Delete survey',
86                                icon: 'Delete'
87                            }
88                        },{
89                            callback: lang.hitch(this,'_onEditSurvey',survey),
90                            properties: {
91                                label: 'Edit',
92                                tooltip: 'Edit survey',
93                                icon: 'Edit'
94                            }
95                        }]
96                    });
97                    this.draftsContainer.addChild(w);
98                },this);
99            }));
100        },
101        refreshPublished: function() {
102            this.publishedContainer.set('content','');
103            when(store.query("_design/surveys/_view/published")
104                    ,lang.hitch(this,function(surveys){
105                this.publishedTab.set('title','Published ('+surveys.length+')');
106                array.forEach(surveys,function(survey){
107                    var w = new LineWithActionsWidget({
108                        title: survey.title,
109                        actions:[{
110                            callback: lang.hitch(this,'_onPreviewSurvey',survey),
111                            properties: {
112                                label: 'Preview',
113                                tooltip: 'Preview survey',
114                                icon: 'Preview'
115                            }
116                        },{
117                            callback: lang.hitch(this,'_onRunSurvey',survey),
118                            properties: {
119                                label: 'Run',
120                                tooltip: 'Run survey',
121                                icon: 'Run'
122                            }
123                        }]
124                    });
125                    this.publishedContainer.addChild(w);
126                },this);
127            }));
128        },
129        refreshRuns: function() {
130            this.runsContainer.set('content','');
131            when(store.query("_design/default/_view/by_type",{key:'SurveyRun'})
132                    ,lang.hitch(this,function(surveyRuns){
133                this.runsTab.set('title','Runs ('+surveyRuns.length+')');
134                array.forEach(surveyRuns,function(surveyRun){
135                    var w = new LineWithActionsWidget({
136                        title: survey.title,
137                        actions:[{
138                            callback: lang.hitch(this,'_onCloseRun',surveyRun),
139                            properties: {
140                                label: 'Close',
141                                tooltip: 'Close survey',
142                                icon: 'Close'
143                            }
144                        }]
145                    });
146                    this.runsContainer.addChild(w);
147                },this);
148            }));
149        }
150    });
151});
152
Note: See TracBrowser for help on using the repository browser.