[531] | 1 | define([ |
---|
| 2 | "../app/Page", |
---|
| 3 | "../app/Router", |
---|
| 4 | "../model/classes/surveyRuns", |
---|
| 5 | "../widgets/LineWithActionsWidget", |
---|
| 6 | "dojo/_base/array", |
---|
| 7 | "dojo/_base/declare", |
---|
| 8 | "dojo/_base/lang", |
---|
| 9 | "dojo/when", |
---|
| 10 | "dojo/text!./templates/surveyRuns.html" |
---|
| 11 | ], function(Page, Router, surveyRuns, LineWithActionsWidget, array, declare, lang, when, template) { |
---|
| 12 | return declare([Page],{ |
---|
| 13 | templateString: template, |
---|
| 14 | startup: function() { |
---|
| 15 | if ( this._started ) { return; } |
---|
| 16 | this.inherited(arguments); |
---|
| 17 | this.currentTab.set('title','Current (<span class="qedLoading"></span>)'); |
---|
| 18 | this.pastTab.set('title','Past (<span class="qedLoading"></span>)'); |
---|
| 19 | this.futureTab.set('title','Future (<span class="qedLoading"></span>)'); |
---|
| 20 | this.refresh(); |
---|
| 21 | }, |
---|
| 22 | _onRunDetails: function(surveyRun) { |
---|
| 23 | Router.go(surveyRuns.getObjectPath(surveyRun)); |
---|
| 24 | }, |
---|
| 25 | _onRunDelete: function(surveyRun) { |
---|
| 26 | if ( !confirm("Are you sure you want to delete this survey run?") ) { |
---|
| 27 | return; |
---|
| 28 | } |
---|
| 29 | surveyRuns.remove(surveyRun) |
---|
| 30 | .then(lang.hitch(this,function(){ |
---|
| 31 | this.notify("SurveyRun successfully deleted."); |
---|
| 32 | this.refreshRuns(); |
---|
| 33 | }),lang.hitch(this,function(err){ |
---|
| 34 | this.notify(err.error,'error'); |
---|
| 35 | })); |
---|
| 36 | }, |
---|
| 37 | refresh: function() { |
---|
| 38 | this.refreshGroup('current','Current'); |
---|
| 39 | this.refreshGroup('past','Past'); |
---|
| 40 | this.refreshGroup('future','Future'); |
---|
| 41 | }, |
---|
| 42 | refreshGroup: function(sub,subname) { |
---|
| 43 | var tab = this[sub+'Tab']; |
---|
| 44 | var container = this[sub+'Container']; |
---|
| 45 | container.set('content','Loading <span class="qedLoading"></span> survey runs.'); |
---|
| 46 | var qs = {}; |
---|
| 47 | qs[sub] = true; |
---|
| 48 | when(surveyRuns.query(qs), |
---|
| 49 | lang.hitch(this,function(surveyRuns){ |
---|
| 50 | container.set('content',''); |
---|
| 51 | tab.set('title',subname+' ('+surveyRuns.length+')'); |
---|
| 52 | array.forEach(surveyRuns,function(surveyRun){ |
---|
| 53 | var w = new LineWithActionsWidget({ |
---|
| 54 | title: surveyRun.title || "", |
---|
| 55 | actions:[{ |
---|
| 56 | callback: lang.hitch(this,'_onRunDetails', |
---|
| 57 | surveyRun), |
---|
| 58 | properties: { |
---|
| 59 | label: 'Details', |
---|
| 60 | tooltip: 'Show details for this run', |
---|
| 61 | icon: 'Edit' |
---|
| 62 | } |
---|
| 63 | },{ |
---|
| 64 | callback: lang.hitch(this,'_onRunDelete', |
---|
| 65 | surveyRun), |
---|
| 66 | properties: { |
---|
| 67 | label: 'Delete', |
---|
| 68 | tooltip: 'Delete this run', |
---|
| 69 | icon: 'Delete' |
---|
| 70 | } |
---|
| 71 | }] |
---|
| 72 | }); |
---|
| 73 | container.addChild(w); |
---|
| 74 | },this); |
---|
| 75 | })); |
---|
| 76 | } |
---|
| 77 | }); |
---|
| 78 | }); |
---|
| 79 | |
---|