1 | define([ |
---|
2 | 'dojo/_base/declare', |
---|
3 | 'dojo/_base/lang', |
---|
4 | 'dojo/_base/Deferred', |
---|
5 | 'dojo/data/ObjectStore', |
---|
6 | '../auth', |
---|
7 | '../store', |
---|
8 | '../app/Controller', |
---|
9 | '../app/Page', |
---|
10 | 'dojo/text!./surveys.html' |
---|
11 | ],function(declare,lang,Deferred,ObjectStore,auth,store,Controller,Page,template){ |
---|
12 | return declare([Page],{ |
---|
13 | templateString: template, |
---|
14 | selectedObject: null, |
---|
15 | startup: function() { |
---|
16 | if ( this._started ) { return; } |
---|
17 | this.inherited(arguments); |
---|
18 | this.grid.setStore( |
---|
19 | ObjectStore({objectStore: store}), |
---|
20 | "_design/default/_view/by_type",{key:'Survey'}); |
---|
21 | |
---|
22 | this.grid.on('rowclick',lang.hitch(this,function(evt){ |
---|
23 | this.selectedObject = evt.grid.getItem(evt.rowIndex); |
---|
24 | this.btnEdit.set('disabled',!this.selectedObject); |
---|
25 | })); |
---|
26 | |
---|
27 | this.grid.on('rowdblclick',lang.hitch(this,function(evt){ |
---|
28 | var obj = evt.grid.getItem(evt.rowIndex); |
---|
29 | Controller.go('/survey/'+store.getIdentity(obj)); |
---|
30 | })); |
---|
31 | |
---|
32 | this.btnNew.on('click',lang.hitch(this,function(){ |
---|
33 | Deferred.when( store.add({type:'Survey',creator:auth.getUser()}) ) |
---|
34 | .then(function(obj) { |
---|
35 | Controller.go('/survey/'+store.getIdentity(obj)); |
---|
36 | }); |
---|
37 | })); |
---|
38 | |
---|
39 | this.btnEdit.on('click',lang.hitch(this,function(){ |
---|
40 | if ( this.selectedObject ) { |
---|
41 | Controller.go('/survey/'+store.getIdentity(this.selectedObject)); |
---|
42 | } |
---|
43 | |
---|
44 | })); |
---|
45 | } |
---|
46 | }); |
---|
47 | }); |
---|
48 | |
---|