source: Dev/trunk/src/client/qed-client/pages/surveys.js @ 463

Last change on this file since 463 was 443, checked in by hendrikvanantwerpen, 12 years ago

Reorganized for Node --- the SVN gods hate us all!

Lost all historical info on moved files, because SVN is a f *.

Also we have Node now, serving both the static content and forwarding
database requests.

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