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

Last change on this file since 529 was 529, checked in by hendrikvanantwerpen, 11 years ago
  • Added grey icons for better highlighting, synced block and large buttons.
  • Introduced extra color for text, now disabled/inactive/hovered -> it's not very clear though.
  • Added confirmation on irrevertable actions.
  • Added support for query string in our new request implementation.
File size: 7.6 KB
Line 
1define([
2    "../app/Page",
3    "../app/Router",
4    "../model/classes/surveyRuns",
5    "../model/classes/surveys",
6    "../widgets/LineWithActionsWidget",
7    "dojo/_base/array",
8    "dojo/_base/declare",
9    "dojo/_base/lang",
10    "dojo/when",
11    "dojo/text!./templates/surveys.html"
12], function(Page, Router, surveyRuns, surveys, LineWithActionsWidget, array, declare, lang, when, template) {
13    return declare([Page],{
14        templateString: template,
15        startup: function() {
16            if ( this._started ) { return; }
17            this.inherited(arguments);
18            this.draftsTab.set('title','Drafts (<span class="qedLoading"></span>)');
19            this.publishedTab.set('title','Published (<span class="qedLoading"></span>)');
20            this.runsTab.set('title','Runs (<span class="qedLoading"></span>)');
21            this.refresh();
22        },
23        _onNewSurvey: function(){
24            Router.go(surveys.getObjectPath('new'));
25        },
26        _onPublishSurvey:function(survey){
27            if ( !confirm("After publication the survey cannot be modified anymore, are you sure?") ) {
28                return;
29            }
30            survey.publicationDate = new Date();
31            surveys.save(survey)
32            .then(lang.hitch(this,function(){
33                this.refreshDrafts();
34                this.refreshPublished();
35            }),lang.hitch(this,function(err){
36                this.notify(err.error,'error');
37            }));
38        },
39        _onDeleteSurvey:function(survey){
40            if ( !confirm("Are you sure you want to delete this draft survey?") ) {
41                return;
42            }
43            surveys.remove(survey)
44            .then(lang.hitch(this,function(){
45                this.refreshDrafts();
46            }),lang.hitch(this,function(err){
47                this.notify(err.error,'error');
48            }));
49        },
50        _onEditSurvey:function(survey){
51            Router.go(surveys.getObjectPath(survey));
52        },
53        _onPreviewSurvey:function(survey){
54            Router.go(surveys.getPreviewPath(survey));
55        },
56        _onRunSurvey:function(survey){
57            var surveyRun = surveyRuns.create();
58            surveyRun.title = 'Run of "' + survey.title + '" of '+(new Date().toString());
59            surveyRun.survey = survey;
60            surveyRuns.save(surveyRun)
61            .then(lang.hitch(this,function(surveyRun){
62                this._onRunDetails(surveyRun);
63            }),lang.hitch(this,function(err){
64                this.notify(err.error,'error');
65            }));
66        },
67        _onRunDetails: function(surveyRun) {
68            Router.go(surveyRuns.getObjectPath(surveyRun));
69        },
70        _onRunDelete: function(surveyRun) {
71            if ( !confirm("Are you sure you want to delete this survey run?") ) {
72                return;
73            }
74            surveyRuns.remove(surveyRun)
75            .then(lang.hitch(this,function(){
76                this.notify("SurveyRun successfully deleted.");
77                this.refreshRuns();
78            }),lang.hitch(this,function(err){
79                this.notify(err.error,'error');
80            }));
81        },
82        refresh: function() {
83            this.refreshDrafts();
84            this.refreshPublished();
85            this.refreshRuns();
86        },
87        refreshDrafts: function() {
88            this.draftsContainer.set('content','');
89            when(surveys.query({drafts:true}), lang.hitch(this,function(surveys) {
90                this.draftsTab.set('title','Drafts ('+surveys.length+')');
91                array.forEach(surveys,function(survey){
92                    var w = new LineWithActionsWidget({
93                        title: survey.title || '(unnamed)',
94                        actions: [{
95                            callback: lang.hitch(this,'_onPublishSurvey',survey),
96                            properties: {
97                                label: 'Publish',
98                                tooltip: 'Publish survey',
99                                icon: 'Publish'
100                            }
101                        },{
102                            callback: lang.hitch(this,'_onPreviewSurvey',survey),
103                            properties: {
104                                label: 'Preview',
105                                tooltip: 'Preview survey',
106                                icon: 'Preview'
107                            }
108                        },{
109                            callback: lang.hitch(this,'_onDeleteSurvey',survey),
110                            properties: {
111                                label: 'Delete',
112                                tooltip: 'Delete survey',
113                                icon: 'Delete'
114                            }
115                        },{
116                            callback: lang.hitch(this,'_onEditSurvey',survey),
117                            properties: {
118                                label: 'Edit',
119                                tooltip: 'Edit survey',
120                                icon: 'Edit'
121                            }
122                        }]
123                    });
124                    this.draftsContainer.addChild(w);
125                },this);
126            }));
127        },
128        refreshPublished: function() {
129            this.publishedContainer.set('content','');
130            when(surveys.query({published:true}), lang.hitch(this, function(surveys) {
131                this.publishedTab.set('title','Published ('+surveys.length+')');
132                array.forEach(surveys,function(survey){
133                    var w = new LineWithActionsWidget({
134                        title: survey.title || "",
135                        actions:[{
136                            callback: lang.hitch(this,'_onPreviewSurvey',survey),
137                            properties: {
138                                label: 'Preview',
139                                tooltip: 'Preview survey',
140                                icon: 'Preview'
141                            }
142                        },{
143                            callback: lang.hitch(this,'_onRunSurvey',survey),
144                            properties: {
145                                label: 'Run',
146                                tooltip: 'Run survey',
147                                icon: 'Forward'
148                            }
149                        }]
150                    });
151                    this.publishedContainer.addChild(w);
152                },this);
153            }));
154        },
155        refreshRuns: function() {
156            this.runsContainer.set('content','');
157            when(surveyRuns.query(), lang.hitch(this,function(surveyRuns){
158                this.runsTab.set('title','Runs ('+surveyRuns.length+')');
159                array.forEach(surveyRuns,function(surveyRun){
160                    var w = new LineWithActionsWidget({
161                        title: surveyRun.title || "",
162                        actions:[{
163                            callback: lang.hitch(this,'_onRunDetails',surveyRun),
164                            properties: {
165                                label: 'Details',
166                                tooltip: 'Show details for this run',
167                                icon: 'Edit'
168                            }
169                        },{
170                            callback: lang.hitch(this,'_onRunDelete',surveyRun),
171                            properties: {
172                                label: 'Delete',
173                                tooltip: 'Delete this run',
174                                icon: 'Delete'
175                            }
176                        }]
177                    });
178                    this.runsContainer.addChild(w);
179                },this);
180            }));
181        }
182    });
183});
184
Note: See TracBrowser for help on using the repository browser.