1 | define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/Deferred','dojo/data/ObjectStore','rft/auth','rft/store','rft/content','rft/ui/_Page'], |
---|
2 | function(declare,lang,Deferred,ObjectStore,auth,store,content,_Page){ |
---|
3 | return declare('rft.pages.surveys',[_Page],{ |
---|
4 | selectedObject: null, |
---|
5 | postCreate: function() { |
---|
6 | this._store = store.getStore('Survey'); |
---|
7 | }, |
---|
8 | onVisit: function() { |
---|
9 | this.grid.setStore(ObjectStore({objectStore: this._store})); |
---|
10 | |
---|
11 | this.grid.on('rowclick',lang.hitch(this,function(evt){ |
---|
12 | this.selectedObject = evt.grid.getItem(evt.rowIndex); |
---|
13 | this.btnEdit.set('disabled',!this.selectedObject); |
---|
14 | })); |
---|
15 | |
---|
16 | this.grid.on('rowdblclick',lang.hitch(this,function(evt){ |
---|
17 | var obj = evt.grid.getItem(evt.rowIndex); |
---|
18 | content.goTo('/survey',{uid:obj.getUid()}); |
---|
19 | })); |
---|
20 | |
---|
21 | this.btnNew.on('click',lang.hitch(this,function(){ |
---|
22 | Deferred.when( this._store.add({'creator':auth.getUser()}) ) |
---|
23 | .then(function(obj) { |
---|
24 | content.goTo('/survey',{uid:obj.getUid()}); |
---|
25 | }); |
---|
26 | })); |
---|
27 | |
---|
28 | this.btnEdit.on('click',lang.hitch(this,function(){ |
---|
29 | if ( this.selectedObject ) { |
---|
30 | content.goTo('/survey',{uid:this.selectedObject.getUid()}); |
---|
31 | } |
---|
32 | |
---|
33 | })); |
---|
34 | } |
---|
35 | }); |
---|
36 | }); |
---|
37 | |
---|